Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active March 2, 2017 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/41cf1df3684d5bcffc4a88402bec22f8 to your computer and use it in GitHub Desktop.
Save deque-blog/41cf1df3684d5bcffc4a88402bec22f8 to your computer and use it in GitHub Desktop.
(defn- sole-owner
"Indicates whether all positions are owned by the same player"
[board positions]
(let [owners (set (map #(board/get-owner-at board %) positions))]
(case owners
#{:owner/circle} :owner/circle
#{:owner/cross} :owner/cross
nil)))
(defn get-winner
"Return the winner, or nil if the game has none"
[{:keys [board]}]
(some #(sole-owner board %) winning-cell-sets))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment