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