Fixing attempt: clients now track tmpIds to know who is online/onfocus. Bug fixed...
[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 {
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
6f2f9437
BA
17 scanKings() {}
18
77691911
BA
19 getPotentialMovesFrom(sq) {
20 // There are only pawns:
21 return this.getPotentialPawnMoves(sq);
22 }
23
24 getPotentialPawnMoves(sq) {
25 const moves = super.getPotentialPawnMoves(sq);
26 // Add king movements, without capturing
27 const steps =
28 this.turn == 'w'
29 ? [ [-1,-1], [-1,1], [0,1], [0,-1], [1,-1], [1,0], [1,1] ]
30 : [ [1,-1], [1,1], [0,1], [0,-1], [-1,-1], [-1,0], [-1,1] ];
31 let addMoves = this.getSlideNJumpMoves(sq, steps, "oneStep");
32 return moves.concat(addMoves.filter(m => m.vanish.length == 1));
33 }
34
35 static GenRandInitFen() {
36 // Non-randomized variant. En-passant possible:
37 return "pppppppp/8/8/8/8/8/8/PPPPPPPP w 0 -";
38 }
39
40 filterValid(moves) {
41 return moves;
42 }
43
44 prePlay() {}
45 postPlay() {}
46 preUndo() {}
47 postUndo() {}
48
6f2f9437
BA
49 getCheckSquares() {
50 return [];
51 }
52
77691911
BA
53 getCurrentScore() {
54 // Turn has changed:
55 const color = V.GetOppCol(this.turn);
56 const lastRank = (color == "w" ? 0 : V.size.x - 1);
57 if (ArrayFun.range(8).some(i => this.getColor(lastRank, i) == color))
58 // The opposing edge is reached!
59 return color == "w" ? "1-0" : "0-1";
60 if (this.atLeastOneMove()) return "*";
61 // Stalemate (will probably never happen)
62 return "1/2";
63 }
64};