Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created March 8, 2017 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/b23732d75a2a1ab4f06242202faa37b6 to your computer and use it in GitHub Desktop.
Save deque-blog/b23732d75a2a1ab4f06242202faa37b6 to your computer and use it in GitHub Desktop.
(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