Commit | Line | Data |
---|---|---|
bc97fdd1 | 1 | import AbstractSpecialCaptureRules from "/variants/_SpecialCaptures/class.js"; |
7c038235 | 2 | import {FenUtil} from "/utils/setupPieces.js"; |
0e466aac | 3 | import {Random} from "/utils/alea.js"; |
0e466aac | 4 | |
a89fb4e9 | 5 | export default class BaroqueRules extends AbstractSpecialCaptureRules { |
0e466aac BA |
6 | |
7 | static get Options() { | |
8 | return { | |
9 | select: C.Options.Select, | |
10 | input: [ | |
11 | { | |
12 | label: "Capture king", | |
13 | variable: "taking", | |
14 | type: "checkbox", | |
15 | defaut: false | |
16 | } | |
17 | ], | |
18 | styles: [ | |
19 | "balance", | |
20 | "capture", | |
21 | "crazyhouse", | |
22 | "cylinder", | |
23 | "doublemove", | |
24 | "progressive", | |
25 | "recycle", | |
26 | "teleport" | |
27 | ] | |
28 | }; | |
29 | } | |
30 | ||
31 | get hasFlags() { | |
32 | return false; | |
33 | } | |
0e466aac BA |
34 | |
35 | genRandInitBaseFen() { | |
7c038235 | 36 | const s = FenUtil.setupPieces( |
10c9010b BA |
37 | ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'i'], |
38 | { | |
39 | randomness: this.options["randomness"], | |
40 | diffCol: ['b'] | |
41 | } | |
42 | ); | |
7c038235 BA |
43 | if (this.options["randomness"] <= 1) { |
44 | // Fix immobilizers/rooks pattern | |
45 | const toExchange1 = s.w.indexOf('r'), | |
46 | toExchange2 = s.w.indexOf('i'); | |
47 | s.w[toExchange1] = 'i'; | |
48 | s.w[toExchange2] = 'r'; | |
0e466aac | 49 | } |
7c038235 BA |
50 | return { |
51 | fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" + | |
52 | s.w.join("").toUpperCase(), | |
53 | o: {} | |
54 | }; | |
0e466aac BA |
55 | } |
56 | ||
0e466aac BA |
57 | pieces() { |
58 | return Object.assign({}, | |
59 | super.pieces(), | |
60 | { | |
61 | 'p': { | |
a89fb4e9 | 62 | "class": "pawn", //pincer |
0e466aac BA |
63 | moves: [ |
64 | {steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]} | |
65 | ] | |
66 | }, | |
67 | 'r': { | |
a89fb4e9 | 68 | "class": "rook", //coordinator |
0e466aac BA |
69 | moves: [ |
70 | { | |
71 | steps: [ | |
72 | [1, 0], [0, 1], [-1, 0], [0, -1], | |
73 | [1, 1], [1, -1], [-1, 1], [-1, -1] | |
74 | ] | |
75 | } | |
76 | ] | |
77 | }, | |
78 | 'n': { | |
a89fb4e9 | 79 | "class": "knight", //long-leaper |
0e466aac BA |
80 | moveas: 'r' |
81 | }, | |
82 | 'b': { | |
a89fb4e9 | 83 | "class": "bishop", //chameleon |
0e466aac BA |
84 | moveas: 'r' |
85 | }, | |
86 | 'q': { | |
a89fb4e9 | 87 | "class": "queen", //withdrawer |
0e466aac BA |
88 | moveas: 'r' |
89 | }, | |
90 | 'i': { | |
91 | "class": "immobilizer", | |
a89fb4e9 | 92 | moveas: 'r' |
0e466aac BA |
93 | } |
94 | } | |
95 | ); | |
96 | } | |
97 | ||
98 | // Is piece on square (x,y) immobilized? | |
99 | isImmobilized([x, y]) { | |
100 | const piece = this.getPiece(x, y); | |
101 | const color = this.getColor(x, y); | |
616a8d7a | 102 | const oppCol = C.GetOppTurn(color); |
bc97fdd1 | 103 | const adjacentSteps = this.pieces()['k'].both[0].steps; |
0e466aac BA |
104 | for (let step of adjacentSteps) { |
105 | const [i, j] = [x + step[0], this.getY(y + step[1])]; | |
106 | if ( | |
107 | this.onBoard(i, j) && | |
108 | this.board[i][j] != "" && | |
109 | this.getColor(i, j) == oppCol | |
110 | ) { | |
111 | const oppPiece = this.getPiece(i, j); | |
112 | if (oppPiece == 'i') { | |
113 | // Moving is possible only if this immobilizer is neutralized | |
114 | for (let step2 of adjacentSteps) { | |
115 | const [i2, j2] = [i + step2[0], this.getY(j + step2[1])]; | |
116 | if (i2 == x && j2 == y) | |
117 | continue; //skip initial piece! | |
118 | if ( | |
119 | this.onBoard(i2, j2) && | |
120 | this.board[i2][j2] != "" && | |
121 | this.getColor(i2, j2) == color | |
122 | ) { | |
123 | if (['b', 'i'].includes(this.getPiece(i2, j2))) | |
124 | return false; | |
125 | } | |
126 | } | |
127 | return true; //immobilizer isn't neutralized | |
128 | } | |
129 | // Chameleons can't be immobilized twice, | |
130 | // because there is only one immobilizer | |
131 | if (oppPiece == 'b' && piece == 'i') | |
132 | return true; | |
133 | } | |
134 | } | |
135 | return false; | |
136 | } | |
137 | ||
138 | canTake([x1, y1], [x2, y2]) { | |
139 | // Deactivate standard captures, except for king: | |
140 | return ( | |
141 | this.getPiece(x1, y1) == 'k' && | |
142 | this.getColor(x1, y1) != this.getColor(x2, y2) | |
143 | ); | |
144 | } | |
145 | ||
146 | postProcessPotentialMoves(moves) { | |
147 | if (moves.length == 0) | |
148 | return []; | |
149 | switch (moves[0].vanish[0].p) { | |
150 | case 'p': | |
a89fb4e9 | 151 | this.addPincerCaptures(moves); |
0e466aac BA |
152 | break; |
153 | case 'r': | |
a89fb4e9 | 154 | this.addCoordinatorCaptures(moves); |
0e466aac BA |
155 | break; |
156 | case 'n': | |
157 | const [x, y] = [moves[0].start.x, moves[0].start.y]; | |
a89fb4e9 | 158 | moves = moves.concat(this.getLeaperCaptures([x, y])); |
0e466aac BA |
159 | break; |
160 | case 'b': | |
a89fb4e9 | 161 | moves = this.getChameleonCaptures(moves, "pull"); |
0e466aac BA |
162 | break; |
163 | case 'q': | |
a89fb4e9 | 164 | this.addPushmePullyouCaptures(moves, false, "pull"); |
0e466aac BA |
165 | break; |
166 | } | |
167 | return moves; | |
168 | } | |
169 | ||
0e466aac | 170 | }; |