Created
April 2, 2017 08:13
-
-
Save shailesh/44b66bef2274e3f5ca7b4e231afd4ccd 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