1 import { ChessRules
, Move
, PiPo
} from "@/base_rules";
3 export class CoronationRules
extends ChessRules
{
4 getPotentialMovesFrom([x
, y
]) {
5 let moves
= super.getPotentialMovesFrom([x
, y
]);
6 // If no queen on board, allow rook+bishop fusions:
7 const color
= this.turn
;
8 const piece
= this.getPiece(x
, y
);
10 [V
.ROOK
, V
.BISHOP
].includes(piece
) &&
11 this.board
.every(b
=> b
.every(cell
=>
12 (cell
== V
.EMPTY
|| cell
[0] != color
|| cell
[1] != V
.QUEEN
)
15 const fusionWith
= [V
.ROOK
, V
.BISHOP
][1 - "rb".indexOf(piece
)];
16 // Can I "self-capture" fusionWith ?
17 for (let step
of V
.steps
[piece
]) {
18 let [i
, j
] = [x
+ step
[0], y
+ step
[1]];
19 while (V
.OnBoard(i
, j
) && this.board
[i
][j
] == V
.EMPTY
) {
25 this.getColor(i
, j
) == color
&&
26 this.getPiece(i
, j
) == fusionWith
30 appear: [new PiPo({ x: i
, y: j
, p: V
.QUEEN
, c: color
})],
32 new PiPo({ x: x
, y: y
, p: piece
, c: color
}),
33 new PiPo({ x: i
, y: j
, p: fusionWith
, c: color
})
44 let notation
= super.getNotation(move);
45 if (move.appear
[0].p
== V
.QUEEN
&& move.vanish
[0].p
!= V
.QUEEN
)