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 ::blue int?) | |
(s/def ::red int?) | |
(s/def ::green int?) | |
(s/def ::scores | |
(s/keys :req-un [::blue ::red ::green])) |
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 ::good-binary-tree | |
(s/cat | |
:value int? | |
:children (s/map-of #{:left :right} ::good-binary-tree))) |
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
[1 {:left [2 {}] | |
:right [3 {:left [4 {}]}] | |
}] |
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
(defprotocol IUserInteractions | |
"A protocol for the interactions that can be triggered from the GUI" | |
(on-new-game [this] "Send a new game command") | |
(on-toogle-help [this] "Send a toggle help command") | |
(on-restart [this] "Send a restart command") | |
(on-undo [this] "Send an undo command") | |
(on-player-move [this x y] "Send a play command at [x y]")) |
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 main-frame | |
[turn suggestions interactions] | |
[:div.game-panel | |
[menu/show-top-menu (:scores turn) (:player turn) interactions] | |
[board/render-board (:board turn) suggestions interactions]]) |
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- player->css-style | |
[player highlight?] | |
(let [player-class (str "score--" (name player)) | |
score-class (if (highlight? player) "score--is-current" "score")] | |
(str player-class " " score-class))) | |
(defn- player->score-text | |
[player score] | |
(str (str/capitalize (name player)) " - " score)) |
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 render-board | |
[board suggestions interactions] | |
(into | |
(empty-svg-board) | |
(for [[position cell] (board/to-seq board)] | |
^{:key position} | |
(if (= :none cell) | |
[empty-cell position interactions (if (suggestions position) :help :none)] | |
[rect-cell position cell])))) |
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 relative-size 0.9) | |
(def border-size (/ (- 1 relative-size) 2)) | |
(defn- rect-cell | |
[[x y] player options] | |
[:rect.cell | |
(merge | |
{:class (str "cell--" (name player)) | |
:x (+ border-size x) :width relative-size | |
:y (+ border-size y) :height relative-size} |