Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active March 3, 2017 21:05
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/ffce2d2403ba23ef3516fb417f8b246b to your computer and use it in GitHub Desktop.
Save deque-blog/ffce2d2403ba23ef3516fb417f8b246b to your computer and use it in GitHub Desktop.
(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