[iagno] Remove the even board constraint.
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] Remove the even board constraint.
- Date: Wed, 1 Oct 2014 17:03:21 +0000 (UTC)
commit ba8c254f47d04292025c3c2a6688578ac6cdcc3f
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Wed Oct 1 13:31:30 2014 +0200
Remove the even board constraint.
https://bugzilla.gnome.org/show_bug.cgi?id=737715
data/iagno.6 | 2 +-
src/computer-player.vala | 4 ++--
src/game.vala | 33 ++++++++++++++++++++++++++-------
src/iagno.vala | 4 ++--
4 files changed, 31 insertions(+), 12 deletions(-)
---
diff --git a/data/iagno.6 b/data/iagno.6
index d63cda7..9d259b3 100644
--- a/data/iagno.6
+++ b/data/iagno.6
@@ -65,7 +65,7 @@ If the two options are given, the game is muted.
.RE
.TP
.B \-s, \-\-size=<size>
-Changes the size of the board. The size must be even and at least 4.
+Changes the size of the board. The size must be at least 4.
.br
This option is for debugging only. The AI may not perform optimally.
.TP
diff --git a/src/computer-player.vala b/src/computer-player.vala
index 71cb5a3..93bea41 100644
--- a/src/computer-player.vala
+++ b/src/computer-player.vala
@@ -166,8 +166,8 @@ public class ComputerPlayer : Object
private void run_search (ref int x, ref int y)
requires (game.current_player_can_move)
{
- /* For the first two moves play randomly so the game is not always the same */
- if (game.n_tiles < 8)
+ /* For the first/first two moves play randomly so the game is not always the same */
+ if (game.n_tiles < game.initial_number_of_tiles + (game.size < 6 ? 2 : 4))
{
random_select (game, out x, out y);
return;
diff --git a/src/game.vala b/src/game.vala
index cb56f1f..73712eb 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -43,6 +43,7 @@ public class Game : Object
* * Number of tiles on the board
\*/
+ public int initial_number_of_tiles { get; private set; }
public int n_tiles
{
get { return n_dark_tiles + n_light_tiles; }
@@ -88,7 +89,6 @@ public class Game : Object
public Game (int tmp_size = 8)
requires (tmp_size >= 4)
- requires (tmp_size % 2 == 0)
{
size = tmp_size;
tiles = new Player[size, size];
@@ -101,15 +101,34 @@ public class Game : Object
* and you could flip max ((size - 2) * 3) tiles in one turn. */
undo_stack = new int?[180 * (size - 1)]; /* (3 + (size - 2) * 3) * 60 */
- /* Setup board with four tiles by default */
- tiles [size / 2 - 1, size / 2 - 1] = Player.LIGHT;
- tiles [size / 2 - 1, size / 2] = Player.DARK;
- tiles [size / 2, size / 2 - 1] = Player.DARK;
- tiles [size / 2, size / 2] = Player.LIGHT;
+ if (size % 2 == 0)
+ {
+ /* Setup board with four tiles by default */
+ initial_number_of_tiles = 4;
+ tiles [size / 2 - 1, size / 2 - 1] = Player.LIGHT;
+ tiles [size / 2 - 1, size / 2] = Player.DARK;
+ tiles [size / 2, size / 2 - 1] = Player.DARK;
+ tiles [size / 2, size / 2] = Player.LIGHT;
+ n_current_tiles = 2;
+ n_opponent_tiles = 2;
+ }
+ else
+ {
+ /* Logical starting position for odd board */
+ initial_number_of_tiles = 7;
+ tiles [(size - 1) / 2, (size - 1) / 2] = Player.DARK;
+ tiles [(size + 1) / 2, (size - 3) / 2] = Player.DARK;
+ tiles [(size - 3) / 2, (size + 1) / 2] = Player.DARK;
+ tiles [(size - 1) / 2, (size - 3) / 2] = Player.LIGHT;
+ tiles [(size - 3) / 2, (size - 1) / 2] = Player.LIGHT;
+ tiles [(size + 1) / 2, (size - 1) / 2] = Player.LIGHT;
+ tiles [(size - 1) / 2, (size + 1) / 2] = Player.LIGHT;
+ n_current_tiles = 3;
+ n_opponent_tiles = 4;
+ }
}
public Game.from_strings (string[] setup, Player to_move, int tmp_size = 8)
- requires (tmp_size >= 4)
requires (setup.length == tmp_size)
{
size = tmp_size;
diff --git a/src/iagno.vala b/src/iagno.vala
index f505cc4..0376fd3 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -113,10 +113,10 @@ public class Iagno : Gtk.Application
return Posix.EXIT_SUCCESS;
}
- if (size < 4 || size % 2 != 0)
+ if (size < 4)
{
/* Console message displayed for an incorrect size */
- stderr.printf ("%s\n", _("Size must be even and at least 4."));
+ stderr.printf ("%s\n", _("Size must be at least 4."));
return Posix.EXIT_FAILURE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]