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 [] | |
[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