+
+ // The opponent piece disappears if we take it
+ if (this.board[ex][ey] != V.EMPTY) {
+ mv.vanish.push(
+ new PiPo({
+ x: ex,
+ y: ey,
+ c: this.getColor(ex, ey),
+ p: this.board[ex][ey].charAt(1)
+ })
+ );
+
+ // If the captured piece has a different nature: take it as well
+ if (mv.vanish[0].p != mv.vanish[1].p) {
+ if (
+ mv.vanish[0].p == V.KING ||
+ Object.keys(V.KING_DECODE).includes(mv.vanish[0].p)
+ ) {
+ mv.appear[0].p = V.KING_CODE[mv.vanish[1].p];
+ } else mv.appear[0].p = mv.vanish[1].p;
+ }
+ }
+ else if (!!tr && mv.vanish[0].p != V.PAWN)
+ // Special case of a non-capturing king-as-pawn promotion
+ mv.appear[0].p = V.KING_CODE[tr.p];
+
+ return mv;
+ }
+
+ getPotentialMovesFrom([x, y]) {
+ const piece = this.board[x][y].charAt(1);
+ if (Object.keys(V.KING_DECODE).includes(piece))
+ return super.getPotentialMovesFrom([x, y], V.KING_DECODE[piece]);
+ return super.getPotentialMovesFrom([x, y], piece);
+ }
+
+ addPawnMoves([x1, y1], [x2, y2], moves) {
+ let finalPieces = [V.PAWN];
+ const color = this.turn;
+ const lastRank = (color == "w" ? 0 : V.size.x - 1);
+ if (x2 == lastRank) {
+ if (this.board[x2][y2] != V.EMPTY)
+ // Cannibal rules: no choice if capture
+ finalPieces = [this.getPiece(x2, y2)];
+ else finalPieces = V.PawnSpecs.promotions;
+ }
+ let tr = null;
+ for (let piece of finalPieces) {
+ tr = (piece != V.PAWN ? { c: color, p: piece } : null);
+ moves.push(this.getBasicMove([x1, y1], [x2, y2], tr));
+ }