77f5c74770b1807b5e5db3f9ea1869e0c1621df6
1 import ChessRules
from "/base_rules.js";
2 import { ArrayFun
} from "/utils/array.js";
3 import { Random
} from "/utils/alea.js";
5 export default class GiveawayRules
extends ChessRules
{
15 {label: "Suicide", value: "suicide"},
16 {label: "Losers", value: "losers"}
19 ].concat(C
.Options
.select
),
20 input: C
.Options
.input
.filter(i
=> i
.variable
== "pawnfall"),
22 "atomic", "cannibal", "cylinder", "dark",
23 "madrasi", "rifle", "teleport", "zen"
29 return this.options
["mode"] == "losers";
32 get pawnPromotions() {
33 let res
= ['q', 'r', 'n', 'b'];
34 if (this.options
["mode"] == "suicide")
39 genRandInitFen(seed
) {
40 if (this.options
["randomness"] == 0) {
42 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w 0 {"enpassant":"-"}'
47 let pieces
= { w: new Array(8), b: new Array(8) };
48 for (let c
of ["w", "b"]) {
49 if (c
== 'b' && this.options
["randomness"] == 1) {
50 pieces
['b'] = pieces
['w'];
54 // Get random squares for every piece, totally freely
55 let positions
= Random
.shuffle(ArrayFun
.range(8));
56 const composition
= ['b', 'b', 'r', 'r', 'n', 'n', 'k', 'q'];
57 const rem2
= positions
[0] % 2;
58 if (rem2
== positions
[1] % 2) {
59 // Fix bishops (on different colors)
60 for (let i
=2; i
<8; i
++) {
61 if (positions
[i
] % 2 != rem2
) {
62 [positions
[1], positions
[i
]] = [positions
[i
], positions
[1]];
67 for (let i
= 0; i
< 8; i
++)
68 pieces
[c
][positions
[i
]] = composition
[i
];
71 pieces
["b"].join("") +
72 "/pppppppp/8/8/8/8/PPPPPPPP/" +
73 pieces
["w"].join("").toUpperCase() +
74 // En-passant allowed, but no flags
75 ' w 0 {"enpassant":"-"}'
80 o
.options
["capture"] = true;
84 underCheck([x
, y
], oppCol
) {
85 if (this.options
["mode"] == "suicide")
87 return super.underCheck([x
, y
], oppCol
);
91 if (this.atLeastOneMove()) return "*";
92 // No valid move: the side who cannot move wins
93 return (this.turn
== "w" ? "1-0" : "0-1");