From 893ffe4aa4ad2e9f63968b1ac205ed1b4da6955b Mon Sep 17 00:00:00 2001 From: David Tahir Date: Fri, 29 Jul 2022 05:53:52 +0000 Subject: [PATCH] make it possible for ai to make the first move --- src/app/board/board.component.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/board/board.component.ts b/src/app/board/board.component.ts index 566f130..9041ce1 100644 --- a/src/app/board/board.component.ts +++ b/src/app/board/board.component.ts @@ -28,7 +28,10 @@ export class BoardComponent implements OnInit { async makeAiMove(){ 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) => { if (v === "X") { return this.xIsNext ? 1 : -1;