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
.cell--blue { | |
fill: blue; | |
} | |
.cell--red { | |
fill: #e80000; | |
} | |
.cell--green { | |
fill: 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/fdef main-frame | |
:args (s/cat | |
:turn ::turn/turn | |
:helps (s/fspec :args (s/cat :coord ::board-model/coord)) | |
:interactions #(satisfies? IUserInteractions %))) |
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
.cell { | |
transition-duration: 0.75s; | |
... | |
} |
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 find-best-move | |
:args (s/cat :game ::game/game) | |
:ret ::board/coord) |
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 triboard [] | |
(frame/main-frame @store/current-turn @store/suggestions | |
(reify view/IUserInteractions | |
(on-new-game [_] (loop/send-game-event! :new-game)) | |
(on-toogle-help [_] (store/toggle-help!)) | |
(on-restart [_] (loop/send-game-event! :restart)) | |
(on-undo [_] (loop/send-game-event! :undo)) | |
(on-player-move [_ x y] (loop/send-play-event! [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
(defonce app-state | |
(reagent/atom | |
{:game (game/new-game) | |
:help false})) |
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 game (reaction (:game @app-state))) | |
(def current-turn (reaction (game/current-turn @game))) | |
(def ai-player? (reaction (player/is-ai? (:player @current-turn)))) |
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 suggestions | |
(reaction | |
(if (and (:help @app-state) (not @ai-player?)) | |
#(contains? (turn/transitions @current-turn) %) | |
(constantly false)))) |
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 swap-game! | |
[update-fn & args] | |
(apply swap! app-state update :game update-fn args)) | |
(defn toggle-help! | |
[] | |
(swap! app-state update :help not)) |
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 animation-delay 500) | |
(def ai-move-delay 1000) | |
(defn ai-computation | |
"Run the computation of the AI asynchronously: | |
* Wait 500ms to start (animation might be frozen otherwise) | |
* Wait 1s to play the move (avoid moves being played too fast)" | |
[game] | |
(go | |
(<! (async/timeout animation-delay)) |