Last active
March 8, 2017 19:36
-
-
Save deque-blog/5ca000507c2a8591810fe018ea385042 to your computer and use it in GitHub Desktop.
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- 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