[iagno/gnome-3-8] Fix infinite loop when neither side has valid move



commit 7557806a0037fc8fba347c5c8325757977ade0ff
Author: John Cheetham <developer johncheetham com>
Date:   Thu Jun 13 18:32:43 2013 +0100

    Fix infinite loop when neither side has valid move
    
    If neither side can move while unoccupied squares still exist iagno
    goes into an infinite loop.
    
    This is a fix for bug https://bugzilla.gnome.org/show_bug.cgi?id=701122

 src/game.vala |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/src/game.vala b/src/game.vala
index d6430ac..a068e54 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -9,7 +9,7 @@ public class Game
 {
     /* Tiles on the board */
     public Player[,] tiles;
-    
+
     public int width
     {
         get { return tiles.length[0]; }
@@ -80,9 +80,29 @@ public class Game
         }
     }
 
+    /* Game is complete if neither side can move */ 
     public bool is_complete
-    {
-        get { return n_tiles == width * height || n_light_tiles == 0 || n_dark_tiles == 0; }
+    {      
+       get
+       {
+           var save_color = current_color;
+           current_color = Player.DARK;
+           if (can_move)
+           {
+               current_color = save_color;
+               return false;
+           }
+
+           current_color = Player.LIGHT;
+           if (can_move)
+           {
+               current_color = save_color;
+               return false;
+           }
+            
+           current_color = save_color;
+           return true; 
+       }
     }
 
     public Game (int width = 8, int height = 8)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]