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