return moves;
}
- getPotentialPawnMoves([x,y])
- {
- const color = this.turn;
- let moves = [];
- const [sizeX,sizeY] = [V.size.x,V.size.y];
- const shift = (color == "w" ? -1 : 1);
- const firstRank = (color == 'w' ? sizeX-1 : 0);
- const startRank = (color == "w" ? sizeX-2 : 1);
- const lastRank = (color == "w" ? 0 : sizeX-1);
-
- if (x+shift >= 0 && x+shift < sizeX && x+shift != lastRank)
- {
- // Normal moves
- if (this.board[x+shift][y] == V.EMPTY)
- {
- moves.push(this.getBasicMove([x,y], [x+shift,y]));
- // Next condition because variants with pawns on 1st rank allow them to jump
- if ([startRank,firstRank].includes(x) && this.board[x+2*shift][y] == V.EMPTY)
- {
- // Two squares jump
- moves.push(this.getBasicMove([x,y], [x+2*shift,y]));
- }
- }
- // Captures
- if (y>0 && this.board[x+shift][y-1] != V.EMPTY
- && this.canTake([x,y], [x+shift,y-1]))
- {
- moves.push(this.getBasicMove([x,y], [x+shift,y-1]));
- }
- if (y<sizeY-1 && this.board[x+shift][y+1] != V.EMPTY
- && this.canTake([x,y], [x+shift,y+1]))
- {
- moves.push(this.getBasicMove([x,y], [x+shift,y+1]));
- }
- }
-
- if (x+shift == lastRank)
- {
- // Promotion
- const pawnColor = this.getColor(x,y); //can be different for checkered
- let promotionPieces = [V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN];
- promotionPieces.forEach(p => {
- // Normal move
- if (this.board[x+shift][y] == V.EMPTY)
- moves.push(this.getBasicMove([x,y], [x+shift,y], {c:pawnColor,p:p}));
- // Captures
- if (y>0 && this.board[x+shift][y-1] != V.EMPTY
- && this.canTake([x,y], [x+shift,y-1]))
- {
- moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:pawnColor,p:p}));
- }
- if (y<sizeY-1 && this.board[x+shift][y+1] != V.EMPTY
- && this.canTake([x,y], [x+shift,y+1]))
- {
- moves.push(this.getBasicMove([x,y], [x+shift,y+1], {c:pawnColor,p:p}));
- }
- });
- }
- return moves; //no en-passant
- }
-
// Complete a move with magnetic actions
// TODO: job is done multiple times for (normal) promotions.
applyMagneticLaws(move)
return true; //TODO: is it right?
}
- underCheck(move)
+ underCheck(color)
{
return false; //there is no check
}
getCheckSquares(move)
{
- const c = this.getOppCol(this.turn); //opponent
- const saveKingPos = this.kingPos[c]; //king might be taken
- this.play(move);
- // The only way to be "under check" is to have lost the king (thus game over)
- let res = this.kingPos[c][0] < 0
- ? [JSON.parse(JSON.stringify(saveKingPos))]
- : [];
- this.undo(move);
- return res;
+ return [];
}
updateVariables(move)
{
super.updateVariables(move);
- const c = this.getColor(move.start.x,move.start.y);
- if (this.board[move.end.x][move.end.y] != V.EMPTY
- && c != this.getColor(move.end.x,move.end.y)
- && this.getPiece(move.end.x,move.end.y) == V.KING)
+ const c = move.vanish[0].c;
+ if (move.vanish.length >= 2 && move.vanish[1].p == V.KING)
{
// We took opponent king !
const oppCol = this.getOppCol(c);
unupdateVariables(move)
{
super.unupdateVariables(move);
- const c = this.getColor(move.start.x,move.start.y);
+ const c = move.vanish[0].c;
const oppCol = this.getOppCol(c);
if (this.kingPos[oppCol][0] < 0)
{