[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-games-devel
Subject:    [Kde-games-devel] Patch for KReversi
From:       Nicolas Hadacek <nicolas.hadacek () comcast ! net>
Date:       2003-05-17 9:29:45
[Download RAW message or body]

Hi,

I've adapted the patch I have sent to the list two or threee months ago. It is 
somehow big but the fixes are more or less lost in a bigger API change (I can 
try to separate both thing if someone really want it...). So it includes:

- use a Player enum to replace the integer variable which leads to much 
clearer code IMHO
- fix the slight shift of the pieces when zooming out and in (you need the new 
attached png files).
- hopefully fix the sounds (if someone could check that, please).
- fix the window size when zooming out.

ok to commit ?

see you,
Nicolas

["kreversi.diff" (text/x-diff)]

? app.cpp_old
? app.h_old
? kreversiui.rc_old
Index: Engine.cpp
===================================================================
RCS file: /home/kde/kdegames/kreversi/Engine.cpp,v
retrieving revision 1.8
diff -u -2 -d -p -b -r1.8 Engine.cpp
--- Engine.cpp	11 Mar 2003 15:00:16 -0000	1.8
+++ Engine.cpp	18 May 2003 02:58:11 -0000
@@ -235,13 +235,13 @@ Move Engine::ComputeMove(Game g) {
   m_exhaustive = false;
 
-  int player = g.GetWhoseTurn();
+  Player player = g.GetWhoseTurn();
 
-  if (player == Score::NOBODY) 
-    return Move(-1,-1,-1);
+  if (player == Nobody)
+    return Move(-1, -1, Nobody);
 
   // Figure out the current score
-  m_score.InitScore(g.GetScore(Score::WHITE), g.GetScore(Score::BLACK));
+  m_score.InitScore(g.GetScore(White), g.GetScore(Black));
   // If the game just started...
-  if (m_score.GetScore(Score::WHITE) + m_score.GetScore(Score::BLACK) == 4)
+  if (m_score.GetScore(White) + m_score.GetScore(Black) == 4)
     return ComputeFirstMove(g);
 
@@ -251,21 +251,21 @@ Move Engine::ComputeMove(Game g) {
   m_depth = m_strength;
 
-  if (m_score.GetScore(Score::WHITE) + m_score.GetScore(Score::BLACK) +
+  if (m_score.GetScore(White) + m_score.GetScore(Black) +
       m_depth + 3 >= 64)
     m_depth =
-      64 - m_score.GetScore(Score::WHITE) - m_score.GetScore(Score::BLACK);
-  else if (m_score.GetScore(Score::WHITE) + m_score.GetScore(Score::BLACK) +
+      64 - m_score.GetScore(White) - m_score.GetScore(Black);
+  else if (m_score.GetScore(White) + m_score.GetScore(Black) +
 	   m_depth + 4 >= 64)
     m_depth += 2;
-  else if (m_score.GetScore(Score::WHITE) + m_score.GetScore(Score::BLACK) +
+  else if (m_score.GetScore(White) + m_score.GetScore(Black) +
 	   m_depth + 5 >= 64)
     m_depth++;
 
-  if (m_score.GetScore(Score::WHITE) + m_score.GetScore(Score::BLACK) +
+  if (m_score.GetScore(White) + m_score.GetScore(Black) +
       m_depth >= 64) m_exhaustive = true;
 
   m_coeff =
     100 - (100*
-	   (m_score.GetScore(Score::WHITE) + m_score.GetScore(Score::BLACK) +
+	   (m_score.GetScore(White) + m_score.GetScore(Black) +
 	    m_depth - 4))/60;
 
@@ -274,5 +274,5 @@ Move Engine::ComputeMove(Game g) {
   for (int x=0; x<10; x++)
     for (int y=0; y<10; y++)
-      m_board[x][y] = Score::NOBODY;
+      m_board[x][y] = Nobody;
 
   for (int x=1; x<9; x++)
@@ -280,8 +280,8 @@ Move Engine::ComputeMove(Game g) {
       m_board[x][y] = g.GetSquare(x, y);
 
-  m_bc_score.InitScore(CalcBcScore(Score::WHITE), CalcBcScore(Score::BLACK));
+  m_bc_score.InitScore(CalcBcScore(White), CalcBcScore(Black));
 
   ULONG64 playerbits = ComputeOccupiedBits(player);
-  ULONG64 opponentbits = ComputeOccupiedBits(Score::GetOpponent(player));
+  ULONG64 opponentbits = ComputeOccupiedBits(opponent(player));
 
   int maxval = -LARGEINT;
@@ -305,5 +305,5 @@ Move Engine::ComputeMove(Game g) {
   for (int x=1; x<9; x++)
     for (int y=1; y<9; y++)
-      if (m_board[x][y] == Score::NOBODY &&
+      if (m_board[x][y] == Nobody &&
 	  (m_neighbor_bits[x][y] & opponentbits) != null_bits)
 	{
@@ -351,9 +351,9 @@ Move Engine::ComputeMove(Game g) {
 
   if (GetInterrupt()) {       
-    return Move(-1, -1, -1);
+    return Move(-1, -1, Nobody);
   } else if (maxval != -LARGEINT) {
     return Move(max_x, max_y, player);
   } else {
-    return Move(-1, -1, -1);
+    return Move(-1, -1, Nobody);
   }
 }
@@ -362,9 +362,9 @@ Move Engine::ComputeMove(Game g) {
 Move Engine::ComputeFirstMove(Game g) {
   int r;
-  int player = g.GetWhoseTurn();
+  Player player = g.GetWhoseTurn();
 
   r = m_random.getLong(4) + 1;
 
-  if (player == Score::WHITE)
+  if (player == White)
     {
       if (r == 1) return Move(3, 5, player);
@@ -383,5 +383,5 @@ Move Engine::ComputeFirstMove(Game g) {
 
 
-int Engine::ComputeMove2(int xplay, int yplay, int player, int level,
+int Engine::ComputeMove2(int xplay, int yplay, Player player, int level,
 			 int cutoffval, ULONG64 playerbits, 
 			 ULONG64 opponentbits)
@@ -389,5 +389,5 @@ int Engine::ComputeMove2(int xplay, int 
   int number_of_turned = 0;
   SquareStackEntry mse;
-  int opponent = Score::GetOpponent(player);
+  Player opponent = ::opponent(player);
 
   m_nodes_searched++;
@@ -490,5 +490,5 @@ int Engine::ComputeMove2(int xplay, int 
     }
 
-  m_board[xplay][yplay] = Score::NOBODY;
+  m_board[xplay][yplay] = Nobody;
   m_score.ScoreSubtract(player, 1);
   m_bc_score.ScoreSubtract(player, m_bc_board[xplay][yplay]);
@@ -499,5 +499,5 @@ int Engine::ComputeMove2(int xplay, int 
 
 
-int Engine::TryAllMoves(int opponent, int level, int cutoffval,
+int Engine::TryAllMoves(Player opponent, int level, int cutoffval,
 			ULONG64 opponentbits, ULONG64 playerbits)
 {
@@ -513,5 +513,5 @@ int Engine::TryAllMoves(int opponent, in
     {
       for (int y=1; y<9; y++)
-	if (m_board[x][y] == Score::NOBODY &&
+	if (m_board[x][y] == Nobody &&
 	    (m_neighbor_bits[x][y] & playerbits) != null_bits)
 	  {
@@ -534,9 +534,9 @@ int Engine::TryAllMoves(int opponent, in
 
 
-int Engine::EvaluatePosition(int player)
+int Engine::EvaluatePosition(Player player)
 {
   int retval;
 
-  int opponent = Score::GetOpponent(player);
+  Player opponent = ::opponent(player);
   int score_player = m_score.GetScore(player);
   int score_opponent = m_score.GetScore(opponent);
@@ -614,5 +614,5 @@ void Engine::SetupBcBoard()
 
 
-int Engine::CalcBcScore(int player)
+int Engine::CalcBcScore(Player player)
 {
   int sum = 0;
@@ -627,5 +627,5 @@ int Engine::CalcBcScore(int player)
 
 
-ULONG64 Engine::ComputeOccupiedBits(int player)
+ULONG64 Engine::ComputeOccupiedBits(Player player)
 {
   ULONG64 retval = 0;
Index: Engine.h
===================================================================
RCS file: /home/kde/kdegames/kreversi/Engine.h,v
retrieving revision 1.10
diff -u -2 -d -p -b -r1.10 Engine.h
--- Engine.h	11 Mar 2003 15:00:16 -0000	1.10
+++ Engine.h	18 May 2003 02:58:11 -0000
@@ -192,15 +192,15 @@ public:
   Move ComputeMove(Game g);
   Move ComputeFirstMove(Game g);
-  int ComputeMove2(int xplay, int yplay, int player, int level,
+  int ComputeMove2(int xplay, int yplay, Player player, int level,
     int cutoffval, ULONG64 playerbits, ULONG64 opponentbits);
 
-  int TryAllMoves(int opponent, int level, int cutoffval,
+  int TryAllMoves(Player opponent, int level, int cutoffval,
 		  ULONG64 opponentbits, ULONG64 playerbits);
 
-  int EvaluatePosition(int player);
+  int EvaluatePosition(Player player);
   void SetupBcBoard();
   void SetupBits();
-  int CalcBcScore(int player);
-  ULONG64 ComputeOccupiedBits(int player);
+  int CalcBcScore(Player player);
+  ULONG64 ComputeOccupiedBits(Player player);
 
   void yield();
@@ -210,5 +210,5 @@ private:
   static const int ILLEGAL_VALUE;
   static const int BC_WEIGHT;
-  int  m_board[10][10];
+  Player m_board[10][10];
   int  m_bc_board[9][9];
   Score m_score;
Index: Game.cpp
===================================================================
RCS file: /home/kde/kdegames/kreversi/Game.cpp,v
retrieving revision 1.3
diff -u -2 -d -p -b -r1.3 Game.cpp
--- Game.cpp	11 Mar 2003 15:00:16 -0000	1.3
+++ Game.cpp	18 May 2003 02:58:11 -0000
@@ -98,5 +98,4 @@
 
 
-#include <qobject.h>
 #include "Game.h"
 
@@ -120,5 +119,5 @@ void Game::Reset()
 bool Game::MakeMove(Move m)
 {
-  if (m.GetPlayer() == Score::NOBODY) return false;
+  if (m.GetPlayer() == Nobody) return false;
   if (GetWhoseTurn() != m.GetPlayer()) return false;
   if (! m_positions[m_movenumber].MoveIsLegal(m)) return false;
@@ -142,5 +141,5 @@ bool Game::TakeBackMove()
 
 
-int Game::GetSquare(int x, int y)
+Player Game::GetSquare(int x, int y)
 {
   return m_positions[m_movenumber].GetSquare(x, y);
@@ -148,5 +147,5 @@ int Game::GetSquare(int x, int y)
 
 
-int Game::GetScore(int player)
+int Game::GetScore(Player player)
 {
   return m_positions[m_movenumber].GetScore(player);
@@ -163,5 +162,5 @@ bool Game::MoveIsLegal(Move m)
 
 
-bool Game::MoveIsPossible(int player)
+bool Game::MoveIsPossible(Player player)
 {
   return m_positions[m_movenumber].MoveIsPossible(player);
@@ -178,10 +177,10 @@ int Game::GetMoveNumber() { return m_mov
 
 
-int Game::GetWhoseTurn()
+Player Game::GetWhoseTurn()
 {
-  if (m_movenumber <= 0) return Score::BLACK;
+  if (m_movenumber <= 0) return Black;
   
-  int player = GetLastMove().GetPlayer();
-  int opponent = Score::GetOpponent(player);
+  Player player = GetLastMove().GetPlayer();
+  Player opponent = ::opponent(player);
   
     if (MoveIsPossible(opponent)) return opponent;
@@ -189,20 +188,14 @@ int Game::GetWhoseTurn()
     if (MoveIsPossible(player)) return player;
     
-    return Score::NOBODY;
+  return Nobody;
 }
 
-int Game::GetWhoseTurnOpponent() {
-  int color = GetWhoseTurn();
-  if(color == Score::NOBODY)
-    return Score::NOBODY;
-  else if(color == Score::BLACK)
-    return Score::WHITE;
-  else
-    return Score::BLACK;
+Player Game::GetWhoseTurnOpponent() {
+  return opponent( GetWhoseTurn() );
 }
 
 bool Game::squareModified(int x, int y) {
   if(GetMoveNumber() == 1)
-    return TRUE;
+    return true;
   else
     return (bool)(m_positions[m_movenumber].GetSquare(x, y) != \
m_positions[m_movenumber-1].GetSquare(x, y)); @@ -211,15 +204,15 @@ bool \
Game::squareModified(int x, int y)   bool Game::wasTurned(int x, int y) {
   if(GetMoveNumber() == 0)
-    return FALSE;
+    return false;
   else {
-    int c1 = m_positions[m_movenumber-1].GetSquare(x, y);
-    int c2 = m_positions[m_movenumber].GetSquare(x, y);
+    Player c1 = m_positions[m_movenumber-1].GetSquare(x, y);
+    Player c2 = m_positions[m_movenumber].GetSquare(x, y);
     
-    if(c1 == Score::NOBODY)
-      return FALSE;
+    if(c1 == Nobody)
+      return false;
     else if(c1 == c2)
-      return FALSE;
+      return false;
     else
-      return TRUE;
+      return true;
   }
 }
Index: Game.h
===================================================================
RCS file: /home/kde/kdegames/kreversi/Game.h,v
retrieving revision 1.4
diff -u -2 -d -p -b -r1.4 Game.h
--- Game.h	11 Mar 2003 15:00:16 -0000	1.4
+++ Game.h	18 May 2003 02:58:11 -0000
@@ -111,13 +111,13 @@ public:
   bool MakeMove(Move m);
   bool TakeBackMove();
-  int GetSquare(int x, int y);
-  int GetScore(int player);
+  Player GetSquare(int x, int y);
+  int GetScore(Player player);
   Move GetLastMove();
   bool MoveIsLegal(Move m);
-  bool MoveIsPossible(int player);
+  bool MoveIsPossible(Player player);
   bool MoveIsAtAllPossible();
   int GetMoveNumber();
-  int GetWhoseTurn();
-  int GetWhoseTurnOpponent();
+  Player GetWhoseTurn();
+  Player GetWhoseTurnOpponent();
   bool squareModified(int x, int y);
   bool wasTurned(int x, int y);
Index: Makefile.am
===================================================================
RCS file: /home/kde/kdegames/kreversi/Makefile.am,v
retrieving revision 1.33
diff -u -2 -d -p -b -r1.33 Makefile.am
--- Makefile.am	9 May 2003 06:54:25 -0000	1.33
+++ Makefile.am	18 May 2003 02:58:11 -0000
@@ -8,5 +8,5 @@ bin_PROGRAMS = kreversi
 kreversi_SOURCES = main.cpp kreversi.cpp board.cpp Game.cpp \
 		Score.cpp SuperEngine.cpp settings.ui \
-		Engine.cpp Position.cpp Move.cpp playsound.cpp
+		Engine.cpp Position.cpp Move.cpp
 
 METASOURCES =	AUTO
@@ -16,5 +16,5 @@ rc_DATA = kreversiui.rc
 
 noinst_HEADERS = Engine.h Game.h kreversi.h Move.h board.h Position.h \
-	playsound.h Score.h version.h SuperEngine.h           
+	Score.h version.h SuperEngine.h           
 
 SUBDIRS = . pics sounds icons
Index: Move.cpp
===================================================================
RCS file: /home/kde/kdegames/kreversi/Move.cpp,v
retrieving revision 1.3
diff -u -2 -d -p -b -r1.3 Move.cpp
--- Move.cpp	4 Oct 1998 04:44:40 -0000	1.3
+++ Move.cpp	18 May 2003 02:58:11 -0000
@@ -61,5 +61,5 @@ void Move::copy(const Move &m) {
 }
 
-Move::Move(int x, int y, int player) { 
+Move::Move(int x, int y, Player player) {
   m_x = x; 
   m_y = y; 
@@ -69,3 +69,3 @@ Move::Move(int x, int y, int player) { 
 int Move::GetX() { return m_x; }
 int Move::GetY() { return m_y; }
-int Move::GetPlayer() { return m_player; }
+Player Move::GetPlayer() { return m_player; }
Index: Move.h
===================================================================
RCS file: /home/kde/kdegames/kreversi/Move.h,v
retrieving revision 1.5
diff -u -2 -d -p -b -r1.5 Move.h
--- Move.h	11 Mar 2003 15:00:16 -0000	1.5
+++ Move.h	18 May 2003 02:58:11 -0000
@@ -51,19 +51,21 @@
 #define __MOVE__H__
 
+#include "Score.h"
+
 class Move
 {
 public:
-  Move() { m_x = -1; m_y = -1; m_player = -1; }
+  Move() { m_x = -1; m_y = -1; m_player = Nobody; }
   Move(const Move &m);
-  Move(int x, int y, int player);
+  Move(int x, int y, Player player);
   void copy(const Move &m);
 
   int GetX();
   int GetY();
-  int GetPlayer();
+  Player GetPlayer();
 
 private:
   int m_x, m_y;
-  int m_player;
+  Player m_player;
 };
 
Index: Position.cpp
===================================================================
RCS file: /home/kde/kdegames/kreversi/Position.cpp,v
retrieving revision 1.2
diff -u -2 -d -p -b -r1.2 Position.cpp
--- Position.cpp	5 Nov 1997 19:42:32 -0000	1.2
+++ Position.cpp	18 May 2003 02:58:11 -0000
@@ -85,10 +85,10 @@ void Position::constrInit() {
   for (int i=0; i<10; i++)
     for (int j=0; j<10; j++)
-      m_board[i][j] = Score::NOBODY;
+      m_board[i][j] = Nobody;
     
-  m_board[4][4] = Score::WHITE;
-  m_board[5][5] = Score::WHITE;
-  m_board[5][4] = Score::BLACK;
-  m_board[4][5] = Score::BLACK;
+  m_board[4][4] = White;
+  m_board[5][5] = White;
+  m_board[5][4] = Black;
+  m_board[4][5] = Black;
 }
 
@@ -106,6 +106,6 @@ void Position::constrCopy(Position &p, M
   m_score.ScoreCopy(p.m_score);
 
-  int player = m.GetPlayer();
-  int opponent = Score::GetOpponent(player);
+  Player player = m.GetPlayer();
+  Player opponent = ::opponent(player);
 
   m_board[m.GetX()][m.GetY()] = player;
@@ -149,9 +149,9 @@ Position::~Position() {
 }
 
-int Position::GetSquare(int x, int y) { 
+Player Position::GetSquare(int x, int y) {
   return m_board[x][y]; 
 }
 
-int Position::GetScore(int player) { return m_score.GetScore(player); }
+int Position::GetScore(Player player) { return m_score.GetScore(player); }
 
 Move Position::GetLastMove() { return m_last_move; }
@@ -159,8 +159,8 @@ Move Position::GetLastMove() { return m_
 bool Position::MoveIsLegal(Move m)
 {
-  if (m_board[m.GetX()][m.GetY()] != Score::NOBODY) return false;
+  if (m_board[m.GetX()][m.GetY()] != Nobody) return false;
 
-  int player = m.GetPlayer();
-  int opponent = Score::GetOpponent(player);
+  Player player = m.GetPlayer();
+  Player opponent = ::opponent(player);
 
   for (int xinc=-1; xinc<=1; xinc++)
@@ -183,5 +183,5 @@ bool Position::MoveIsLegal(Move m)
 
 
-bool Position::MoveIsPossible(int player)
+bool Position::MoveIsPossible(Player player)
 {
   for (int i=1; i<9; i++)
@@ -195,4 +195,4 @@ bool Position::MoveIsPossible(int player
 bool Position::MoveIsAtAllPossible()
 {
-  return (bool)(MoveIsPossible(Score::WHITE) || MoveIsPossible(Score::BLACK));
+  return (bool)(MoveIsPossible(White) || MoveIsPossible(Black));
 }
Index: Position.h
===================================================================
RCS file: /home/kde/kdegames/kreversi/Position.h,v
retrieving revision 1.4
diff -u -2 -d -p -b -r1.4 Position.h
--- Position.h	11 Mar 2003 15:00:16 -0000	1.4
+++ Position.h	18 May 2003 02:58:11 -0000
@@ -94,13 +94,13 @@ public:
   void constrCopy(Position &p, Move &m);
 
-  int GetSquare(int x, int y);
-  int GetScore(int player);
+  Player GetSquare(int x, int y);
+  int GetScore(Player player);
   Move GetLastMove();
   bool MoveIsLegal(Move m);
-  bool MoveIsPossible(int player);
+  bool MoveIsPossible(Player player);
   bool MoveIsAtAllPossible();
 
 private:
-  int m_board[10][10];
+  Player m_board[10][10];
   Move m_last_move;
   Score m_score;
Index: Score.cpp
===================================================================
RCS file: /home/kde/kdegames/kreversi/Score.cpp,v
retrieving revision 1.2
diff -u -2 -d -p -b -r1.2 Score.cpp
--- Score.cpp	5 Nov 1997 19:42:34 -0000	1.2
+++ Score.cpp	18 May 2003 02:58:11 -0000
@@ -53,45 +53,48 @@
 #include "Score.h"
 
-const int Score::NOBODY=0;
-const int Score::WHITE=1;
-const int Score::BLACK=2;
-
 Score::Score() 
 { 
-  m_score[0] = 0; 
-  m_score[1] = 0;
+  m_score[White] = 0;
+  m_score[Black] = 0;
 }
 
 Score::Score(int whitescore, int blackscore) 
 {
-  m_score[WHITE-1] = whitescore;
-  m_score[BLACK-1] = blackscore;
+  m_score[White] = whitescore;
+  m_score[Black] = blackscore;
 }
 
 
-int Score::GetOpponent(int player) { return player % 2 + 1; }
-
+Player opponent(Player player)
+{
+  switch (player) {
+  case Nobody: break;
+  case White: return Black;
+  case Black: return White;
+  }
+  return Nobody;
+}
 
 void Score::ScoreCopy(Score &s)
 {
-  m_score[0] = s.m_score[0];
-  m_score[1] = s.m_score[1];
+  m_score[White] = s.m_score[White];
+  m_score[Black] = s.m_score[Black];
 }
 
 
-int Score::GetScore(int player) { return m_score[player-1]; }
+int Score::GetScore(Player player) { return m_score[player]; }
 
 
-void Score::SetScore(int player, int score) { m_score[player-1] = score; }
+void Score::SetScore(Player player, int score) { m_score[player] = score; }
 
 
-void Score::ScoreAdd(int player, int amount)
+void Score::ScoreAdd(Player player, int amount)
 {
-  m_score[player-1] += amount;
+  m_score[player] += amount;
 }
 
 
-void Score::ScoreSubtract(int player, int amount)
+void Score::ScoreSubtract(Player player, int amount)
 {
-  m_score[player-1] -= amount;
+  m_score[player] -= amount;
 }
Index: Score.h
===================================================================
RCS file: /home/kde/kdegames/kreversi/Score.h,v
retrieving revision 1.4
diff -u -2 -d -p -b -r1.4 Score.h
--- Score.h	11 Mar 2003 15:00:16 -0000	1.4
+++ Score.h	18 May 2003 02:58:11 -0000
@@ -54,4 +54,7 @@
 #define __SCORE__H__
 
+enum Player { Nobody = -1, White = 0, Black = 1 };
+Player opponent(Player player);
+
 class Score {
 public:
@@ -59,19 +62,12 @@ public:
   Score(int whitescore, int blackscore);
   void ScoreCopy(Score &s);
-  void InitScore(int w, int b) { SetScore(Score::BLACK, b); SetScore(Score::WHITE, \
                w); }
-  int  GetScore(int player);
-  void SetScore(int player, int score);
-  void ScoreAdd(int player, int amount);
-  void ScoreSubtract(int player, int amount);
-
-  static int GetOpponent(int player);
+  void InitScore(int w, int b) { SetScore(Black, b); SetScore(White, w); }
+  int GetScore(Player player);
+  void SetScore(Player player, int score);
+  void ScoreAdd(Player player, int amount);
+  void ScoreSubtract(Player player, int amount);
   
 private:
   int m_score[2];
-
-public:
-  static const int NOBODY;
-  static const int WHITE;
-  static const int BLACK;
 };
 
Index: SuperEngine.h
===================================================================
RCS file: /home/kde/kdegames/kreversi/SuperEngine.h,v
retrieving revision 1.5
diff -u -2 -d -p -b -r1.5 SuperEngine.h
Index: board.cpp
===================================================================
RCS file: /home/kde/kdegames/kreversi/board.cpp,v
retrieving revision 1.26
diff -u -2 -d -p -b -r1.26 board.cpp
--- board.cpp	28 Apr 2003 21:41:09 -0000	1.26
+++ board.cpp	18 May 2003 02:58:12 -0000
@@ -38,4 +38,7 @@
 
 #include "board.h"
+
+#include <unistd.h>
+
 #include <qpainter.h>
 
@@ -43,6 +46,6 @@
 #include <kstandarddirs.h>
 #include <kconfig.h>
+#include <kaudioplayer.h>
 
-#include "playsound.h"
 #include "Engine.h"
 
@@ -50,37 +53,34 @@
 #include <unistd.h>
 
-#define APPDATA(x) KGlobal::dirs()->findResource("appdata", x)
 #define PICDATA(x) KGlobal::dirs()->findResource("appdata", QString("pics/")+ x)
 
-extern QString SOUNDDIR;
+const char * const Board::SOUND[Nb_Sounds] = {
+    "reversi-click.wav", "reversi-drawn.wav", "reversi-won.wav",
+    "reversi-lost.wav", "reversi-hof.wav", "reversi-illegalmove.wav"
+};
 
-const int HINT_BLINKRATE = 250000;
-const int DEFAULT_ANIMATION_DELAY = 4;
-const int ANIMATION_DELAY = 3000;
-const int CHIP_BLACK	  = 1;
-const int CHIP_WHITE      = 24;
-const int CHIP_MAX	  = 25;
-const int CHIP_SIZE       = 36;
+const uint HINT_BLINKRATE = 250000;
+const uint DEFAULT_ANIMATION_DELAY = 4;
+const uint ANIMATION_DELAY = 3000;
+const uint CHIP_BLACK	   = 1;
+const uint CHIP_WHITE      = 24;
+const uint CHIP_SIZE       = 36;
 
 Board::Board(QWidget *parent, const char *name) : QWidget(parent, name), 
-  chipname(""),
   // ensure that the first time adjustsize does
   // pixmap loading
   oldsizehint(-1),
-  _size(32),
   _zoom(100),
-  _zoomed_size((_size * _zoom) / 100 + 2),
-
-  human(Score::BLACK),
-  nopaint(FALSE){
+  _zoomed_size(CHIP_SIZE),
+  human(Black),
+  nopaint(false),
+  chiptype(Unloaded)
+{
   
   setAnimationSpeed(DEFAULT_ANIMATION_DELAY);
-  setUpdatesEnabled(FALSE);
   engine = new Engine();
   game = new Game();
   setStrength(1);
 
-  connect(this, SIGNAL(signalFieldClicked(int, int)),
-	  this, SLOT(slotFieldClicked(int, int)));
   loadSettings();
 }
@@ -94,26 +94,23 @@ Board::~Board() {
 void Board::start() {
   // make sure a signal is emitted  
-  setStrength(engine->GetStrength());
+  setStrength(strength());
   newGame();
   adjustSize();
-  setUpdatesEnabled(TRUE);
 }
 
-void Board::loadChips(const char *filename) {
-  allchips.load(PICDATA(filename));
-  chipname = filename;
-  if(scaled_allchips.width())
-  {
-    loadPixmaps(); // Reload
+void Board::loadChips(ChipType type) {
+  QString name("pics/");
+  name += (type==Colored ? "chips.png" : "chips_mono.png");
+  QString s = KGlobal::dirs()->findResource("appdata", name);
+  bool ok = allchips.load(s);
+  Q_ASSERT( ok && allchips.width()==CHIP_SIZE*5
+            && allchips.height()==CHIP_SIZE*5 );
+  chiptype = type;
+  scaled_allchips = QPixmap();
+  loadPixmaps();
     update();
-  }
-}
-
-QString Board::chipsName() {
-  return chipname;
 }
 
-
-int Board::getMoveNumber() {
+int Board::moveNumber() const {
   return game->GetMoveNumber();
 }
@@ -126,11 +123,7 @@ void Board::setAnimationSpeed(int speed)
 }
 
-int Board::animationSpeed() {
-  return anim_speed;
-}
-
 /// takes back last set of moves
 void Board::undo() {
-  if((getState() == READY)) {
+  if(state() == READY) {
     int last_player = game->GetLastMove().GetPlayer();
     while ((game->GetMoveNumber() != 0) && 
@@ -148,6 +141,6 @@ void Board::interrupt() {
 }
 
-bool Board::interrupted() {
-  return ((game->GetWhoseTurn() == computerIs()) && (getState() == READY));
+bool Board::interrupted() const {
+  return ((game->GetWhoseTurn() == computerPlayer()) && (state() == READY));
 }
 
@@ -164,22 +157,10 @@ void Board::adjustSize() {
   if(sizeHint().width() != oldsizehint) {
     loadPixmaps();
-    resize(sizeHint());
+    setFixedSize(sizeHint());
     oldsizehint = sizeHint().width();
-    emit sizeChange();
+    update();
   }
 }
 
-/// returns which color the human plays
-int  Board::humanIs() {
-  return human;
-}
-
-/// returns which color the computer plays
-int  Board::computerIs() {
-  if(human == Score::BLACK)
-    return Score::WHITE;
-  return Score::BLACK;
-}
-
 /// starts a new game
 void Board::newGame() {  
@@ -189,8 +170,8 @@ void Board::newGame() {  
   setState(READY);
 
-  emit turn(Score::BLACK);
+  emit turn(Black);
   
   // computer makes first move
-  if(human == Score::WHITE)
+  if(human == White)
     computerMakeMove();
 }
@@ -202,9 +183,9 @@ void Board::mousePressEvent(QMouseEvent 
     return;
   }
-  if(getState() == READY) {
+  if(state() == READY) {
     int px = (e->pos().x()-1) / _zoomed_size;
     int py = (e->pos().y()-1) / _zoomed_size;
-    emit signalFieldClicked(py, px);
-  } else if(getState() == HINT)
+    fieldClicked(py, px);
+  } else if(state() == HINT)
     setState(READY);
   else
@@ -214,10 +195,10 @@ void Board::mousePressEvent(QMouseEvent 
 
 /// handles piece settings
-void Board::slotFieldClicked(int row, int col) {
-  if(getState() == READY) {
-    int color = game->GetWhoseTurn();
+void Board::fieldClicked(int row, int col) {
+  if(state() == READY) {
+    Player player = game->GetWhoseTurn();
 
     /// makes a human move
-    Move m(col + 1, row + 1, color);
+    Move m(col + 1, row + 1, player);
     if(game->MoveIsLegal(m)) {
       //      playSound("click.wav");
@@ -234,5 +215,5 @@ void Board::slotFieldClicked(int row, in
       updateBoard();
 
-      if(color != game->GetWhoseTurn())
+      if(player != game->GetWhoseTurn())
 	computerMakeMove();
     } else 
@@ -245,10 +226,10 @@ void Board::slotFieldClicked(int row, in
 void Board::computerMakeMove() {
   // check if the computer can move
-  int color = game->GetWhoseTurn();
-  int opponent = game->GetWhoseTurnOpponent();
+  Player player = game->GetWhoseTurn();
+  Player opponent = game->GetWhoseTurnOpponent();
 
-  emit turn(color);
+  emit turn(player);
 
-  if(game->MoveIsPossible(color)) {
+  if(game->MoveIsPossible(player)) {
     setState(THINKING);
     do {
@@ -288,7 +269,7 @@ void Board::computerMakeMove() {
 
 /// returns the current score
-void Board::getScore(int &black, int &white) {
-  black = game->GetScore(Score::BLACK);
-  white = game->GetScore(Score::WHITE);
+void Board::getScore(int &black, int &white) const {
+  black = game->GetScore(Black);
+  white = game->GetScore(White);
 } 
 
@@ -300,19 +281,16 @@ void Board::gameEnded() {
   getScore(b, w);
   if(b > w)
-    emit gameWon(Score::BLACK);
+    emit gameWon(Black);
   else if(b < w)
-    emit gameWon(Score::WHITE);
+    emit gameWon(White);
   else
-    emit gameWon(Score::NOBODY);
-  emit turn(Score::NOBODY);
+    emit gameWon(Nobody);
+  emit turn(Nobody);
 }
 
 
 void Board::switchSides() {
-  if(getState() == READY) {
-    if(human == Score::WHITE)
-      human = Score::BLACK;
-    else
-      human = Score::WHITE;
+  if(state() == READY) {
+    human = opponent(human);
     emit score();
     kapp->processEvents();
@@ -321,9 +299,4 @@ void Board::switchSides() {
 }
 
-
-int  Board::getState() {
-  return _status;
-}
-
 void Board::setState(int nstatus) {
   _status = nstatus;
@@ -334,14 +307,14 @@ void Board::setStrength(int st) {
   if((st >= 1) && (st <= 8)) {
     engine->SetStrength(st);
-    emit strengthChanged(engine->GetStrength());
+    emit strengthChanged(strength());
   }
 }
 
-int Board::getStrength() {
+int Board::strength() const {
   return engine->GetStrength();
 }
 
 void Board::hint() {
-  if(getState() == READY) {
+  if(state() == READY) {
     setState(THINKING);
     Move m = engine->ComputeMove(*game);
@@ -351,9 +324,9 @@ void Board::hint() {
       // 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) && (getState() != READY) && isVisible(); \
flash++) { +      for(int flash = 0; (flash < 100) && (state() != READY) && \
isVisible(); flash++) {  if(flash & 1)
-	  drawOnePiece(m.GetY() - 1, m.GetX() - 1, Score::NOBODY);
+	  drawPiece(m.GetY() - 1, m.GetX() - 1, Nobody);
 	else
-	  drawOnePiece(m.GetY() - 1, m.GetX() - 1, game->GetWhoseTurn());
+	  drawPiece(m.GetY() - 1, m.GetX() - 1, game->GetWhoseTurn());
 
 	// keep GUI alive while waiting
@@ -363,6 +336,5 @@ void Board::hint() {
 	}
       }
-      
-      drawOnePiece(m.GetY() - 1, m.GetX() - 1, 
+      drawPiece(m.GetY() - 1, m.GetX() - 1,
 		   game->GetSquare(m.GetX(), m.GetY()));
     }
@@ -371,4 +343,11 @@ void Board::hint() {
 }
 
+void Board::playSound(SoundType type)
+{
+    if ( !sound ) return;
+    QString s("kreversi/sounds/");
+    s += SOUND[type];
+    KAudioPlayer::play( locate("data", s) );
+}
 
 // ********************************************************
@@ -387,7 +366,6 @@ void Board::animateChanged(Move m) {
 
   // draw the new piece
-
-  drawOnePiece(m.GetY()-1, m.GetX()-1, m.GetPlayer());
-  soundSync();
+  drawPiece(m.GetY()-1, m.GetX()-1, m.GetPlayer());
+//  soundSync();
 
   for(int dx = -1; dx < 2; dx++)
@@ -398,5 +376,5 @@ void Board::animateChanged(Move m) {
 
 
-bool Board::isField(int row, int col) {
+bool Board::isField(int row, int col) const {
   return (bool)((row > -1) && (row < 8) && (col > -1) && (col < 8));
 }
@@ -408,7 +386,6 @@ void Board::animateChangedRow(int row, i
   while(isField(row, col)) {
     if(game->wasTurned(col+1, row+1)) {
-      playSound("reversi-click.wav");
+      playSound(ClickSound);
       rotateChip(row, col);
-      soundSync();
    } else
       return;
@@ -419,57 +396,38 @@ void Board::animateChangedRow(int row, i
 }
 
-// NOTE: this code is S**T
 void Board::rotateChip(int row, int col) {
   // 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
-  int color = game->GetSquare(col+1, row+1);
+  Player player = game->GetSquare(col+1, row+1);
   int from, end, delta;
-  if(color == Score::WHITE) {
-    from = CHIP_BLACK + 2;
-    end  = CHIP_WHITE - 2;
+  switch (player) {
+  case White:
+    from = CHIP_BLACK + 1;
+    end  = CHIP_WHITE - 1;
     delta = 1;
-  } else if(color == Score::BLACK) {
-    from = CHIP_WHITE -2;
-    end  = CHIP_BLACK + 2;
+    break;
+  case Black:
+    from = CHIP_WHITE - 1;
+    end  = CHIP_BLACK + 1;
     delta = -1;
-  } else
+    break;
+  case Nobody:
     return;
-
-  int px = col * _zoomed_size + 2;
-  int py = row * _zoomed_size + 2;
-
-  int w = scaled_allchips.width()/5;
-  int h = scaled_allchips.height()/5;
-
-  QPainter p;
+  }
   
   for(int i = from; i != end; i += delta) {
-    QPixmap pix(_zoomed_size-2, _zoomed_size-2);
-
-    p.begin(&pix);
-    if (bg.width())
-       p.drawTiledPixmap(0, 0, _zoomed_size-2, _zoomed_size-2, bg, px, py);
-    else
-       p.fillRect(0, 0, _zoomed_size-2, _zoomed_size-2, eraseColor());
-    p.drawPixmap(0, 0, scaled_allchips, (i % 5) * w + 10, (i / 5) * h + 10,
-	   _zoomed_size-2, _zoomed_size-2);
-    p.flush();
-    p.end();
-
-    bitBlt(this, px, py, &pix, 0, 0, _zoomed_size-2, _zoomed_size-2, CopyROP);
-    kapp->flushX();
+    drawOnePiece(row, col, i);
+    kapp->flushX(); // use QCanvas to avoid flicker...
     usleep(ANIMATION_DELAY * anim_speed);
   }
-  
-  drawOnePiece(row, col, color);
 }
 
-bool Board::canZoomIn() {
+bool Board::canZoomIn() const {
   return (bool)(width() < 640);
 }
 
 
-bool Board::canZoomOut() {
+bool Board::canZoomOut() const {
   return (bool)(width() > 200);
 }
@@ -481,5 +439,5 @@ void Board::setZoom(int _new) {
     if(_new != _zoom) {
       _zoom = _new;
-      _zoomed_size = (_size * _zoom) / 100 + 2;
+      _zoomed_size = qRound(float(CHIP_SIZE) * _zoom / 100);
       adjustSize();
     }
@@ -487,10 +445,4 @@ void Board::setZoom(int _new) {
 }
 
-
-int Board::getZoom() const {
-  return _zoom;
-}
-
-
 void Board::zoomIn() {
   setZoom(_zoom + 20);
@@ -502,4 +454,5 @@ void Board::zoomOut() {
 }
 
+
 void Board::loadPixmaps() {
   if (scaled_allchips.width() != (_zoomed_size*5))
@@ -507,10 +460,7 @@ void Board::loadPixmaps() {
     scaled_allchips = QPixmap(_zoomed_size*5, _zoomed_size*5);
     QWMatrix wm3;
-    wm3.scale((float)(_zoomed_size*5)/(CHIP_SIZE * 5),
-              (float)(_zoomed_size*5)/(CHIP_SIZE * 5));
+    wm3.scale(float(_zoomed_size)/CHIP_SIZE, float(_zoomed_size)/CHIP_SIZE);
     scaled_allchips = allchips.xForm(wm3);
   }
-  if (bg.width())
-    setErasePixmap(bg);
 }
 
@@ -519,5 +469,8 @@ void Board::updateBoard(bool force) {
   for(int row = 0; row < 8; row++)
     for(int col = 0; col < 8; col++) 
-      drawPiece(row, col, force);
+        if ( force || game->squareModified(col+1, row+1) ) {
+            Player player = game->GetSquare(col + 1, row + 1);
+            drawPiece(row, col, player);
+        }
 
   emit score();
@@ -525,73 +478,41 @@ void Board::updateBoard(bool force) {
 
 
-void Board::drawOnePiece(int row, int col, int color) {
-  int px = col * _zoomed_size + 2;
-  int py = row * _zoomed_size + 2;
-
-  int w = scaled_allchips.width()/5;
-  int h = scaled_allchips.height()/5;
-
-  QPixmap tmp(_zoomed_size-2, _zoomed_size-2);
+void Board::drawOnePiece(int row, int col, int i) {
+  int px = col * _zoomed_size;
+  int py = row * _zoomed_size;
 
-  QPainter p;
-  p.begin(&tmp);
+  QPainter p(this);
   if (bg.width())
-    p.drawTiledPixmap(0, 0, _zoomed_size-2, _zoomed_size-2, bg, px, py);
-  else
-    p.fillRect(0, 0, _zoomed_size-2, _zoomed_size-2, eraseColor());
+      p.drawTiledPixmap(px, py, _zoomed_size, _zoomed_size, bg, px, py);
+  else p.fillRect(px, py, _zoomed_size, _zoomed_size, bgColor);
   
-  if(color == Score::BLACK) {
-    // easy to understand, isn't it :-)
-    int i = CHIP_BLACK;
-    p.drawPixmap(0, 0, scaled_allchips, (i % 5) * w + 10, (i / 5) * h + 10,
-	   _zoomed_size-2, _zoomed_size-2);
-  }
-  else if(color == Score::WHITE) {
-    // easy to understand, isn't it :-)
-    int i = CHIP_WHITE;
-    p.drawPixmap(0, 0, scaled_allchips, (i % 5) * w + 10, (i / 5) * h + 10,
-	   _zoomed_size-2, _zoomed_size-2);
-  }
-  p.flush();
-  p.end();  
-  bitBlt(this, px, py, &tmp, 0, 0, _zoomed_size-2, _zoomed_size-2, CopyROP);
-  kapp->flushX();
+  p.setPen(black);
+  p.drawRect(px, py, _zoomed_size, _zoomed_size);
+
+  if ( i==-1 ) return;
+  p.drawPixmap(px, py, scaled_allchips,
+               (i%5) * _zoomed_size, (i/5) * _zoomed_size,
+               _zoomed_size, _zoomed_size);
 }
 
 
-void Board::drawPiece(int row, int col, bool force) {
-  if(game->squareModified(col+1, row+1) || force) {
-    int color = game->GetSquare(col + 1, row + 1);
-    drawOnePiece(row, col, color);
+void Board::drawPiece(int row, int col, Player player) {
+  int i = -1;
+  switch (player) {
+  case Black:
+    i = CHIP_BLACK;
+    break;
+  case White:
+    i = CHIP_WHITE;
+    break;
+  case Nobody:
+    break;
   }
+  drawOnePiece(row, col, i);
 }
 
 
 void Board::paintEvent(QPaintEvent *) {
-  int w = sizeHint().width() - 2;
-  
-  if(!nopaint) {
-    QPainter p;
-    
-    p.begin(this);
-    p.setPen(QPen(QColor("black"), 2));
-    
-    // draw vertical lines
-    for(int i = 1; i < 8; i++) {
-      int x = i * _zoomed_size;
-      p.drawLine(x+1, 0, x+1, w);
-    }
-    
-    // draw horizontal lines
-    for(int i = 1; i < 8; i++) {
-      int y = i * _zoomed_size;
-      p.drawLine(0, y+1, w, y+1);
-    }
-
-    p.drawRect(1, 1, w+1, w+1);
-    
-    p.end();
-    updateBoard(TRUE);
-  }
+  updateBoard(true);
 }
 
@@ -603,20 +524,15 @@ QSize Board::sizeHint() const {
 
 void Board::setPixmap(QPixmap &pm) {
+  if ( pm.width()==0 ) return;
   bg = pm;
-  if(scaled_allchips.width())
-  {
-    loadPixmaps(); // Reload
     update();
-  }
+  setErasePixmap(pm);
 }
 
 void Board::setColor(const QColor &c) {
-  setBackgroundColor(c);
-  bg.resize(0, 0);
-  if(scaled_allchips.width())
-  {
-    loadPixmaps(); // Reload
+  bgColor = c;
+  bg = QPixmap();
     update();
-  }
+  setEraseColor(c);
 } 
 
@@ -624,13 +540,12 @@ void Board::setColor(const QColor &c) {
 void Board::saveGame(KConfig *config) {
   interrupt(); // stop thinking
-  config->writeEntry("NumberOfMoves", game->GetMoveNumber());
-  int nmoves = game->GetMoveNumber();
-  config->writeEntry("State", getState());
-  config->writeEntry("Strength", getStrength());
-  for(int i = nmoves; i > 0; i--) {    
+  config->writeEntry("NumberOfMoves", moveNumber());
+  config->writeEntry("State", state());
+  config->writeEntry("Strength", strength());
+  for(int i = moveNumber(); i > 0; i--) {
     Move m = game->GetLastMove();
     game->TakeBackMove();
     QString s, idx;
-    s.sprintf("%d %d %d", m.GetX(), m.GetY(), m.GetPlayer());
+    s.sprintf("%d %d %d", m.GetX(), m.GetY(), (int)m.GetPlayer());
     idx.sprintf("Move_%d", i);
     config->writeEntry(idx, s);
@@ -638,5 +553,5 @@ void Board::saveGame(KConfig *config) {
   
   // save whose turn it is
-  config->writeEntry("WhoseTurn", human);
+  config->writeEntry("WhoseTurn", (int)human);
 
   // all moves must be redone
@@ -659,6 +574,6 @@ void Board::loadGame(KConfig *config, bo
       int x = (*s.at(0)).toInt();
       int y = (*s.at(1)).toInt();
-      int pl = (*s.at(2)).toInt();
-      Move m(x, y, pl);
+      Player player = (Player)(*s.at(2)).toInt();
+      Move m(x, y, player);
       game->MakeMove(m);
     }
@@ -667,5 +582,5 @@ void Board::loadGame(KConfig *config, bo
       return;
 
-    human = config->readNumEntry("WhoseTurn");
+    human = (Player)config->readNumEntry("WhoseTurn");
   
     updateBoard(TRUE);
@@ -676,7 +591,7 @@ void Board::loadGame(KConfig *config, bo
       doContinue();
     else {      
-      emit turn(Score::BLACK);
+      emit turn(Black);
       // computer makes first move
-      if(human == Score::WHITE)
+      if(human == White)
 	computerMakeMove();
     }
@@ -692,10 +607,10 @@ void Board::loadSettings(){
   KConfig *config = kapp->config();
   config->setGroup("Game");
-  if(config->readBoolEntry("Grayscale", false)){
-    if(chipname != "chips_mono.png")
-      loadChips("chips_mono.png");
+  if(config->readBoolEntry("Grayscale", false)) {
+    if(chiptype != Grayscale)
+        loadChips(Grayscale);
   }
-  else{
-    if(chipname != "chips.png") loadChips("chips.png");
+  else {
+    if(chiptype != Colored) loadChips(Colored);
   }
 
Index: board.h
===================================================================
RCS file: /home/kde/kdegames/kreversi/board.h,v
retrieving revision 1.6
diff -u -2 -d -p -b -r1.6 board.h
--- board.h	11 Mar 2003 15:00:16 -0000	1.6
+++ board.h	18 May 2003 02:58:12 -0000
@@ -49,4 +49,5 @@ class Engine;
 class Game;
 
+
 class Board : public QWidget {
   Q_OBJECT
@@ -59,10 +60,10 @@ public:
 
   void newGame();
-  int humanIs();
-  int computerIs();
-  void getScore(int&, int&);
+  Player humanPlayer() const { return human; }
+  Player computerPlayer() const { return opponent(human); }
+  void getScore(int&, int&) const;
   void setStrength(int);
-  int  getStrength();
-  bool interrupted();
+  int  strength() const;
+  bool interrupted() const;
   
   // starts all: emits some signal, so it can't be called from 
@@ -76,19 +77,21 @@ public:
 
   /// stuff for zooming
-  bool canZoomIn();
-  bool canZoomOut();
+  bool canZoomIn() const;
+  bool canZoomOut() const;
   void zoomIn();
   void zoomOut();
   void setZoom(int);
-  int  getZoom() const;
+  int  zoom() const { return _zoom; }
 
-  int  getState();
+  int  state() const { return _status; }
   void setState(int);
   void setAnimationSpeed(int);
-  int  animationSpeed();
+  int  animationSpeed() const { return anim_speed; }
 
-  int  getMoveNumber();
-  void loadChips(const char *);
-  QString chipsName();
+  int  moveNumber() const;
+
+  enum ChipType { Unloaded, Colored, Grayscale };
+  void loadChips(ChipType);
+  ChipType chipType() const { return chiptype; }
 
   void loadGame(KConfig *, bool noupdate = FALSE);
@@ -96,8 +99,14 @@ public:
   bool canLoad(KConfig *);
 
-public slots:
   void setColor(const QColor &);
+  QColor color() const { return bgColor; }
   void setPixmap(QPixmap &);
 
+  enum SoundType { ClickSound = 0, DrawSound, WonSound, LostSound,
+                   HallOfFameSound, IllegalMoveSound, Nb_Sounds };
+  static const char * const SOUND[Nb_Sounds];
+  void playSound(SoundType);
+
+public slots:
   void undo();
   void hint();
@@ -105,27 +114,24 @@ public slots:
   void doContinue();
   void switchSides();
-
   void loadSettings();
   
-protected slots:
-  void slotFieldClicked(int, int);  
-
 signals:
-  void signalFieldClicked(int, int);
   void score();
-  void sizeChange();
-  void gameWon(int);
+  void gameWon(Player);
   void statusChange(int);
   void illegalMove();
-  void turn(int);
   void strengthChanged(int);
+  void sizeChange();
+  void turn(Player);
 
 private:  
+  void fieldClicked(int, int);
   void gameEnded();
   void computerMakeMove();
   
   void updateBoard(bool force = FALSE);
-  void drawPiece(int row, int col, bool force = FALSE);
-  void drawOnePiece(int row, int col, int color);
+
+  void drawPiece(int row, int col, Player);
+  void drawOnePiece(int row, int col, int i);
   void loadPixmaps();
   void adjustSize();
@@ -133,5 +139,5 @@ private:  
   void animateChangedRow(int row, int col, int dy, int dx);
   void rotateChip(int row, int col);
-  bool isField(int row, int col);
+  bool isField(int row, int col) const;
 
 private:
@@ -139,16 +145,17 @@ private:
   Game *game;
   
-  QString chipname;
   int  _status;
   int oldsizehint;
-  int _size;
   int _zoom;
   int _zoomed_size;
-  int human;
+  Player human;
   bool nopaint;
+  bool sound;
   
+  QColor bgColor;
   QPixmap bg;
 
   // the chips
+  ChipType chiptype;
   QPixmap allchips;
   QPixmap scaled_allchips;
Index: kreversi.cpp
===================================================================
RCS file: /home/kde/kdegames/kreversi/kreversi.cpp,v
retrieving revision 1.6
diff -u -2 -d -p -b -r1.6 kreversi.cpp
--- kreversi.cpp	14 May 2003 13:15:31 -0000	1.6
+++ kreversi.cpp	18 May 2003 02:58:12 -0000
@@ -37,5 +37,7 @@
  */
 
-#include <config.h>
+#include "config.h"
+
+#include <qlayout.h>
 
 #include <kapplication.h>
@@ -45,5 +47,4 @@
 #include <klocale.h>
 #include <kmessagebox.h>
-
 #include <kaction.h>
 #include <kstdgameaction.h>
@@ -56,5 +57,4 @@
 #include "kreversi.h"
 #include "kreversi.moc"
-#include "playsound.h"
 #include "board.h"
 #include "settings.h"
@@ -70,14 +70,19 @@ KReversi::KReversi( QWidget* parent, con
 
   // create reversi board
-  board = new Board(this, "Board");
+  QWidget *w = new QWidget(this);
+  setCentralWidget(w);
+  QHBoxLayout *top = new QHBoxLayout(w);
+  top->addStretch(1);
+  board = new Board(w, "Board");
+  board->setFixedSize(board->sizeHint());
+  top->addWidget(board);
+  top->addStretch(1);
+
   createKActions();
   createStatusBar();
 
-  board->setFixedSize(board->sizeHint());
-  setCentralWidget(board);
-
   connect(board, SIGNAL(score()), this, SLOT(slotScore()));
-  connect(board, SIGNAL(gameWon(int)), this, SLOT(slotGameEnded(int)));
-  connect(board, SIGNAL(turn(int)), this, SLOT(slotTurn(int)));
+  connect(board, SIGNAL(gameWon(Player)), this, SLOT(slotGameEnded(Player)));
+  connect(board, SIGNAL(turn(Player)), this, SLOT(slotTurn(Player)));
   connect(board, SIGNAL(statusChange(int)), this, SLOT(slotStatusChange(int)));
   connect(board, SIGNAL(illegalMove()), this, SLOT(slotIllegalMove()));
@@ -162,14 +167,17 @@ void KReversi::configureKeyBindings(){
 }
 
-void KReversi::sizeChanged(){
-  resize(sizeHint().width(), sizeHint().height());
+bool KReversi::eventFilter(QObject *, QEvent *e)
+{
+    if ( e->type()==QEvent::LayoutHint )
+        setFixedSize(minimumSize()); // because QMainWindow and KMainWindow
+                                     // do not manage fixed central widget
+    return false;
 }
 
 void KReversi::zoomIn(){
   board->zoomIn();
-  board->setFixedSize(board->sizeHint());
   KConfig *config = kapp->config();
   config->setGroup("Game");
-  config->writeEntry("Zoom", board->getZoom());
+  config->writeEntry("Zoom", board->zoom());
 
   if(!board->canZoomIn())
@@ -181,8 +189,7 @@ void KReversi::zoomIn(){
 void KReversi::zoomOut(){
   board->zoomOut();
-  board->setFixedSize(board->sizeHint());
   KConfig *config = kapp->config();
   config->setGroup("Game");
-  config->writeEntry("Zoom", board->getZoom());
+  config->writeEntry("Zoom", board->zoom());
   if(board->canZoomIn())
     zoomInAction->setEnabled(true);
@@ -197,6 +204,6 @@ void KReversi::slotScore() {
   board->getScore(black, white);
 
-  if(board->chipsName() == "chips.png") {
-    if(board->humanIs() == Score::BLACK) {
+  if(board->chipType() == Board::Colored) {
+    if(board->humanPlayer() == Black) {
       s1 = i18n("You (blue): %1").arg(black);
       s2 = i18n("Computer (red): %1").arg(white);
@@ -206,5 +213,5 @@ void KReversi::slotScore() {
     }
   } else {
-    if(board->humanIs() == Score::BLACK) {
+    if(board->humanPlayer() == Black) {
       s1 = i18n("You (black): %1").arg(black);
       s2 = i18n("Computer (white): %1").arg(white);
@@ -219,5 +226,5 @@ void KReversi::slotScore() {
 }
 
-void KReversi::slotGameEnded(int color) {
+void KReversi::slotGameEnded(Player player) {
   QString s;
   int winner, loser;
@@ -226,21 +233,21 @@ void KReversi::slotGameEnded(int color) 
 
   // get the score
-  if(color == Score::BLACK)
+  if(player == Black)
     board->getScore(winner, loser);
   else
     board->getScore(loser, winner);
 
-  if(color == Score::NOBODY) {
-    playSound("reversi-drawn.wav");
+  if(player == Nobody) {
+    board->playSound(Board::DrawSound);
     s = i18n("Game is drawn!\n\nYou     : %1\nComputer: %2").arg(winner).arg(loser);
     KMessageBox::information(this, s, i18n("Game Ended"));
-  } else if(board->humanIs() == color) {
+  } else if(board->humanPlayer() == player) {
     // calculate score
-    int  st = board->getStrength();
+    int  st = board->strength();
     int sum = winner + loser;
     // 8 is the highest level so it is the bases for the scale.
     float score= (float)winner / sum * ((100/8)*st);
 
-    playSound("reversi-won.wav");
+    board->playSound(Board::WonSound);
     s = i18n("Congratulations, you have won!\n\nYou     : %1\nComputer: %2\nYour \
                rating %3%")
 	      .arg(winner).arg(loser).arg(score,1);
@@ -258,5 +265,5 @@ void KReversi::slotGameEnded(int color) 
     }
   } else {
-    playSound("reversi-lost.wav");
+    board->playSound(Board::LostSound);
     s = i18n("You have lost the game!\n\nYou     : %1\nComputer: %2")
 	      .arg(loser).arg(winner);
@@ -266,5 +273,5 @@ void KReversi::slotGameEnded(int color) 
 }
 
-void KReversi::slotTurn(int color) {
+void KReversi::slotTurn(Player player) {
   if (gameOver)
     return;
@@ -272,21 +279,10 @@ void KReversi::slotTurn(int color) {
   QString s;
 
-  if(board->humanIs() == Score::WHITE) {
-    if(color == Score::WHITE)
+  if(player == board->humanPlayer())
       s = i18n("Your turn");
-    else if(color == Score::BLACK)
-      s = i18n("Computer's turn");
-    else
-      s = "";
-  }
-  else
-  {
-    if(color == Score::WHITE)
+  else if(player == board->computerPlayer())
       s = i18n("Computer's turn");
-    else if(color == Score::BLACK)
-      s = i18n("Your turn");
     else
       s = "";
-  }
   statusBar()->changeItem(s, SB_TURN);
 }
@@ -305,8 +301,5 @@ void KReversi::slotStatusChange(int stat
 
 void KReversi::slotIllegalMove() {
-  if(!audioOK())
-    kapp->beep();
-  else
-    playSound("reversi-illegalmove.wav");
+    board->playSound(Board::IllegalMoveSound);
 }
 
Index: kreversi.h
===================================================================
RCS file: /home/kde/kdegames/kreversi/kreversi.h,v
retrieving revision 1.3
diff -u -2 -d -p -b -r1.3 kreversi.h
--- kreversi.h	28 Apr 2003 21:41:09 -0000	1.3
+++ kreversi.h	18 May 2003 02:58:12 -0000
@@ -42,4 +42,6 @@
 #include <kmainwindow.h>
 
+#include "Score.h"
+
 class Board;
 class KAction;
@@ -56,4 +58,5 @@ private:
   void createStatusBar();
   QString getPlayerName();
+  bool eventFilter(QObject *, QEvent *e);
 
   virtual void saveProperties(KConfig *);
@@ -62,6 +65,6 @@ private:
 private slots:
   void slotScore();
-  void slotGameEnded(int);
-  void slotTurn(int);
+  void slotGameEnded(Player);
+  void slotTurn(Player);
   void slotStatusChange(int);
   void slotIllegalMove();
@@ -73,5 +76,4 @@ private slots:
   void zoomIn();
   void zoomOut();
-  void sizeChanged();
   
   void showHighScoreDialog();
Index: pics/chips.png
===================================================================
RCS file: /home/kde/kdegames/kreversi/pics/chips.png,v
retrieving revision 1.1
diff -u -2 -d -p -b -r1.1 chips.png
Binary files /tmp/cvsbzm4K1 and chips.png differ
Index: pics/chips_mono.png
===================================================================
RCS file: /home/kde/kdegames/kreversi/pics/chips_mono.png,v
retrieving revision 1.1
diff -u -2 -d -p -b -r1.1 chips_mono.png
Binary files /tmp/cvsdwK6o3 and chips_mono.png differ


["chips_mono.png" (image/png)]
["chips.png" (image/png)]

_______________________________________________
kde-games-devel mailing list
kde-games-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-games-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic