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