1 import ChessRules
from "/base_rules";
2 import GiveawayRules
from "/variants/Giveaway";
3 import { ArrayFun
} from "/utils/array.js";
4 import { Random
} from "/utils/alea.js";
5 import PiPo
from "/utils/PiPo.js";
6 import Move
from "/utils/Move.js";
8 export class ChakartRules
extends ChessRules
{
10 static get Options() {
15 variable: "randomness",
18 { label: "Deterministic", value: 0 },
19 { label: "Symmetric random", value: 1 },
20 { label: "Asymmetric random", value: 2 }
27 get pawnPromotions() {
28 return ['q', 'r', 'n', 'b', 'k'];
38 static get IMMOBILIZE_CODE() {
49 static get IMMOBILIZE_DECODE() {
60 static get INVISIBLE_QUEEN() {
64 // Fictive color 'a', bomb banana mushroom egg
69 return 'd'; //"Donkey"
74 static get MUSHROOM() {
78 genRandInitFen(seed
) {
79 const gr
= new GiveawayRules({mode: "suicide"}, true);
81 gr
.genRandInitFen(seed
).slice(0, -1) +
82 // Add Peach + Mario flags + capture counts
83 '{"flags": "1111", "ccount": "000000000000"}'
90 ? "w" + f
.toLowerCase()
91 : (['w', 'd', 'e', 'm'].includes(f
) ? "a" : "b") + f
96 // King can send shell? Queen can be invisible?
98 w: {k: false, q: false},
99 b: {k: false, q: false}
101 for (let c
of ['w', 'b']) {
102 for (let p
of ['k', 'q']) {
103 this.powerFlags
[c
][p
] =
104 fenflags
.charAt((c
== "w" ? 0 : 2) + (p
== 'k' ? 0 : 1)) == "1";
110 return this.powerFlags
;
113 disaggregateFlags(flags
) {
114 this.powerFlags
= flags
;
118 return super.getFen() + " " + this.getCapturedFen();
122 return ['w', 'b'].map(c
=> {
123 return ['k', 'q'].map(p
=> this.powerFlags
[c
][p
] ? "1" : "0").join("");
128 const res
= ['w', 'b'].map(c
=> {
129 Object
.values(this.captured
[c
])
131 return res
[0].concat(res
[1]).join("");
134 setOtherVariables(fenParsed
) {
135 super.setOtherVariables(fenParsed
);
136 // Initialize captured pieces' counts from FEN
137 const allCapts
= fenParsed
.captured
.split("").map(x
=> parseInt(x
, 10));
138 const pieces
= ['p', 'r', 'n', 'b', 'q', 'k'];
140 w: Array
.toObject(pieces
, allCapts
.slice(0, 6)),
141 b: Array
.toObject(pieces
, allCapts
.slice(6, 12))
143 this.reserve
= { w: {}, b: {} }; //to be replaced by this.captured
147 // For Toadette bonus
148 getDropMovesFrom([c
, p
]) {
149 if (this.reserve
[c
][p
] == 0)
152 const start
= (c
== 'w' && p
== 'p' ? 1 : 0);
153 const end
= (color
== 'b' && p
== 'p' ? 7 : 8);
154 for (let i
= start
; i
< end
; i
++) {
155 for (let j
= 0; j
< this.size
.y
; j
++) {
156 const pieceIJ
= this.getPiece(i
, j
);
158 this.board
[i
][j
] == "" ||
159 this.getColor(i
, j
) == 'a' ||
160 pieceIJ
== V
.INVISIBLE_QUEEN
165 appear: [new PiPo({x: i
, y: j
, c: c
, p: p
})],
168 // A drop move may remove a bonus (or hidden queen!)
169 if (this.board
[i
][j
] != "")
170 m
.vanish
.push(new PiPo({x: i
, y: j
, c: 'a', p: pieceIJ
}));
187 // TODO: rethink from here:
189 getPotentialMovesFrom([x
, y
]) {
191 if (this.subTurn
== 1) {
192 moves
= super.getPotentialMovesFrom([x
, y
]);
193 const finalPieces
= V
.PawnSpecs
.promotions
;
194 const color
= this.turn
;
195 const lastRank
= (color
== "w" ? 0 : 7);
199 m
.appear
.length
> 0 &&
200 ['p', 's'].includes(m
.appear
[0].p
) &&
201 m
.appear
[0].x
== lastRank
203 for (let i
= 1; i
< finalPieces
.length
; i
++) {
204 const piece
= finalPieces
[i
];
205 let otherM
= JSON
.parse(JSON
.stringify(m
));
207 m
.appear
[0].p
== V
.PAWN
209 : V
.IMMOBILIZE_CODE
[finalPieces
[i
]];
212 // Finally alter m itself:
214 m
.appear
[0].p
== V
.PAWN
216 : V
.IMMOBILIZE_CODE
[finalPieces
[0]];
219 Array
.prototype.push
.apply(moves
, pMoves
);
223 const L
= this.effects
.length
;
224 switch (this.effects
[L
-1]) {
226 // Exchange position with any visible piece,
227 // except pawns if arriving on last rank.
228 const lastRank
= { 'w': 0, 'b': 7 };
229 const color
= this.turn
;
230 const allowLastRank
= (this.getPiece(x
, y
) != V
.PAWN
);
231 for (let i
=0; i
<8; i
++) {
232 for (let j
=0; j
<8; j
++) {
233 const colIJ
= this.getColor(i
, j
);
234 const pieceIJ
= this.getPiece(i
, j
);
236 (i
!= x
|| j
!= y
) &&
237 this.board
[i
][j
] != V
.EMPTY
&&
238 pieceIJ
!= V
.INVISIBLE_QUEEN
&&
242 (pieceIJ
!= V
.PAWN
|| x
!= lastRank
[colIJ
]) &&
243 (allowLastRank
|| i
!= lastRank
[color
])
245 const movedUnit
= new PiPo({
249 p: this.getPiece(i
, j
)
251 let mMove
= this.getBasicMove({ x: x
, y: y
}, [i
, j
]);
252 mMove
.appear
.push(movedUnit
);
260 // Resurrect a captured piece
261 if (x
>= V
.size
.x
) moves
= this.getReserveMoves([x
, y
]);
264 // Play again with any piece
265 moves
= super.getPotentialMovesFrom([x
, y
]);
272 // Helper for getBasicMove(): banana/bomb effect
273 getRandomSquare([x
, y
], steps
) {
274 const validSteps
= steps
.filter(s
=> V
.OnBoard(x
+ s
[0], y
+ s
[1]));
275 const step
= validSteps
[randInt(validSteps
.length
)];
276 return [x
+ step
[0], y
+ step
[1]];
279 // Apply mushroom, bomb or banana effect (hidden to the player).
280 // Determine egg effect, too, and apply its first part if possible.
281 getBasicMove_aux(psq1
, sq2
, tr
, initMove
) {
282 const [x1
, y1
] = [psq1
.x
, psq1
.y
];
283 const color1
= this.turn
;
284 const piece1
= (!!tr
? tr
.p : (psq1
.p
|| this.getPiece(x1
, y1
)));
285 const oppCol
= V
.GetOppCol(color1
);
291 // banana or bomb defines next square, or the move ends there
300 if (this.board
[x1
][y1
] != V
.EMPTY
) {
301 const initP1
= this.getPiece(x1
, y1
);
306 c: this.getColor(x1
, y1
),
310 if ([V
.BANANA
, V
.BOMB
].includes(initP1
)) {
311 const steps
= V
.steps
[initP1
== V
.BANANA
? V
.ROOK : V
.BISHOP
];
312 move.next
= this.getRandomSquare([x1
, y1
], steps
);
315 move.end
= { x: x1
, y: y1
};
318 const [x2
, y2
] = [sq2
[0], sq2
[1]];
319 // The move starts normally, on board:
320 let move = super.getBasicMove([x1
, y1
], [x2
, y2
], tr
);
321 if (!!tr
) move.promoteInto
= tr
.c
+ tr
.p
; //in case of (chomped...)
322 const L
= this.effects
.length
;
324 [V
.PAWN
, V
.KNIGHT
].includes(piece1
) &&
326 (this.subTurn
== 1 || this.effects
[L
-1] == "daisy")
330 const twoSquaresMove
= (Math
.abs(x2
- x1
) == 2);
331 const mushroomX
= x1
+ (twoSquaresMove
? (x2
- x1
) / 2 : 0);
340 if (this.getColor(mushroomX
, y1
) == 'a') {
346 p: this.getPiece(mushroomX
, y1
)
353 const deltaX
= Math
.abs(x2
- x1
);
354 const deltaY
= Math
.abs(y2
- y1
);
356 x1
+ (deltaX
== 2 ? (x2
- x1
) / 2 : 0),
357 y1
+ (deltaY
== 2 ? (y2
- y1
) / 2 : 0)
360 this.board
[eggSquare
[0]][eggSquare
[1]] != V
.EMPTY
&&
361 this.getColor(eggSquare
[0], eggSquare
[1]) != 'a'
374 if (this.getColor(eggSquare
[0], eggSquare
[1]) == 'a') {
380 p: this.getPiece(eggSquare
[0], eggSquare
[1])
388 // For (wa)luigi effect:
389 const changePieceColor
= (color
) => {
391 const oppLastRank
= (color
== 'w' ? 7 : 0);
392 for (let i
=0; i
<8; i
++) {
393 for (let j
=0; j
<8; j
++) {
394 const piece
= this.getPiece(i
, j
);
396 (i
!= move.vanish
[0].x
|| j
!= move.vanish
[0].y
) &&
397 this.board
[i
][j
] != V
.EMPTY
&&
398 piece
!= V
.INVISIBLE_QUEEN
&&
399 this.getColor(i
, j
) == color
401 if (piece
!= V
.KING
&& (piece
!= V
.PAWN
|| i
!= oppLastRank
))
402 pieces
.push({ x: i
, y: j
, p: piece
});
406 // Special case of the current piece (still at its initial position)
408 pieces
.push({ x: move.appear
[0].x
, y: move.appear
[0].y
, p: piece1
});
409 const cp
= pieces
[randInt(pieces
.length
)];
410 if (move.appear
[0].x
!= cp
.x
|| move.appear
[0].y
!= cp
.y
) {
420 else move.appear
.shift();
425 c: V
.GetOppCol(color
),
430 const applyEggEffect
= () => {
431 if (this.subTurn
== 2)
432 // No egg effects at subTurn 2
434 // 1) Determine the effect (some may be impossible)
435 let effects
= ["kingboo", "koopa", "chomp", "bowser", "daisy"];
436 if (Object
.values(this.captured
[color1
]).some(c
=> c
>= 1))
437 effects
.push("toadette");
438 const lastRank
= { 'w': 0, 'b': 7 };
440 this.board
.some((b
,i
) =>
445 (cell
[1] != V
.PAWN
|| i
!= lastRank
[color1
])
450 effects
.push("luigi");
455 (piece1
!= V
.PAWN
|| move.appear
[0].x
!= lastRank
[oppCol
])
457 this.board
.some((b
,i
) =>
462 (cell
[1] != V
.PAWN
|| i
!= lastRank
[oppCol
])
467 effects
.push("waluigi");
469 const effect
= effects
[randInt(effects
.length
)];
470 move.end
.effect
= effect
;
471 // 2) Apply it if possible
472 if (!(["kingboo", "toadette", "daisy"].includes(effect
))) {
476 // Maybe egg effect was applied after others,
477 // so just shift vanish array:
484 move.appear
[0].p
= V
.IMMOBILIZE_CODE
[piece1
];
487 changePieceColor(oppCol
);
490 changePieceColor(color1
);
495 const applyMushroomEffect
= () => {
496 if ([V
.PAWN
, V
.KING
, V
.KNIGHT
].includes(piece1
)) {
497 // Just make another similar step, if possible (non-capturing)
499 move.appear
[0].x
+ (x2
- x1
),
500 move.appear
[0].y
+ (y2
- y1
)
505 this.board
[i
][j
] == V
.EMPTY
||
506 this.getPiece(i
, j
) == V
.INVISIBLE_QUEEN
||
507 this.getColor(i
, j
) == 'a'
510 move.appear
[0].x
= i
;
511 move.appear
[0].y
= j
;
512 if (this.board
[i
][j
] != V
.EMPTY
) {
513 const object
= this.getPiece(i
, j
);
514 const color
= this.getColor(i
, j
);
526 const steps
= V
.steps
[object
== V
.BANANA
? V
.ROOK : V
.BISHOP
];
527 move.next
= this.getRandomSquare([i
, j
], steps
);
533 applyMushroomEffect();
540 // Queen, bishop or rook:
542 (x2
- x1
) / Math
.abs(x2
- x1
) || 0,
543 (y2
- y1
) / Math
.abs(y2
- y1
) || 0
545 const next
= [move.appear
[0].x
+ step
[0], move.appear
[0].y
+ step
[1]];
547 V
.OnBoard(next
[0], next
[1]) &&
548 this.board
[next
[0]][next
[1]] != V
.EMPTY
&&
549 this.getPiece(next
[0], next
[1]) != V
.INVISIBLE_QUEEN
&&
550 this.getColor(next
[0], next
[1]) != 'a'
552 const afterNext
= [next
[0] + step
[0], next
[1] + step
[1]];
553 if (V
.OnBoard(afterNext
[0], afterNext
[1])) {
554 const afterColor
= this.getColor(afterNext
[0], afterNext
[1]);
556 this.board
[afterNext
[0]][afterNext
[1]] == V
.EMPTY
||
559 move.appear
[0].x
= afterNext
[0];
560 move.appear
[0].y
= afterNext
[1];
561 if (this.board
[afterNext
[0]][afterNext
[1]] != V
.EMPTY
) {
562 // object = banana, bomb, mushroom or egg
563 const object
= this.getPiece(afterNext
[0], afterNext
[1]);
576 V
.steps
[object
== V
.BANANA
? V
.ROOK : V
.BISHOP
];
577 move.next
= this.getRandomSquare(
578 [afterNext
[0], afterNext
[1]], steps
);
584 applyMushroomEffect();
593 const color2
= this.getColor(x2
, y2
);
594 const piece2
= this.getPiece(x2
, y2
);
599 const steps
= V
.steps
[piece2
== V
.BANANA
? V
.ROOK : V
.BISHOP
];
600 move.next
= this.getRandomSquare([x2
, y2
], steps
);
603 applyMushroomEffect();
606 if (this.subTurn
== 1)
607 // No egg effect at subTurn 2
615 move.appear
.length
> 0 &&
616 [V
.ROOK
, V
.BISHOP
].includes(piece1
)
618 const finalSquare
= [move.appear
[0].x
, move.appear
[0].y
];
621 this.getColor(finalSquare
[0], finalSquare
[1]) != 'a' ||
622 this.getPiece(finalSquare
[0], finalSquare
[1]) != V
.EGG
625 V
.steps
[piece1
== V
.ROOK
? V
.BISHOP : V
.ROOK
].filter(s
=> {
626 const [i
, j
] = [finalSquare
[0] + s
[0], finalSquare
[1] + s
[1]];
629 // NOTE: do not place a bomb or banana on the invisible queen!
630 (this.board
[i
][j
] == V
.EMPTY
|| this.getColor(i
, j
) == 'a')
633 if (validSteps
.length
>= 1) {
634 const randIdx
= randInt(validSteps
.length
);
636 finalSquare
[0] + validSteps
[randIdx
][0],
637 finalSquare
[1] + validSteps
[randIdx
][1]
644 p: (piece1
== V
.ROOK
? V
.BANANA : V
.BOMB
)
647 if (this.board
[x
][y
] != V
.EMPTY
) {
649 new PiPo({ x: x
, y: y
, c: 'a', p: this.getPiece(x
, y
) }));
657 getBasicMove(psq1
, sq2
, tr
) {
659 if (Array
.isArray(psq1
)) psq1
= { x: psq1
[0], y: psq1
[1] };
660 let m
= this.getBasicMove_aux(psq1
, sq2
, tr
, "initMove");
662 // Last move ended on bomb or banana, direction change
663 V
.PlayOnBoard(this.board
, m
);
665 m
= this.getBasicMove_aux(
666 { x: m
.appear
[0].x
, y: m
.appear
[0].y
}, m
.next
);
668 for (let i
=moves
.length
-1; i
>=0; i
--) V
.UndoOnBoard(this.board
, moves
[i
]);
670 // Now merge moves into one
672 // start is wrong for Toadette moves --> it's fixed later
673 move.start
= { x: psq1
.x
, y: psq1
.y
};
674 move.end
= !!sq2
? { x: sq2
[0], y: sq2
[1] } : { x: psq1
.x
, y: psq1
.y
};
675 if (!!tr
) move.promoteInto
= moves
[0].promoteInto
;
676 let lm
= moves
[moves
.length
-1];
677 if (this.subTurn
== 1 && !!lm
.end
.effect
)
678 move.end
.effect
= lm
.end
.effect
;
679 if (moves
.length
== 1) {
680 move.appear
= moves
[0].appear
;
681 move.vanish
= moves
[0].vanish
;
684 // Keep first vanish and last appear (if any)
685 move.appear
= lm
.appear
;
686 move.vanish
= moves
[0].vanish
;
688 move.vanish
.length
>= 1 &&
689 move.appear
.length
>= 1 &&
690 move.vanish
[0].x
== move.appear
[0].x
&&
691 move.vanish
[0].y
== move.appear
[0].y
693 // Loopback on initial square:
697 for (let i
=1; i
< moves
.length
- 1; i
++) {
698 for (let v
of moves
[i
].vanish
) {
699 // Only vanishing objects, not appearing at init move
703 moves
[0].appear
.length
== 1 ||
704 moves
[0].appear
[1].x
!= v
.x
||
705 moves
[0].appear
[1].y
!= v
.y
712 // Final vanish is our piece, but others might be relevant
713 // (for some egg bonuses at least).
714 for (let i
=1; i
< lm
.vanish
.length
; i
++) {
716 lm
.vanish
[i
].c
!= 'a' ||
717 moves
[0].appear
.length
== 1 ||
718 moves
[0].appear
[1].x
!= lm
.vanish
[i
].x
||
719 moves
[0].appear
[1].y
!= lm
.vanish
[i
].y
721 move.vanish
.push(lm
.vanish
[i
]);
728 getPotentialPawnMoves([x
, y
]) {
729 const color
= this.turn
;
730 const oppCol
= V
.GetOppCol(color
);
731 const [sizeX
, sizeY
] = [V
.size
.x
, V
.size
.y
];
732 const shiftX
= V
.PawnSpecs
.directions
[color
];
733 const firstRank
= (color
== "w" ? sizeX
- 1 : 0);
736 this.board
[x
+ shiftX
][y
] == V
.EMPTY
||
737 this.getColor(x
+ shiftX
, y
) == 'a' ||
738 this.getPiece(x
+ shiftX
, y
) == V
.INVISIBLE_QUEEN
740 this.addPawnMoves([x
, y
], [x
+ shiftX
, y
], moves
);
742 [firstRank
, firstRank
+ shiftX
].includes(x
) &&
744 this.board
[x
+ 2 * shiftX
][y
] == V
.EMPTY
||
745 this.getColor(x
+ 2 * shiftX
, y
) == 'a' ||
746 this.getPiece(x
+ 2 * shiftX
, y
) == V
.INVISIBLE_QUEEN
749 moves
.push(this.getBasicMove({ x: x
, y: y
}, [x
+ 2 * shiftX
, y
]));
752 for (let shiftY
of [-1, 1]) {
755 y
+ shiftY
< sizeY
&&
756 this.board
[x
+ shiftX
][y
+ shiftY
] != V
.EMPTY
&&
757 // Pawns cannot capture invisible queen this way!
758 this.getPiece(x
+ shiftX
, y
+ shiftY
) != V
.INVISIBLE_QUEEN
&&
759 ['a', oppCol
].includes(this.getColor(x
+ shiftX
, y
+ shiftY
))
761 this.addPawnMoves([x
, y
], [x
+ shiftX
, y
+ shiftY
], moves
);
767 getPotentialQueenMoves(sq
) {
768 const normalMoves
= super.getPotentialQueenMoves(sq
);
769 // If flag allows it, add 'invisible movements'
770 let invisibleMoves
= [];
771 if (this.powerFlags
[this.turn
][V
.QUEEN
]) {
772 normalMoves
.forEach(m
=> {
774 m
.appear
.length
== 1 &&
775 m
.vanish
.length
== 1 &&
776 // Only simple non-capturing moves:
779 let im
= JSON
.parse(JSON
.stringify(m
));
780 im
.appear
[0].p
= V
.INVISIBLE_QUEEN
;
781 im
.end
.noHighlight
= true;
782 invisibleMoves
.push(im
);
786 return normalMoves
.concat(invisibleMoves
);
789 getPotentialKingMoves([x
, y
]) {
790 let moves
= super.getPotentialKingMoves([x
, y
]);
791 const color
= this.turn
;
792 // If flag allows it, add 'remote shell captures'
793 if (this.powerFlags
[this.turn
][V
.KING
]) {
794 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]).forEach(step
=> {
795 let [i
, j
] = [x
+ step
[0], y
+ step
[1]];
799 this.board
[i
][j
] == V
.EMPTY
||
800 this.getPiece(i
, j
) == V
.INVISIBLE_QUEEN
||
802 this.getColor(i
, j
) == 'a' &&
803 [V
.EGG
, V
.MUSHROOM
].includes(this.getPiece(i
, j
))
810 if (V
.OnBoard(i
, j
)) {
811 const colIJ
= this.getColor(i
, j
);
812 if (colIJ
!= color
) {
813 // May just destroy a bomb or banana:
816 start: { x: x
, y: y
},
821 x: i
, y: j
, c: colIJ
, p: this.getPiece(i
, j
)
833 getSlideNJumpMoves([x
, y
], steps
, oneStep
) {
835 outerLoop: for (let step
of steps
) {
841 this.board
[i
][j
] == V
.EMPTY
||
842 this.getPiece(i
, j
) == V
.INVISIBLE_QUEEN
||
844 this.getColor(i
, j
) == 'a' &&
845 [V
.EGG
, V
.MUSHROOM
].includes(this.getPiece(i
, j
))
849 moves
.push(this.getBasicMove({ x: x
, y: y
}, [i
, j
]));
850 if (oneStep
) continue outerLoop
;
854 if (V
.OnBoard(i
, j
) && this.canTake([x
, y
], [i
, j
]))
855 moves
.push(this.getBasicMove({ x: x
, y: y
}, [i
, j
]));
860 getAllPotentialMoves() {
861 if (this.subTurn
== 1) return super.getAllPotentialMoves();
863 const color
= this.turn
;
864 const L
= this.effects
.length
;
865 switch (this.effects
[L
-1]) {
868 for (let i
=0; i
<8; i
++) {
869 for (let j
=0; j
<8; j
++) {
870 const colIJ
= this.getColor(i
, j
);
871 const pieceIJ
= this.getPiece(i
, j
);
874 this.board
[i
][j
] != V
.EMPTY
&&
876 pieceIJ
!= V
.INVISIBLE_QUEEN
878 allPieces
.push({ x: i
, y: j
, c: colIJ
, p: pieceIJ
});
882 for (let x
=0; x
<8; x
++) {
883 for (let y
=0; y
<8; y
++) {
884 if (this.getColor(i
, j
) == color
) {
885 // Add exchange with something
886 allPieces
.forEach(pp
=> {
887 if (pp
.x
!= i
|| pp
.y
!= j
) {
888 const movedUnit
= new PiPo({
894 let mMove
= this.getBasicMove({ x: x
, y: y
}, [pp
.x
, pp
.y
]);
895 mMove
.appear
.push(movedUnit
);
905 const x
= V
.size
.x
+ (this.turn
== 'w' ? 0 : 1);
906 for (let y
= 0; y
< 8; y
++)
907 Array
.prototype.push
.apply(moves
, this.getReserveMoves([x
, y
]));
911 moves
= super.getAllPotentialMoves();
928 if (move.effect
== "toadette")
929 this.reserve
= this.captured
;
931 this.reserve
= { w: {}, b: {} };;
932 const color
= this.turn
;
934 move.vanish
.length
== 2 &&
935 move.vanish
[1].c
!= 'a' &&
936 move.appear
.length
== 1 //avoid king Boo!
938 // Capture: update this.captured
939 let capturedPiece
= move.vanish
[1].p
;
940 if (capturedPiece
== V
.INVISIBLE_QUEEN
)
941 capturedPiece
= V
.QUEEN
;
942 else if (Object
.keys(V
.IMMOBILIZE_DECODE
).includes(capturedPiece
))
943 capturedPiece
= V
.IMMOBILIZE_DECODE
[capturedPiece
];
944 this.captured
[move.vanish
[1].c
][capturedPiece
]++;
946 else if (move.vanish
.length
== 0) {
947 if (move.appear
.length
== 0 || move.appear
[0].c
== 'a') return;
948 // A piece is back on board
949 this.captured
[move.appear
[0].c
][move.appear
[0].p
]--;
951 if (move.appear
.length
== 0) {
952 // Three cases: king "shell capture", Chomp or Koopa
953 if (this.getPiece(move.start
.x
, move.start
.y
) == V
.KING
)
954 // King remote capture:
955 this.powerFlags
[color
][V
.KING
] = false;
956 else if (move.end
.effect
== "chomp")
957 this.captured
[color
][move.vanish
[0].p
]++;
959 else if (move.appear
[0].p
== V
.INVISIBLE_QUEEN
)
960 this.powerFlags
[move.appear
[0].c
][V
.QUEEN
] = false;
961 if (this.subTurn
== 2) return;
964 move.appear
.length
== 0 ||
965 !(Object
.keys(V
.IMMOBILIZE_DECODE
).includes(move.appear
[0].p
))
967 // Look for an immobilized piece of my color: it can now move
968 for (let i
=0; i
<8; i
++) {
969 for (let j
=0; j
<8; j
++) {
970 if (this.board
[i
][j
] != V
.EMPTY
) {
971 const piece
= this.getPiece(i
, j
);
973 this.getColor(i
, j
) == color
&&
974 Object
.keys(V
.IMMOBILIZE_DECODE
).includes(piece
)
976 this.board
[i
][j
] = color
+ V
.IMMOBILIZE_DECODE
[piece
];
977 move.wasImmobilized
= [i
, j
];
983 // Also make opponent invisible queen visible again, if any
984 const oppCol
= V
.GetOppCol(color
);
985 for (let i
=0; i
<8; i
++) {
986 for (let j
=0; j
<8; j
++) {
988 this.board
[i
][j
] != V
.EMPTY
&&
989 this.getColor(i
, j
) == oppCol
&&
990 this.getPiece(i
, j
) == V
.INVISIBLE_QUEEN
992 this.board
[i
][j
] = oppCol
+ V
.QUEEN
;
993 move.wasInvisible
= [i
, j
];
1001 this.playOnBoard(move);
1002 if (["kingboo", "toadette", "daisy"].includes(move.effect
)) {
1003 this.effect
= move.effect
;
1007 this.turn
= C
.GetOppCol(this.turn
);
1013 filterValid(moves
) {
1017 // TODO + display bonus messages
1018 // + animation + multi-moves for bananas/bombs/mushrooms