1 import { ChessRules
} from "@/base_rules";
3 export const VariantRules
= class KnightrelayRules
extends ChessRules
{
4 getPotentialMovesFrom([x
, y
]) {
5 let moves
= super.getPotentialMovesFrom([x
, y
]);
7 // Expand possible moves if guarded by a knight:
8 if (this.getPiece(x
,y
) != V
.KNIGHT
) {
9 const color
= this.turn
;
10 let guardedByKnight
= false;
11 for (const step
of V
.steps
[V
.KNIGHT
]) {
13 V
.OnBoard(x
+step
[0],y
+step
[1]) &&
14 this.getPiece(x
+step
[0],y
+step
[1]) == V
.KNIGHT
&&
15 this.getColor(x
+step
[0],y
+step
[1]) == color
17 guardedByKnight
= true;
21 if (guardedByKnight
) {
22 for (const step
of V
.steps
[V
.KNIGHT
]) {
24 V
.OnBoard(x
+step
[0],y
+step
[1]) &&
25 this.getColor(x
+step
[0],y
+step
[1]) != color
27 let m
= this.getBasicMove([x
,y
], [x
+step
[0],y
+step
[1]]);
28 if (!m
.appear
[0].c
|| !m
.vanish
[0].c
)
31 //moves.push(this.getBasicMove([x,y], [x+step[0],y+step[1]]));
41 if (move.appear
.length
== 2 && move.appear
[0].p
== V
.KING
)
43 return move.end
.y
< move.start
.y
? "0-0-0" : "0-0";
45 // Translate final and initial square
46 const initSquare
= V
.CoordsToSquare(move.start
);
47 const finalSquare
= V
.CoordsToSquare(move.end
);
48 const piece
= this.getPiece(move.start
.x
, move.start
.y
);
50 // Since pieces and pawns could move like knight, indicate start and end squares
54 (move.vanish
.length
> move.appear
.length
? "x" : "") +
59 move.appear
.length
> 0 &&
60 move.appear
[0].p
!= V
.PAWN
63 notation
+= "=" + move.appear
[0].p
.toUpperCase();