Finish code refactoring to generate initial positions (untested)
[xogo.git] / variants / Giveaway / class.js
CommitLineData
8f57fbf2 1import ChessRules from "/base_rules.js";
f3e90e30
BA
2import {ArrayFun} from "/utils/array.js";
3import {Random} from "/utils/alea.js";
7c038235 4import {FenUtil} from "/utils/setupPieces.js";
8f57fbf2
BA
5
6export default class GiveawayRules extends ChessRules {
7
8 static get Options() {
9 return {
10 select: [
11 {
12 label: "Mode",
13 variable: "mode",
14 defaut: "suicide",
15 options: [
16 {label: "Suicide", value: "suicide"},
17 {label: "Losers", value: "losers"}
18 ]
19 }
20 ].concat(C.Options.select),
21 input: C.Options.input.filter(i => i.variable == "pawnfall"),
22 styles: [
23 "atomic", "cannibal", "cylinder", "dark",
24 "madrasi", "rifle", "teleport", "zen"
25 ]
26 };
27 }
28
29 get hasFlags() {
30 return this.options["mode"] == "losers";
31 }
32
33 get pawnPromotions() {
34 let res = ['q', 'r', 'n', 'b'];
35 if (this.options["mode"] == "suicide")
36 res.push('k');
37 return res;
38 }
39
f31de5e4 40 genRandInitBaseFen() {
7c038235
BA
41 let setupOpts = {diffCol: ['b']};
42 if (this.options["mode"] == "losers") {
43 setupOpts["between"] = ['k', 'r'];
44 setupOpts["flags"] = ['r'];
8f57fbf2 45 }
7c038235
BA
46 const s = FenUtil.setupPieces(
47 ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'], setupOpts);
48 return {
49 fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
50 s.w.join("").toUpperCase(),
51 o: {flags: s.flags}
52 };
8f57fbf2
BA
53 }
54
55 constructor(o) {
56 o.options["capture"] = true;
57 super(o);
58 }
59
9aebe2aa 60 underCheck(square_s, oppCol) {
8f57fbf2
BA
61 if (this.options["mode"] == "suicide")
62 return false;
9aebe2aa 63 return super.underCheck(square_s, oppCol);
8f57fbf2
BA
64 }
65
66 getCurrentScore() {
f31de5e4
BA
67 if (this.atLeastOneMove(this.turn))
68 return "*";
8f57fbf2
BA
69 // No valid move: the side who cannot move wins
70 return (this.turn == "w" ? "1-0" : "0-1");
71 }
72
73};