After base_rules refactoring. Still a few issues (Dark...)
[xogo.git] / variants / Atomic / class.js
1 import ChessRules from "/base_rules.js";
2 import PiPo from "/utils/PiPo.js";
3 import Move from "/utils/Move.js";
4
5 export default class AtomicRules extends ChessRules {
6
7 static get Options() {
8 return {
9 select: C.Options.select,
10 check: [
11 {
12 label: "Balanced",
13 defaut: false,
14 variable: "rempawn"
15 },
16 {
17 label: "Falling pawn",
18 defaut: false,
19 variable: "pawnfall"
20 }
21 ],
22 styles: C.Options.styles.filter(s => s != "atomic")
23 };
24 }
25
26 constructor(o) {
27 o.options["atomic"] = true;
28 super(o);
29 }
30
31 canIplay(x, y) {
32 if (this.options["rempawn"] && this.movesCount == 0)
33 return (this.turn == side && this.getPiece(x, y) == "p");
34 return super.canIplay(x, y);
35 }
36
37 getPotentialMovesFrom([x, y], color) {
38 if (this.options["rempawn"] && this.movesCount == 0) {
39 if ([1, 6].includes(x)) {
40 const c = this.getColor(x, y);
41 return [
42 new Move({
43 appear: [],
44 vanish: [
45 new PiPo({
46 x: x,
47 y: y,
48 p: "p",
49 c: c
50 })
51 ],
52 start: { x: x, y: y },
53 end: { x: x, y: y }
54 })
55 ];
56 }
57 return [];
58 }
59 return super.getPotentialMovesFrom([x, y], color);
60 }
61
62 doClick(square) {
63 if (!this.options["rempawn"] || this.movesCount >= 1)
64 return super.doClick(square);
65 const [x, y] = [square[0], square[1]];
66 const moves = this.getPotentialMovesFrom([x, y]);
67 return (moves.length >= 1 ? moves[0] : null);
68 }
69
70 };