1 import { ChessRules
} from "@/base_rules";
2 import { AbsorptionRules
} from "@/variants/Absorption";
4 export class SelfabsorbRules
extends AbsorptionRules
{
6 canTake([x1
, y1
], [x2
, y2
]) {
7 if (this.getColor(x1
, y1
) !== this.getColor(x2
, y2
)) return true;
8 const p1
= this.getPiece(x1
, y1
);
9 const p2
= this.getPiece(x2
, y2
);
12 [V
.QUEEN
, V
.RN
, V
.BN
, V
.ROOK
, V
.KNIGHT
, V
.BISHOP
].includes(p1
) &&
13 [V
.QUEEN
, V
.RN
, V
.BN
, V
.ROOK
, V
.KNIGHT
, V
.BISHOP
].includes(p2
) &&
14 (p1
!= V
.QUEEN
|| p2
== V
.KNIGHT
) &&
15 (p2
!= V
.QUEEN
|| p1
== V
.KNIGHT
) &&
16 (p1
!= V
.RN
|| p2
== V
.BISHOP
) &&
17 (p2
!= V
.RN
|| p1
== V
.BISHOP
) &&
18 (p1
!= V
.BN
|| p2
== V
.ROOK
) &&
19 (p2
!= V
.BN
|| p1
== V
.ROOK
)
23 getPotentialMovesFrom(sq
) {
25 const piece
= this.getPiece(sq
[0], sq
[1]);
29 super.getPotentialRookMoves(sq
).concat(
30 super.getPotentialKnightMoves(sq
));
34 super.getPotentialBishopMoves(sq
).concat(
35 super.getPotentialKnightMoves(sq
));
39 super.getPotentialQueenMoves(sq
).concat(
40 super.getPotentialKnightMoves(sq
));
43 moves
= super.getPotentialPawnMoves(sq
);
46 moves
= super.getPotentialRookMoves(sq
);
49 moves
= super.getPotentialKnightMoves(sq
);
52 moves
= super.getPotentialBishopMoves(sq
);
55 moves
= super.getPotentialQueenMoves(sq
);
58 moves
= super.getPotentialKingMoves(sq
);
63 m
.vanish
.length
== 2 && m
.appear
.length
== 1 &&
64 piece
!= m
.vanish
[1].p
&& m
.vanish
[0].c
== m
.vanish
[1].c
66 // Augment pieces abilities in case of self-captures
67 m
.appear
[0].p
= V
.Fusion(piece
, m
.vanish
[1].p
);