j++;
}
}
+ // TODO: since we keep moves stack, next 2 are redundant
let epSq = undefined;
if (fenParts[2] != "-")
{
return false;
}
+ // Is color c under check after move ?
underCheck(move, c)
{
this.play(move);
return res;
}
+ // On which squares is color c under check (after move) ?
+ getCheckSquares(move, c)
+ {
+ this.play(move);
+ let res = this.isAttacked(this.kingPos[c], this.getOppCol(c))
+ ? [ JSON.parse(JSON.stringify(this.kingPos[c])) ] //need to duplicate!
+ : [ ];
+ this.undo(move);
+ return res;
+ }
+
// Apply a move on board
static PlayOnBoard(board, move)
{
alphabeta(color, oppCol, depth, alpha, beta)
{
- const moves = this.getAllValidMoves(color);
- if (moves.length == 0)
+ if (!this.atLeastOneMove(color))
{
switch (this.checkGameEnd(color))
{
}
if (depth == 0)
return this.evalPosition();
+ const moves = this.getAllValidMoves(color);
let v = color=="w" ? -1000 : 1000;
if (color == "w")
{