Skip to content

Instantly share code, notes, and snippets.

.cell--blue {
fill: blue;
}
.cell--red {
fill: #e80000;
}
.cell--green {
fill: green;
(s/fdef main-frame
:args (s/cat
:turn ::turn/turn
:helps (s/fspec :args (s/cat :coord ::board-model/coord))
:interactions #(satisfies? IUserInteractions %)))
.cell {
transition-duration: 0.75s;
...
}
(s/fdef find-best-move
:args (s/cat :game ::game/game)
:ret ::board/coord)
(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]))
)))
(defonce app-state
(reagent/atom
{:game (game/new-game)
:help false}))
(def game (reaction (:game @app-state)))
(def current-turn (reaction (game/current-turn @game)))
(def ai-player? (reaction (player/is-ai? (:player @current-turn))))
(def suggestions
(reaction
(if (and (:help @app-state) (not @ai-player?))
#(contains? (turn/transitions @current-turn) %)
(constantly false))))
(defn swap-game!
[update-fn & args]
(apply swap! app-state update :game update-fn args))
(defn toggle-help!
[]
(swap! app-state update :help not))
(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))