Add some more variants; TODO: Doublemove options
[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 super(o);
28 this.options.atomic = true;
29 }
30
31 genRandInitFen(seed) {
32 return super.genRandInitFen(seed).slice(0, -1) + ',"rempawn":' + (this.options.rempawn ? "1" : "0") + "}";
33 }
34
35 // TODO: capture king option doesn't make sense
36
37 setOtherVariables(fenParsed) {
38 super.setOtherVariables(fenParsed);
39 this.options["rempawn"] = (fenParsed.rempawn == 1);
40 }
41
42 getFen() {
43 return super.getFen().slice(0, -1) + ',"rempawn":' + (this.options["rempawn"] ? "1" : "0") + "}";
44 }
45
46 canIplay(x, y) {
47 if (this.options["rempawn"] && this.movesCount == 0)
48 return (this.turn == side && this.getPiece(x, y) == "p");
49 return super.canIplay(x, y);
50 }
51
52 getPotentialMovesFrom([x, y], color) {
53 if (this.options["rempawn"] && this.movesCount == 0) {
54 if ([1, 6].includes(x)) {
55 const c = this.getColor(x, y);
56 return [
57 new Move({
58 appear: [],
59 vanish: [
60 new PiPo({
61 x: x,
62 y: y,
63 p: "p",
64 c: c
65 })
66 ],
67 start: { x: x, y: y },
68 end: { x: x, y: y }
69 })
70 ];
71 }
72 return [];
73 }
74 return super.getPotentialMovesFrom([x, y], color);
75 }
76
77 doClick(square) {
78 if (!this.options["rempawn"] || this.movesCount >= 1)
79 return super.doClick(square);
80 const [x, y] = [square[0], square[1]];
81 const moves = this.getPotentialMovesFrom([x, y]);
82 return (moves.length >= 1 ? moves[0] : null);
83 }
84
85 };