| 1 | import ChessRules from "/base_rules.js"; |
| 2 | import {ArrayFun} from "/utils/array.js"; |
| 3 | import {Random} from "/utils/alea.js"; |
| 4 | import {FenUtil} from "/utils/setupPieces.js"; |
| 5 | |
| 6 | export 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 | |
| 40 | genRandInitBaseFen() { |
| 41 | let setupOpts = { |
| 42 | randomness: this.options["randomness"], |
| 43 | diffCol: ['b'] |
| 44 | }; |
| 45 | if (this.options["mode"] == "losers") { |
| 46 | setupOpts["between"] = [{p1: 'k', p2: 'r'}]; |
| 47 | setupOpts["flags"] = ['r']; |
| 48 | } |
| 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 | }; |
| 56 | } |
| 57 | |
| 58 | constructor(o) { |
| 59 | o.options["capture"] = true; |
| 60 | super(o); |
| 61 | } |
| 62 | |
| 63 | underCheck(square_s, oppCol) { |
| 64 | if (this.options["mode"] == "suicide") |
| 65 | return false; |
| 66 | return super.underCheck(square_s, oppCol); |
| 67 | } |
| 68 | |
| 69 | getCurrentScore() { |
| 70 | if (this.atLeastOneMove(this.turn)) |
| 71 | return "*"; |
| 72 | // No valid move: the side who cannot move wins |
| 73 | return (this.turn == "w" ? "1-0" : "0-1"); |
| 74 | } |
| 75 | |
| 76 | }; |