[four-in-a-row] Tweak count_3_in_a_row method.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [four-in-a-row] Tweak count_3_in_a_row method.
- Date: Thu, 26 Dec 2019 17:12:25 +0000 (UTC)
commit a205a7f4746c11b1e6b5543f32ad9ea86624034d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Tue Dec 24 14:32:26 2019 +0100
Tweak count_3_in_a_row method.
src/ai.vala | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/src/ai.vala b/src/ai.vala
index 0a2709e..2d90c84 100644
--- a/src/ai.vala
+++ b/src/ai.vala
@@ -327,15 +327,15 @@ private class DecisionTree
private int heurist_hard ()
{
- int count = count_3_in_a_row (Player.OPPONENT) - count_3_in_a_row (Player.HUMAN);
- return count == 0 ? (int) Random.int_range (1, 49) : count * 100;
+ int8 count = count_3_in_a_row (Player.OPPONENT) - count_3_in_a_row (Player.HUMAN);
+ return count == 0 ? (int) Random.int_range (1, 49) : (int) count * 100;
}
- /* Count the number of threes in a row for Player P. It counts all those 3 which have an empty cell in
the vicinity to make it
- four in a row. */
- private int count_3_in_a_row (Player p)
+ /* Count the number of threes in a row for Player P. It counts all those 3
+ which have an empty cell in the vicinity to make it four in a row. */
+ private int8 count_3_in_a_row (Player p)
{
- int count = 0;
+ int8 count = 0;
Player old_last_moving_player = last_moving_player;
@@ -354,7 +354,12 @@ private class DecisionTree
board [i, j] = p;
if (victory (j))
- count++;
+ {
+ if (count < int8.MAX)
+ count++;
+ else
+ warning ("Method count_3_in_a_row() exceeded its maximum count.");
+ }
board [i, j] = Player.NOBODY;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]