Skip to content

Instantly share code, notes, and snippets.

@shailesh
Created April 2, 2017 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shailesh/09d090a94825697e4a15f96a362c08ac to your computer and use it in GitHub Desktop.
Save shailesh/09d090a94825697e4a15f96a362c08ac to your computer and use it in GitHub Desktop.
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