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