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