- canTake([x1,y1], [x2,y2])
- {
- const color1 = this.getColor(x1,y1);
- const color2 = this.getColor(x2,y2);
- // Checkered aren't captured
- return color1 != color2 && color2 != 'c' && (color1 != 'c' || color2 != this.turn);
- }
-
- // Post-processing: apply "checkerization" of standard moves
- getPotentialMovesFrom([x,y])
- {
- let standardMoves = super.getPotentialMovesFrom([x,y]);
- const lastRank = this.turn == "w" ? 0 : 7;
- if (this.getPiece(x,y) == V.KING)
- return standardMoves; //king has to be treated differently (for castles)
- let moves = [];
- standardMoves.forEach(m => {
- if (m.vanish[0].p == V.PAWN)
- {
- if (Math.abs(m.end.x-m.start.x)==2 && !this.pawnFlags[this.turn][m.start.y])
- return; //skip forbidden 2-squares jumps
- if (this.board[m.end.x][m.end.y] == V.EMPTY && m.vanish.length==2
- && this.getColor(m.start.x,m.start.y) == 'c')
- {
- return; //checkered pawns cannot take en-passant
- }
- }
- if (m.vanish.length == 1)
- moves.push(m); //no capture
- else
- {
- // A capture occured (m.vanish.length == 2)
- m.appear[0].c = "c";
- moves.push(m);
- if (m.appear[0].p != m.vanish[1].p //avoid promotions (already treated):
- && (m.vanish[0].p != V.PAWN || m.end.x != lastRank))
- {
- // Add transformation into captured piece
- let m2 = JSON.parse(JSON.stringify(m));
- m2.appear[0].p = m.vanish[1].p;
- moves.push(m2);
- }
- }
- });
- return moves;
- }
-
- canIplay(side, [x,y])
- {
- return (side == this.turn && [side,'c'].includes(this.getColor(x,y)));
- }
-
- // Does m2 un-do m1 ? (to disallow undoing checkered moves)
- oppositeMoves(m1, m2)
- {
- return (!!m1 && m2.appear[0].c == 'c'
+ canTake([x1,y1], [x2,y2])
+ {
+ const color1 = this.getColor(x1,y1);
+ const color2 = this.getColor(x2,y2);
+ // Checkered aren't captured
+ return color1 != color2 && color2 != 'c' && (color1 != 'c' || color2 != this.turn);
+ }
+
+ // Post-processing: apply "checkerization" of standard moves
+ getPotentialMovesFrom([x,y])
+ {
+ let standardMoves = super.getPotentialMovesFrom([x,y]);
+ const lastRank = this.turn == "w" ? 0 : 7;
+ if (this.getPiece(x,y) == V.KING)
+ return standardMoves; //king has to be treated differently (for castles)
+ let moves = [];
+ standardMoves.forEach(m => {
+ if (m.vanish[0].p == V.PAWN)
+ {
+ if (Math.abs(m.end.x-m.start.x)==2 && !this.pawnFlags[this.turn][m.start.y])
+ return; //skip forbidden 2-squares jumps
+ if (this.board[m.end.x][m.end.y] == V.EMPTY && m.vanish.length==2
+ && this.getColor(m.start.x,m.start.y) == 'c')
+ {
+ return; //checkered pawns cannot take en-passant
+ }
+ }
+ if (m.vanish.length == 1)
+ moves.push(m); //no capture
+ else
+ {
+ // A capture occured (m.vanish.length == 2)
+ m.appear[0].c = "c";
+ moves.push(m);
+ if (m.appear[0].p != m.vanish[1].p //avoid promotions (already treated):
+ && (m.vanish[0].p != V.PAWN || m.end.x != lastRank))
+ {
+ // Add transformation into captured piece
+ let m2 = JSON.parse(JSON.stringify(m));
+ m2.appear[0].p = m.vanish[1].p;
+ moves.push(m2);
+ }
+ }
+ });
+ return moves;
+ }
+
+ canIplay(side, [x,y])
+ {
+ return (side == this.turn && [side,'c'].includes(this.getColor(x,y)));
+ }
+
+ // Does m2 un-do m1 ? (to disallow undoing checkered moves)
+ oppositeMoves(m1, m2)
+ {
+ return (!!m1 && m2.appear[0].c == 'c'