make it possible for ai to make the first move

This commit is contained in:
2022-07-29 05:53:52 +00:00
parent f71602f385
commit 893ffe4aa4

View File

@@ -28,7 +28,10 @@ export class BoardComponent implements OnInit {
async makeAiMove(){ async makeAiMove(){
const history = this.history.slice(); const history = this.history.slice();
const squares = history[history.length - 1]; let squares = history[history.length - 1];
if(squares === undefined) {
squares = this.fields.slice();
}
const normalizedMoves = squares.map((v) => { const normalizedMoves = squares.map((v) => {
if (v === "X") { if (v === "X") {
return this.xIsNext ? 1 : -1; return this.xIsNext ? 1 : -1;