Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created March 18, 2017 17:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save deque-blog/f6a2eb257cbfe64c00fa0b5dbd2d6ad8 to your computer and use it in GitHub Desktop.
(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))
(let [ai-chan (go (ai/find-best-move game))]
(<! (async/timeout ai-move-delay))
(<! ai-chan))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment