Pandemonium 1 & 2, Stealthbomb 1 & 2
[vchess.git] / client / src / variants / Newzealand.js
CommitLineData
afa7abae
BA
1import { ChessRules } from "@/base_rules";
2
3// NOTE: a lot copy-pasted from Hoppelpoppel
4export class NewzealandRules extends ChessRules {
5
6 getSlideNJumpMoves_([x, y], steps, oneStep, options) {
7 options = options || {};
8 let moves = [];
9 outerLoop: for (let step of steps) {
10 let i = x + step[0];
11 let j = y + step[1];
12 while (V.OnBoard(i, j) && this.board[i][j] == V.EMPTY) {
13 if (!options.onlyTake) moves.push(this.getBasicMove([x, y], [i, j]));
14 if (!!oneStep) continue outerLoop;
15 i += step[0];
16 j += step[1];
17 }
18 if (V.OnBoard(i, j) && this.canTake([x, y], [i, j]) && !options.onlyMove)
19 moves.push(this.getBasicMove([x, y], [i, j]));
20 }
21 return moves;
22 }
23
24 getPotentialKnightMoves(sq) {
25 // The knight captures like a rook
26 return (
27 this.getSlideNJumpMoves_(
28 sq, ChessRules.steps[V.KNIGHT], "oneStep", { onlyMove: true })
29 .concat(
30 this.getSlideNJumpMoves_(
31 sq, ChessRules.steps[V.ROOK], null, { onlyTake: true }))
32 );
33 }
34
35 getPotentialRookMoves(sq) {
36 // The rook captures like a knight
37 return (
38 this.getSlideNJumpMoves_(
39 sq, ChessRules.steps[V.ROOK], null, { onlyMove: true })
40 .concat(
41 this.getSlideNJumpMoves_(
42 sq, ChessRules.steps[V.KNIGHT], "oneStep", { onlyTake: true }))
43 );
44 }
45
46 isAttackedByKnight([x, y], color) {
47 return super.isAttackedBySlideNJump(
48 [x, y],
49 color,
50 V.KNIGHT,
51 V.steps[V.ROOK]
52 );
53 }
54
73968079 55 isAttackedByRook([x, y], color) {
afa7abae
BA
56 return super.isAttackedBySlideNJump(
57 [x, y],
58 color,
59 V.ROOK,
60 V.steps[V.KNIGHT],
61 "oneStep"
62 );
63 }
64
65};