Fix Maxima (immobilize kings too)
[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
4313762d 6 // TODO: merge with base_rules.js
afa7abae
BA
7 getSlideNJumpMoves_([x, y], steps, oneStep, options) {
8 options = options || {};
9 let moves = [];
10 outerLoop: for (let step of steps) {
11 let i = x + step[0];
12 let j = y + step[1];
13 while (V.OnBoard(i, j) && this.board[i][j] == V.EMPTY) {
14 if (!options.onlyTake) moves.push(this.getBasicMove([x, y], [i, j]));
4313762d 15 if (oneStep) continue outerLoop;
afa7abae
BA
16 i += step[0];
17 j += step[1];
18 }
19 if (V.OnBoard(i, j) && this.canTake([x, y], [i, j]) && !options.onlyMove)
20 moves.push(this.getBasicMove([x, y], [i, j]));
21 }
22 return moves;
23 }
24
25 getPotentialKnightMoves(sq) {
26 // The knight captures like a rook
27 return (
28 this.getSlideNJumpMoves_(
29 sq, ChessRules.steps[V.KNIGHT], "oneStep", { onlyMove: true })
30 .concat(
31 this.getSlideNJumpMoves_(
32 sq, ChessRules.steps[V.ROOK], null, { onlyTake: true }))
33 );
34 }
35
36 getPotentialRookMoves(sq) {
37 // The rook captures like a knight
38 return (
39 this.getSlideNJumpMoves_(
40 sq, ChessRules.steps[V.ROOK], null, { onlyMove: true })
41 .concat(
42 this.getSlideNJumpMoves_(
43 sq, ChessRules.steps[V.KNIGHT], "oneStep", { onlyTake: true }))
44 );
45 }
46
47 isAttackedByKnight([x, y], color) {
48 return super.isAttackedBySlideNJump(
4313762d 49 [x, y], color, V.KNIGHT, V.steps[V.ROOK]);
afa7abae
BA
50 }
51
73968079 52 isAttackedByRook([x, y], color) {
afa7abae 53 return super.isAttackedBySlideNJump(
4313762d 54 [x, y], color, V.ROOK, V.steps[V.KNIGHT], 1);
afa7abae
BA
55 }
56
57};