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