[英]Square brackets after arguments list in JavaScript/TypeScript
let value = this.recurseMinimax(board, !player) [0] ; 让值= this.recurseMinimax(board,!player) [0] ;
function: 功能:
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];
}
}
return this.recurseMinimax(board, true) [1] ; 返回this.recurseMinimax(board,true) [1] ;
function: 功能:
minimaxMove(board: boolean[][]): any {
this.numNodes = 0;
return this.recurseMinimax(board, true)[1];
}
It Means the index of the Array (that is returning from your functions) are you accessing ... be carefully to do this without do a check maybe before, for example: 这意味着您正在访问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.