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