Created
January 21, 2016 19:31
-
-
Save paytonrules/1f7e9662972422a60ae2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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- minimax-square | |
[{:keys [board current-player opposing-player player-turn square] :as params}] | |
(let [new-board (board/take-square board player-turn square)] | |
(cond | |
(board/winner? new-board current-player) 10 | |
(board/winner? new-board opposing-player) -10 | |
(board/tie? new-board current-player opposing-player) 0 | |
:else (let [next-player (next-player current-player opposing-player player-turn) | |
next-board-states (board/open-squares new-board)] | |
(minimax-for-open-postions | |
(assoc params :board new-board :player-turn next-player) next-board-states))))) | |
(defn- minimax-for-open-postions [{:keys [current-player player-turn] :as params} open-squares] | |
(let [scores (map #(minimax-square (assoc params :square %)) open-squares)] | |
(if (= player-turn current-player) | |
(apply max scores) | |
(apply min scores)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment