Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active Mar 3, 2017
Embed
What would you like to do?
(defn new-game []
[turn/start-turn])
(defn current-turn
[game]
(peek game))
(defn play-move
"Play current player move at the provided coordinate"
[game coord]
(if-let [new-turn (turn/next-turn (current-turn game) coord)]
(conj game new-turn)
game))
(defn undo-last-move
"Remove the last game if there is enough game played"
[game]
(if (< 1 (count game)) (pop game) game))
(defn handle-event
"Callback to dispath the event on the game"
[game event]
(cond
(= event :restart) (new-game)
(= event :undo) (undo-last-move game)
:else (play-move game event)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment