| 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 | input: [ |
| 11 | { |
| 12 | label: "Balanced", |
| 13 | variable: "rempawn", |
| 14 | type: "checkbox", |
| 15 | defaut: false |
| 16 | }, |
| 17 | { |
| 18 | label: "Falling pawn", |
| 19 | variable: "pawnfall", |
| 20 | type: "checkbox", |
| 21 | defaut: false |
| 22 | } |
| 23 | ], |
| 24 | styles: C.Options.styles.filter(s => s != "atomic") |
| 25 | }; |
| 26 | } |
| 27 | |
| 28 | constructor(o) { |
| 29 | o.options["atomic"] = true; |
| 30 | super(o); |
| 31 | } |
| 32 | |
| 33 | canIplay(x, y) { |
| 34 | if (this.options["rempawn"] && this.movesCount == 0) |
| 35 | return (this.playerColor == this.turn && this.getPiece(x, y) == "p"); |
| 36 | return super.canIplay(x, y); |
| 37 | } |
| 38 | |
| 39 | getPotentialMovesFrom([x, y], color) { |
| 40 | if (this.options["rempawn"] && this.movesCount == 0) { |
| 41 | if ([1, 6].includes(x)) { |
| 42 | const c = this.getColor(x, y); |
| 43 | return [ |
| 44 | new Move({ |
| 45 | appear: [], |
| 46 | vanish: [ |
| 47 | new PiPo({ |
| 48 | x: x, |
| 49 | y: y, |
| 50 | p: "p", |
| 51 | c: c |
| 52 | }) |
| 53 | ], |
| 54 | start: { x: x, y: y }, |
| 55 | end: { x: x, y: y } |
| 56 | }) |
| 57 | ]; |
| 58 | } |
| 59 | return []; |
| 60 | } |
| 61 | return super.getPotentialMovesFrom([x, y], color); |
| 62 | } |
| 63 | |
| 64 | doClick(square) { |
| 65 | if (!this.options["rempawn"] || this.movesCount >= 1) |
| 66 | return super.doClick(square); |
| 67 | const [x, y] = [square[0], square[1]]; |
| 68 | const moves = this.getPotentialMovesFrom([x, y]); |
| 69 | return (moves.length >= 1 ? moves[0] : null); |
| 70 | } |
| 71 | |
| 72 | }; |