blob: edd36d85429cc37b60b18a4e0ca579f6d09f12c7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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))))))
|