Commit | Line | Data |
---|---|---|
41534b92 BA |
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 { | |
cc2c7183 | 8 | select: C.Options.select, |
e2be4b04 BA |
9 | input: [ |
10 | { | |
11 | label: "Cleopatra", | |
12 | variable: "cleopatra", | |
13 | type: "checkbox", | |
14 | defaut: false | |
15 | } | |
16 | ], | |
b99ce1fb BA |
17 | styles: [ |
18 | "balance", | |
19 | "cylinder", | |
20 | "dark", | |
21 | "doublemove", | |
22 | "progressive", | |
23 | "zen" | |
24 | ] | |
41534b92 BA |
25 | }; |
26 | } | |
27 | ||
28 | get hasEnpassant() { | |
29 | return false; | |
30 | } | |
31 | ||
082e639a BA |
32 | canTake() { |
33 | return false; | |
34 | } | |
35 | ||
e2be4b04 BA |
36 | pieces(color, x, y) { |
37 | if (!this.options["cleopatra"]) | |
38 | return super.pieces(color, x, y); | |
65cf1690 BA |
39 | const allSpecs = super.pieces(color, x, y); |
40 | return Object.assign({}, | |
41 | allSpecs, | |
42 | {'q': Object.assign({}, allSpecs['q'], {"class": "cleopatra"})} | |
43 | ); | |
e2be4b04 BA |
44 | } |
45 | ||
41534b92 | 46 | postProcessPotentialMoves(moves) { |
6b9320bb BA |
47 | const oppCol = C.GetOppCol(this.turn); |
48 | let bMoves = super.postProcessPotentialMoves(moves); | |
49 | bMoves.forEach(m => { | |
e2be4b04 BA |
50 | m.flips = []; |
51 | if (!this.options["cleopatra"] || m.vanish[0].p == 'q') { | |
52 | super.playOnBoard(m); | |
af9c9be3 BA |
53 | let attacks = super.findDestSquares( |
54 | [m.end.x, m.end.y], | |
6b9320bb BA |
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 | } | |
af9c9be3 | 65 | ); |
e2be4b04 | 66 | if (this.options["zen"]) { |
af9c9be3 BA |
67 | const zenAttacks = super.findCapturesOn( |
68 | [m.end.x, m.end.y], | |
6b9320bb BA |
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]) | |
af9c9be3 BA |
75 | ); |
76 | Array.prototype.push.apply(attacks, zenAttacks); | |
e2be4b04 BA |
77 | } |
78 | super.undoOnBoard(m); | |
af9c9be3 | 79 | attacks.forEach(a => m.flips.push({x: a.sq[0], y: a.sq[1]})); |
41534b92 | 80 | } |
41534b92 | 81 | }); |
6b9320bb | 82 | return bMoves; |
41534b92 BA |
83 | } |
84 | ||
6997e386 BA |
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 | ||
6997e386 | 101 | // Moves cannot flip our king's color, so all are valid |
41534b92 | 102 | filterValid(moves) { |
41534b92 BA |
103 | return moves; |
104 | } | |
105 | ||
6997e386 | 106 | // A king under (regular) check flips color, and the game is over. |
082e639a | 107 | underCheck() { |
41534b92 BA |
108 | return false; |
109 | } | |
110 | ||
6997e386 BA |
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 | ||
41534b92 | 119 | }; |