: super.getPotentialMovesFrom([x, y]);
if (piece != V.KING) {
// Add non-capturing knight movements
- const lastRank = (this.turn == 'w' ? 0 : 7);
+ const color = this.turn;
+ const lastRank = (color == 'w' ? 0 : 7);
V.steps[V.KNIGHT].forEach(step => {
+ // Pawns cannot go backward:
+ if (
+ piece == V.PAWN &&
+ (
+ (color == 'w' && step[0] > 0) ||
+ (color == 'b' && step[0] < 0)
+ )
+ ) {
+ return;
+ }
const [i, j] = [x + step[0], y + step[1]];
if (
V.OnBoard(i, j) &&
}
getPotentialMovesFrom([x, y]) {
- let moves = super.getPotentialMovesFrom([x, y]);
+ let moves = super.getPotentialMovesFrom([x, y]).filter(m => {
+ if (
+ m.vanish[0].p != V.PAWN ||
+ m.appear[0].p == V.PAWN ||
+ m.vanish.length == 1
+ ) {
+ return true;
+ }
+ // Pawn promotion, "capturing": remove duplicates
+ return m.appear[0].p == V.QUEEN;
+ });
// Complete moves: stuns & kicks
let promoteAfterStun = [];
const color = this.turn;