Almost added TitanChess + EvolutionChess
[vchess.git] / client / src / variants / Evolution.js
1 import { ChessRules } from "@/base_rules";
2
3 export class EvolutionRules extends ChessRules {
4
5 getPotentialMovesFrom([x, y]) {
6 let moves = super.getPotentialMovesFrom([x, y]);
7 const c = this.getColor(x, y);
8 const piece = this.getPiece(x, y);
9 if (
10 [V.BISHOP, V.ROOK, V.QUEEN].includes(piece) &&
11 (c == 'w' && x == 7) || (c == 'b' && x == 0)
12 ) {
13 // Move from first rank
14 const forward = (c == 'w' ? -1 : 1);
15 for (let shift of [-2, 0, 2]) {
16 if (
17 (piece == V.ROOK && shift != 0) ||
18 (piece == V.BISHOP && shift == 0)
19 ) {
20 continue;
21 }
22 if (
23 V.OnBoard(x+2*forward, y+shift) &&
24 this.board[x+forward][y+shift/2] != V.EMPTY &&
25 this.getColor(x+2*forward, y+shift) != c
26 ) {
27 moves.push(this.getBasicMove([x,y], [x+2*forward,y+shift]));
28 }
29 }
30 }
31 return moves;
32 }
33
34 };