summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2022-01-21 20:01:07 -0500
committerRobby Zambito <contact@robbyzambito.me>2022-01-21 20:01:07 -0500
commit967974665fb2375924c454e25448c837af1b6586 (patch)
tree188787233e729e2f02e14039a7055d39ff019914
parent42a6b86d27751b3dec95dd64b4996ea13ad58a10 (diff)
Added a strategy
Added strategy which will try to minimize the potential flips for the opponents next turn.
-rw-r--r--strategies/least-potential-for-opponents-next-move.scm17
1 files changed, 17 insertions, 0 deletions
diff --git a/strategies/least-potential-for-opponents-next-move.scm b/strategies/least-potential-for-opponents-next-move.scm
new file mode 100644
index 0000000..edd36d8
--- /dev/null
+++ b/strategies/least-potential-for-opponents-next-move.scm
@@ -0,0 +1,17 @@
+(use-modules (srfi srfi-1))
+
+; The potential is the total amount of flips that a player can do by all of
+; their possible moves.
+(define (potential board player)
+ (fold +
+ 0
+ (map (lambda (move) (flipped-by-move move board player))
+ (valid-moves board player))))
+
+
+; Sort the valid moves by the one which, when applied, leaves the opponent with
+; the minimum ability to flip on their next turn.
+(first (sort (valid-moves)
+ (lambda (a b)
+ (< (potential (apply-move a) (other-player))
+ (potential (apply-move b) (other-player))))))