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