[iagno] Improvement.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] Improvement.
- Date: Wed, 22 May 2019 13:00:47 +0000 (UTC)
commit 0fe9fca57d67a5ef1300685e5c1dac62f8ea736a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu May 2 15:50:06 2019 +0200
Improvement.
src/game.vala | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/src/game.vala b/src/game.vala
index 008a16f..4e3d230 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -120,12 +120,19 @@ private class GameState : Object
_n_light_tiles++;
}
- private void remove_tile_of_opponent_color (Player color)
+ private void flip_tile_to_color (Player color)
{
if (color == Player.LIGHT)
+ {
_n_dark_tiles--;
+ _n_light_tiles++;
+ }
else if (color == Player.DARK)
+ {
_n_light_tiles--;
+ _n_dark_tiles++;
+ }
+ else assert_not_reached ();
}
/*\
@@ -173,10 +180,10 @@ private class GameState : Object
private uint8 place_tile (uint8 x, uint8 y, Player color, bool apply)
requires (is_valid_location_unsigned (x, y))
{
- if (tiles [x, y] != Player.NONE)
- return 0;
if (empty_neighbors [x, y] == neighbor_tiles [x, y])
return 0;
+ if (tiles [x, y] != Player.NONE)
+ return 0;
uint8 tiles_turned = 0;
tiles_turned += flip_tiles (x, y, color, 1, 0, apply);
@@ -300,7 +307,7 @@ private class GameState : Object
{
if (!is_valid_location_signed (x, y))
return 0;
- if (get_owner ((uint8) x, (uint8) y) != Player.NONE)
+ if (tiles [x, y] != Player.NONE)
return 0;
return 1;
@@ -310,8 +317,8 @@ private class GameState : Object
{
int8 xmm = ((int8) x) - 1;
int8 ymm = ((int8) y) - 1;
- int8 xpp = ((int8) x) + 1;
- int8 ypp = ((int8) y) + 1;
+ int8 xpp = xmm + 2;
+ int8 ypp = ymm + 2;
bool ymm_is_valid = ymm >= 0;
bool ypp_is_valid = ypp < size;
@@ -346,8 +353,7 @@ private class GameState : Object
{
for (int8 i = 1; i <= enemy_count; i++)
{
- remove_tile_of_opponent_color (color);
- add_tile_of_color (color);
+ flip_tile_to_color (color);
tiles [(int8) x + (i * x_step),
(int8) y + (i * y_step)] = color;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]