Usually the Ai moves on corners or center on it's first move. I wanted the make the ai move to the edges instead on the first turn, so I hard coded the ai to move on a particular edge, but for some reason this causes next move of the ai to be suboptimal.
//global variable
let onlyFirstMove = true
...
if (OPPONENT == "computer") {
// get id of space using minimax algorithm
let id = minimax(gameData, player.computer).id;
if (onlyFirstMove) {
id = 3;
onlyFirstMove = false;
}
// store the player's move to gameData
gameData[id] = player.computer;
...
turn 2: Ai player is hard coded to move on a2
a b c
| |
1 - | x | -
_____|_____|_____
| |
2 o | - | -
_____|_____|_____
| |
3 - | - | -
| |
turn 3: Human player picks b2
a b c
| |
1 - | x | -
_____|_____|_____
| |
2 o | x | -
_____|_____|_____
| |
3 - | - | -
| |
turn 4: Ai player picks a1, when it should have picked b3
a b c
| |
1 o | x | -
_____|_____|_____
| |
2 o | x | -
_____|_____|_____
| |
3 - | - | -
| |
Usually the Ai moves on corners or center on it's first move. I wanted the make the ai move to the edges instead on the first turn, so I hard coded the ai to move on a particular edge, but for some reason this causes next move of the ai to be suboptimal.