[Kde-games-devel] Kreversi: small cleanup patch
Inge Wallin
inge at lysator.liu.se
Sun May 30 15:03:11 CEST 2004
Hi,
I am trying to work on the bug 58039: "two human players game option".
For this I am developing a more general Player concept, that can be both a
computer player or a human player.
However, there was already a class Player in kreversi, except that the
concept it encoded was not a player at all but a color. So here is a small
cleanup patch that changes the name of the class Player into Color, and
also fixes all its usages.
I am doing this because I want to learn GUI programming for KDE and Qt.
I am pretty experienced in the area of developing game AIs for board
games, but I am totally new to Qt and KDE.
I think that I could use some advice at this point. What is the best way
to create a "New Game" dialog? Is it to use a KBaseDialog and then
enter a NewGameWidget that I created with Qt Designer? I tried to read
the tutorials in KDevelop and Qt Designer, but couldn't find much about
simple dialogs. Then I looked in the source code for the other games in
kdegames, and found an example like that in KGoldruner.
-Inge
Inge Wallin | Thus spake the master programmer: |
| "After three days without programming, |
inge at lysator.liu.se | life becomes meaningless." |
| Geoffrey James: The Tao of Programming. |
-------------- next part --------------
diff -ur kreversi.orig/Engine.cpp kreversi/Engine.cpp
--- kreversi.orig/Engine.cpp 2004-05-29 22:01:04.000000000 -0400
+++ kreversi/Engine.cpp 2004-05-30 12:23:48.000000000 -0400
@@ -234,9 +234,9 @@
Move Engine::computeMove(Game g) {
m_exhaustive = false;
- Player player = g.whoseTurn();
+ Color color = g.whoseTurn();
- if (player == Nobody)
+ if (color == Nobody)
return Move(-1, -1, Nobody);
// Figure out the current score
@@ -278,13 +278,13 @@
for (uint x=1; x<9; x++)
for (uint y=1; y<9; y++)
- m_board[x][y] = g.player(x, y);
+ m_board[x][y] = g.color(x, y);
m_bc_score.set(White, CalcBcScore(White));
m_bc_score.set(Black, CalcBcScore(Black));
- ULONG64 playerbits = ComputeOccupiedBits(player);
- ULONG64 opponentbits = ComputeOccupiedBits(opponent(player));
+ ULONG64 colorbits = ComputeOccupiedBits(color);
+ ULONG64 opponentbits = ComputeOccupiedBits(opponent(color));
int maxval = -LARGEINT;
int max_x = 0;
@@ -310,8 +310,8 @@
(m_neighbor_bits[x][y] & opponentbits) != null_bits)
{
- int val = ComputeMove2(x, y, player, 1, maxval,
- playerbits, opponentbits);
+ int val = ComputeMove2(x, y, color, 1, maxval,
+ colorbits, opponentbits);
if (val != ILLEGAL_VALUE)
{
@@ -354,7 +354,7 @@
if (interrupt()) {
return Move(-1, -1, Nobody);
} else if (maxval != -LARGEINT) {
- return Move(max_x, max_y, player);
+ return Move(max_x, max_y, color);
} else {
return Move(-1, -1, Nobody);
}
@@ -363,41 +363,41 @@
Move Engine::ComputeFirstMove(Game g) {
int r;
- Player player = g.whoseTurn();
+ Color color = g.whoseTurn();
r = m_random.getLong(4) + 1;
- if (player == White)
+ if (color == White)
{
- if (r == 1) return Move(3, 5, player);
- else if (r == 2) return Move(4, 6, player);
- else if (r == 3) return Move(5, 3, player);
- else return Move(6, 4, player);
+ if (r == 1) return Move(3, 5, color);
+ else if (r == 2) return Move(4, 6, color);
+ else if (r == 3) return Move(5, 3, color);
+ else return Move(6, 4, color);
}
else
{
- if (r == 1) return Move(3, 4, player);
- else if (r == 2) return Move(5, 6, player);
- else if (r == 3) return Move(4, 3, player);
- else return Move(6, 5, player);
+ if (r == 1) return Move(3, 4, color);
+ else if (r == 2) return Move(5, 6, color);
+ else if (r == 3) return Move(4, 3, color);
+ else return Move(6, 5, color);
}
}
-int Engine::ComputeMove2(int xplay, int yplay, Player player, int level,
- int cutoffval, ULONG64 playerbits,
+int Engine::ComputeMove2(int xplay, int yplay, Color color, int level,
+ int cutoffval, ULONG64 colorbits,
ULONG64 opponentbits)
{
int number_of_turned = 0;
SquareStackEntry mse;
- Player opponent = ::opponent(player);
+ Color opponent = ::opponent(color);
m_nodes_searched++;
- m_board[xplay][yplay] = player;
- playerbits |= m_coord_bit[xplay][yplay];
- m_score.inc(player);
- m_bc_score.add(player, m_bc_board[xplay][yplay]);
+ m_board[xplay][yplay] = color;
+ colorbits |= m_coord_bit[xplay][yplay];
+ m_score.inc(color);
+ m_bc_score.add(color, m_bc_board[xplay][yplay]);
///////////////////
// Turn all pieces:
@@ -413,15 +413,15 @@
x += xinc, y += yinc)
;
- if (m_board[x][y] == player)
+ if (m_board[x][y] == color)
for (x -= xinc, y -= yinc; x != xplay || y != yplay;
x -= xinc, y -= yinc)
{
- m_board[x][y] = player;
- playerbits |= m_coord_bit[x][y];
+ m_board[x][y] = color;
+ colorbits |= m_coord_bit[x][y];
opponentbits &= ~m_coord_bit[x][y];
m_squarestack.Push(x, y);
- m_bc_score.add(player, m_bc_board[x][y]);
+ m_bc_score.add(color, m_bc_board[x][y]);
m_bc_score.sub(opponent, m_bc_board[x][y]);
number_of_turned++;
}
@@ -435,22 +435,22 @@
// Legal move:
//////////////
- m_score.add(player, number_of_turned);
+ m_score.add(color, number_of_turned);
m_score.sub(opponent, number_of_turned);
- if (level >= m_depth) retval = EvaluatePosition(player); // Terminal node
+ if (level >= m_depth) retval = EvaluatePosition(color); // Terminal node
else
{
int maxval = TryAllMoves(opponent, level, cutoffval, opponentbits,
- playerbits);
+ colorbits);
if (maxval != -LARGEINT) retval = -maxval;
else
{
///////////////////////////////////////////////////////////////
- // No possible move for the opponent, it is players turn again:
+ // No possible move for the opponent, it is colors turn again:
///////////////////////////////////////////////////////////////
- retval= TryAllMoves(player, level, -LARGEINT, playerbits,
+ retval= TryAllMoves(color, level, -LARGEINT, colorbits,
opponentbits);
if (retval == -LARGEINT)
@@ -460,7 +460,7 @@
///////////////////////////////////////////////
int finalscore =
- m_score.score(player) - m_score.score(opponent);
+ m_score.score(color) - m_score.score(opponent);
if (m_exhaustive) retval = finalscore;
else
@@ -476,7 +476,7 @@
}
m_score.add(opponent, number_of_turned);
- m_score.sub(player, number_of_turned);
+ m_score.sub(color, number_of_turned);
}
/////////////////
@@ -487,21 +487,21 @@
{
mse = m_squarestack.Pop();
m_bc_score.add(opponent, m_bc_board[mse.m_x][mse.m_y]);
- m_bc_score.sub(player, m_bc_board[mse.m_x][mse.m_y]);
+ m_bc_score.sub(color, m_bc_board[mse.m_x][mse.m_y]);
m_board[mse.m_x][mse.m_y] = opponent;
}
m_board[xplay][yplay] = Nobody;
- m_score.sub(player, 1);
- m_bc_score.sub(player, m_bc_board[xplay][yplay]);
+ m_score.sub(color, 1);
+ m_bc_score.sub(color, m_bc_board[xplay][yplay]);
if (number_of_turned < 1 || interrupt()) return ILLEGAL_VALUE;
else return retval;
}
-int Engine::TryAllMoves(Player opponent, int level, int cutoffval,
- ULONG64 opponentbits, ULONG64 playerbits)
+int Engine::TryAllMoves(Color opponent, int level, int cutoffval,
+ ULONG64 opponentbits, ULONG64 colorbits)
{
int maxval = -LARGEINT;
@@ -515,10 +515,10 @@
{
for (int y=1; y<9; y++)
if (m_board[x][y] == Nobody &&
- (m_neighbor_bits[x][y] & playerbits) != null_bits)
+ (m_neighbor_bits[x][y] & colorbits) != null_bits)
{
int val = ComputeMove2(x, y, opponent, level+1, maxval, opponentbits,
- playerbits);
+ colorbits);
if (val != ILLEGAL_VALUE && val > maxval)
{
@@ -535,21 +535,21 @@
}
-int Engine::EvaluatePosition(Player player)
+int Engine::EvaluatePosition(Color color)
{
int retval;
- Player opponent = ::opponent(player);
- int score_player = m_score.score(player);
+ Color opponent = ::opponent(color);
+ int score_color = m_score.score(color);
int score_opponent = m_score.score(opponent);
- if (m_exhaustive) retval = score_player - score_opponent;
+ if (m_exhaustive) retval = score_color - score_opponent;
else
{
retval = (100-m_coeff) *
- (m_score.score(player) - m_score.score(opponent)) +
+ (m_score.score(color) - m_score.score(opponent)) +
m_coeff * BC_WEIGHT *
- (m_bc_score.score(player)-m_bc_score.score(opponent));
+ (m_bc_score.score(color)-m_bc_score.score(opponent));
}
return retval;
@@ -615,26 +615,26 @@
}
-int Engine::CalcBcScore(Player player)
+int Engine::CalcBcScore(Color color)
{
int sum = 0;
for (int i=1; i < 9; i++)
for (int j=1; j < 9; j++)
- if (m_board[i][j] == player)
+ if (m_board[i][j] == color)
sum += m_bc_board[i][j];
return sum;
}
-ULONG64 Engine::ComputeOccupiedBits(Player player)
+ULONG64 Engine::ComputeOccupiedBits(Color color)
{
ULONG64 retval = 0;
for (int i=1; i < 9; i++)
for (int j=1; j < 9; j++)
- if (m_board[i][j] == player) retval |= m_coord_bit[i][j];
+ if (m_board[i][j] == color) retval |= m_coord_bit[i][j];
return retval;
}
diff -ur kreversi.orig/Engine.h kreversi/Engine.h
--- kreversi.orig/Engine.h 2004-05-29 22:01:04.000000000 -0400
+++ kreversi/Engine.h 2004-05-30 12:22:39.000000000 -0400
@@ -189,17 +189,17 @@
Move computeMove(Game g);
Move ComputeFirstMove(Game g);
- int ComputeMove2(int xplay, int yplay, Player player, int level,
- int cutoffval, ULONG64 playerbits, ULONG64 opponentbits);
+ int ComputeMove2(int xplay, int yplay, Color color, int level,
+ int cutoffval, ULONG64 colorbits, ULONG64 opponentbits);
- int TryAllMoves(Player opponent, int level, int cutoffval,
- ULONG64 opponentbits, ULONG64 playerbits);
+ int TryAllMoves(Color opponent, int level, int cutoffval,
+ ULONG64 opponentbits, ULONG64 colorbits);
- int EvaluatePosition(Player player);
+ int EvaluatePosition(Color color);
void SetupBcBoard();
void SetupBits();
- int CalcBcScore(Player player);
- ULONG64 ComputeOccupiedBits(Player player);
+ int CalcBcScore(Color color);
+ ULONG64 ComputeOccupiedBits(Color color);
void yield();
@@ -207,7 +207,7 @@
static const int LARGEINT;
static const int ILLEGAL_VALUE;
static const int BC_WEIGHT;
- Player m_board[10][10];
+ Color m_board[10][10];
int m_bc_board[9][9];
Score m_score;
Score m_bc_score;
diff -ur kreversi.orig/Game.cpp kreversi/Game.cpp
--- kreversi.orig/Game.cpp 2004-05-29 22:01:05.000000000 -0400
+++ kreversi/Game.cpp 2004-05-30 12:23:51.000000000 -0400
@@ -114,8 +114,8 @@
bool Game::MakeMove(Move m)
{
- if (m.player() == Nobody) return false;
- if (whoseTurn() != m.player()) return false;
+ if (m.color() == Nobody) return false;
+ if (whoseTurn() != m.color()) return false;
if (! m_positions[m_movenumber].moveIsLegal(m)) return false;
m_positions[m_movenumber+1].constrCopy(m_positions[m_movenumber], m);
@@ -135,15 +135,15 @@
}
-Player Game::player(uint x, uint y) const
+Color Game::color(uint x, uint y) const
{
- return m_positions[m_movenumber].player(x, y);
+ return m_positions[m_movenumber].color(x, y);
}
-uint Game::score(Player player) const
+uint Game::score(Color color) const
{
- return m_positions[m_movenumber].score(player);
+ return m_positions[m_movenumber].score(color);
}
@@ -156,9 +156,9 @@
}
-bool Game::moveIsPossible(Player player) const
+bool Game::moveIsPossible(Color color) const
{
- return m_positions[m_movenumber].moveIsPossible(player);
+ return m_positions[m_movenumber].moveIsPossible(color);
}
@@ -168,15 +168,15 @@
}
-Player Game::whoseTurn() const
+Color Game::whoseTurn() const
{
if (m_movenumber == 0) return Black;
- Player player = lastMove().player();
- Player opponent = ::opponent(player);
+ Color color = lastMove().color();
+ Color opponent = ::opponent(color);
if (moveIsPossible(opponent)) return opponent;
- if (moveIsPossible(player)) return player;
+ if (moveIsPossible(color)) return color;
return Nobody;
}
@@ -184,15 +184,15 @@
if(moveNumber() == 0)
return true;
else
- return (m_positions[m_movenumber].player(x, y) != m_positions[m_movenumber-1].player(x, y));
+ return (m_positions[m_movenumber].color(x, y) != m_positions[m_movenumber-1].color(x, y));
}
bool Game::wasTurned(uint x, uint y) const {
if(moveNumber() == 0)
return false;
else {
- Player c1 = m_positions[m_movenumber-1].player(x, y);
- Player c2 = m_positions[m_movenumber].player(x, y);
+ Color c1 = m_positions[m_movenumber-1].color(x, y);
+ Color c2 = m_positions[m_movenumber].color(x, y);
if(c1 == Nobody)
return false;
diff -ur kreversi.orig/Game.h kreversi/Game.h
--- kreversi.orig/Game.h 2004-05-29 22:01:05.000000000 -0400
+++ kreversi/Game.h 2004-05-30 12:21:44.000000000 -0400
@@ -112,14 +112,14 @@
bool MakeMove(Move m);
bool TakeBackMove();
- Player player(uint x, uint y) const;
- uint score(Player player) const;
+ Color color(uint x, uint y) const;
+ uint score(Color color) const;
Move lastMove() const;
bool moveIsLegal(Move m) const;
- bool moveIsPossible(Player player) const;
+ bool moveIsPossible(Color color) const;
bool moveIsAtAllPossible() const;
uint moveNumber() const { return m_movenumber; }
- Player whoseTurn() const;
+ Color whoseTurn() const;
bool squareModified(uint x, uint y) const;
bool wasTurned(uint x, uint y) const;
diff -ur kreversi.orig/Move.cpp kreversi/Move.cpp
--- kreversi.orig/Move.cpp 2004-05-29 22:01:05.000000000 -0400
+++ kreversi/Move.cpp 2004-05-30 12:19:28.000000000 -0400
@@ -46,8 +46,8 @@
#include "Move.h"
-Move::Move(int x, int y, Player player) {
+Move::Move(int x, int y, Color color) {
m_x = x;
m_y = y;
- m_player = player;
+ m_color = color;
}
diff -ur kreversi.orig/Move.h kreversi/Move.h
--- kreversi.orig/Move.h 2004-05-29 22:01:05.000000000 -0400
+++ kreversi/Move.h 2004-05-30 12:20:22.000000000 -0400
@@ -55,16 +55,16 @@
class Move
{
public:
- Move() { m_x = -1; m_y = -1; m_player = Nobody; }
- Move(int x, int y, Player player);
+ Move() { m_x = -1; m_y = -1; m_color = Nobody; }
+ Move(int x, int y, Color color);
int x() const { return m_x; }
int y() const { return m_y; }
- Player player() const { return m_player; }
+ Color color() const { return m_color; }
private:
int m_x, m_y;
- Player m_player;
+ Color m_color;
};
#endif
diff -ur kreversi.orig/Position.cpp kreversi/Position.cpp
--- kreversi.orig/Position.cpp 2004-05-29 22:01:05.000000000 -0400
+++ kreversi/Position.cpp 2004-05-30 12:21:45.000000000 -0400
@@ -100,11 +100,11 @@
m_score = p.m_score;
- Player player = m.player();
- Player opponent = ::opponent(player);
+ Color color = m.color();
+ Color opponent = ::opponent(color);
- m_board[m.x()][m.y()] = player;
- m_score.inc(player);
+ m_board[m.x()][m.y()] = color;
+ m_score.inc(color);
for (int xinc=-1; xinc<=1; xinc++)
for (int yinc=-1; yinc<=1; yinc++)
@@ -116,12 +116,12 @@
x += xinc, y += yinc)
;
- if (m_board[x][y] == player)
+ if (m_board[x][y] == color)
for (x -= xinc, y -= yinc; x != m.x() || y != m.y();
x -= xinc, y -= yinc)
{
- m_board[x][y] = player;
- m_score.inc(player);
+ m_board[x][y] = color;
+ m_score.inc(color);
m_score.dec(opponent);
}
}
@@ -141,18 +141,18 @@
}
-Player Position::player(uint x, uint y) const {
+Color Position::color(uint x, uint y) const {
return m_board[x][y];
}
-uint Position::score(Player player) const { return m_score.score(player); }
+uint Position::score(Color color) const { return m_score.score(color); }
bool Position::moveIsLegal(Move m) const
{
if (m_board[m.x()][m.y()] != Nobody) return false;
- Player player = m.player();
- Player opponent = ::opponent(player);
+ Color color = m.color();
+ Color opponent = ::opponent(color);
for (int xinc=-1; xinc<=1; xinc++)
for (int yinc=-1; yinc<=1; yinc++)
@@ -164,7 +164,7 @@
x += xinc, y += yinc)
;
- if (m_board[x][y] == player &&
+ if (m_board[x][y] == color &&
(x - xinc != m.x() || y - yinc != m.y()))
return true;
}
@@ -173,11 +173,11 @@
}
-bool Position::moveIsPossible(Player player) const
+bool Position::moveIsPossible(Color color) const
{
for (uint i=1; i<9; i++)
for (uint j=1; j<9; j++)
- if (moveIsLegal(Move(i, j, player))) return true;
+ if (moveIsLegal(Move(i, j, color))) return true;
return false;
}
diff -ur kreversi.orig/Position.h kreversi/Position.h
--- kreversi.orig/Position.h 2004-05-29 22:01:05.000000000 -0400
+++ kreversi/Position.h 2004-05-30 12:20:21.000000000 -0400
@@ -92,15 +92,15 @@
void constrInit();
void constrCopy(Position &p, Move &m);
- Player player(uint x, uint y) const;
- uint score(Player player) const;
+ Color color(uint x, uint y) const;
+ uint score(Color color) const;
Move lastMove() const { return m_last_move; }
bool moveIsLegal(Move m) const;
- bool moveIsPossible(Player player) const;
+ bool moveIsPossible(Color color) const;
bool moveIsAtAllPossible() const;
private:
- Player m_board[10][10];
+ Color m_board[10][10];
Move m_last_move;
Score m_score;
};
diff -ur kreversi.orig/Score.cpp kreversi/Score.cpp
--- kreversi.orig/Score.cpp 2004-05-29 22:01:05.000000000 -0400
+++ kreversi/Score.cpp 2004-05-30 12:19:29.000000000 -0400
@@ -52,9 +52,9 @@
m_score[Black] = 0;
}
-Player opponent(Player player)
+Color opponent(Color color)
{
- switch (player) {
+ switch (color) {
case White: return Black;
case Black: return White;
case Nobody: break;
diff -ur kreversi.orig/Score.h kreversi/Score.h
--- kreversi.orig/Score.h 2004-05-29 22:01:05.000000000 -0400
+++ kreversi/Score.h 2004-05-30 12:18:10.000000000 -0400
@@ -49,21 +49,21 @@
#include <qglobal.h>
-enum Player { White = 0, Black = 1, NbPlayers = 2, Nobody = NbPlayers };
-Player opponent(Player player);
+enum Color { White = 0, Black = 1, NbColors = 2, Nobody = NbColors };
+Color opponent(Color color);
class Score {
public:
Score();
- uint score(Player player) const { return m_score[player]; }
- void set(Player player, uint score) { m_score[player] = score; }
- void inc(Player player) { m_score[player]++; }
- void dec(Player player) { m_score[player]--; }
- void add(Player player, uint s) { m_score[player] += s; }
- void sub(Player player, uint s) { m_score[player] -= s; }
+ uint score(Color color) const { return m_score[color]; }
+ void set(Color color, uint score) { m_score[color] = score; }
+ void inc(Color color) { m_score[color]++; }
+ void dec(Color color) { m_score[color]--; }
+ void add(Color color, uint s) { m_score[color] += s; }
+ void sub(Color color, uint s) { m_score[color] -= s; }
private:
- uint m_score[NbPlayers];
+ uint m_score[NbColors+1];
};
#endif
Only in kreversi: Score.h.~1.6.~
Binary files kreversi.orig/Score.o and kreversi/Score.o differ
diff -ur kreversi.orig/board.cpp kreversi/board.cpp
--- kreversi.orig/board.cpp 2004-05-29 22:01:05.000000000 -0400
+++ kreversi/board.cpp 2004-05-30 12:30:06.000000000 -0400
@@ -62,7 +62,7 @@
const uint HINT_BLINKRATE = 250000;
const uint ANIMATION_DELAY = 3000;
-const uint CHIP_OFFSET[NbPlayers] = { 24, 1 };
+const uint CHIP_OFFSET[NbColors] = { 24, 1 };
const uint CHIP_SIZE = 36;
Board::Board(QWidget *parent)
@@ -115,9 +115,9 @@
/// takes back last set of moves
void Board::undo() {
if(state() == Ready) {
- Player last_player = game->lastMove().player();
+ Color last_color = game->lastMove().color();
while ((game->moveNumber() != 0) &&
- (last_player == game->lastMove().player()))
+ (last_color == game->lastMove().color()))
game->TakeBackMove();
game->TakeBackMove();
update();
@@ -131,7 +131,7 @@
}
bool Board::interrupted() const {
- return ((game->whoseTurn() == computerPlayer()) && (state() == Ready));
+ return ((game->whoseTurn() == computerColor()) && (state() == Ready));
}
@@ -185,10 +185,10 @@
/// handles piece settings
void Board::fieldClicked(int row, int col) {
if(state() == Ready) {
- Player player = game->whoseTurn();
+ Color color = game->whoseTurn();
/// makes a human move
- Move m(col + 1, row + 1, player);
+ Move m(col + 1, row + 1, color);
if(game->moveIsLegal(m)) {
// playSound("click.wav");
game->MakeMove(m);
@@ -203,7 +203,7 @@
updateBoard();
- if(player != game->whoseTurn())
+ if(color != game->whoseTurn())
computerMakeMove();
} else
emit illegalMove();
@@ -214,12 +214,12 @@
/// makes a computer move
void Board::computerMakeMove() {
// check if the computer can move
- Player player = game->whoseTurn();
- Player opponent = ::opponent(player);
+ Color color = game->whoseTurn();
+ Color opponent = ::opponent(color);
- emit turn(player);
+ emit turn(color);
- if(game->moveIsPossible(player)) {
+ if(game->moveIsPossible(color)) {
setState(Thinking);
do {
Move m;
@@ -298,11 +298,11 @@
return game->moveNumber();
}
-uint Board::score(Player player) const {
- return game->score(player);
+uint Board::score(Color color) const {
+ return game->score(color);
}
-Player Board::whoseTurn() const {
+Color Board::whoseTurn() const {
return game->whoseTurn();
}
@@ -312,7 +312,7 @@
Move m = engine->computeMove(*game);
setState(Hint);
if(m.x() != -1) {
- // the isVisible condition has been added so that when the player was viewing
+ // the isVisible condition has been added so that when the color was viewing
// a hint and quits the game window, the game doesn't still have to do all this looping
// and directly ends
for(int flash = 0; (flash < 100) && (state() != Ready) && isVisible(); flash++) {
@@ -327,7 +327,7 @@
qApp->processEvents();
}
}
- drawPiece(m.y() - 1, m.x() - 1, game->player(m.x(), m.y()));
+ drawPiece(m.y() - 1, m.x() - 1, game->color(m.x(), m.y()));
}
setState(Ready);
}
@@ -355,7 +355,7 @@
return;
// draw the new piece
- drawPiece(m.y()-1, m.x()-1, m.player());
+ drawPiece(m.y()-1, m.x()-1, m.color());
for(int dx = -1; dx < 2; dx++)
for(int dy = -1; dy < 2; dy++)
@@ -388,10 +388,10 @@
// check which direction the chip has to be rotated
// if the new chip is white, the chip was black first,
// so lets begin at index 1, otherwise it was white
- Player player = game->player(col+1, row+1);
- uint from = CHIP_OFFSET[opponent(player)];
- uint end = CHIP_OFFSET[player];
- int delta = (player==White ? 1 : -1);
+ Color color = game->color(col+1, row+1);
+ uint from = CHIP_OFFSET[opponent(color)];
+ uint end = CHIP_OFFSET[color];
+ int delta = (color==White ? 1 : -1);
from += delta;
end -= delta;
@@ -437,8 +437,8 @@
for(uint row = 0; row < 8; row++)
for(uint col = 0; col < 8; col++)
if ( force || game->squareModified(col+1, row+1) ) {
- Player player = game->player(col + 1, row + 1);
- drawPiece(row, col, player);
+ Color color = game->color(col + 1, row + 1);
+ drawPiece(row, col, color);
}
QPainter p(this);
p.setPen(black);
@@ -447,9 +447,9 @@
emit score();
}
-QPixmap Board::chipPixmap(Player player, uint size) const
+QPixmap Board::chipPixmap(Color color, uint size) const
{
- return chipPixmap(CHIP_OFFSET[player], size);
+ return chipPixmap(CHIP_OFFSET[color], size);
}
QPixmap Board::chipPixmap(uint i, uint size) const
@@ -478,8 +478,8 @@
p.drawPixmap(px, py, chipPixmap(i, _zoomed_size));
}
-void Board::drawPiece(uint row, uint col, Player player) {
- int i = (player==Nobody ? -1 : int(CHIP_OFFSET[player]));
+void Board::drawPiece(uint row, uint col, Color color) {
+ int i = (color==Nobody ? -1 : int(CHIP_OFFSET[color]));
drawOnePiece(row, col, i);
}
@@ -518,7 +518,7 @@
Move m = game->lastMove();
game->TakeBackMove();
QString s, idx;
- s.sprintf("%d %d %d", m.x(), m.y(), (int)m.player());
+ s.sprintf("%d %d %d", m.x(), m.y(), (int)m.color());
idx.sprintf("Move_%d", i);
config->writeEntry(idx, s);
}
@@ -546,15 +546,15 @@
QStringList s = config->readListEntry(idx, ' ');
uint x = (*s.at(0)).toUInt();
uint y = (*s.at(1)).toUInt();
- Player player = (Player)(*s.at(2)).toInt();
- Move m(x, y, player);
+ Color color = (Color)(*s.at(2)).toInt();
+ Move m(x, y, color);
game->MakeMove(m);
}
if(noupdate)
return true;
- human = (Player)config->readNumEntry("WhoseTurn");
+ human = (Color)config->readNumEntry("WhoseTurn");
updateBoard(TRUE);
setState(State(config->readNumEntry("State")));
Only in kreversi: board.cpp.~1.31.~
diff -ur kreversi.orig/board.h kreversi/board.h
--- kreversi.orig/board.h 2004-05-29 22:01:05.000000000 -0400
+++ kreversi/board.h 2004-05-30 12:29:27.000000000 -0400
@@ -59,10 +59,10 @@
~Board();
void newGame();
- Player whoseTurn() const;
- Player humanPlayer() const { return human; }
- Player computerPlayer() const { return opponent(human); }
- uint score(Player) const;
+ Color whoseTurn() const;
+ Color humanColor() const { return human; }
+ Color computerColor() const { return opponent(human); }
+ uint score(Color) const;
void setStrength(uint);
uint strength() const;
bool interrupted() const;
@@ -93,7 +93,7 @@
enum ChipType { Unloaded, Colored, Grayscale };
void loadChips(ChipType);
ChipType chipType() const { return chiptype; }
- QPixmap chipPixmap(Player player, uint size) const;
+ QPixmap chipPixmap(Color color, uint size) const;
QPixmap chipPixmap(uint i, uint size) const;
bool loadGame(KConfig *, bool noupdate = FALSE);
@@ -118,12 +118,12 @@
signals:
void score();
- void gameWon(Player);
+ void gameWon(Color);
void statusChange(Board::State);
void illegalMove();
void strengthChanged(int);
void sizeChange();
- void turn(Player);
+ void turn(Color);
private:
void fieldClicked(int, int);
@@ -132,7 +132,7 @@
void updateBoard(bool force = FALSE);
- void drawPiece(uint row, uint col, Player);
+ void drawPiece(uint row, uint col, Color);
void drawOnePiece(uint row, uint col, int i);
void adjustSize();
void animateChanged(Move m);
@@ -148,7 +148,7 @@
int oldsizehint;
uint _zoom;
uint _zoomed_size;
- Player human;
+ Color human;
bool nopaint;
QColor bgColor;
diff -ur kreversi.orig/kreversi.cpp kreversi/kreversi.cpp
--- kreversi.orig/kreversi.cpp 2004-05-30 11:13:03.000000000 -0400
+++ kreversi/kreversi.cpp 2004-05-30 12:30:05.000000000 -0400
@@ -218,24 +208,24 @@
}
void KReversi::slotScore() {
- _humanStatus->setScore(board->score(board->humanPlayer()));
- _computerStatus->setScore(board->score(board->computerPlayer()));
+ _humanStatus->setScore(board->score(board->humanColor()));
+ _computerStatus->setScore(board->score(board->computerColor()));
}
-void KReversi::slotGameEnded(Player player) {
+void KReversi::slotGameEnded(Color color) {
QString s;
statusBar()->message(i18n("End of game"));
// get the scores
- uint human = board->score(board->humanPlayer());
- uint computer = board->score(board->computerPlayer());
+ uint human = board->score(board->humanColor());
+ uint computer = board->score(board->computerColor());
- if(player == Nobody) {
+ if(color == Nobody) {
board->playSound(Board::DrawSound);
s = i18n("Game is drawn!\n\nYou : %1\nComputer: %2").arg(human).arg(computer);
KMessageBox::information(this, s, i18n("Game Ended"));
- } else if(board->humanPlayer() == player) {
+ } else if(board->humanColor() == color) {
// calculate score
int st = board->strength();
int sum = human + computer;
@@ -267,13 +257,13 @@
gameOver = true;
}
-void KReversi::slotTurn(Player player) {
+void KReversi::slotTurn(Color color) {
if (gameOver)
return;
- if(player == board->humanPlayer())
+ if(color == board->humanColor())
statusBar()->message(i18n("Your turn"));
- else if(player == board->computerPlayer())
+ else if(color == board->computerColor())
statusBar()->message(i18n("Computer's turn"));
else
statusBar()->clear();
@@ -324,8 +314,8 @@
void KReversi::updateColors()
{
- _humanStatus->setPixmap(board->chipPixmap(board->humanPlayer(), 20));
- _computerStatus->setPixmap(board->chipPixmap(board->computerPlayer(), 20));
+ _humanStatus->setPixmap(board->chipPixmap(board->humanColor(), 20));
+ _computerStatus->setPixmap(board->chipPixmap(board->computerColor(), 20));
}
void KReversi::loadSettings()
diff -ur kreversi.orig/kreversi.h kreversi/kreversi.h
--- kreversi.orig/kreversi.h 2004-05-30 09:53:39.000000000 -0400
+++ kreversi/kreversi.h 2004-05-30 12:29:31.000000000 -0400
@@ -82,8 +80,8 @@
private slots:
void slotScore();
- void slotGameEnded(Player);
- void slotTurn(Player);
+ void slotGameEnded(Color);
+ void slotTurn(Color);
void slotStatusChange(Board::State);
void slotIllegalMove();
void switchSides();
More information about the kde-games-devel
mailing list