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-board | |
:ret ::board) | |
(s/fdef convert-cell | |
:args (s/cat :board ::board | |
:coord ::coord | |
:owner ::player/player) | |
:ret ::board) | |
(s/fdef get-owner-at |
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
(def coordinates | |
(vec (for [x (range width) | |
y (range height)] | |
[x y]))) | |
(s/def ::coord (set coordinates)) |
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 zip | |
"Create a sequence of tuples, each element being drawn from one collection" | |
[& colls] | |
(apply map vector colls)) | |
(defn pick-n-of-each | |
"Pick n `elements` for each of the `groups` starting from the beginning" | |
[n elements groups] | |
(zip elements (mapcat #(repeat n %) groups))) |
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
(deftest test-pick-n-of-each | |
(let [pick-n-of-each (comp vec algo/pick-n-of-each)] | |
(testing "Varying number of each group" | |
(are | |
[expected n] (= expected (pick-n-of-each n (range) [:a :b])) | |
[] 0 | |
[[0 :a] [1 :b]] 1 | |
[[0 :a] [1 :a] [2 :b] [3 :b]] 2 | |
)) | |
(testing "Varying number of groups" |
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 new-board | |
"Creates a new board with initial positions of each players" | |
[] | |
(->> | |
(conj player/all :wall) | |
(algo/randomly-pick-n-of-each cst/init-block-count coordinates) | |
(reduce | |
(fn [board [coord owner]] (convert-cell board coord owner)) | |
empty-board))) |
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
;; Imported from "triboard.logic.scores.cljs" | |
(s/def ::scores | |
(s/map-of ::player/player int?)) | |
(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 next-turn | |
:args (s/cat :turn ::turn | |
:transition ::transition/transition) | |
:ret ::turn) | |
(s/fdef transitions | |
:args (s/cat :turn ::turn) | |
:ret (s/map-of ::transition/destination ::transition/transition)) |
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 ::destination ::board/coord) | |
(s/def ::taken (s/coll-of ::board/coord)) | |
(s/def ::winner ::player/player) | |
(s/def ::looser ::player/player) | |
(s/def ::jump | |
(s/keys :req-un [::destination ::taken ::winner ::looser])) | |
(s/def ::transition (s/every ::jump)) |
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 | |
"Apply the transtion to the current turn, yielding a new turn" | |
[turn transition] | |
(-> turn | |
(update :board transition/apply-transition transition) | |
(update :scores scores/update-scores transition) | |
(with-next-player))) |
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 |