[iagno/gnome-3-14] computer-player: on level one, try to lose
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno/gnome-3-14] computer-player: on level one, try to lose
- Date: Sun, 21 Sep 2014 23:40:12 +0000 (UTC)
commit e7d4fec5d261033402db0520aaf4faf5e643bb89
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Thu Sep 18 23:57:13 2014 -0500
computer-player: on level one, try to lose
After fixing some AI bugs, it's now just too hard to win. This AI seems
to be easy enough. We could probably make it easier by inverting the
BEST heuristic instead of the PERFECT heuristic, but that seems
unnecessary.
https://bugzilla.gnome.org/show_bug.cgi?id=736938
src/computer-player.vala | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/src/computer-player.vala b/src/computer-player.vala
index 0e1b885..cb091cc 100644
--- a/src/computer-player.vala
+++ b/src/computer-player.vala
@@ -15,7 +15,8 @@ public class ComputerPlayer : Object
{
PERFECT,
VICTORY,
- BEST
+ BEST,
+ WORST
}
private struct PossibleMove
@@ -80,15 +81,17 @@ public class ComputerPlayer : Object
* At the end of the game try and maximise the number of tokens.
* Near the end try and push for a win.
* For the rest of the game try and maximise everything.
- * Note, for level 1 we default to the "PERFECT" strategy, which is not as
- * good as the "BEST" strategy, so as not to make the AI too difficult.
+ * Note, for level 1 we deliberately play badly.
*/
- var strategy = (level == 1) ? Strategy.PERFECT : Strategy.BEST;
+ var strategy = Strategy.BEST;
if (tiles_remaining <= depth + 10)
strategy = Strategy.PERFECT;
else if (tiles_remaining <= depth + 12)
strategy = Strategy.VICTORY;
+ if (level == 1)
+ strategy = Strategy.WORST;
+
/* 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. */
@@ -193,6 +196,10 @@ public class ComputerPlayer : Object
case Strategy.VICTORY:
return tile_difference.clamp (-1, 1);
+ /* Try to lose */
+ case Strategy.WORST:
+ return -tile_difference;
+
/* Try to maximise a number of values */
default:
return tile_difference + eval_heuristic (g) + around (g) ;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]