Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Games
KReversi
Commits
a037c24b
Commit
a037c24b
authored
Jan 28, 2014
by
Inge Wallin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Remove an unneeded member in KReversiGame which will make future changes simpler."
This reverts commit
004c2918
.
parent
451a516c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
30 deletions
+32
-30
kreversigame.cpp
kreversigame.cpp
+22
-28
kreversigame.h
kreversigame.h
+10
-2
No files found.
kreversigame.cpp
View file @
a037c24b
...
...
@@ -57,8 +57,6 @@ KReversiGame::~KReversiGame()
void
KReversiGame
::
makePlayerMove
(
int
row
,
int
col
,
bool
demoMode
)
{
PosList
changedChips
;
m_curPlayer
=
m_playerColor
;
KReversiPos
move
;
...
...
@@ -73,8 +71,8 @@ void KReversiGame::makePlayerMove(int row, int col, bool demoMode)
if
(
!
isMovePossible
(
move
))
{
return
;
}
makeMove
(
move
,
changedChips
);
m_undoStack
.
push
(
changedChips
);
makeMove
(
move
);
m_undoStack
.
push
(
m_
changedChips
);
}
void
KReversiGame
::
startNextTurn
(
bool
demoMode
)
...
...
@@ -114,7 +112,6 @@ void KReversiGame::startNextTurn(bool demoMode)
void
KReversiGame
::
makeComputerMove
()
{
PosList
changedChips
;
m_curPlayer
=
m_computerColor
;
// FIXME dimsuz: m_competitive. Read from config.
// (also there's computeMove in getHint)
...
...
@@ -127,8 +124,8 @@ void KReversiGame::makeComputerMove()
return
;
}
makeMove
(
move
,
changedChips
);
m_undoStack
.
push
(
changedChips
);
makeMove
(
move
);
m_undoStack
.
push
(
m_
changedChips
);
}
int
KReversiGame
::
undo
()
...
...
@@ -173,25 +170,30 @@ int KReversiGame::undo()
//kDebug() << "Undone" << movesUndone << "moves.";
//kDebug() << "Current player changed to" << (m_curPlayer == White ? "White" : "Black");
if
(
!
m_undoStack
.
empty
())
m_changedChips
=
m_undoStack
.
top
();
else
m_changedChips
.
clear
();
emit
boardChanged
();
return
movesUndone
;
}
void
KReversiGame
::
makeMove
(
const
KReversiPos
&
move
,
PosList
&
changedChips
)
void
KReversiGame
::
makeMove
(
const
KReversiPos
&
move
)
{
changedChips
.
clear
();
m_
changedChips
.
clear
();
setChipColor
(
move
.
color
,
move
.
row
,
move
.
col
);
// the first one is the move itself
changedChips
.
append
(
move
);
m_
changedChips
.
append
(
move
);
// now turn color of all chips that were won
if
(
hasChunk
(
Up
,
move
))
{
for
(
int
r
=
move
.
row
-
1
;
r
>=
0
;
--
r
)
{
if
(
m_cells
[
r
][
move
.
col
]
==
move
.
color
)
break
;
setChipColor
(
move
.
color
,
r
,
move
.
col
);
changedChips
.
append
(
KReversiPos
(
move
.
color
,
r
,
move
.
col
));
m_
changedChips
.
append
(
KReversiPos
(
move
.
color
,
r
,
move
.
col
));
}
}
if
(
hasChunk
(
Down
,
move
))
{
...
...
@@ -199,7 +201,7 @@ void KReversiGame::makeMove(const KReversiPos& move, PosList &changedChips)
if
(
m_cells
[
r
][
move
.
col
]
==
move
.
color
)
break
;
setChipColor
(
move
.
color
,
r
,
move
.
col
);
changedChips
.
append
(
KReversiPos
(
move
.
color
,
r
,
move
.
col
));
m_
changedChips
.
append
(
KReversiPos
(
move
.
color
,
r
,
move
.
col
));
}
}
if
(
hasChunk
(
Left
,
move
))
{
...
...
@@ -207,7 +209,7 @@ void KReversiGame::makeMove(const KReversiPos& move, PosList &changedChips)
if
(
m_cells
[
move
.
row
][
c
]
==
move
.
color
)
break
;
setChipColor
(
move
.
color
,
move
.
row
,
c
);
changedChips
.
append
(
KReversiPos
(
move
.
color
,
move
.
row
,
c
));
m_
changedChips
.
append
(
KReversiPos
(
move
.
color
,
move
.
row
,
c
));
}
}
if
(
hasChunk
(
Right
,
move
))
{
...
...
@@ -215,7 +217,7 @@ void KReversiGame::makeMove(const KReversiPos& move, PosList &changedChips)
if
(
m_cells
[
move
.
row
][
c
]
==
move
.
color
)
break
;
setChipColor
(
move
.
color
,
move
.
row
,
c
);
changedChips
.
append
(
KReversiPos
(
move
.
color
,
move
.
row
,
c
));
m_
changedChips
.
append
(
KReversiPos
(
move
.
color
,
move
.
row
,
c
));
}
}
if
(
hasChunk
(
UpLeft
,
move
))
{
...
...
@@ -223,7 +225,7 @@ void KReversiGame::makeMove(const KReversiPos& move, PosList &changedChips)
if
(
m_cells
[
r
][
c
]
==
move
.
color
)
break
;
setChipColor
(
move
.
color
,
r
,
c
);
changedChips
.
append
(
KReversiPos
(
move
.
color
,
r
,
c
));
m_
changedChips
.
append
(
KReversiPos
(
move
.
color
,
r
,
c
));
}
}
if
(
hasChunk
(
UpRight
,
move
))
{
...
...
@@ -231,7 +233,7 @@ void KReversiGame::makeMove(const KReversiPos& move, PosList &changedChips)
if
(
m_cells
[
r
][
c
]
==
move
.
color
)
break
;
setChipColor
(
move
.
color
,
r
,
c
);
changedChips
.
append
(
KReversiPos
(
move
.
color
,
r
,
c
));
m_
changedChips
.
append
(
KReversiPos
(
move
.
color
,
r
,
c
));
}
}
if
(
hasChunk
(
DownLeft
,
move
))
{
...
...
@@ -239,7 +241,7 @@ void KReversiGame::makeMove(const KReversiPos& move, PosList &changedChips)
if
(
m_cells
[
r
][
c
]
==
move
.
color
)
break
;
setChipColor
(
move
.
color
,
r
,
c
);
changedChips
.
append
(
KReversiPos
(
move
.
color
,
r
,
c
));
m_
changedChips
.
append
(
KReversiPos
(
move
.
color
,
r
,
c
));
}
}
if
(
hasChunk
(
DownRight
,
move
))
{
...
...
@@ -247,7 +249,7 @@ void KReversiGame::makeMove(const KReversiPos& move, PosList &changedChips)
if
(
m_cells
[
r
][
c
]
==
move
.
color
)
break
;
setChipColor
(
move
.
color
,
r
,
c
);
changedChips
.
append
(
KReversiPos
(
move
.
color
,
r
,
c
));
m_
changedChips
.
append
(
KReversiPos
(
move
.
color
,
r
,
c
));
}
}
...
...
@@ -256,14 +258,6 @@ void KReversiGame::makeMove(const KReversiPos& move, PosList &changedChips)
emit
moveFinished
();
}
PosList
KReversiGame
::
changedChips
()
const
{
if
(
!
m_undoStack
.
empty
())
return
m_undoStack
.
top
();
else
return
PosList
();
}
bool
KReversiGame
::
isMovePossible
(
const
KReversiPos
&
move
)
const
{
// first - the trivial case:
...
...
@@ -496,11 +490,11 @@ KReversiPos KReversiGame::getHint() const
KReversiPos
KReversiGame
::
getLastMove
()
const
{
// we'll take this move from changed list
if
(
m_
undoStack
.
isEmpty
())
if
(
m_
changedChips
.
isEmpty
())
return
KReversiPos
(
NoColor
,
-
1
,
-
1
);
// invalid one
// first item in this list is the actual move, rest is turned chips
return
m_
undoStack
.
top
()
.
first
();
return
m_
changedChips
.
first
();
}
PosList
KReversiGame
::
possibleMoves
()
const
...
...
kreversigame.h
View file @
a037c24b
...
...
@@ -145,7 +145,7 @@ public:
* First of them will be the move itself, and the rest - chips which
* were turned by that move
*/
PosList
changedChips
()
const
;
PosList
changedChips
()
const
{
return
m_changedChips
;
}
/**
* @return a list of possible moves for current player
*/
...
...
@@ -179,7 +179,7 @@ private:
* Performs move, i.e. marks all the chips that player wins with
* this move with current player color
*/
void
makeMove
(
const
KReversiPos
&
move
,
PosList
&
changedChips
);
void
makeMove
(
const
KReversiPos
&
move
);
/**
* Sets the type of chip at (row,col)
*/
...
...
@@ -210,6 +210,14 @@ private:
*/
Engine
*
m_engine
;
/**
* This list holds chips that were changed/added during last move
* First of them will be the chip added to the board by the player
* during last move. The rest of them - chips that were turned by that
* move.
*/
PosList
m_changedChips
;
/**
* This is an undo stack.
* It contains a lists of chips changed with each turn.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment