[iagno] ComputerPlayer: own Strategy and PossibleMove



commit 9813fdf81e937ae3631e40b79e65923ba098857e
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Fri Sep 27 22:08:56 2013 -0500

    ComputerPlayer: own Strategy and PossibleMove
    
    These enums are never needed or used outside ComputerPlayer
    
    Also, give PossibleMove a constructor, for convenience

 src/computer-player.vala |   44 ++++++++++++++++++++++----------------------
 1 files changed, 22 insertions(+), 22 deletions(-)
---
diff --git a/src/computer-player.vala b/src/computer-player.vala
index 7e13dc2..ff90d47 100644
--- a/src/computer-player.vala
+++ b/src/computer-player.vala
@@ -8,22 +8,29 @@
  * license.
  */
 
-private enum Strategy
+public class ComputerPlayer : Object
 {
-    PERFECT,
-    VICTORY,
-    BEST
-}
+    private enum Strategy
+    {
+        PERFECT,
+        VICTORY,
+        BEST
+    }
 
-private struct PossibleMove
-{
-    int x;
-    int y;
-    int n_tiles;
-}
+    private struct PossibleMove
+    {
+        public int x;
+        public int y;
+        public int n_tiles;
+
+        public PossibleMove (int x, int y, int n_tiles)
+        {
+            this.x = x;
+            this.y = y;
+            this.n_tiles = n_tiles;
+        }
+    }
 
-public class ComputerPlayer : Object
-{
     /* Game being played */
     private Game game;
 
@@ -100,11 +107,7 @@ public class ComputerPlayer : Object
                 var n_tiles = g.place_tile (x, y);
                 if (n_tiles > 0)
                 {
-                    var move = PossibleMove ();
-                    move.x = x;
-                    move.y = y;
-                    //warning ("%d %d", x, y);
-                    move.n_tiles = n_tiles;
+                    var move = PossibleMove (x, y, n_tiles);
                     moves.insert_sorted (move, compare_move);
                     g.undo ();
                 }
@@ -114,10 +117,7 @@ public class ComputerPlayer : Object
         /* If no moves then pass */
         if (moves == null)
         {
-            var move = PossibleMove ();
-            move.x = 0;
-            move.y = 0;
-            move.n_tiles = 0;
+            var move = PossibleMove (0, 0, 0);
             moves.append (move);
         }
 


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