Commit | Line | Data |
---|---|---|
77691911 BA |
1 | import { ChessRules } from "@/base_rules"; |
2 | import { ArrayFun } from "@/utils/array"; | |
3 | ||
4 | export class RugbyRules extends ChessRules { | |
5 | static get HasFlags() { | |
6 | return false; | |
7 | } | |
8 | ||
9 | static get PawnSpecs() { | |
10 | return Object.assign( | |
11 | {}, | |
12 | ChessRules.PawnSpecs, | |
13 | { promotions: [V.PAWN] } | |
14 | ); | |
15 | } | |
16 | ||
17 | getPotentialMovesFrom(sq) { | |
18 | // There are only pawns: | |
19 | return this.getPotentialPawnMoves(sq); | |
20 | } | |
21 | ||
22 | getPotentialPawnMoves(sq) { | |
23 | const moves = super.getPotentialPawnMoves(sq); | |
24 | // Add king movements, without capturing | |
25 | const steps = | |
26 | this.turn == 'w' | |
27 | ? [ [-1,-1], [-1,1], [0,1], [0,-1], [1,-1], [1,0], [1,1] ] | |
28 | : [ [1,-1], [1,1], [0,1], [0,-1], [-1,-1], [-1,0], [-1,1] ]; | |
29 | let addMoves = this.getSlideNJumpMoves(sq, steps, "oneStep"); | |
30 | return moves.concat(addMoves.filter(m => m.vanish.length == 1)); | |
31 | } | |
32 | ||
33 | static GenRandInitFen() { | |
34 | // Non-randomized variant. En-passant possible: | |
35 | return "pppppppp/8/8/8/8/8/8/PPPPPPPP w 0 -"; | |
36 | } | |
37 | ||
38 | filterValid(moves) { | |
39 | return moves; | |
40 | } | |
41 | ||
42 | prePlay() {} | |
43 | postPlay() {} | |
44 | preUndo() {} | |
45 | postUndo() {} | |
46 | ||
47 | getCurrentScore() { | |
48 | // Turn has changed: | |
49 | const color = V.GetOppCol(this.turn); | |
50 | const lastRank = (color == "w" ? 0 : V.size.x - 1); | |
51 | if (ArrayFun.range(8).some(i => this.getColor(lastRank, i) == color)) | |
52 | // The opposing edge is reached! | |
53 | return color == "w" ? "1-0" : "0-1"; | |
54 | if (this.atLeastOneMove()) return "*"; | |
55 | // Stalemate (will probably never happen) | |
56 | return "1/2"; | |
57 | } | |
58 | }; |