Skip to content

Instantly share code, notes, and snippets.

@mistercam
Created April 29, 2012 13:19
Show Gist options
  • Save mistercam/2550411 to your computer and use it in GitHub Desktop.
Save mistercam/2550411 to your computer and use it in GitHub Desktop.
Functions to help determine who the winner is
(defn count-pieces [board piece]
"Returns the number of squares occupied by the specified piece"
(count (filter #(= % piece) (flatten board))))
(defn winner [board]
"Returns the winner, or nil if there's a tie"
(let [w (count-pieces board :w ) b (count-pieces board :b )]
(cond
(> w b) :w (> b w) :b :else nil)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment