A few bug fixes
[vchess.git] / client / src / variants / Pawnsking.js
1 import { ChessRules } from "@/base_rules";
2
3 export class PawnskingRules extends ChessRules {
4
5 static get Options() {
6 return null;
7 }
8
9 static get PawnSpecs() {
10 return Object.assign(
11 {},
12 ChessRules.PawnSpecs,
13 // The promotion piece doesn't matter, the game is won
14 { promotions: [V.QUEEN] }
15 );
16 }
17
18 static get HasFlags() {
19 return false;
20 }
21
22 static GenRandInitFen() {
23 return "4k3/pppppppp/8/8/8/8/PPPPPPPP/4K3 w 0 -";
24 }
25
26 filterValid(moves) {
27 return moves;
28 }
29
30 getCheckSquares() {
31 return [];
32 }
33
34 getCurrentScore() {
35 const color = this.turn;
36 if (this.kingPos[color][0] < 0) return (color == "w" ? "0-1" : "1-0");
37 const oppCol = V.GetOppCol(color);
38 const lastRank = (oppCol == 'w' ? 0 : 7);
39 if (this.board[lastRank].some(cell => cell[0] == oppCol))
40 // The opposing edge is reached!
41 return (oppCol == "w" ? "1-0" : "0-1");
42 if (this.atLeastOneMove()) return "*";
43 return "1/2";
44 }
45
46 postPlay(move) {
47 super.postPlay(move);
48 if (move.vanish.length == 2 && move.vanish[1].p == V.KING)
49 this.kingPos[this.turn] = [-1, -1];
50 }
51
52 postUndo(move) {
53 super.postUndo(move);
54 if (move.vanish.length == 2 && move.vanish[1].p == V.KING)
55 this.kingPos[move.vanish[1].c] = [move.vanish[1].x, move.vanish[1].y];
56 }
57
58 static get SEARCH_DEPTH() {
59 return 4;
60 }
61
62 };