- if (this.subTurn == 1) {
- // 1) Determine the effect (some may be impossible)
- let effects = ["kingboo", "koopa", "chomp", "bowser"];
- if (this.captured[color1].some(c => c >= 1))
- effects.push("toadette");
- V.PlayOnBoard(this.board, move);
- const canPlayAgain = this.getPotentialMovesFrom([x2, y2]).length > 0;
- V.UndoOnBoard(this.board, move);
- if (canPlayAgain) effects.push("daisy");
- if (
- board.some(b =>
- b.some(cell => cell[0] == oppCol && cell[1] != V.KING))
- ) {
- effects.push("luigi");
- }
- if (
- board.some(b =>
- b.some(cell => cell[0] == color1 && cell[1] != V.KING))
- ) {
- effects.push("waluigi");
- }
- const effect = effects[randInd(effects.length)];
- // 2) Apply it if possible, or set move.end.effect
- if (["kingboo", "toadette", "daisy"].includes(effect))
- move.end.effect = effect;
- else {
- switch (effect) {
- case "koopa":
- move.appear[0].x = x1;
- move.appear[0].y = y1;
- break;
- case "chomp":
- move.appear.unshift();
- break;
- case "bowser":
- move.appear[0].p = V.IMMOBILIZE_CODE[piece1];
- break;
- case "luigi":
- changePieceColor(oppCol);
- break;
- case "waluigi":
- changePieceColor(color1);
- break;
- }
+ if (this.subTurn == 2)
+ // No egg effects at subTurn 2
+ return;
+ // 1) Determine the effect (some may be impossible)
+ let effects = ["kingboo", "koopa", "chomp", "bowser"];
+ if (Object.values(this.captured[color1]).some(c => c >= 1))
+ effects.push("toadette");
+ const lastRank = { 'w': 0, 'b': 7 };
+ let canPlayAgain = undefined;
+ if (
+ move.appear[0].p == V.PAWN &&
+ move.appear[0].x == lastRank[color1]
+ ) {
+ // Always possible: promote into a queen rook or king
+ canPlayAgain = true;
+ }
+ else {
+ move.end.effect = "toadette";
+ this.play(move);
+ canPlayAgain = this.getPotentialMovesFrom([x2, y2]).length > 0;
+ this.undo(move);
+ delete move.end["effect"];
+ }
+ if (canPlayAgain) effects.push("daisy");
+ if (
+ this.board.some((b,i) =>
+ b.some(cell => {
+ return (
+ cell[0] == oppCol &&
+ cell[1] != V.KING &&
+ (cell[1] != V.PAWN || i != lastRank[oppCol])
+ );
+ })
+ )
+ ) {
+ effects.push("luigi");
+ }
+ if (
+ this.board.some((b,i) =>
+ b.some(cell => {
+ return (
+ cell[0] == color1 &&
+ cell[1] != V.KING &&
+ (cell[1] != V.PAWN || i != lastRank[color1])
+ );
+ })
+ )
+ ) {
+ effects.push("waluigi");
+ }
+ const effect = effects[randInt(effects.length)];
+ move.end.effect = effect;
+ // 2) Apply it if possible
+ if (!(["kingboo", "toadette", "daisy"].includes(effect))) {
+ switch (effect) {
+ case "koopa":
+ move.appear = [];
+ // Maybe egg effect was applied after others,
+ // so just shift vanish array:
+ move.vanish.shift();
+ break;
+ case "chomp":
+ move.appear = [];
+ break;
+ case "bowser":
+ move.appear[0].p = V.IMMOBILIZE_CODE[piece1];
+ break;
+ case "luigi":
+ changePieceColor(oppCol);
+ break;
+ case "waluigi":
+ changePieceColor(color1);
+ break;