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