Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active March 14, 2017 13:21
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/25ac8379e9d2c8bb2e954b651c88fec4 to your computer and use it in GitHub Desktop.
Save deque-blog/25ac8379e9d2c8bb2e954b651c88fec4 to your computer and use it in GitHub Desktop.
(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)
(s/fdef new-init-turn
:ret ::turn)
;; Moving from one turn to the next
(s/fdef next-turn
:args (s/cat :turn ::turn
:transition ::transition/transition)
:ret ::turn)
;; Getting the transitions to the next turns
(s/fdef transitions
:args (s/cat :turn ::turn)
:ret (s/map-of ::transition/destination ::transition/transition))
;; The data that we can retrieve from a turn
(s/def ::turn-data
(s/keys :req-un
[::board/board
::player/player
::scores/scores]))
;; A way to retrieve the current state information
(s/fdef turn->info
:args (s/cat :turn ::turn)
:ret ::turn-data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment