This file contains hidden or 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
new-init-turn :: IO Turn | |
transitions :: Turn -> Map Coord Transition | |
next-turn :: Turn -> Transition -> Turn |
This file contains hidden or 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
new-game :: IO Game | |
current-turn :: Game -> Turn | |
play-at :: Game -> Coord -> Game | |
undo-player-move :: Game -> Game |
This file contains hidden or 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
(s/def ::turn | |
(s/keys :req-un | |
[::board/board | |
::player/player | |
::scores/scores])) |
This file contains hidden or 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
(s/fdef new-init-turn | |
:ret ::turn) | |
(s/def ::turn-data | |
(s/keys :req-un | |
[::board/board | |
::player/player | |
::scores/scores])) | |
(defn new-init-turn [] |
This file contains hidden or 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
(s/fdef next-turn | |
:args (s/cat | |
:turn ::turn | |
:transition ::transition/transition) | |
:ret ::turn) |
This file contains hidden or 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
(defprotocol ITurn | |
(-next-turn [turn transition] "Move to the next turn of the game") | |
(-transitions [turn] "Provides the list of transitions to next turns") | |
(-turn-status [turn] "Provides the status of the board, player and scores")) | |
;; The turn that is being manipulated in the API | |
(s/def ::turn | |
#(satisfies? ITurn %)) | |
;; Instantiate a new turn (for example with reify) |
This file contains hidden or 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
;; Transition by destination | |
(s/map-of ::transition/destination ::transition/transition) | |
;; Resulting turn by destination (after realizing each transition) | |
(s/map-of ::transition/destination ::turn) |
This file contains hidden or 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 next-turn-gen | |
"Generator for a valid next turn from a previous valid turn" | |
[turn] | |
(gen/fmap | |
#(turn/next-turn turn %) | |
(gen/elements (vals (turn/transitions turn))))) | |
(gen/sample (next-turn-gen (turn/new-init-turn)) 1) | |
=> ;; Output not displayed since is a bit long |
This file contains hidden or 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
(s/def ::left ::bad-binary-tree) | |
(s/def ::right ::bad-binary-tree) | |
(s/def ::bad-binary-tree | |
(s/cat | |
:value any? | |
:children (s/keys :opt [::left ::right]))) |
This file contains hidden or 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
(s/def ::scores | |
(s/map-of #{:blue :red :green} int?)) |