Add Koopa chess, fix Apocalypse and Dice variants
[vchess.git] / client / src / variants / Balaklava.js
CommitLineData
a0224b03
BA
1import { ChessRules } from "@/base_rules";
2
3export class BalaklavaRules extends ChessRules {
4 static get PawnSpecs() {
5 return Object.assign(
6 {},
7 ChessRules.PawnSpecs,
8 { promotions: [V.ROOK, V.MAMMOTH, V.BISHOP, V.QUEEN] }
9 );
10 }
11
12 static get HasEnpassant() {
13 return false;
14 }
15
16 getPpath(b) {
17 return (b[1] == V.MAMMOTH ? "Balaklava/" : "") + b;
18 }
19
20 // Alfil + Dabbaba:
21 static get MAMMOTH() {
22 return "m";
23 }
24
25 static get PIECES() {
26 return [V.PAWN, V.ROOK, V.MAMMOTH, V.BISHOP, V.QUEEN, V.KING];
27 }
28
29 static get steps() {
30 return Object.assign(
31 {},
32 ChessRules.steps,
33 {
34 m: [
35 [-2, -2],
36 [-2, 0],
37 [-2, 2],
38 [0, -2],
39 [0, 2],
40 [2, -2],
41 [2, 0],
42 [2, 2],
43 ]
44 }
45 );
46 }
47
48 static GenRandInitFen(randomness) {
49 // No collision between 'n' and castle flags, so next replacement is fine
50 return (
51 ChessRules.GenRandInitFen(randomness)
52 .replace(/n/g, 'm').replace(/N/g, 'M')
53 );
54 }
55
56 getPotentialMovesFrom([x, y]) {
57 const piece = this.getPiece(x, y);
58 let moves =
59 piece == V.MAMMOTH
60 ? this.getPotentialMammothMoves([x, y])
61 : super.getPotentialMovesFrom([x, y]);
62 if (piece != V.KING) {
63 // Add non-capturing knight movements
64 const lastRank = (this.turn == 'w' ? 0 : 7);
65 V.steps[V.KNIGHT].forEach(step => {
66 const [i, j] = [x + step[0], y + step[1]];
67 if (
68 V.OnBoard(i, j) &&
69 this.board[i][j] == V.EMPTY &&
70 // Pawns don't promote with a knight move
71 (piece != V.PAWN || i != lastRank)
72 ) {
73 moves.push(this.getBasicMove([x, y], [i, j]));
74 }
75 });
76 }
77 return moves;
78 }
79
80 getPotentialMammothMoves(sq) {
81 return this.getSlideNJumpMoves(sq, V.steps[V.MAMMOTH], "oneStep");
82 }
83
84 isAttacked(sq, color) {
85 return (
86 super.isAttacked(sq, color) ||
87 this.isAttackedByMammoth(sq, color)
88 );
89 }
90
91 isAttackedByMammoth(sq, color) {
92 return (
93 this.isAttackedBySlideNJump(
94 sq, color, V.MAMMOTH, V.steps[V.MAMMOTH], "oneStep")
95 );
96 }
97
98 static get SEARCH_DEPTH() {
99 return 2;
100 }
101
102 static get VALUES() {
103 return Object.assign(
104 // A mammoth is probably worth a little more than a knight
105 { m: 4 },
106 ChessRules.VALUES
107 );
108 }
109};