![](/img/trans.png)
[英]Square brackets and space in function declaration arguments Javascript
[英]Square brackets after arguments list in JavaScript/TypeScript
讓值= this.recurseMinimax(board,!player) [0] ;
功能:
recurseMinimax(board: boolean[][], player: boolean): any {
this.numNodes++;
let winner = this.getWinner(board);
if (winner != null) {
switch (winner) {
case 1:
return [1, board];
case 0:
return [-1, board];
case -1:
return [0, board];
}
} else {
let nextVal = null;
let nextBoard = null;
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
if (board[i][j] == null) {
board[i][j] = player;
let value = this.recurseMinimax(board, !player)[0];
if ((player && (nextVal == null || value > nextVal)) || (!player && (nextVal == null || value < nextVal))) {
nextBoard = board.map(function (arr) {
return arr.slice();
});
nextVal = value;
}
board[i][j] = null;
}
}
}
return [nextVal, nextBoard];
}
}
返回this.recurseMinimax(board,true) [1] ;
功能:
minimaxMove(board: boolean[][]): any {
this.numNodes = 0;
return this.recurseMinimax(board, true)[1];
}
這意味着您正在訪問Array的索引(從您的函數返回),請謹慎執行此操作,例如,可能無需事先進行檢查,例如:
minimaxMove(board: boolean[][]): any {
this.numNodes = 0;
return this.recurseMinimax(board, true) && this.recurseMinimax(board, true).lenght>=1 ? this.recurseMinimax(board, true)[1] : {} ;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.