- getAllValidMoves() {
- let moves = super.getAllValidMoves().filter(m => {
- // Remove jailer captures
- return m.vanish[0].p != V.JAILER || m.vanish.length == 1;
- });
- const L = this.sentryPush.length;
- if (!!this.sentryPush[L-1] && this.subTurn == 1) {
- // Delete moves walking back on sentry push path
- moves = moves.filter(m => {
- if (
- m.vanish[0].p != V.PAWN &&
- this.sentryPush[L-1].some(sq => sq.x == m.end.x && sq.y == m.end.y)
- ) {
- return false;
+ getPotentialPawnMoves([x, y]) {
+ const color = this.turn;
+ let moves = [];
+ const [sizeX, sizeY] = [V.size.x, V.size.y];
+ let shiftX = color == "w" ? -1 : 1;
+ // Special case of a sentry push: pawn goes in the capturer direction
+ if (this.subTurn == 2) shiftX *= -1;
+ const startRank = color == "w" ? sizeX - 2 : 1;
+ const lastRank = color == "w" ? 0 : sizeX - 1;
+
+ const finalPieces =
+ x + shiftX == lastRank
+ ?
+ [V.ROOK, V.KNIGHT, V.BISHOP, V.QUEEN, V.SENTRY, V.JAILER]
+ .concat(Object.keys(V.LANCER_DIRS))
+ : [V.PAWN];
+ if (this.board[x + shiftX][y] == V.EMPTY) {
+ // One square forward
+ for (let piece of finalPieces) {
+ moves.push(
+ this.getBasicMove([x, y], [x + shiftX, y], {
+ c: color,
+ p: piece
+ })
+ );
+ }
+ if (
+ x == startRank &&
+ this.board[x + 2 * shiftX][y] == V.EMPTY
+ ) {
+ // Two squares jump
+ moves.push(this.getBasicMove([x, y], [x + 2 * shiftX, y]));
+ }
+ }
+ // Captures
+ for (let shiftY of [-1, 1]) {
+ if (
+ y + shiftY >= 0 &&
+ y + shiftY < sizeY &&
+ this.board[x + shiftX][y + shiftY] != V.EMPTY &&
+ this.canTake([x, y], [x + shiftX, y + shiftY])
+ ) {
+ for (let piece of finalPieces) {
+ moves.push(
+ this.getBasicMove([x, y], [x + shiftX, y + shiftY], {
+ c: color,
+ p: piece
+ })
+ );