Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active March 8, 2017 19:36
Show Gist options
  • Save deque-blog/5ca000507c2a8591810fe018ea385042 to your computer and use it in GitHub Desktop.
Save deque-blog/5ca000507c2a8591810fe018ea385042 to your computer and use it in GitHub Desktop.
(defn- who-can-play
"Given the current player and the transitions for the next turn,
returns the next player that has at least one transition available"
[player transitions]
(filter ;; Keep only the players which
#(contains? transitions %) ;; have at least a valid move to play
(player/next-three player))) ;; from the next three players
(defn- with-next-player
"Complete the turn to compute to find the next player than can act
* Requires to look-ahead for the next possible transitions
* To save computation, keep this look-ahead available"
[{:keys [board player] :as turn}]
(let [transitions (transition/all-transitions board)
next-player (first (who-can-play player transitions))]
(merge turn
{:transitions (get transitions next-player) ;; Keep the transitions of player
:player next-player}))) ;; Inside the turn (caching)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment