Some fixes, draw lines on board, add 7 variants
[vchess.git] / client / src / variants / Gridolina.js
diff --git a/client/src/variants/Gridolina.js b/client/src/variants/Gridolina.js
new file mode 100644 (file)
index 0000000..fd43be3
--- /dev/null
@@ -0,0 +1,37 @@
+import { ChessRules } from "@/base_rules";
+import { BerolinaRules } from "@/variants/Berolina";
+
+export class GridolinaRules extends BerolinaRules {
+  static get Lines() {
+    return [
+      [[2, 0], [2, 8]],
+      [[4, 0], [4, 8]],
+      [[6, 0], [6, 8]],
+      [[0, 2], [8, 2]],
+      [[0, 4], [8, 4]],
+      [[0, 6], [8, 6]]
+    ];
+  }
+
+  static OnDifferentGrids([x1, y1], [x2, y2]) {
+    return (
+        Math.abs(Math.floor(x1 / 2) - Math.floor(x2 / 2)) >= 1 ||
+        Math.abs(Math.floor(y1 / 2) - Math.floor(y2 / 2)) >= 1
+    );
+  }
+
+  canTake([x1, y1], [x2, y2]) {
+    return (
+      V.OnDifferentGrids([x1, y1], [x2, y2]) &&
+      super.canTake([x1, y1], [x2, y2])
+    );
+  }
+
+  getPotentialMovesFrom([x, y]) {
+    return (
+      super.getPotentialMovesFrom([x, y]).filter(m => {
+        return V.OnDifferentGrids([x, y], [m.end.x, m.end.y]);
+      })
+    );
+  }
+};