[iagno] Optimization and clarification.



commit 727ea681cb496af6ef4a9d0a0fdd68c457f467a6
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Aug 3 10:40:18 2019 +0200

    Optimization and clarification.

 src/computer-reversi.vala | 67 +++++++++++++++++++++++++++++++----------------
 1 file changed, 45 insertions(+), 22 deletions(-)
---
diff --git a/src/computer-reversi.vala b/src/computer-reversi.vala
index ad4e1ea..798d81d 100644
--- a/src/computer-reversi.vala
+++ b/src/computer-reversi.vala
@@ -143,28 +143,51 @@ private class ComputerReversiHard : ComputerReversi
     {
         uint8 size = g.size;
         int16 count = 0;
-        for (uint8 x = 0; x < size; x++)
-        {
-            for (uint8 y = 0; y < size; y++)
-            {
-                bool is_move_color = (even_depth && !g.is_current_color (x, y)) || g.is_opponent_color (x, 
y);
-
-                // 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;
-            }
-        }
+
+        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);
+
+                    // 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++)
+                {
+                    is_move_color = g.is_opponent_color (x, y);
+
+                    // 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;
+                }
+
         return count;
     }
 


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