1 import { ChessRules
} from "@/base_rules";
3 export const VariantRules
= class RacingkingsRules
extends ChessRules
{
4 static get HasFlags() {
8 static get HasEnpassant() {
12 static get CanFlip() {
16 static GenRandInitFen() {
17 return "8/8/8/8/8/8/krbnNBRK/qrbnNBRQ w 0";
21 if (moves
.length
== 0) return [];
22 const color
= this.turn
;
23 const oppCol
= V
.GetOppCol(color
);
24 return moves
.filter(m
=> {
26 // Giving check is forbidden as well:
27 const res
= !this.underCheck(color
) && !this.underCheck(oppCol
);
34 // If both kings arrived on the last rank, it's a draw
35 if (this.kingPos
['w'][0] == 0 && this.kingPos
['b'][0] == 0) return "1/2";
36 // If after my move the opponent king is on last rank, I lose.
37 // This is only possible with black.
38 if (this.turn
== 'w' && this.kingPos
['w'][0] == 0) return "1-0";
40 const color
= V
.GetOppCol(this.turn
);
41 if (this.kingPos
[color
][0] == 0) {
42 // The opposing edge is reached!
43 // If color is white and the black king can arrive on 8th rank
44 // at next move, then it should be a draw:
45 if (color
== "w" && this.kingPos
['b'][0] == 1) {
47 const oppKingMoves
= this.getPotentialKingMoves(this.kingPos
['b']);
48 if (oppKingMoves
.some(m
=> m
.end
.x
== 0)) return "*";
50 return color
== "w" ? "1-0" : "0-1";
52 if (this.atLeastOneMove()) return "*";
53 // Stalemate (will probably never happen)
59 let evaluation
= super.evalPosition();
60 // Ponder with king position:
61 return evaluation
/5 + this.kingPos
["b"][0] - this.kingPos
["w"][0];