Cleaner fen generation + first draft of Apocalypse + a few fixes
[xogo.git] / variants / Chakart / class.js
CommitLineData
bc2bc396
BA
1import ChessRules from "/base_rules.js";
2import GiveawayRules from "/variants/Giveaway/class.js";
f3e90e30
BA
3import {ArrayFun} from "/utils/array.js";
4import {Random} from "/utils/alea.js";
8f57fbf2
BA
5import PiPo from "/utils/PiPo.js";
6import Move from "/utils/Move.js";
f382c57b 7
bc2bc396 8export default class ChakartRules extends ChessRules {
f8b43ef7
BA
9
10 static get Options() {
11 return {
12 select: [
13 {
14 label: "Randomness",
15 variable: "randomness",
16 defaut: 2,
17 options: [
37481d1e
BA
18 {label: "Deterministic", value: 0},
19 {label: "Symmetric random", value: 1},
20 {label: "Asymmetric random", value: 2}
f8b43ef7
BA
21 ]
22 }
3b641716
BA
23 ],
24 styles: ["cylinder"]
f8b43ef7
BA
25 };
26 }
27
8f57fbf2
BA
28 get pawnPromotions() {
29 return ['q', 'r', 'n', 'b', 'k'];
f8b43ef7 30 }
8f57fbf2 31
2b9b90da 32 get hasCastle() {
f8b43ef7
BA
33 return false;
34 }
2b9b90da 35 get hasEnpassant() {
f8b43ef7
BA
36 return false;
37 }
24872b22
BA
38 get hasReserve() {
39 return true;
40 }
41 get hasReserveFen() {
42 return false;
43 }
f8b43ef7 44
f8b43ef7
BA
45 static get IMMOBILIZE_CODE() {
46 return {
47 'p': 's',
48 'r': 'u',
49 'n': 'o',
50 'b': 'c',
51 'q': 't',
52 'k': 'l'
53 };
54 }
55
56 static get IMMOBILIZE_DECODE() {
57 return {
58 's': 'p',
59 'u': 'r',
60 'o': 'n',
61 'c': 'b',
62 't': 'q',
63 'l': 'k'
64 };
65 }
66
f8b43ef7
BA
67 // Fictive color 'a', bomb banana mushroom egg
68 static get BOMB() {
69 return 'w'; //"Wario"
70 }
71 static get BANANA() {
72 return 'd'; //"Donkey"
73 }
74 static get EGG() {
75 return 'e';
76 }
77 static get MUSHROOM() {
78 return 'm';
79 }
80
24872b22
BA
81 static get EGG_SURPRISE() {
82 return [
83 "kingboo", "bowser", "daisy", "koopa",
84 "luigi", "waluigi", "toadette", "chomp"];
85 }
86
3b641716
BA
87 canIplay(x, y) {
88 if (
89 this.playerColor != this.turn ||
90 Object.keys(V.IMMOBILIZE_DECODE).includes(this.getPiece(x, y))
91 ) {
92 return false;
93 }
94 return this.egg == "kingboo" || this.getColor(x, y) == this.turn;
95 }
96
24872b22 97 pieces(color, x, y) {
3b641716 98 const specials = {
24872b22 99 'i': {"class": "invisible"}, //queen
cc9fe4f1 100 '?': {"class": "mystery"}, //...initial square
24872b22
BA
101 'e': {"class": "egg"},
102 'm': {"class": "mushroom"},
103 'd': {"class": "banana"},
3b641716
BA
104 'w': {"class": "bomb"},
105 'z': {"class": "remote-capture"}
24872b22 106 };
3b641716
BA
107 const bowsered = {
108 's': {"class": ["immobilized", "pawn"]},
109 'u': {"class": ["immobilized", "rook"]},
110 'o': {"class": ["immobilized", "knight"]},
111 'c': {"class": ["immobilized", "bishop"]},
112 't': {"class": ["immobilized", "queen"]},
113 'l': {"class": ["immobilized", "king"]}
114 };
f5435757
BA
115 return Object.assign(
116 {
117 'y': {
118 // Virtual piece for "king remote shell captures"
119 moves: [],
120 attack: [
121 {
122 steps: [
123 [0, 1], [0, -1], [1, 0], [-1, 0],
124 [1, 1], [1, -1], [-1, 1], [-1, -1]
125 ]
126 }
127 ]
128 }
129 },
6b9320bb
BA
130 specials, bowsered, super.pieces(color, x, y)
131 );
24872b22
BA
132 }
133
f31de5e4 134 genRandInitBaseFen() {
554e3ad3
BA
135 const options = Object.assign({mode: "suicide"}, this.options);
136 const gr = new GiveawayRules({options: options, genFenOnly: true});
f31de5e4
BA
137 let res = gr.genRandInitBaseFen();
138 res.o["flags"] = "1111"; //Peach + Mario flags
139 return res;
91339921
BA
140 }
141
8f57fbf2 142 fen2board(f) {
f8b43ef7
BA
143 return (
144 f.charCodeAt() <= 90
145 ? "w" + f.toLowerCase()
146 : (['w', 'd', 'e', 'm'].includes(f) ? "a" : "b") + f
147 );
148 }
149
f8b43ef7
BA
150 setFlags(fenflags) {
151 // King can send shell? Queen can be invisible?
152 this.powerFlags = {
8f57fbf2
BA
153 w: {k: false, q: false},
154 b: {k: false, q: false}
f8b43ef7 155 };
8f57fbf2 156 for (let c of ['w', 'b']) {
f8b43ef7
BA
157 for (let p of ['k', 'q']) {
158 this.powerFlags[c][p] =
159 fenflags.charAt((c == "w" ? 0 : 2) + (p == 'k' ? 0 : 1)) == "1";
160 }
161 }
162 }
163
164 aggregateFlags() {
165 return this.powerFlags;
166 }
167
168 disaggregateFlags(flags) {
169 this.powerFlags = flags;
170 }
171
91339921
BA
172 getFlagsFen() {
173 return ['w', 'b'].map(c => {
174 return ['k', 'q'].map(p => this.powerFlags[c][p] ? "1" : "0").join("");
175 }).join("");
176 }
177
8f57fbf2 178 setOtherVariables(fenParsed) {
5f08c59b 179 super.setOtherVariables(fenParsed);
bc2bc396 180 this.egg = null;
3b641716
BA
181 // Change seed (after FEN generation!!)
182 // so that further calls differ between players:
554e3ad3 183 Random.setSeed(Math.floor(19840 * Math.random()));
f8b43ef7
BA
184 }
185
5f08c59b
BA
186 initReserves() {
187 this.reserve = {}; //to be filled later
188 }
189
ca8a3993
BA
190 canStepOver(i, j) {
191 return (
192 this.board[i][j] == "" ||
193 ['i', V.EGG, V.MUSHROOM].includes(this.getPiece(i, j))
194 );
195 }
196
c7c2f41c 197 // For Toadette bonus
ca8a3993
BA
198 canDrop([c, p], [i, j]) {
199 return (
200 (
201 this.board[i][j] == "" ||
202 this.getColor(i, j) == 'a' ||
203 this.getPiece(i, j) == 'i'
204 )
205 &&
206 (p != "p" || (c == 'w' && i < this.size.x - 1) || (c == 'b' && i > 0))
207 );
f8b43ef7
BA
208 }
209
bc2bc396 210 getPotentialMovesFrom([x, y]) {
f8b43ef7 211 let moves = [];
3b641716 212 const piece = this.getPiece(x, y);
bc2bc396 213 if (this.egg == "toadette")
24872b22
BA
214 moves = this.getDropMovesFrom([x, y]);
215 else if (this.egg == "kingboo") {
3b641716 216 const color = this.turn;
37481d1e 217 const oppCol = C.GetOppCol(color);
3b641716 218 // Only allow to swap (non-immobilized!) pieces
37481d1e
BA
219 for (let i=0; i<this.size.x; i++) {
220 for (let j=0; j<this.size.y; j++) {
bc2bc396
BA
221 const colIJ = this.getColor(i, j);
222 const pieceIJ = this.getPiece(i, j);
223 if (
224 (i != x || j != y) &&
225 ['w', 'b'].includes(colIJ) &&
3b641716 226 !Object.keys(V.IMMOBILIZE_DECODE).includes(pieceIJ) &&
bc2bc396
BA
227 // Next conditions = no pawn on last rank
228 (
3b641716 229 piece != 'p' ||
bc2bc396
BA
230 (
231 (color != 'w' || i != 0) &&
232 (color != 'b' || i != this.size.x - 1)
233 )
234 )
235 &&
236 (
237 pieceIJ != 'p' ||
238 (
239 (colIJ != 'w' || x != 0) &&
240 (colIJ != 'b' || x != this.size.x - 1)
241 )
242 )
243 ) {
37481d1e 244 let m = this.getBasicMove([x, y], [i, j]);
3b641716
BA
245 m.appear.push(new PiPo({x: x, y: y, p: pieceIJ, c: colIJ}));
246 m.kingboo = true; //avoid some side effects (bananas/bombs)
37481d1e
BA
247 moves.push(m);
248 }
249 }
250 }
be3cb9d1 251 }
24872b22
BA
252 else {
253 // Normal case (including bonus daisy)
24872b22
BA
254 switch (piece) {
255 case 'p':
256 moves = this.getPawnMovesFrom([x, y]); //apply promotions
257 break;
258 case 'q':
259 moves = this.getQueenMovesFrom([x, y]);
260 break;
261 case 'k':
262 moves = this.getKingMovesFrom([x, y]);
263 break;
264 case 'n':
265 moves = this.getKnightMovesFrom([x, y]);
266 break;
267 case 'b':
268 case 'r':
3b641716 269 // Explicitely listing types to avoid moving immobilized piece
6b9320bb 270 moves = super.getPotentialMovesOf(piece, [x, y]);
24872b22
BA
271 break;
272 }
273 }
24872b22
BA
274 return moves;
275 }
276
37481d1e 277 getPawnMovesFrom([x, y]) {
f8b43ef7 278 const color = this.turn;
be3cb9d1
BA
279 const oppCol = C.GetOppCol(color);
280 const shiftX = (color == 'w' ? -1 : 1);
281 const firstRank = (color == "w" ? this.size.x - 1 : 0);
f8b43ef7 282 let moves = [];
cc9fe4f1 283 const frontPiece = this.getPiece(x + shiftX, y);
f8b43ef7 284 if (
be3cb9d1 285 this.board[x + shiftX][y] == "" ||
f8b43ef7 286 this.getColor(x + shiftX, y) == 'a' ||
cc9fe4f1 287 frontPiece == 'i'
f8b43ef7 288 ) {
7562d2c2 289 moves.push(this.getBasicMove([x, y], [x + shiftX, y]));
f8b43ef7
BA
290 if (
291 [firstRank, firstRank + shiftX].includes(x) &&
cc9fe4f1 292 ![V.BANANA, V.BOMB].includes(frontPiece) &&
f8b43ef7 293 (
7562d2c2 294 this.board[x + 2 * shiftX][y] == "" ||
f8b43ef7 295 this.getColor(x + 2 * shiftX, y) == 'a' ||
cc9fe4f1 296 this.getPiece(x + 2 * shiftX, y) == 'i'
f8b43ef7
BA
297 )
298 ) {
7562d2c2 299 moves.push(this.getBasicMove([x, y], [x + 2 * shiftX, y]));
f8b43ef7
BA
300 }
301 }
302 for (let shiftY of [-1, 1]) {
f5435757 303 const nextY = this.getY(y + shiftY);
f8b43ef7 304 if (
f5435757
BA
305 nextY >= 0 &&
306 nextY < this.size.y &&
307 this.board[x + shiftX][nextY] != "" &&
f8b43ef7 308 // Pawns cannot capture invisible queen this way!
f5435757
BA
309 this.getPiece(x + shiftX, nextY) != 'i' &&
310 ['a', oppCol].includes(this.getColor(x + shiftX, nextY))
f8b43ef7 311 ) {
f5435757 312 moves.push(this.getBasicMove([x, y], [x + shiftX, nextY]));
f8b43ef7
BA
313 }
314 }
f5435757
BA
315 this.pawnPostProcess(moves, color, oppCol);
316 // Add mushroom on before-last square (+ potential segments)
24872b22 317 moves.forEach(m => {
f5435757
BA
318 let [mx, my] = [x, y];
319 if (Math.abs(m.end.x - m.start.x) == 2)
320 mx = (m.start.x + m.end.x) / 2;
321 m.appear.push(new PiPo({x: mx, y: my, c: 'a', p: 'm'}));
322 if (mx != x && this.board[mx][my] != "") {
3b641716 323 m.vanish.push(new PiPo({
f5435757
BA
324 x: mx,
325 y: my,
326 c: this.getColor(mx, my),
327 p: this.getPiece(mx, my)
3b641716 328 }));
24872b22 329 }
f5435757
BA
330 if (Math.abs(m.end.y - m.start.y) > 1) {
331 m.segments = [
332 [[x, y], [x, y]],
333 [[m.end.x, m.end.y], [m.end.x, m.end.y]]
334 ];
335 }
24872b22 336 });
3b641716 337 return moves;
24872b22
BA
338 }
339
340 getKnightMovesFrom([x, y]) {
341 // Add egg on initial square:
6b9320bb 342 return super.getPotentialMovesOf('n', [x, y]).map(m => {
24872b22
BA
343 m.appear.push(new PiPo({p: "e", c: "a", x: x, y: y}));
344 return m;
345 });
346 }
347
37481d1e 348 getQueenMovesFrom(sq) {
6b9320bb 349 const normalMoves = super.getPotentialMovesOf('q', sq);
f8b43ef7
BA
350 // If flag allows it, add 'invisible movements'
351 let invisibleMoves = [];
7562d2c2 352 if (this.powerFlags[this.turn]['q']) {
f8b43ef7
BA
353 normalMoves.forEach(m => {
354 if (
355 m.appear.length == 1 &&
356 m.vanish.length == 1 &&
357 // Only simple non-capturing moves:
358 m.vanish[0].c != 'a'
359 ) {
360 let im = JSON.parse(JSON.stringify(m));
cc9fe4f1 361 im.appear[0].p = 'i';
24872b22 362 im.noAnimate = true;
f8b43ef7
BA
363 invisibleMoves.push(im);
364 }
365 });
366 }
367 return normalMoves.concat(invisibleMoves);
368 }
369
37481d1e 370 getKingMovesFrom([x, y]) {
6b9320bb 371 let moves = super.getPotentialMovesOf('k', [x, y]);
f8b43ef7 372 // If flag allows it, add 'remote shell captures'
7562d2c2 373 if (this.powerFlags[this.turn]['k']) {
6b9320bb 374 let shellCaptures = super.getPotentialMovesOf('y', [x, y]);
f5435757
BA
375 shellCaptures.forEach(sc => {
376 sc.shell = true; //easier play()
377 sc.choice = 'z'; //to display in showChoices()
378 // Fix move (Rifle style):
379 sc.vanish.shift();
380 sc.appear.shift();
f8b43ef7 381 });
f5435757 382 Array.prototype.push.apply(moves, shellCaptures);
f8b43ef7
BA
383 }
384 return moves;
385 }
386
7562d2c2 387 play(move) {
a2bb7e06
BA
388 const color = this.turn;
389 const oppCol = C.GetOppCol(color);
390 if (
391 move.appear.length > 0 &&
392 move.appear[0].p == 'p' &&
393 (
394 (color == 'w' && move.end.x == 0) ||
395 (color == 'b' && move.end.x == this.size.x - 1)
396 )
397 ) {
398 // "Forgotten" promotion, which occurred after some effect
399 let moves = [move];
400 super.pawnPostProcess(moves, color, oppCol);
401 super.showChoices(moves);
402 return false;
403 }
5f08c59b
BA
404 this.postPlay(move, color, oppCol);
405 return true;
406 }
407
408 postPlay(move, color, oppCol) {
24872b22 409 this.egg = move.egg;
24872b22
BA
410 if (move.egg == "toadette") {
411 this.reserve = { w: {}, b: {} };
412 // Randomly select a piece in pawnPromotions
3b641716
BA
413 if (!move.toadette)
414 move.toadette = Random.sample(this.pawnPromotions);
415 this.reserve[color][move.toadette] = 1;
24872b22 416 this.re_drawReserve([color]);
f8b43ef7 417 }
24872b22
BA
418 else if (Object.keys(this.reserve).length > 0) {
419 this.reserve = {};
420 this.re_drawReserve([color]);
f8b43ef7 421 }
24872b22
BA
422 if (move.shell)
423 this.powerFlags[color]['k'] = false;
cc9fe4f1 424 else if (move.appear.length > 0 && move.appear[0].p == 'i') {
24872b22 425 this.powerFlags[move.appear[0].c]['q'] = false;
cc9fe4f1
BA
426 if (color == this.playerColor) {
427 move.appear.push(
428 new PiPo({x: move.start.x, y: move.start.y, c: color, p: '?'}));
429 }
3b641716
BA
430 }
431 if (color == this.playerColor) {
432 // Look for an immobilized piece of my color: it can now move
433 for (let i=0; i<8; i++) {
434 for (let j=0; j<8; j++) {
435 if ((i != move.end.x || j != move.end.y) && this.board[i][j] != "") {
436 const piece = this.getPiece(i, j);
437 if (
438 this.getColor(i, j) == color &&
439 Object.keys(V.IMMOBILIZE_DECODE).includes(piece)
440 ) {
441 move.vanish.push(new PiPo({
442 x: i, y: j, c: color, p: piece
443 }));
444 move.appear.push(new PiPo({
445 x: i, y: j, c: color, p: V.IMMOBILIZE_DECODE[piece]
446 }));
447 }
f8b43ef7
BA
448 }
449 }
450 }
3b641716
BA
451 // Also make opponent invisible queen visible again, if any
452 for (let i=0; i<8; i++) {
453 for (let j=0; j<8; j++) {
454 if (
455 this.board[i][j] != "" &&
cc9fe4f1 456 this.getColor(i, j) == oppCol
3b641716 457 ) {
cc9fe4f1 458 const pieceIJ = this.getPiece(i, j);
6b9320bb
BA
459 if (
460 pieceIJ == 'i' &&
461 // Ensure that current move doesn't erase invisible queen
462 move.appear.every(a => a.x != i || a.y != j)
463 ) {
cc9fe4f1
BA
464 move.vanish.push(new PiPo({x: i, y: j, c: oppCol, p: 'i'}));
465 move.appear.push(new PiPo({x: i, y: j, c: oppCol, p: 'q'}));
466 }
467 else if (pieceIJ == '?')
468 move.vanish.push(new PiPo({x: i, y: j, c: oppCol, p: '?'}));
3b641716 469 }
f8b43ef7
BA
470 }
471 }
472 }
5f08c59b
BA
473 this.playOnBoard(move);
474 super.postPlay(move);
475 }
476
477 playVisual(move, r) {
478 super.playVisual(move, r);
bc2bc396 479 if (move.egg)
cc9fe4f1 480 this.displayBonus(move);
5f08c59b
BA
481 }
482
483 computeNextMove(move) {
484 // Set potential random effects, so that play() is deterministic
485 // from opponent viewpoint:
486 const endPiece = this.getPiece(move.end.x, move.end.y);
487 switch (endPiece) {
488 case V.EGG:
489 move.egg = Random.sample(V.EGG_SURPRISE);
490 move.next = this.getEggEffect(move);
491 break;
492 case V.MUSHROOM:
493 move.next = this.getMushroomEffect(move);
494 break;
495 case V.BANANA:
496 case V.BOMB:
497 move.next = this.getBombBananaEffect(move, endPiece);
498 break;
499 }
500 // NOTE: Chakart has also some side-effects:
501 if (
502 !move.next && move.appear.length > 0 &&
503 !move.kingboo && !move.luigiEffect
504 ) {
505 const movingPiece = move.appear[0].p;
506 if (['b', 'r'].includes(movingPiece)) {
507 // Drop a banana or bomb:
508 const bs =
509 this.getRandomSquare([move.end.x, move.end.y],
510 movingPiece == 'r'
511 ? [[1, 1], [1, -1], [-1, 1], [-1, -1]]
512 : [[1, 0], [-1, 0], [0, 1], [0, -1]],
513 "freeSquare");
514 if (bs) {
515 move.appear.push(
516 new PiPo({
517 x: bs[0],
518 y: bs[1],
519 c: 'a',
520 p: movingPiece == 'r' ? 'd' : 'w'
521 })
522 );
523 if (this.board[bs[0]][bs[1]] != "") {
524 move.vanish.push(
525 new PiPo({
526 x: bs[0],
527 y: bs[1],
528 c: this.getColor(bs[0], bs[1]),
529 p: this.getPiece(bs[0], bs[1])
530 })
531 );
532 }
533 }
534 }
535 }
536 }
537
538 isLastMove(move) {
539 return !move.next && !["daisy", "toadette", "kingboo"].includes(move.egg);
bc2bc396
BA
540 }
541
3b641716
BA
542 // Helper to set and apply banana/bomb effect
543 getRandomSquare([x, y], steps, freeSquare) {
544 let validSteps = steps.filter(s => this.onBoard(x + s[0], y + s[1]));
545 if (freeSquare) {
546 // Square to put banana/bomb cannot be occupied by a piece
547 validSteps = validSteps.filter(s => {
548 return ["", 'a'].includes(this.getColor(x + s[0], y + s[1]))
549 });
550 }
551 if (validSteps.length == 0)
552 return null;
553 const step = validSteps[Random.randInt(validSteps.length)];
554 return [x + step[0], y + step[1]];
f8b43ef7
BA
555 }
556
3b641716
BA
557 getEggEffect(move) {
558 const getRandomPiece = (c) => {
559 let bagOfPieces = [];
560 for (let i=0; i<this.size.x; i++) {
561 for (let j=0; j<this.size.y; j++) {
562 if (this.getColor(i, j) == c && this.getPiece(i, j) != 'k')
563 bagOfPieces.push([i, j]);
564 }
565 }
566 if (bagOfPieces.length >= 1)
567 return Random.sample(bagOfPieces);
568 return null;
569 };
570 const color = this.turn;
571 let em = null;
572 switch (move.egg) {
573 case "luigi":
574 case "waluigi":
575 // Change color of friendly or enemy piece, king excepted
576 const oldColor = (move.egg == "waluigi" ? color : C.GetOppCol(color));
577 const newColor = C.GetOppCol(oldColor);
578 const coords = getRandomPiece(oldColor);
579 if (coords) {
580 const piece = this.getPiece(coords[0], coords[1]);
581 em = new Move({
582 appear: [
583 new PiPo({x: coords[0], y: coords[1], c: newColor, p: piece})
584 ],
585 vanish: [
586 new PiPo({x: coords[0], y: coords[1], c: oldColor, p: piece})
587 ]
588 });
5f08c59b 589 em.luigiEffect = true; //avoid dropping bomb/banana by mistake
3b641716
BA
590 }
591 break;
592 case "bowser":
593 em = new Move({
594 appear: [
595 new PiPo({
596 x: move.end.x,
597 y: move.end.y,
598 c: color,
599 p: V.IMMOBILIZE_CODE[move.appear[0].p]
600 })
601 ],
602 vanish: [
603 new PiPo({
604 x: move.end.x,
605 y: move.end.y,
606 c: color,
607 p: move.appear[0].p
608 })
609 ]
610 });
611 break;
612 case "koopa":
613 // Reverse move
614 em = new Move({
615 appear: [
616 new PiPo({
617 x: move.start.x, y: move.start.y, c: color, p: move.appear[0].p
618 })
619 ],
620 vanish: [
621 new PiPo({
622 x: move.end.x, y: move.end.y, c: color, p: move.appear[0].p
623 })
624 ]
625 });
626 if (this.board[move.start.x][move.start.y] != "") {
627 // Pawn or knight let something on init square
628 em.vanish.push(new PiPo({
629 x: move.start.x,
630 y: move.start.y,
631 c: 'a',
632 p: this.getPiece(move.start.x, move.start.y)
633 }));
634 }
635 break;
636 case "chomp":
637 // Eat piece
638 em = new Move({
639 appear: [],
640 vanish: [
641 new PiPo({
642 x: move.end.x, y: move.end.y, c: color, p: move.appear[0].p
643 })
644 ],
645 end: {x: move.end.x, y: move.end.y}
646 });
647 break;
648 }
649 if (em && move.egg != "koopa")
650 em.noAnimate = true; //static move
651 return em;
f8b43ef7
BA
652 }
653
24872b22 654 getMushroomEffect(move) {
fc12475f
BA
655 if (
656 typeof move.start.x == "string" || //drop move (toadette)
657 ['b', 'r', 'q'].includes(move.vanish[0].p) //slider
658 ) {
cc9fe4f1 659 return null;
37481d1e 660 }
fc12475f
BA
661 let step = [move.end.x - move.start.x, move.end.y - move.start.y];
662 if (Math.abs(step[0]) == 2 && Math.abs(step[1]) == 0)
663 // Pawn initial 2-squares move: normalize step
664 step[0] /= 2;
24872b22 665 const nextSquare = [move.end.x + step[0], move.end.y + step[1]];
24872b22 666 let nextMove = null;
fc12475f
BA
667 if (
668 this.onBoard(nextSquare[0], nextSquare[1]) &&
669 (
670 this.board[nextSquare[0]][nextSquare[1]] == "" ||
671 this.getColor(nextSquare[0], nextSquare[1]) == 'a'
672 )
673 ) {
bc5d61a7 674 this.playOnBoard(move); //HACK for getBasicMove()
24872b22 675 nextMove = this.getBasicMove([move.end.x, move.end.y], nextSquare);
bc5d61a7 676 this.undoOnBoard(move);
24872b22 677 }
24872b22 678 return nextMove;
37481d1e
BA
679 }
680
3b641716
BA
681 getBombBananaEffect(move, item) {
682 const steps = item == V.BANANA
683 ? [[1, 0], [-1, 0], [0, 1], [0, -1]]
684 : [[1, 1], [1, -1], [-1, 1], [-1, -1]];
685 const nextSquare = this.getRandomSquare([move.end.x, move.end.y], steps);
686 this.playOnBoard(move); //HACK for getBasicMove()
687 const res = this.getBasicMove([move.end.x, move.end.y], nextSquare);
688 this.undoOnBoard(move);
689 return res;
690 }
691
cc9fe4f1
BA
692 displayBonus(move) {
693 let divBonus = document.createElement("div");
694 divBonus.classList.add("bonus-text");
695 divBonus.innerHTML = move.egg;
696 let container = document.getElementById(this.containerId);
697 container.appendChild(divBonus);
698 setTimeout(() => container.removeChild(divBonus), 2000);
3b641716
BA
699 }
700
701 atLeastOneMove() {
702 return true;
703 }
704
705 filterValid(moves) {
706 return moves;
707 }
708
5f08c59b
BA
709 // Kingboo bonus can be animated better:
710 customAnimate(move, segments, cb) {
711 if (!move.kingboo)
712 return 0;
713 super.animateMoving(move.end, move.start, null,
714 segments.reverse().map(s => s.reverse()), cb);
715 return 1;
be3cb9d1 716 }
f8b43ef7
BA
717
718};