Skip to content

Instantly share code, notes, and snippets.

@7hoenix
Last active May 18, 2016 16:04
Show Gist options
  • Save 7hoenix/e05b27154576be6059e843b0eb50eb2a to your computer and use it in GitHub Desktop.
Save 7hoenix/e05b27154576be6059e843b0eb50eb2a to your computer and use it in GitHub Desktop.
(defn minimax [board func]
(if (game-is-over? board)
(score board func)
(let [available (find-available board)
states (map #(make-move board player %))]
(reduce func states))))
(defn maxi [board]
(apply max (map minimax board mini)))
(defn mini [board]
(apply min (map minimax board mini)))
(defn game-is-over? returns true if the current board is a game over)
(defn score returns the score of the board (which will depend on who is invoking minimax the first time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment