- getPotentialPawnMoves([x, y]) {
- const color = this.getColor(x, y);
- let moves = [];
- const sizeY = V.size.y;
- const shift = color == "w" ? -1 : 1;
- const startRank = color == "w" ? sizeY - 2 : 1;
- const firstRank = color == "w" ? sizeY - 1 : 0;
- const lastRank = color == "w" ? 0 : sizeY - 1;
-
- if (x + shift != lastRank) {
- // Normal moves
- if (this.board[x + shift][y] == V.EMPTY) {
- moves.push(this.getBasicMove([x, y], [x + shift, y]));
- 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]));
- }
- }
- }
- else {
- // Promotion
- 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: color, p: p })
- );
- });
- }
-
- // No en passant here
-
- 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));
- }
-