Last active
March 30, 2017 15:49
-
-
Save lhartikk/7a4eeaa91f874ab3b1468298320c5624 to your computer and use it in GitHub Desktop.
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
var minimax = function (depth, game, isMaximisingPlayer) { | |
if (depth === 0) { | |
return -evaluateBoard(game.board()); | |
} | |
var newGameMoves = game.ugly_moves(); | |
if (isMaximisingPlayer) { | |
var bestMove = -9999; | |
for (var i = 0; i < newGameMoves.length; i++) { | |
game.ugly_move(newGameMoves[i]); | |
bestMove = Math.max(bestMove, minimax(depth - 1, game, !isMaximisingPlayer)); | |
game.undo(); | |
} | |
return bestMove; | |
} else { | |
var bestMove = 9999; | |
for (var i = 0; i < newGameMoves.length; i++) { | |
game.ugly_move(newGameMoves[i]); | |
bestMove = Math.min(bestMove, minimax(depth - 1, game, !isMaximisingPlayer)); | |
game.undo(); | |
} | |
return bestMove; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment