| 1 | import ChessRules from "/base_rules.js"; |
| 2 | import PiPo from "/utils/PiPo.js"; |
| 3 | |
| 4 | export default class BenedictRules extends ChessRules { |
| 5 | |
| 6 | static get Options() { |
| 7 | return { |
| 8 | select: C.Options.select, |
| 9 | input: [ |
| 10 | { |
| 11 | label: "Cleopatra", |
| 12 | variable: "cleopatra", |
| 13 | type: "checkbox", |
| 14 | defaut: false |
| 15 | } |
| 16 | ], |
| 17 | styles: [ |
| 18 | "balance", |
| 19 | "cylinder", |
| 20 | "dark", |
| 21 | "doublemove", |
| 22 | "progressive", |
| 23 | "zen" |
| 24 | ] |
| 25 | }; |
| 26 | } |
| 27 | |
| 28 | get hasEnpassant() { |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | canTake() { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | pieces(color, x, y) { |
| 37 | if (!this.options["cleopatra"]) |
| 38 | return super.pieces(color, x, y); |
| 39 | const allSpecs = super.pieces(color, x, y); |
| 40 | return Object.assign({}, |
| 41 | allSpecs, |
| 42 | {'q': Object.assign({}, allSpecs['q'], {"class": "cleopatra"})} |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | postProcessPotentialMoves(moves) { |
| 47 | const oppCol = C.GetOppCol(this.turn); |
| 48 | let bMoves = super.postProcessPotentialMoves(moves); |
| 49 | bMoves.forEach(m => { |
| 50 | m.flips = []; |
| 51 | if (!this.options["cleopatra"] || m.vanish[0].p == 'q') { |
| 52 | super.playOnBoard(m); |
| 53 | let attacks = super.findDestSquares( |
| 54 | [m.end.x, m.end.y], |
| 55 | { |
| 56 | attackOnly: true, |
| 57 | segments: this.options["cylinder"] |
| 58 | }, |
| 59 | ([i1, j1], [i2, j2]) => { |
| 60 | return ( |
| 61 | super.canTake([i1, j1], [i2, j2]) && |
| 62 | (!this.options["zen"] || this.getPiece(i2, j2) == 'k') |
| 63 | ); |
| 64 | } |
| 65 | ); |
| 66 | if (this.options["zen"]) { |
| 67 | const zenAttacks = super.findCapturesOn( |
| 68 | [m.end.x, m.end.y], |
| 69 | { |
| 70 | byCol: [oppCol], |
| 71 | segments: this.options["cylinder"] |
| 72 | }, |
| 73 | ([i1, j1], [i2, j2]) => |
| 74 | this.getPiece(i1, j1) != 'k' && super.canTake([i2, j2], [i1, j1]) |
| 75 | ); |
| 76 | Array.prototype.push.apply(attacks, zenAttacks); |
| 77 | } |
| 78 | super.undoOnBoard(m); |
| 79 | attacks.forEach(a => m.flips.push({x: a.sq[0], y: a.sq[1]})); |
| 80 | } |
| 81 | }); |
| 82 | return bMoves; |
| 83 | } |
| 84 | |
| 85 | playOnBoard(move) { |
| 86 | super.playOnBoard(move); |
| 87 | this.flipColorOf(move.flips); |
| 88 | } |
| 89 | undoOnBoard(move) { |
| 90 | super.undoOnBoard(move); |
| 91 | this.flipColorOf(move.flips); |
| 92 | } |
| 93 | |
| 94 | flipColorOf(flips) { |
| 95 | for (let xy of flips) { |
| 96 | const newColor = C.GetOppCol(this.getColor(xy.x, xy.y)); |
| 97 | this.board[xy.x][xy.y] = newColor + this.board[xy.x][xy.y][1]; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // Moves cannot flip our king's color, so all are valid |
| 102 | filterValid(moves) { |
| 103 | return moves; |
| 104 | } |
| 105 | |
| 106 | // A king under (regular) check flips color, and the game is over. |
| 107 | underCheck() { |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | playVisual(move, r) { |
| 112 | super.playVisual(move, r); |
| 113 | move.flips.forEach(f => { |
| 114 | this.g_pieces[f.x][f.y].classList.toggle("white"); |
| 115 | this.g_pieces[f.x][f.y].classList.toggle("black"); |
| 116 | }); |
| 117 | } |
| 118 | |
| 119 | }; |