[iagno] Little things in computer-player.vala.
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] Little things in computer-player.vala.
- Date: Wed, 24 Sep 2014 13:38:34 +0000 (UTC)
commit 84eb5d30936a2bfc263f0692825602080d69ceff
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Sep 22 07:59:51 2014 +0200
Little things in computer-player.vala.
https://bugzilla.gnome.org/show_bug.cgi?id=736934
src/computer-player.vala | 12 ++++++------
src/game.vala | 11 ++++++-----
2 files changed, 12 insertions(+), 11 deletions(-)
---
diff --git a/src/computer-player.vala b/src/computer-player.vala
index 649edea..e40b27a 100644
--- a/src/computer-player.vala
+++ b/src/computer-player.vala
@@ -68,7 +68,7 @@ public class ComputerPlayer : Object
{
if (game.place_tile (x, y) == 0)
{
- critical ("Computer chose an invalid move: %d,%d", x, y);
+ critical ("Computer chose an invalid move: %d,%d\n%s", x, y, game.to_string ());
assert_not_reached ();
}
}
@@ -207,7 +207,7 @@ public class ComputerPlayer : Object
}
else if (g.place_tile (move.x, move.y) == 0)
{
- critical ("Computer marked move (depth %d, %d,%d, %d flips) as valid, but is invalid when
checking", depth, move.x, move.y, move.n_tiles);
+ critical ("Computer marked move (depth %d, %d,%d, %d flips) as valid, but is invalid when
checking.\n%s", depth, move.x, move.y, move.n_tiles, g.to_string ());
assert_not_reached ();
}
@@ -236,7 +236,7 @@ public class ComputerPlayer : Object
private static int calculate_heuristic (Game g, Strategy strategy)
{
- var tile_difference = g.current_color == Player.DARK ? g.n_dark_tiles - g.n_light_tiles :
g.n_light_tiles - g.n_dark_tiles;
+ var tile_difference = g.n_current_tiles - g.n_opponent_tiles;
switch (strategy)
{
@@ -308,10 +308,10 @@ public class ComputerPlayer : Object
private static int is_empty (Game g, int x, int y)
{
- if (x < 0 || x >= g.size || y < 0 || y >= g.size || g.get_owner (x, y) != Player.NONE)
- return 0;
+ if (g.is_valid_location (x, y) && g.get_owner (x, y) == Player.NONE)
+ return 1;
- return 1;
+ return 0;
}
private static void random_select (Game g, out int move_x, out int move_y)
diff --git a/src/game.vala b/src/game.vala
index f996b12..927b813 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -67,6 +67,7 @@ public class Game : Object
_n_dark_tiles = value;
}
}
+
public int n_opponent_tiles
{
get { return current_color == Player.DARK ? n_light_tiles : n_dark_tiles; }
@@ -156,6 +157,11 @@ public class Game : Object
* * Public information
\*/
+ public bool is_valid_location (int x, int y)
+ {
+ return x >= 0 && x < size && y >= 0 && y < size;
+ }
+
public Player get_owner (int x, int y)
requires (is_valid_location (x, y))
{
@@ -247,11 +253,6 @@ public class Game : Object
* * Flipping tiles
\*/
- private bool is_valid_location (int x, int y)
- {
- return x >= 0 && x < size && y >= 0 && y < size;
- }
-
private int flip_tiles (int x, int y, int x_step, int y_step, Player color, bool apply)
{
var enemy = Player.flip_color (color);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]