From 967974665fb2375924c454e25448c837af1b6586 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Fri, 21 Jan 2022 20:01:07 -0500 Subject: Added a strategy Added strategy which will try to minimize the potential flips for the opponents next turn. --- strategies/least-potential-for-opponents-next-move.scm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 strategies/least-potential-for-opponents-next-move.scm 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)))))) -- cgit v1.2.3