New variant idea
[xogo.git] / variants / Atomic / class.js
CommitLineData
3a77a0b4
BA
1import ChessRules from "/base_rules.js";
2import PiPo from "/utils/PiPo.js";
3import Move from "/utils/Move.js";
4
5export default class AtomicRules extends ChessRules {
6
7 static get Options() {
8 return {
9 select: C.Options.select,
535c464b 10 input: [
3a77a0b4
BA
11 {
12 label: "Balanced",
535c464b
BA
13 variable: "rempawn",
14 type: "checkbox",
15 defaut: false
3a77a0b4 16 }
8f57fbf2 17 ].concat(C.Options.input.filter(i => i.variable == "pawnfall")),
3a77a0b4
BA
18 styles: C.Options.styles.filter(s => s != "atomic")
19 };
20 }
21
22 constructor(o) {
c9ab0340 23 o.options["atomic"] = true;
3a77a0b4 24 super(o);
3a77a0b4
BA
25 }
26
27 canIplay(x, y) {
28 if (this.options["rempawn"] && this.movesCount == 0)
639afc98 29 return (this.playerColor == this.turn && this.getPiece(x, y) == "p");
3a77a0b4
BA
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 ],
33b42748
BA
48 start: {x: x, y: y},
49 end: {x: x, y: y}
3a77a0b4
BA
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};