[iagno] Improve a bit AI.



commit 77a7f1adfa523cf667a0873c4846d775cd21d557
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Aug 3 17:56:59 2019 +0200

    Improve a bit AI.

 src/computer-reversi.vala | 56 ++++++++++++++---------------------------------
 src/game.vala             |  4 ++--
 2 files changed, 19 insertions(+), 41 deletions(-)
---
diff --git a/src/computer-reversi.vala b/src/computer-reversi.vala
index 798d81d..91521ce 100644
--- a/src/computer-reversi.vala
+++ b/src/computer-reversi.vala
@@ -144,49 +144,27 @@ private class ComputerReversiHard : ComputerReversi
         uint8 size = g.size;
         int16 count = 0;
 
-        bool is_move_color;
-        if (even_depth)
-            for (uint8 x = 0; x < size; x++)
-                for (uint8 y = 0; y < size; y++)
-                {
-                    is_move_color = !g.is_current_color (x, y);
+        for (uint8 x = 0; x < size; x++)
+            for (uint8 y = 0; y < size; y++)
+            {
+                int16 a = (int16) g.get_empty_neighbors (x, y);
+                if (a == 0) // completely surrounded
+                    a = -6;
 
-                    // heuristic
-                    if (is_move_color)
-                        count -= heuristic [x, y];
-                    else
-                        count += heuristic [x, y];
-
-                    // around
-                    int16 a = (int16) g.get_empty_neighbors (x, y);
-                    if (a == 0) // completely surrounded
-                        a = -6;
-                    if (is_move_color)
-                        count += 9 * a;
-                    else
-                        count -= 9 * a;
-                }
-        else
-            for (uint8 x = 0; x < size; x++)
-                for (uint8 y = 0; y < size; y++)
+                int16 tile_heuristic = heuristic [x, y] - 9 * a;
+                if (g.is_empty_tile (x, y))
                 {
-                    is_move_color = g.is_opponent_color (x, y);
-
-                    // heuristic
-                    if (is_move_color)
-                        count -= heuristic [x, y];
+                    tile_heuristic /= 2;
+                    if (even_depth)
+                        count -= tile_heuristic;
                     else
-                        count += heuristic [x, y];
-
-                    // around
-                    int16 a = (int16) g.get_empty_neighbors (x, y);
-                    if (a == 0) // completely surrounded
-                        a = -6;
-                    if (is_move_color)
-                        count += 9 * a;
-                    else
-                        count -= 9 * a;
+                        count += tile_heuristic;
                 }
+                else if (g.is_current_color (x, y))
+                    count += tile_heuristic;
+                else
+                    count -= tile_heuristic;
+            }
 
         return count;
     }
diff --git a/src/game.vala b/src/game.vala
index 660d4ef..11d8b21 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -168,10 +168,10 @@ private struct GameStateStruct
         return tiles [x, y] == current_color;
     }
 
-    internal inline bool is_opponent_color (uint8 x, uint8 y)
+    internal inline bool is_empty_tile (uint8 x, uint8 y)
      // requires (is_valid_location_unsigned (x, y))
     {
-        return tiles [x, y] == opponent_color;
+        return tiles [x, y] == Player.NONE;
     }
 
     private inline bool is_valid_location_signed (int8 x, int8 y)


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