Several small improvements + integrate options + first working draft of Cwda
[vchess.git] / client / src / variants / Hoppelpoppel.js
CommitLineData
dbc79ee6
BA
1import { ChessRules } from "@/base_rules";
2
3export class HoppelpoppelRules extends ChessRules {
4
4313762d 5 // TODO: merge with base_rules.js (see also Orda, Empire)
dbc79ee6
BA
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]));
4313762d 14 if (oneStep) continue outerLoop;
dbc79ee6
BA
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 bishop
26 return (
27 this.getSlideNJumpMoves_(
28 sq, ChessRules.steps[V.KNIGHT], "oneStep", { onlyMove: true })
29 .concat(
30 this.getSlideNJumpMoves_(
31 sq, ChessRules.steps[V.BISHOP], null, { onlyTake: true }))
32 );
33 }
34
35 getPotentialBishopMoves(sq) {
36 // The bishop captures like a knight
37 return (
38 this.getSlideNJumpMoves_(
39 sq, ChessRules.steps[V.BISHOP], 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(
4313762d 48 [x, y], color, V.KNIGHT, V.steps[V.BISHOP]);
dbc79ee6
BA
49 }
50
2baa6f2c 51 isAttackedByBishop([x, y], color) {
dbc79ee6 52 return super.isAttackedBySlideNJump(
4313762d 53 [x, y], color, V.BISHOP, V.steps[V.KNIGHT], 1);
dbc79ee6
BA
54 }
55
56};