return moves;
}
- getPotentialRookMoves(sq) {
- return this.getSlideNJumpMoves(sq, V.steps[V.ROOK]);
- }
-
- getPotentialKnightMoves(sq) {
- return this.getSlideNJumpMoves(sq, V.steps[V.KNIGHT], "oneStep");
- }
-
- getPotentialBishopMoves(sq) {
- return this.getSlideNJumpMoves(sq, V.steps[V.BISHOP]);
- }
-
- getPotentialQueenMoves(sq) {
- return this.getSlideNJumpMoves(
- sq,
- V.steps[V.ROOK].concat(V.steps[V.BISHOP])
- );
- }
-
- getPotentialKingMoves(sq) {
- // Initialize with normal (non-capturing) moves
- let noCaptures = this.getSlideNJumpMoves(
- sq,
- V.steps[V.ROOK].concat(V.steps[V.BISHOP]),
- "oneStep"
- );
- return noCaptures.concat(this.getCastleMoves(sq));
- }
-
// No "under check" verifications:
getCastleMoves([x, y]) {
const c = this.getColor(x, y);
castleSide < 2;
castleSide++ //large, then small
) {
- if (!this.castleFlags[c][castleSide]) continue;
+ if (this.castleFlags[c][castleSide] >= 8) continue;
// If this code is reached, rooks and king are on initial position
- const rookPos = this.INIT_COL_ROOK[c][castleSide];
+ const rookPos = this.castleFlags[c][castleSide];
if (this.getColor(x, rookPos) != c)
// Rook is here but changed color
continue;
// Nothing on the path to the rook?
step = castleSide == 0 ? -1 : 1;
- for (i = y + step; i != this.INIT_COL_ROOK[c][castleSide]; i += step) {
+ for (i = y + step; i != rookPos; i += step) {
if (this.board[x][i] != V.EMPTY) continue castlingCheck;
}
let newAppear = [];
let newVanish = [];
V.PlayOnBoard(this.board, m);
- // If castling, m.appear has 2 elements:
- m.appear.forEach(a => {
- const flipped = this.findCaptures([a.x, a.y]);
- flipped.forEach(sq => {
- const piece = this.getPiece(sq[0],sq[1]);
- const pipoA = new PiPo({
- x:sq[0],
- y:sq[1],
- c:color,
- p:piece
+ // If castling, m.appear has 2 elements.
+ // In this case, consider the attacks of moving units only.
+ // (Sometimes the king or rook doesn't move).
+ for (let i = 0; i < m.appear.length; i++) {
+ const a = m.appear[i];
+ if (m.vanish[i].x != a.x || m.vanish[i].y != a.y) {
+ const flipped = this.findCaptures([a.x, a.y]);
+ flipped.forEach(sq => {
+ const piece = this.getPiece(sq[0],sq[1]);
+ const pipoA = new PiPo({
+ x:sq[0],
+ y:sq[1],
+ c:color,
+ p:piece
+ });
+ const pipoV = new PiPo({
+ x:sq[0],
+ y:sq[1],
+ c:oppCol,
+ p:piece
+ });
+ newAppear.push(pipoA);
+ newVanish.push(pipoV);
});
- const pipoV = new PiPo({
- x:sq[0],
- y:sq[1],
- c:oppCol,
- p:piece
- });
- newAppear.push(pipoA);
- newVanish.push(pipoV);
- });
- });
+ }
+ }
Array.prototype.push.apply(m.appear, newAppear);
Array.prototype.push.apply(m.vanish, newVanish);
V.UndoOnBoard(this.board, m);
// Stalemate:
return "1/2";
}
+
+ getNotation(move) {
+ // Just remove flips:
+ const basicMove = {
+ appear: [move.appear[0]],
+ vanish: [move.vanish[0]],
+ start: move.start,
+ end: move.end
+ };
+ return super.getNotation(basicMove);
+ }
};