Fix memory leak of moves hash on server side. Draft Align4
[xogo.git] / variants / Align4 / class.js
CommitLineData
4cec374b
BA
1import ChessRules from "/base_rules.js";
2
3export default class Align4Rules extends ChessRules {
4
5 static get Options() {
6 return {
7 select: [{
8 label: "Randomness",
9 variable: "randomness",
10 defaut: 0,
11 options: [
12 {label: "Deterministic", value: 0},
13 {label: "Random", value: 1}
14 ]
15 }],
16 styles: ["atomic", "capture", "cylinder"]
17 };
18 }
19
20 get hasReserve() {
21 return true;
22 }
23 get hasReserveFen() {
24 return false;
25 }
26
27 genRandInitFen(seed) {
28 const baseFen = super.genRandInitFen(seed);
29 return "4k3/8" + baseFen.substring(17, 50) + " -"; //TODO: + flags 1188
30 }
31
32 setOtherVariables(fenParsed) {
33 super.setOtherVariables(fenParsed);
34 this.reserve = { b: { p: 1 } };
35 }
36
37 // Just do not update any reserve (infinite supply)
38 updateReserve() {}
39
40 getCastleMoves([x, y]) {
41 if (this.GetColor(x, y) == 'b')
42 return [];
43 return super.getCastleMoves([x, y]);
44 }
45
46 getCurrentScore(move) {
47 const score = super.getCurrentScore(move);
48 if (score != "*")
49 return score;
50 // Check pawns connection:
51 for (let i = 0; i < this.size.x; i++) {
52 for (let j = 0; j < this.size.y; j++) {
53 if (
54 this.board[i][j] != "" &&
55 this.getColor(i, j) == 'b' &&
56 this.getPiece(i, j) == 'p'
57 ) {
58 // Exploration "rightward + downward" is enough
59 for (let step of [[1, 0], [0, 1], [1, 1], [-1, 1]]) {
60 let [ii, jj] = [i + step[0], j + step[1]];
61 let kounter = 1;
62 while (
63 this.onBoard(ii, jj) &&
64 this.board[ii][jj] != "" &&
65 this.getColor(ii, jj) == 'b' &&
66 this.getPiece(ii, jj) == 'p'
67 ) {
68 kounter++;
69 ii += step[0];
70 jj += step[1];
71 }
72 if (kounter == 4)
73 return "0-1";
74 }
75 }
76 }
77 }
78 return "*";
79 }
80
81};