Fix king tracking bugs in Pacosako + Otage
[vchess.git] / client / src / variants / Football.js
CommitLineData
107dc1bd 1import { ChessRules } from "@/base_rules";
0f7762c1 2import { SuicideRules } from "@/variants/Suicide";
107dc1bd
BA
3
4export class FootballRules extends ChessRules {
7e8a7ea1 5
107dc1bd
BA
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++;
0f7762c1
BA
46 }
47 else {
e50a8025 48 const num = parseInt(row[i], 10);
107dc1bd
BA
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 }
b9ce3d0f
BA
83
84 static GenRandInitFen(randomness) {
0f7762c1 85 return SuicideRules.GenRandInitFen(randomness);
b9ce3d0f 86 }
7e8a7ea1 87
107dc1bd 88};