| 1 | import { ChessRules } from "@/base_rules"; |
| 2 | import { ArrayFun } from "@/utils/array"; |
| 3 | |
| 4 | export class RugbyRules extends ChessRules { |
| 5 | |
| 6 | static get Options() { |
| 7 | return null; |
| 8 | } |
| 9 | |
| 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 | |
| 22 | scanKings() {} |
| 23 | |
| 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] ]; |
| 36 | let addMoves = this.getSlideNJumpMoves(sq, steps, 1); |
| 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 | |
| 54 | getCheckSquares() { |
| 55 | return []; |
| 56 | } |
| 57 | |
| 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 | } |
| 69 | |
| 70 | getNotation(move) { |
| 71 | return V.CoordsToSquare(move.start) + V.CoordsToSquare(move.end); |
| 72 | } |
| 73 | |
| 74 | }; |