1 import { ChessRules
} from "@/base_rules";
3 export class AbsorptionRules
extends ChessRules
{
6 if ([V
.BN
, V
.RN
, V
.QN
].includes(b
[1])) return "Absorption/" + b
;
10 // Three new pieces: rook+knight, bishop+knight and queen+knight
25 return ChessRules
.PIECES
.concat([V
.RN
, V
.BN
, V
.QN
]);
28 static get MergeComposed() {
42 static Fusion(p1
, p2
) {
43 if (p1
== V
.KING
) return p1
;
44 if (p1
== V
.PAWN
) return p2
;
45 if (p2
== V
.PAWN
) return p1
;
46 if ([p1
, p2
].includes(V
.KNIGHT
)) {
47 if ([p1
, p2
].includes(V
.QUEEN
)) return V
.QN
;
48 if ([p1
, p2
].includes(V
.ROOK
)) return V
.RN
;
49 if ([p1
, p2
].includes(V
.BISHOP
)) return V
.BN
;
50 // p1 or p2 already have knight + other piece
51 return (p1
== V
.KNIGHT
? p2 : p1
);
53 if ([p1
, p2
].includes(V
.QN
)) return V
.QN
;
54 for (let p
of [p1
, p2
]) {
55 if ([V
.BN
, V
.RN
].includes(p
))
56 return V
.MergeComposed
[[p1
, p2
].sort().join("")];
58 // bishop + rook, or queen + [bishop or rook]
62 getPotentialMovesFrom(sq
) {
64 const piece
= this.getPiece(sq
[0], sq
[1]);
68 super.getPotentialRookMoves(sq
).concat(
69 super.getPotentialKnightMoves(sq
));
73 super.getPotentialBishopMoves(sq
).concat(
74 super.getPotentialKnightMoves(sq
));
78 super.getPotentialQueenMoves(sq
).concat(
79 super.getPotentialKnightMoves(sq
));
82 moves
= super.getPotentialMovesFrom(sq
);
84 // Filter out capturing promotions (except one),
85 // because they are all the same.
86 moves
= moves
.filter(m
=> {
88 m
.vanish
.length
== 1 ||
89 m
.vanish
[0].p
!= V
.PAWN
||
90 [V
.PAWN
, V
.QUEEN
].includes(m
.appear
[0].p
)
95 m
.vanish
.length
== 2 &&
96 m
.appear
.length
== 1 &&
97 piece
!= m
.vanish
[1].p
99 // Augment pieces abilities in case of captures
100 m
.appear
[0].p
= V
.Fusion(piece
, m
.vanish
[1].p
);
106 isAttacked(sq
, color
) {
108 super.isAttacked(sq
, color
) ||
109 this.isAttackedByBN(sq
, color
) ||
110 this.isAttackedByRN(sq
, color
) ||
111 this.isAttackedByQN(sq
, color
)
115 isAttackedByBN(sq
, color
) {
117 this.isAttackedBySlideNJump(sq
, color
, V
.BN
, V
.steps
[V
.BISHOP
]) ||
118 this.isAttackedBySlideNJump(
119 sq
, color
, V
.BN
, V
.steps
[V
.KNIGHT
], "oneStep")
123 isAttackedByRN(sq
, color
) {
125 this.isAttackedBySlideNJump(sq
, color
, V
.RN
, V
.steps
[V
.ROOK
]) ||
126 this.isAttackedBySlideNJump(
127 sq
, color
, V
.RN
, V
.steps
[V
.KNIGHT
], "oneStep")
131 isAttackedByQN(sq
, color
) {
133 this.isAttackedBySlideNJump(
134 sq
, color
, V
.QN
, V
.steps
[V
.BISHOP
].concat(V
.steps
[V
.ROOK
])) ||
135 this.isAttackedBySlideNJump(
136 sq
, color
, V
.QN
, V
.steps
[V
.KNIGHT
], "oneStep")
140 static get VALUES() {
141 return Object
.assign(
142 { a: 12, e: 7, s: 5 },
148 let notation
= super.getNotation(move);
149 if (move.vanish
[0].p
!= V
.PAWN
&& move.appear
[0].p
!= move.vanish
[0].p
)
150 // Fusion (not from a pawn: handled in ChessRules)
151 notation
+= "=" + move.appear
[0].p
.toUpperCase();