Add Giveaway. Preparing for Chakart a little more
[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 input: [
11 {
12 label: "Balanced",
13 variable: "rempawn",
14 type: "checkbox",
15 defaut: false
16 }
17 ].concat(C.Options.input.filter(i => i.variable == "pawnfall")),
18 styles: C.Options.styles.filter(s => s != "atomic")
19 };
20 }
21
22 constructor(o) {
23 o.options["atomic"] = true;
24 super(o);
25 }
26
27 canIplay(x, y) {
28 if (this.options["rempawn"] && this.movesCount == 0)
29 return (this.playerColor == this.turn && this.getPiece(x, y) == "p");
30 return super.canIplay(x, y);
31 }
32
33 getPotentialMovesFrom([x, y], color) {
34 if (this.options["rempawn"] && this.movesCount == 0) {
35 if ([1, 6].includes(x)) {
36 const c = this.getColor(x, y);
37 return [
38 new Move({
39 appear: [],
40 vanish: [
41 new PiPo({
42 x: x,
43 y: y,
44 p: "p",
45 c: c
46 })
47 ],
48 start: { x: x, y: y },
49 end: { x: x, y: y }
50 })
51 ];
52 }
53 return [];
54 }
55 return super.getPotentialMovesFrom([x, y], color);
56 }
57
58 doClick(square) {
59 if (!this.options["rempawn"] || this.movesCount >= 1)
60 return super.doClick(square);
61 const [x, y] = [square[0], square[1]];
62 const moves = this.getPotentialMovesFrom([x, y]);
63 return (moves.length >= 1 ? moves[0] : null);
64 }
65
66 };