- getPotentialPawnMoves([x, y]) {
-
- let moves = super.getPotentialPawnMoves([x, y]);
- // Remove pawns on 8th rank ("fallen"):
- const color = this.turn;
- const lastRank = (color == "w" ? 0 : V.size.x - 1);
- moves.forEach(m => {
- if (m.appear[0].x == lastRank) m.appear.pop();
- });
+ getPotentialPawnMoves(sq) {
+ let moves = super.getPotentialPawnMoves(sq);
+ if (moves.length > 0 && moves[0].vanish[0].p == 's') {
+ // Remove captures for non-violent pawns:
+ moves = moves.filter(m => m.vanish.length == 1);
+ moves.forEach(m => {
+ if (m.appear[0].p != 's') {
+ // Promotion pieces should be non-violent as well:
+ const pIdx = ChessRules.PIECES.findIndex(p => p == m.appear[0].p)
+ m.appear[0].p = V.NON_VIOLENT[pIdx];
+ }
+ });
+ }
+ return moves;
+ }
+
+ getSlideNJumpMoves([x, y], steps, oneStep) {
+ let moves = [];
+ const canTake = ChessRules.PIECES.includes(this.getPiece(x, y));
+ outerLoop: for (let step of steps) {
+ let i = x + step[0];
+ let j = y + step[1];
+ while (V.OnBoard(i, j) && this.board[i][j] == V.EMPTY) {
+ moves.push(this.getBasicMove([x, y], [i, j]));
+ if (oneStep) continue outerLoop;
+ i += step[0];
+ j += step[1];
+ }
+ if (V.OnBoard(i, j) && canTake && this.canTake([x, y], [i, j]))
+ moves.push(this.getBasicMove([x, y], [i, j]));
+ }