(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))))))