Bug 90190 - KReversi: Switch sides and then Undo gets the program out of sync.
Summary: KReversi: Switch sides and then Undo gets the program out of sync.
Status: RESOLVED FIXED
Alias: None
Product: kreversi
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Inge Wallin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-24 21:42 UTC by Inge Wallin
Modified: 2004-09-26 16:04 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Inge Wallin 2004-09-24 21:42:48 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources

(Setting: black/white pieces)

If you choose Move->Switch Sides, then the computer becomes Black and makes the first move.  If you then chooses Undo the computers takes back the move it just made, but it doesn't understand that it is still the computers move.

Instead, the game locks up, with the computer not moving and the human unable to do it.

The same happens if Switch Sides is chosen later in the game and the game is undone to the beginning.
Comment 1 Inge Wallin 2004-09-26 16:04:27 UTC
CVS commit by ingwa: 

Fix Bug 90190: KReversi: Switch sides and then Undo gets the program
out of sync.

 - If it is the computers turn to move after an undo, call computerMakeMove().
 - Fix repainting so that it looks nice.

I will backport to KDE_3_3_BRANCH.

CCMAIL: 90190-done@bugs.kde.org


  M +9 -1      ChangeLog   1.38
  M +18 -1     board.cpp   1.48


--- kdegames/kreversi/ChangeLog  #1.37:1.38
@@ -1,2 +1,10 @@
+2004-09-26  Inge Wallin  <ingwa@c83-250-5-110.bredband.comhem.se>
+
+        Fix Bug 90190: KReversi: Switch sides and then Undo gets the
+        program out of sync.
+        * board.cpp (doUndo): If it is the computers turn to move after an
+        undo, call computerMakeMove().
+        (doUndo): Fix repainting so that it looks nice.
+
 2004-09-25  Inge Wallin  <inge@lysator.liu.se>
 
@@ -40,5 +48,5 @@
         Tested Inges fix and found it works well.
         
-2004-09-22  Inge Wallin  <ing@lysator.liu.se>
+2004-09-22  Inge Wallin  <inge@lysator.liu.se>
 
         Fix bug 89829: "KReversi: When you save a game, the color for

--- kdegames/kreversi/board.cpp  #1.47:1.48
@@ -371,10 +371,27 @@ void Board::doUndo()
     return;
 
+  // Can't undo anything if no moves are made.
+  if (m_game->moveNumber() == 0)
+    return;
+
+  // Get the color of the last move.  
   Color last_color = m_game->lastMove().color();
+
+  // Undo all moves of the same color as the last one.
   while (m_game->moveNumber() != 0
          && last_color == m_game->lastMove().color())
     m_game->TakeBackMove();
 
+  // Take back one move more.
   m_game->TakeBackMove();
+
+
+  if (m_game->toMove() == computerColor()) {
+    // Must repaint so that the new move is not shown before the old
+    // one is removed on the screen.
+    repaint();
+    computerMakeMove();
+  }
+  else
   update();
 }