Created
March 8, 2017 22:36
-
-
Save deque-blog/b23732d75a2a1ab4f06242202faa37b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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