Attempt to improve scrolling on smartphone
[vchess.git] / client / src / variants / Makpong.js
CommitLineData
dbc79ee6
BA
1import { MakrukRules } from "@/variants/Makruk";
2
3export class MakpongRules extends MakrukRules {
4
5 filterValid(moves) {
6 const color = this.turn;
f5cd0fb8
BA
7 if (!this.underCheck(color)) return super.filterValid(moves);
8 // Filter out all moves involving king, except for capturing a
9 // potential attacker.
10 const pawnAttack = (color == 'w' ? -1 : 1);
11 return super.filterValid(moves.filter(m => {
12 const p = (m.vanish.length == 2 ? m.vanish[1].p : null);
13 return (
14 m.vanish[0].p != V.KING ||
15 (
16 m.vanish.length == 2 &&
17 (
18 (
19 p == V.PAWN &&
20 m.end.x - m.start.x == pawnAttack &&
21 Math.abs(m.end.y - m.start.y) == 1
22 )
23 ||
24 (
25 p == V.ROOK &&
26 (m.end.x == m.start.x || m.end.y == m.start.y)
27 )
28 ||
29 (
30 [V.PROMOTED, V.QUEEN].includes(p) &&
31 m.end.x != m.start.x && m.end.y != m.start.y
32 )
33 ||
34 (
35 p == V.BISHOP &&
36 (
37 m.end.x - m.start.x == pawnAttack ||
38 (
39 m.end.x - m.start.x == -pawnAttack &&
40 Math.abs(m.end.y - m.start.y) == 1
41 )
42 )
43 )
44 )
45 )
46 );
47 }));
dbc79ee6
BA
48 }
49
50};