Skip to content

Instantly share code, notes, and snippets.

@tarynsauer
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save tarynsauer/9316443 to your computer and use it in GitHub Desktop.

Select an option

Save tarynsauer/9316443 to your computer and use it in GitHub Desktop.
(def player-types ["human" "computer" "ai"])
(defmulti get-move (fn [current-player board] (:player-type current-player)))
(defmethod get-move "human" [current-player board]
(get-human-move))
(defmethod get-move "computer" [current-player board]
(get-random-move board))
(defmethod get-move "ai" [current-player board]
(get-ai-move (:piece current-player) board))
;; current-player methods
(defn current-player [board player-x player-o]
(if (even? (count (filter string? board)))
player-x
player-o))
(defn current-piece [board]
(if (even? (count (filter string? board)))
(first piece)
(second piece)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment