1 import ChessRules
from "/base_rules.js";
3 export default class AbsorptionRules
extends ChessRules
{
7 select: C
.Options
.select
,
17 "rifle", //TODO? absorb powers from afar?
30 [0, 1], [0, -1], [1, 0], [-1, 0],
31 [1, 1], [1, -1], [-1, 1], [-1, -1]
34 //TODO: steps object avec range + steps... "moving"?
37 [1, 2], [1, -2], [-1, 2], [-1, -2],
38 [2, 1], [-2, 1], [2, -1], [-2, -1]
40 steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]
46 [1, 2], [1, -2], [-1, 2], [-1, -2],
47 [2, 1], [-2, 1], [2, -1], [-2, -1]
53 steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]]
68 static get MergeComposed() {
82 static Fusion(p1
, p2
) {
83 if (p1
== V
.KING
) return p1
;
84 if (p1
== V
.PAWN
) return p2
;
85 if (p2
== V
.PAWN
) return p1
;
86 if ([p1
, p2
].includes(V
.KNIGHT
)) {
87 if ([p1
, p2
].includes(V
.QUEEN
)) return V
.QN
;
88 if ([p1
, p2
].includes(V
.ROOK
)) return V
.RN
;
89 if ([p1
, p2
].includes(V
.BISHOP
)) return V
.BN
;
90 // p1 or p2 already have knight + other piece
91 return (p1
== V
.KNIGHT
? p2 : p1
);
93 if ([p1
, p2
].includes(V
.QN
)) return V
.QN
;
94 for (let p
of [p1
, p2
]) {
95 if ([V
.BN
, V
.RN
].includes(p
))
96 return V
.MergeComposed
[[p1
, p2
].sort().join("")];
98 // bishop + rook, or queen + [bishop or rook]
102 getPotentialMovesFrom(sq
) {
104 const piece
= this.getPiece(sq
[0], sq
[1]);
108 super.getPotentialRookMoves(sq
).concat(
109 super.getPotentialKnightMoves(sq
));
113 super.getPotentialBishopMoves(sq
).concat(
114 super.getPotentialKnightMoves(sq
));
118 super.getPotentialQueenMoves(sq
).concat(
119 super.getPotentialKnightMoves(sq
));
122 moves
= super.getPotentialMovesFrom(sq
);
124 // Filter out capturing promotions (except one),
125 // because they are all the same.
126 moves
= moves
.filter(m
=> {
128 m
.vanish
.length
== 1 ||
129 m
.vanish
[0].p
!= V
.PAWN
||
130 [V
.PAWN
, V
.QUEEN
].includes(m
.appear
[0].p
)
135 m
.vanish
.length
== 2 &&
136 m
.appear
.length
== 1 &&
137 piece
!= m
.vanish
[1].p
139 // Augment pieces abilities in case of captures
140 m
.appear
[0].p
= V
.Fusion(piece
, m
.vanish
[1].p
);
146 isAttacked(sq
, color
) {
148 super.isAttacked(sq
, color
) ||
149 this.isAttackedByBN(sq
, color
) ||
150 this.isAttackedByRN(sq
, color
) ||
151 this.isAttackedByQN(sq
, color
)
155 isAttackedByBN(sq
, color
) {
157 this.isAttackedBySlideNJump(sq
, color
, V
.BN
, V
.steps
[V
.BISHOP
]) ||
158 this.isAttackedBySlideNJump(
159 sq
, color
, V
.BN
, V
.steps
[V
.KNIGHT
], 1)
163 isAttackedByRN(sq
, color
) {
165 this.isAttackedBySlideNJump(sq
, color
, V
.RN
, V
.steps
[V
.ROOK
]) ||
166 this.isAttackedBySlideNJump(
167 sq
, color
, V
.RN
, V
.steps
[V
.KNIGHT
], 1)
171 isAttackedByQN(sq
, color
) {
173 this.isAttackedBySlideNJump(
174 sq
, color
, V
.QN
, V
.steps
[V
.BISHOP
].concat(V
.steps
[V
.ROOK
])) ||
175 this.isAttackedBySlideNJump(
176 sq
, color
, V
.QN
, V
.steps
[V
.KNIGHT
], 1)
180 static get VALUES() {
181 return Object
.assign(
182 { a: 12, e: 7, s: 5 },
188 let notation
= super.getNotation(move);
189 if (move.vanish
[0].p
!= V
.PAWN
&& move.appear
[0].p
!= move.vanish
[0].p
)
190 // Fusion (not from a pawn: handled in ChessRules)
191 notation
+= "=" + move.appear
[0].p
.toUpperCase();