Fix Eightpieces
[vchess.git] / client / src / variants / Hoppelpoppel.js
1 import { ChessRules } from "@/base_rules";
2
3 export class HoppelpoppelRules extends ChessRules {
4
5 // TODO: merge with base_rules.js (see also Orda, Empire)
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 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(
48 [x, y], color, V.KNIGHT, V.steps[V.BISHOP]);
49 }
50
51 isAttackedByBishop([x, y], color) {
52 return super.isAttackedBySlideNJump(
53 [x, y], color, V.BISHOP, V.steps[V.KNIGHT], 1);
54 }
55
56 };