Fix typo
[vchess.git] / client / src / variants / Kinglet.js
CommitLineData
34bfe151
BA
1import { ChessRules } from "@/base_rules";
2import { SuicideRules } from "@/variants/Suicide";
3
4export class KingletRules extends ChessRules {
5 static get HasFlags() {
6 return false;
7 }
8
9 static get PawnSpecs() {
10 return Object.assign(
11 {},
12 ChessRules.PawnSpecs,
13 { promotions: [V.KING] }
14 );
15 }
16
17 static IsGoodPosition(position) {
18 if (position.length == 0) return false;
19 const rows = position.split("/");
20 if (rows.length != V.size.x) return false;
21 // Just check that at least one pawn of each color is there:
22 let pawns = { "w": 0, "b": 0 };
23 for (let row of rows) {
24 let sumElts = 0;
25 for (let i = 0; i < row.length; i++) {
26 const lowerRi = row[i].toLowerCase();
27 if (V.PIECES.includes(lowerRi)) {
28 if (lowerRi == 'p') pawns[row[i] == lowerRi ? "b" : "w"]++;
29 sumElts++;
30 } else {
e50a8025 31 const num = parseInt(row[i], 10);
34bfe151
BA
32 if (isNaN(num)) return false;
33 sumElts += num;
34 }
35 }
36 if (sumElts != V.size.y) return false;
37 }
38 if (Object.values(pawns).some(v => v == 0)) return false;
39 return true;
40 }
41
42 scanKings() {}
43
44 filterValid(moves) {
45 return moves;
46 }
47
48 getCheckSquares() {
49 return [];
50 }
51
52 // No variables update because no royal king + no castling
53 prePlay() {}
54 postPlay() {}
55 preUndo() {}
56 postUndo() {}
57
58 getCurrentScore() {
59 const pawnRemain = {
60 'w': this.board.some(b =>
61 b.some(cell => cell[0] == 'w' && cell[1] == 'p')),
62 'b': this.board.some(b =>
63 b.some(cell => cell[0] == 'b' && cell[1] == 'p'))
64 }
65 if (!pawnRemain['w']) return "0-1";
66 if (!pawnRemain['b']) return "1-0";
67 if (this.atLeastOneMove()) return "*";
68 // Stalemate: draw
69 return "1/2";
70 }
71
72 static GenRandInitFen(randomness) {
73 return SuicideRules.GenRandInitFen(randomness);
74 }
75
76 static get VALUES() {
77 // TODO: no clue what correct values would be
78 return {
79 p: 5,
80 r: 4,
81 n: 3,
82 b: 3,
83 q: 7,
84 k: 4
85 };
86 }
87};