Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(defn new-game []
(list (turn/new-init-turn)))
(defn current-turn
"Return the current state of the game:
* Board (cells and owners)
* Player score
* Next player to play"
[game]
(first game))
(defn play-at
"Play a move, adding a new turn into the game"
[game coord]
(let [curr-turn (current-turn game)]
(if-let [transition (get (turn/transitions curr-turn) coord)]
(conj game (turn/next-turn curr-turn transition))
game)))
(defn undo-player-move
"Cancel the last player move, getting back to the previous player move"
[game]
(let [new-game (drop-while (comp player/is-ai? :player) (drop 1 game))]
(if (empty? new-game)
(take-last 1 game)
new-game)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.