Fix Arena diag
[vchess.git] / client / src / variants / Racingkings.js
1 import { ChessRules } from "@/base_rules";
2
3 export class RacingkingsRules extends ChessRules {
4
5 static get Options() {
6 return null;
7 }
8
9 static get HasFlags() {
10 return false;
11 }
12
13 static get HasEnpassant() {
14 return false;
15 }
16
17 static get CanFlip() {
18 return false;
19 }
20
21 static GenRandInitFen() {
22 return "8/8/8/8/8/8/krbnNBRK/qrbnNBRQ w 0";
23 }
24
25 filterValid(moves) {
26 if (moves.length == 0) return [];
27 const color = this.turn;
28 const oppCol = V.GetOppCol(color);
29 return moves.filter(m => {
30 this.play(m);
31 // Giving check is forbidden as well:
32 const res = !this.underCheck(color) && !this.underCheck(oppCol);
33 this.undo(m);
34 return res;
35 });
36 }
37
38 getCurrentScore() {
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";
44 // Turn has changed:
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) {
51 // Search for a move
52 const oppKingMoves = this.filterValid(
53 this.getPotentialKingMoves(this.kingPos['b']));
54 if (oppKingMoves.some(m => m.end.x == 0)) return "*";
55 }
56 return color == "w" ? "1-0" : "0-1";
57 }
58 if (this.atLeastOneMove()) return "*";
59 // Stalemate (will probably never happen)
60 return "1/2";
61 }
62
63 evalPosition() {
64 // Count material:
65 let evaluation = super.evalPosition();
66 // Ponder with king position:
67 return evaluation/5 + this.kingPos["b"][0] - this.kingPos["w"][0];
68 }
69
70 };