[iagno] Fix infinite loop when neither side has valid move



commit f58e4af7610cb22030855a2ab107ce69ba64701f
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 2998983..b1fd33a 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -19,7 +19,7 @@ public class Game
 {
     /* Tiles on the board */
     public Player[,] tiles;
-    
+
     public int width
     {
         get { return tiles.length[0]; }
@@ -90,9 +90,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]