Add Madrasi, fix Absorption, better pieces management
[xogo.git] / variants / Madrasi / class.js
CommitLineData
57b8015b
BA
1import ChessRules from "/base_rules.js";
2
3export default class MadrasiRules extends ChessRules {
4
5 static get Options() {
6 return {
7 select: C.Options.select,
8 check: [
9 {
10 label: "Rex Incl.",
11 defaut: false,
12 variable: "rexincl"
13 }
14 ].concat(C.Options.check),
15 styles: C.Options.styles.filter(s => s != "madrasi")
16 };
17 }
18
19 constructor(o) {
20 o.options["madrasi"] = true;
21 super(o);
22 }
23
24 underCheck([x, y], color) {
25 if (this.options["rexincl"]) {
26 // If Rex Inclusive, kings do not check each other:
27 // we just replace it very temporarily.
28 const [ox, oy] = this.searchKingPos(color);
29 const saveOppKing = this.board[ox][oy];
30 this.board[ox][oy] = C.GetOppCol(color) + "q"; //arbitrary
31 const res = super.underCheck([x, y], color);
32 this.board[ox][oy] = saveOppKing;
33 return res;
34 }
35 return super.underCheck([x, y], color);
36 }
37
38};