Created
April 2, 2017 08:12
-
-
Save shailesh/09d090a94825697e4a15f96a362c08ac 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 calculateBestMove = function (game) { | |
var newGameMoves = game.ugly_moves(); | |
var bestMove = null; | |
//use any negative large number | |
var bestValue = -9999; | |
for (var i = 0; i < newGameMoves.length; i++) { | |
var newGameMove = newGameMoves[i]; | |
game.ugly_move(newGameMove); | |
//take the negative as AI plays as black | |
var boardValue = -evaluateBoard(game.board()) | |
game.undo(); | |
if (boardValue > bestValue) { | |
bestValue = boardValue; | |
bestMove = newGameMove | |
} | |
} | |
return bestMove; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment