Attempt to improve scrolling on smartphone
[vchess.git] / client / src / variants / Gridolina.js
1 import { ChessRules } from "@/base_rules";
2 import { BerolinaRules } from "@/variants/Berolina";
3
4 export class GridolinaRules extends BerolinaRules {
5
6 static get Lines() {
7 return [
8 [[2, 0], [2, 8]],
9 [[4, 0], [4, 8]],
10 [[6, 0], [6, 8]],
11 [[0, 2], [8, 2]],
12 [[0, 4], [8, 4]],
13 [[0, 6], [8, 6]]
14 ];
15 }
16
17 static OnDifferentGrids([x1, y1], [x2, y2]) {
18 return (
19 Math.abs(Math.floor(x1 / 2) - Math.floor(x2 / 2)) >= 1 ||
20 Math.abs(Math.floor(y1 / 2) - Math.floor(y2 / 2)) >= 1
21 );
22 }
23
24 canTake([x1, y1], [x2, y2]) {
25 return (
26 V.OnDifferentGrids([x1, y1], [x2, y2]) &&
27 super.canTake([x1, y1], [x2, y2])
28 );
29 }
30
31 getPotentialMovesFrom([x, y]) {
32 return (
33 super.getPotentialMovesFrom([x, y]).filter(m => {
34 return V.OnDifferentGrids([x, y], [m.end.x, m.end.y]);
35 })
36 );
37 }
38
39 isAttackedBySlideNJump([x, y], color, piece, steps, oneStep) {
40 for (let step of steps) {
41 let rx = x + step[0],
42 ry = y + step[1];
43 while (V.OnBoard(rx, ry) && this.board[rx][ry] == V.EMPTY && !oneStep) {
44 rx += step[0];
45 ry += step[1];
46 }
47 if (
48 V.OnBoard(rx, ry) &&
49 this.getPiece(rx, ry) == piece &&
50 this.getColor(rx, ry) == color &&
51 V.OnDifferentGrids([x, y], [rx, ry])
52 ) {
53 return true;
54 }
55 }
56 return false;
57 }
58
59 };