Some advances in Checkered variant
[xogo.git] / variants / Align4 / class.js
1 import ChessRules from "/base_rules.js";
2
3 export 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 genRandInitBaseFen() {
28 let baseFen = super.genRandInitBaseFen();
29 return {
30 fen: baseFen.fen.replace("rnbqkbnr/pppppppp", "4k3/8"),
31 o: {flags: baseFen.o.flags.substr(0, 2) + "88"}
32 };
33 }
34
35 initReserves() {
36 this.reserve = { b: { p: 1 } };
37 }
38
39 // Just do not update any reserve (infinite supply)
40 updateReserve() {}
41
42 getCurrentScore(move_s) {
43 const score = super.getCurrentScore(move_s);
44 if (score != "*")
45 return score;
46 // Check pawns connection:
47 for (let i = 0; i < this.size.x; i++) {
48 for (let j = 0; j < this.size.y; j++) {
49 if (
50 this.board[i][j] != "" &&
51 this.getColor(i, j) == 'b' &&
52 this.getPiece(i, j) == 'p'
53 ) {
54 // Exploration "rightward + downward" is enough
55 for (let step of [[1, 0], [0, 1], [1, 1], [-1, 1]]) {
56 let [ii, jj] = [i + step[0], j + step[1]];
57 let kounter = 1;
58 while (
59 this.onBoard(ii, jj) &&
60 this.board[ii][jj] != "" &&
61 this.getColor(ii, jj) == 'b' &&
62 this.getPiece(ii, jj) == 'p'
63 ) {
64 kounter++;
65 ii += step[0];
66 jj += step[1];
67 }
68 if (kounter == 4)
69 return "0-1";
70 }
71 }
72 }
73 }
74 return "*";
75 }
76
77 };