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 if ([p1
, p2
].includes(V
.QN
)) return V
.QN
;
53 for (let p
of [p1
, p2
]) {
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
);
83 // Filter out capturing promotions (except one),
84 // because they are all the same.
85 moves
= moves
.filter(m
=> {
87 m
.vanish
.length
== 1 ||
88 m
.vanish
[0].p
!= V
.PAWN
||
89 [V
.PAWN
, V
.QUEEN
].includes(m
.appear
[0].p
)
93 if (m
.vanish
.length
== 2) {
94 // Augment pieces abilities in case of captures
95 const piece2
= m
.vanish
[1].p
;
96 if (piece
!= piece2
) m
.appear
[0].p
= V
.Fusion(piece
, piece2
);
102 isAttacked(sq
, color
) {
104 super.isAttacked(sq
, color
) ||
105 this.isAttackedByBN(sq
, color
) ||
106 this.isAttackedByRN(sq
, color
) ||
107 this.isAttackedByQN(sq
, color
)
111 isAttackedByBN(sq
, color
) {
113 this.isAttackedBySlideNJump(sq
, color
, V
.BN
, V
.steps
[V
.BISHOP
]) ||
114 this.isAttackedBySlideNJump(
115 sq
, color
, V
.BN
, V
.steps
[V
.KNIGHT
], "oneStep")
119 isAttackedByRN(sq
, color
) {
121 this.isAttackedBySlideNJump(sq
, color
, V
.RN
, V
.steps
[V
.ROOK
]) ||
122 this.isAttackedBySlideNJump(
123 sq
, color
, V
.RN
, V
.steps
[V
.KNIGHT
], "oneStep")
127 isAttackedByQN(sq
, color
) {
129 this.isAttackedBySlideNJump(
130 sq
, color
, V
.QN
, V
.steps
[V
.BISHOP
].concat(V
.steps
[V
.ROOK
])) ||
131 this.isAttackedBySlideNJump(
132 sq
, color
, V
.QN
, V
.steps
[V
.KNIGHT
], "oneStep")
136 static get VALUES() {
137 return Object
.assign(
138 { a: 12, e: 7, s: 5 },
144 let notation
= super.getNotation(move);
145 if (move.vanish
[0].p
!= V
.PAWN
&& move.appear
[0].p
!= move.vanish
[0].p
)
146 // Fusion (not from a pawn: handled in ChessRules)
147 notation
+= "=" + move.appear
[0].p
.toUpperCase();