[iagno] More optimisations.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] More optimisations.
- Date: Wed, 22 May 2019 13:00:42 +0000 (UTC)
commit 74a2008e9729f023ada98d89608d8b82511c2f1c
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu May 2 14:49:09 2019 +0200
More optimisations.
src/computer-reversi.vala | 2 +-
src/game.vala | 30 ++++++++----------------------
2 files changed, 9 insertions(+), 23 deletions(-)
---
diff --git a/src/computer-reversi.vala b/src/computer-reversi.vala
index 64d499c..793d1c3 100644
--- a/src/computer-reversi.vala
+++ b/src/computer-reversi.vala
@@ -94,7 +94,7 @@ private class ComputerReversi : ComputerPlayer
/* Choose a location to place by building the tree of possible moves and
* using the minimax algorithm to pick the best branch with the chosen
* strategy. */
- GameState g = new GameState.copy (game.current_state);
+ GameState g = game.current_state;
/* The search sometimes returns NEGATIVE_INFINITY. */
int16 a = LESS_THAN_NEGATIVE_INFINITY;
diff --git a/src/game.vala b/src/game.vala
index bec5fb5..008a16f 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -47,22 +47,9 @@ private class GameState : Object
private Player [,] tiles;
private unowned uint8 [,] neighbor_tiles;
- internal GameState.copy (GameState game)
- {
- Object (size: game.size, current_color: game.current_color);
- neighbor_tiles = game.neighbor_tiles;
- empty_neighbors = game.empty_neighbors;
- tiles = game.tiles;
- _n_light_tiles = game._n_light_tiles;
- _n_dark_tiles = game._n_dark_tiles;
-
- update_who_can_move ();
- if (current_player_can_move != game.current_player_can_move
- || is_complete != game.is_complete)
- assert_not_reached ();
- }
-
internal GameState.copy_and_pass (GameState game)
+ requires (!game.current_player_can_move)
+ requires (!game.is_complete)
{
Object (size: game.size, current_color: Player.flip_color (game.current_color));
neighbor_tiles = game.neighbor_tiles;
@@ -70,11 +57,8 @@ private class GameState : Object
tiles = game.tiles;
_n_light_tiles = game._n_light_tiles;
_n_dark_tiles = game._n_dark_tiles;
-
- // we already know all that, it is just for checking
- update_who_can_move ();
- if (!current_player_can_move || is_complete)
- assert_not_reached ();
+ current_player_can_move = true;
+ is_complete = false;
}
internal GameState.copy_and_move (GameState game, uint8 move_x, uint8 move_y)
@@ -237,6 +221,8 @@ private class GameState : Object
current_player_can_move = true;
return;
}
+ if (opponent_can_move)
+ continue;
if (can_place (x, y, enemy))
opponent_can_move = true;
}
@@ -254,10 +240,10 @@ private class GameState : Object
private bool can_place (uint8 x, uint8 y, Player color)
{
- if (tiles [x, y] != Player.NONE)
- return false;
if (empty_neighbors [x, y] == neighbor_tiles [x, y])
return false;
+ if (tiles [x, y] != Player.NONE)
+ return false;
if (can_flip_tiles (x, y, color, 1, 0) > 0) return true;
if (can_flip_tiles (x, y, color, 1, 1) > 0) return true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]