[iagno] computer-player: split searching out of move()



commit 1b5b968aad5d6225d531a2a626e731f3d56ef2aa
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Thu Sep 18 21:02:17 2014 -0500

    computer-player: split searching out of move()
    
    Let's split the move action out from the search logic, so that we can do
    more complex things in move(), like returning after a delay and running
    the search in another thread.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=736932

 src/computer-player.vala |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/src/computer-player.vala b/src/computer-player.vala
index 1b0b30b..40aedad 100644
--- a/src/computer-player.vala
+++ b/src/computer-player.vala
@@ -62,14 +62,23 @@ public class ComputerPlayer : Object
     }
 
     public void move ()
+    {
+        int x = 0;
+        int y = 0;
+
+        run_search (ref x, ref y);
+
+        if (game.place_tile (x, y) == 0)
+            critical ("Computer chose an invalid move: %d,%d", x, y);
+    }
+
+    private void run_search (ref int x, ref int y)
         requires (game.can_move (game.current_color))
     {
         /* For the first two moves play randomly so the game is not always the same */
         if (game.n_tiles < 8)
         {
-            int x, y;
             random_select (game, out x, out y);
-            game.place_tile (x, y);
             return;
         }
 
@@ -85,10 +94,8 @@ public class ComputerPlayer : Object
         /* Choose a location to place by building the tree of possible moves and
          * using the minimax algorithm to pick the best branch with the chosen
          * strategy. */
-        int x = 0, y = 0;
         search (new Game.copy (game), strategy, depth, NEGATIVE_INFINITY, POSITIVE_INFINITY, ref x, ref y);
-        if (game.place_tile (x, y) == 0)
-            critical ("Computer chose an invalid move: %d,%d", x, y);
+
     }
 
     private static int search (Game g, Strategy strategy, int depth, int a, int b, ref int move_x, ref int 
move_y)


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