1 import { ChessRules
} from "@/base_rules";
3 export class ThreechecksRules
extends ChessRules
{
5 static IsGoodFlags(flags
) {
6 // 4 for castle + 2 for checks (0,1 or 2)
7 return !!flags
.match(/^[01]{4,4}[012]{2,2}$/);
11 super.setFlags(fenflags
); //castleFlags
12 this.checkFlags
= { w: 0, b: 0 };
13 const flags
= fenflags
.substr(4); //skip first 4 digits, for castle
14 for (let c
of ["w", "b"]) {
15 this.checkFlags
[c
] = parseInt(flags
.charAt(c
== "w" ? 0 : 1), 10);
20 return [this.castleFlags
, this.checkFlags
];
23 disaggregateFlags(flags
) {
24 this.castleFlags
= flags
[0];
25 this.checkFlags
= flags
[1];
29 // TODO: !!this.checkFlags condition for printDiagram, but it's not good.
30 // This is just a temporary fix.
31 if (b
[1] == 'k' && !!this.checkFlags
&& this.checkFlags
[b
[0]] > 0)
32 return "Threechecks/" + b
[0] + 'k_' + this.checkFlags
[b
[0]];
38 // Does this move give check?
39 const oppCol
= this.turn
;
40 if (this.underCheck(oppCol
))
41 this.checkFlags
[oppCol
]++;
45 const color
= this.turn
;
46 if (this.checkFlags
[color
] >= 3)
47 return color
== "w" ? "0-1" : "1-0";
48 return super.getCurrentScore();
51 static GenRandInitFen(options
) {
52 // Add check flags (at 0)
53 return ChessRules
.GenRandInitFen(options
).slice(0, -2) + "00";
57 let fen
= super.getFlagsFen();
59 for (let c
of ["w", "b"]) fen
+= this.checkFlags
[c
];
64 const baseEval
= super.evalPosition();
65 // Take number of checks into account
66 return baseEval
/5 - this.checkFlags
["w"] + this.checkFlags
["b"];