Skip to content

Instantly share code, notes, and snippets.

@ahmaxed
Last active September 28, 2018 21:16
Show Gist options
  • Save ahmaxed/afe882cb85952353b114465079f3719a to your computer and use it in GitHub Desktop.
Save ahmaxed/afe882cb85952353b114465079f3719a to your computer and use it in GitHub Desktop.
// an array to collect all the objects
var moves = [];
// loop through available spots
for (var i = 0; i < availSpots.length; i++){
//create an object for each and store the index of that spot
var move = {};
move.index = newBoard[availSpots[i]];
// set the empty spot to the current player
newBoard[availSpots[i]] = player;
/*collect the score resulted from calling minimax
on the opponent of the current player*/
if (player == aiPlayer){
var result = minimax(newBoard, huPlayer);
move.score = result.score;
}
else{
var result = minimax(newBoard, aiPlayer);
move.score = result.score;
}
// reset the spot to empty
newBoard[availSpots[i]] = move.index;
// push the object to the array
moves.push(move);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment