1 import { ChessRules
} from "@/base_rules";
3 // Pawns relayed by one square at a time (but with relaying piece movements)
4 // diff from https://www.chessvariants.com/rules/relay-chess ==> new name
5 export class RelayupRules
extends ChessRules
{
7 static get PawnSpecs() {
15 static get HasFlags() {
19 static get HasEnpassant() {
23 getPotentialMovesFrom([x
, y
]) {
24 let moves
= super.getPotentialMovesFrom([x
, y
]);
25 // Expand potential moves if guarded by friendly pieces.
26 // NOTE: pawns cannot be promoted through a relaying move
27 const piece
= this.getPiece(x
,y
);
28 const color
= this.turn
;
29 const lastRank
= (color
== 'w' ? 0 : 7);
31 const oneStep
= (piece
== V
.PAWN
);
33 if (piece
!= V
.ROOK
&& super.isAttackedByRook(sq
, color
))
34 guardedBy
[V
.ROOK
] = true;
35 if (piece
!= V
.KNIGHT
&& super.isAttackedByKnight(sq
, color
))
36 guardedBy
[V
.KNIGHT
] = true;
37 if (piece
!= V
.BISHOP
&& super.isAttackedByBishop(sq
, color
))
38 guardedBy
[V
.BISHOP
] = true;
39 if (piece
!= V
.QUEEN
&& super.isAttackedByQueen(sq
, color
))
40 guardedBy
[V
.QUEEN
] = true;
41 if (piece
!= V
.KING
&& super.isAttackedByKing(sq
, color
))
42 guardedBy
[V
.KING
] = true;
43 Object
.keys(guardedBy
).forEach(pg
=> {
45 if ([V
.ROOK
, V
.KNIGHT
, V
.BISHOP
].includes(pg
)) steps
= V
.steps
[pg
];
46 else steps
= V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]);
48 super.getSlideNJumpMoves(
49 sq
, steps
, oneStep
|| [V
.KNIGHT
, V
.KING
].includes(pg
))
52 (piece
!= V
.PAWN
|| m
.end
.x
!= lastRank
) &&
53 (moves
.every(mv
=> mv
.end
.x
!= m
.end
.x
|| mv
.end
.y
!= m
.end
.y
))
56 moves
= moves
.concat(extraMoves
);
70 if (move.vanish
.length
== 2 && move.vanish
[1].p
== V
.KING
)
71 this.kingPos
[move.vanish
[1].c
] = [-1, -1];
76 if (move.vanish
.length
== 2 && move.vanish
[1].p
== V
.KING
) {
77 const v
= move.vanish
[1];
78 this.kingPos
[v
.c
] = [v
.x
, v
.y
];
84 if (this.kingPos
[c
][0] < 0) return (c
== 'w' ? "0-1" : "1-0");
85 // It seems that there is always a possible move (TODO: check this)
90 // Translate final and initial square
91 const initSquare
= V
.CoordsToSquare(move.start
);
92 const finalSquare
= V
.CoordsToSquare(move.end
);
93 const piece
= this.getPiece(move.start
.x
, move.start
.y
);
95 // Since pieces and pawns could move like knight,
96 // indicate start and end squares
100 (move.vanish
.length
> move.appear
.length
? "x" : "") +
105 move.appear
.length
> 0 &&
106 move.appear
[0].p
!= V
.PAWN
109 notation
+= "=" + move.appear
[0].p
.toUpperCase();