Last active
September 28, 2018 21:16
-
-
Save ahmaxed/afe882cb85952353b114465079f3719a 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
// 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