New variant idea
[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() {
10c9010b
BA
41 let setupOpts = {
42 randomness: this.options["randomness"],
43 diffCol: ['b']
44 };
7c038235 45 if (this.options["mode"] == "losers") {
52718c94 46 setupOpts["between"] = [{p1: 'k', p2: 'r'}];
7c038235 47 setupOpts["flags"] = ['r'];
8f57fbf2 48 }
7c038235
BA
49 const s = FenUtil.setupPieces(
50 ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'], setupOpts);
51 return {
52 fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
53 s.w.join("").toUpperCase(),
54 o: {flags: s.flags}
55 };
8f57fbf2
BA
56 }
57
58 constructor(o) {
59 o.options["capture"] = true;
60 super(o);
61 }
62
9aebe2aa 63 underCheck(square_s, oppCol) {
8f57fbf2
BA
64 if (this.options["mode"] == "suicide")
65 return false;
9aebe2aa 66 return super.underCheck(square_s, oppCol);
8f57fbf2
BA
67 }
68
69 getCurrentScore() {
f31de5e4
BA
70 if (this.atLeastOneMove(this.turn))
71 return "*";
8f57fbf2
BA
72 // No valid move: the side who cannot move wins
73 return (this.turn == "w" ? "1-0" : "0-1");
74 }
75
76};