Created
April 29, 2012 13:19
-
-
Save mistercam/2550411 to your computer and use it in GitHub Desktop.
Functions to help determine who the winner is
This file contains 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 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