c6e1de7476af0c61f08a69d059f0907ee4016efa
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
)
94 if (m
.vanish
.length
== 2) {
95 // Augment pieces abilities in case of captures
96 const piece2
= m
.vanish
[1].p
;
97 if (piece
!= piece2
) m
.appear
[0].p
= V
.Fusion(piece
, piece2
);
103 isAttacked(sq
, color
) {
105 super.isAttacked(sq
, color
) ||
106 this.isAttackedByBN(sq
, color
) ||
107 this.isAttackedByRN(sq
, color
) ||
108 this.isAttackedByQN(sq
, color
)
112 isAttackedByBN(sq
, color
) {
114 this.isAttackedBySlideNJump(sq
, color
, V
.BN
, V
.steps
[V
.BISHOP
]) ||
115 this.isAttackedBySlideNJump(
116 sq
, color
, V
.BN
, V
.steps
[V
.KNIGHT
], "oneStep")
120 isAttackedByRN(sq
, color
) {
122 this.isAttackedBySlideNJump(sq
, color
, V
.RN
, V
.steps
[V
.ROOK
]) ||
123 this.isAttackedBySlideNJump(
124 sq
, color
, V
.RN
, V
.steps
[V
.KNIGHT
], "oneStep")
128 isAttackedByQN(sq
, color
) {
130 this.isAttackedBySlideNJump(
131 sq
, color
, V
.QN
, V
.steps
[V
.BISHOP
].concat(V
.steps
[V
.ROOK
])) ||
132 this.isAttackedBySlideNJump(
133 sq
, color
, V
.QN
, V
.steps
[V
.KNIGHT
], "oneStep")
137 static get VALUES() {
138 return Object
.assign(
139 { a: 12, e: 7, s: 5 },
145 let notation
= super.getNotation(move);
146 if (move.vanish
[0].p
!= V
.PAWN
&& move.appear
[0].p
!= move.vanish
[0].p
)
147 // Fusion (not from a pawn: handled in ChessRules)
148 notation
+= "=" + move.appear
[0].p
.toUpperCase();