bf3684afc9f8c866096a4ec444074d40d7972c76
[xogo.git] / variants / Coronation / class.js
1 import ChessRules from "/base_rules.js";
2
3 export default class CoronationRules extends ChessRules {
4
5 get hasSelfCaptures() {
6 return true;
7 }
8
9 canSelfTake([x1, y1], [x2, y2]) {
10 const c = this.getColor(x1, y1);
11 if (
12 this.board.some(row =>
13 row.some(square =>
14 square[0] == c && square[1] == 'q')
15 )
16 ) {
17 // Already a queen on the board: no coronation
18 return false;
19 }
20 const [p1, p2] = [this.getPiece(x1, y1), this.getPiece(x2, y2)];
21 return ((p1 == 'r' && p2 == 'b') || (p1 == 'b' && p2 == 'r'));
22 }
23
24 getPotentialMovesOf(piece, [x, y]) {
25 const res = super.getPotentialMovesOf(piece, [x, y]);
26 if (['r', 'b'].includes(piece)) {
27 res.forEach(m => {
28 if (
29 m.vanish.length == 2 &&
30 m.appear.length == 1 &&
31 m.vanish[1].c == m.vanish[0].c
32 ) {
33 m.appear[0].p = 'q';
34 }
35 });
36 }
37 return res;
38 }
39
40 };