[iagno] ComputerPlayer: game over should be max alpha/beta
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] ComputerPlayer: game over should be max alpha/beta
- Date: Sat, 28 Sep 2013 23:41:28 +0000 (UTC)
commit 769c6cb1576cd707e51278065ca2c9be481d3bd5
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Fri Sep 27 23:20:24 2013 -0500
ComputerPlayer: game over should be max alpha/beta
src/computer-player.vala | 22 ++++++++++++++++++++--
src/game.vala | 2 +-
2 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/src/computer-player.vala b/src/computer-player.vala
index 32b9df5..bd50c14 100644
--- a/src/computer-player.vala
+++ b/src/computer-player.vala
@@ -95,7 +95,7 @@ public class ComputerPlayer : Object
private static int search (Game g, Strategy strategy, int depth, int a, int b, int p, ref int move_x,
ref int move_y)
{
/* If the end of the search depth or end of the game calculate how good a result this is */
- if (depth == 0 || g.is_complete ())
+ if (depth == 0)
return calculate_heuristic (g, strategy);
/* Find all possible moves and sort from most new tiles to least new tiles */
@@ -105,12 +105,30 @@ public class ComputerPlayer : Object
for (var y = 0; y < 8; y++)
{
var n_tiles = g.place_tile (x, y);
- if (n_tiles > 0)
+
+ if (g.is_complete ())
+ {
+ move_x = x;
+ move_y = y;
+
+ if (g.count_tiles (g.current_color) > g.count_tiles (Player.flip_color
(g.current_color)))
+ {
+ g.undo ();
+ return p > 0 ? int.MAX : int.MIN;
+ }
+ else
+ {
+ g.undo ();
+ return p > 0 ? int.MIN : int.MAX;
+ }
+ }
+ else if (n_tiles > 0)
{
var move = PossibleMove (x, y, n_tiles);
moves.insert_sorted (move, compare_move);
g.undo ();
}
+ /* Do not undo if place_tile failed */
}
}
diff --git a/src/game.vala b/src/game.vala
index 9a8b0e9..f0fa393 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -190,7 +190,7 @@ public class Game : Object
return n_flips;
}
- private int count_tiles (Player color)
+ public int count_tiles (Player color)
{
var count = 0;
for (var x = 0; x < width; x++)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]