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