update
[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
BA
16 },
17 {
18 label: "Falling pawn",
535c464b
BA
19 variable: "pawnfall",
20 type: "checkbox",
21 defaut: false
3a77a0b4
BA
22 }
23 ],
24 styles: C.Options.styles.filter(s => s != "atomic")
25 };
26 }
27
28 constructor(o) {
c9ab0340 29 o.options["atomic"] = true;
3a77a0b4 30 super(o);
3a77a0b4
BA
31 }
32
33 canIplay(x, y) {
34 if (this.options["rempawn"] && this.movesCount == 0)
639afc98 35 return (this.playerColor == this.turn && this.getPiece(x, y) == "p");
3a77a0b4
BA
36 return super.canIplay(x, y);
37 }
38
39 getPotentialMovesFrom([x, y], color) {
40 if (this.options["rempawn"] && this.movesCount == 0) {
41 if ([1, 6].includes(x)) {
42 const c = this.getColor(x, y);
43 return [
44 new Move({
45 appear: [],
46 vanish: [
47 new PiPo({
48 x: x,
49 y: y,
50 p: "p",
51 c: c
52 })
53 ],
54 start: { x: x, y: y },
55 end: { x: x, y: y }
56 })
57 ];
58 }
59 return [];
60 }
61 return super.getPotentialMovesFrom([x, y], color);
62 }
63
64 doClick(square) {
65 if (!this.options["rempawn"] || this.movesCount >= 1)
66 return super.doClick(square);
67 const [x, y] = [square[0], square[1]];
68 const moves = this.getPotentialMovesFrom([x, y]);
69 return (moves.length >= 1 ? moves[0] : null);
70 }
71
72};