Remove some irrelevant text (because of Football variant)
[vchess.git] / client / src / variants / Coronation.js
CommitLineData
107dc1bd
BA
1import { ChessRules, Move, PiPo } from "@/base_rules";
2
3export class CoronationRules extends ChessRules {
7e8a7ea1 4
107dc1bd
BA
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);
10 if (
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)
14 ))
15 ) {
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) {
21 i += step[0];
22 j += step[1];
23 }
24 if (
25 V.OnBoard(i, j) &&
26 this.getColor(i, j) == color &&
27 this.getPiece(i, j) == fusionWith
28 ) {
29 moves.push(
30 new Move({
31 appear: [new PiPo({ x: i, y: j, p: V.QUEEN, c: color })],
32 vanish: [
33 new PiPo({ x: x, y: y, p: piece, c: color }),
34 new PiPo({ x: i, y: j, p: fusionWith, c: color })
35 ]
36 })
37 );
38 }
39 }
40 }
41 return moves;
42 }
43
44 getNotation(move) {
45 let notation = super.getNotation(move);
46 if (move.appear[0].p == V.QUEEN && move.vanish[0].p != V.QUEEN)
47 // Coronation
48 notation += "=Q";
49 return notation;
50 }
7e8a7ea1 51
107dc1bd 52};