Fix typo
[vchess.git] / client / src / variants / Coronation.js
1 import { ChessRules, Move, PiPo } from "@/base_rules";
2
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);
9 if (
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)
13 ))
14 ) {
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) {
20 i += step[0];
21 j += step[1];
22 }
23 if (
24 V.OnBoard(i, j) &&
25 this.getColor(i, j) == color &&
26 this.getPiece(i, j) == fusionWith
27 ) {
28 moves.push(
29 new Move({
30 appear: [new PiPo({ x: i, y: j, p: V.QUEEN, c: color })],
31 vanish: [
32 new PiPo({ x: x, y: y, p: piece, c: color }),
33 new PiPo({ x: i, y: j, p: fusionWith, c: color })
34 ]
35 })
36 );
37 }
38 }
39 }
40 return moves;
41 }
42
43 getNotation(move) {
44 let notation = super.getNotation(move);
45 if (move.appear[0].p == V.QUEEN && move.vanish[0].p != V.QUEEN)
46 // Coronation
47 notation += "=Q";
48 return notation;
49 }
50 };