summaryrefslogtreecommitdiff
path: root/strategies/least-potential-for-opponents-next-move.scm
blob: 4c62c7ca2d2539c5dd2e7ed6efe3cec358e6e9d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
(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))))))