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