Skip to content

Instantly share code, notes, and snippets.

new-init-turn :: IO Turn
transitions :: Turn -> Map Coord Transition
next-turn :: Turn -> Transition -> Turn
new-game :: IO Game
current-turn :: Game -> Turn
play-at :: Game -> Coord -> Game
undo-player-move :: Game -> Game
(s/def ::turn
(s/keys :req-un
[::board/board
::player/player
::scores/scores]))
(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 []
(s/fdef next-turn
:args (s/cat
:turn ::turn
:transition ::transition/transition)
:ret ::turn)
(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)
;; Transition by destination
(s/map-of ::transition/destination ::transition/transition)
;; Resulting turn by destination (after realizing each transition)
(s/map-of ::transition/destination ::turn)
(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
(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])))
(s/def ::scores
(s/map-of #{:blue :red :green} int?))