import { ChessRules, PiPo } from "@/base_rules";
export class KoopaRules extends ChessRules {
+
static get HasEnpassant() {
return false;
}
// stand for stunned indicator.
scanKings(fen) {
- this.INIT_COL_KING = { w: -1, b: -1 };
// Squares of white and black king:
this.kingPos = { w: [-1, -1], b: [-1, -1] };
const fenRows = V.ParseFen(fen).position.split("/");
case "k":
case "l":
this.kingPos["b"] = [i, k];
- this.INIT_COL_KING["b"] = k;
break;
case "K":
case "L":
this.kingPos["w"] = [i, k];
- this.INIT_COL_KING["w"] = k;
break;
default: {
const num = parseInt(fenRows[i].charAt(j), 10);
}
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;
getPotentialKingMoves(sq) {
return (
this.getSlideNJumpMoves(
- sq,
- V.steps[V.ROOK].concat(V.steps[V.BISHOP]),
- "oneStep"
- ).concat(super.getCastleMoves(sq, true, ['r']))
+ sq, V.steps[V.ROOK].concat(V.steps[V.BISHOP]), 1
+ ).concat(super.getCastleMoves(sq, null, true, ['r']))
);
}
// Forbid kicking own king out
const color = this.turn;
return moves.filter(m => {
- const kingAppear = m.appear.some(a => a.c == color && a.p == V.KING);
- return m.vanish.every(v => {
- return (
- v.c != color ||
- !["k", "l"].includes(v.p) ||
- (v.p == "k" && kingAppear)
- );
- });
+ const kingVanish =
+ m.vanish.some(v => v.c == color && ['k', 'l'].includes(v.p));
+ if (kingVanish) {
+ const kingAppear =
+ m.appear.some(a => a.c == color && ['k', 'l'].includes(a.p));
+ return kingAppear;
+ }
+ return true;
});
}
}
return notation;
}
+
};