1 import { ChessRules
} from "@/base_rules";
3 export class AbsorptionRules
extends ChessRules
{
5 if ([V
.BN
, V
.RN
, V
.QN
].includes(b
[1])) return "Absorption/" + b
;
9 // Three new pieces: rook+knight, bishop+knight and queen+knight
24 return ChessRules
.PIECES
.concat([V
.RN
, V
.BN
, V
.QN
]);
27 static get MergeComposed() {
41 static Fusion(p1
, p2
) {
42 if (p1
== V
.KING
) return p1
;
43 if (p1
== V
.PAWN
) return p2
;
44 if (p2
== V
.PAWN
) return p1
;
45 if ([p1
, p2
].includes(V
.KNIGHT
)) {
46 if ([p1
, p2
].includes(V
.QUEEN
)) return V
.QN
;
47 if ([p1
, p2
].includes(V
.ROOK
)) return V
.RN
;
48 if ([p1
, p2
].includes(V
.BISHOP
)) return V
.BN
;
49 // p1 or p2 already have knight + other piece
50 return (p1
== V
.KNIGHT
? p2 : p1
);
52 for (let p
of [p1
, p2
]) {
53 if (p
== V
.QN
) return V
.QN
;
54 if ([V
.BN
, V
.RN
].includes(p
))
55 return V
.MergeComposed
[[p1
, p2
].sort().join("")];
57 // bishop + rook, or queen + [bishop or rook]
61 getPotentialMovesFrom(sq
) {
63 const piece
= this.getPiece(sq
[0], sq
[1]);
67 super.getPotentialRookMoves(sq
).concat(
68 super.getPotentialKnightMoves(sq
));
72 super.getPotentialBishopMoves(sq
).concat(
73 super.getPotentialKnightMoves(sq
));
77 super.getPotentialQueenMoves(sq
).concat(
78 super.getPotentialKnightMoves(sq
));
81 moves
= super.getPotentialMovesFrom(sq
);
84 if (m
.vanish
.length
== 2) {
85 // Augment pieces abilities in case of captures
86 const piece2
= m
.vanish
[1].p
;
87 if (piece
!= piece2
) m
.appear
[0].p
= V
.Fusion(piece
, piece2
);
93 isAttacked(sq
, color
) {
95 super.isAttacked(sq
, color
) ||
96 this.isAttackedByBN(sq
, color
) ||
97 this.isAttackedByRN(sq
, color
) ||
98 this.isAttackedByQN(sq
, color
)
102 isAttackedByBN(sq
, color
) {
104 this.isAttackedBySlideNJump(sq
, color
, V
.BN
, V
.steps
[V
.BISHOP
]) ||
105 this.isAttackedBySlideNJump(
106 sq
, color
, V
.BN
, V
.steps
[V
.KNIGHT
], "oneStep")
110 isAttackedByRN(sq
, color
) {
112 this.isAttackedBySlideNJump(sq
, color
, V
.RN
, V
.steps
[V
.ROOK
]) ||
113 this.isAttackedBySlideNJump(
114 sq
, color
, V
.RN
, V
.steps
[V
.KNIGHT
], "oneStep")
118 isAttackedByQN(sq
, color
) {
120 this.isAttackedBySlideNJump(
121 sq
, color
, V
.QN
, V
.steps
[V
.BISHOP
].concat(V
.steps
[V
.ROOK
])) ||
122 this.isAttackedBySlideNJump(
123 sq
, color
, V
.QN
, V
.steps
[V
.KNIGHT
], "oneStep")
128 let notation
= super.getNotation(move);
129 if (move.vanish
[0].p
!= V
.PAWN
&& move.appear
[0].p
!= move.vanish
[0].p
)
130 // Fusion (not from a pawn: handled in ChessRules)
131 notation
+= "=" + move.appear
[0].p
.toUpperCase();