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