make it possible for ai to make the first move
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user