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