a9f11fb957190a3bbc6cc181a2d08ae959344847
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 getDropMovesFrom([c
, p
]) {
148 if (this.reserve
[c
][p
] == 0) return [];
150 const start
= (c
== 'w' && p
== 'p' ? 1 : 0);
151 const end
= (color
== 'b' && p
== 'p' ? 7 : 8);
152 for (let i
= start
; i
< end
; i
++) {
153 for (let j
= 0; j
< this.size
.y
; j
++) {
154 const pieceIJ
= this.getPiece(i
, j
);
156 this.board
[i
][j
] == "" ||
157 this.getColor(i
, j
) == 'a' ||
158 pieceIJ
== V
.INVISIBLE_QUEEN
163 appear: [new PiPo({x: i
, y: j
, c: c
, p: p
})],
166 // A drop move may remove a bonus (or hidden queen!)
167 if (this.board
[i
][j
] != "")
168 m
.vanish
.push(new PiPo({x: i
, y: j
, c: 'a', p: pieceIJ
}));
185 // TODO: rethink from here:
187 getPotentialMovesFrom([x
, y
]) {
189 if (this.subTurn
== 1) {
190 moves
= super.getPotentialMovesFrom([x
, y
]);
191 const finalPieces
= V
.PawnSpecs
.promotions
;
192 const color
= this.turn
;
193 const lastRank
= (color
== "w" ? 0 : 7);
197 m
.appear
.length
> 0 &&
198 ['p', 's'].includes(m
.appear
[0].p
) &&
199 m
.appear
[0].x
== lastRank
201 for (let i
= 1; i
< finalPieces
.length
; i
++) {
202 const piece
= finalPieces
[i
];
203 let otherM
= JSON
.parse(JSON
.stringify(m
));
205 m
.appear
[0].p
== V
.PAWN
207 : V
.IMMOBILIZE_CODE
[finalPieces
[i
]];
210 // Finally alter m itself:
212 m
.appear
[0].p
== V
.PAWN
214 : V
.IMMOBILIZE_CODE
[finalPieces
[0]];
217 Array
.prototype.push
.apply(moves
, pMoves
);
221 const L
= this.effects
.length
;
222 switch (this.effects
[L
-1]) {
224 // Exchange position with any visible piece,
225 // except pawns if arriving on last rank.
226 const lastRank
= { 'w': 0, 'b': 7 };
227 const color
= this.turn
;
228 const allowLastRank
= (this.getPiece(x
, y
) != V
.PAWN
);
229 for (let i
=0; i
<8; i
++) {
230 for (let j
=0; j
<8; j
++) {
231 const colIJ
= this.getColor(i
, j
);
232 const pieceIJ
= this.getPiece(i
, j
);
234 (i
!= x
|| j
!= y
) &&
235 this.board
[i
][j
] != V
.EMPTY
&&
236 pieceIJ
!= V
.INVISIBLE_QUEEN
&&
240 (pieceIJ
!= V
.PAWN
|| x
!= lastRank
[colIJ
]) &&
241 (allowLastRank
|| i
!= lastRank
[color
])
243 const movedUnit
= new PiPo({
247 p: this.getPiece(i
, j
)
249 let mMove
= this.getBasicMove({ x: x
, y: y
}, [i
, j
]);
250 mMove
.appear
.push(movedUnit
);
258 // Resurrect a captured piece
259 if (x
>= V
.size
.x
) moves
= this.getReserveMoves([x
, y
]);
262 // Play again with any piece
263 moves
= super.getPotentialMovesFrom([x
, y
]);
270 // Helper for getBasicMove(): banana/bomb effect
271 getRandomSquare([x
, y
], steps
) {
272 const validSteps
= steps
.filter(s
=> V
.OnBoard(x
+ s
[0], y
+ s
[1]));
273 const step
= validSteps
[randInt(validSteps
.length
)];
274 return [x
+ step
[0], y
+ step
[1]];
277 // Apply mushroom, bomb or banana effect (hidden to the player).
278 // Determine egg effect, too, and apply its first part if possible.
279 getBasicMove_aux(psq1
, sq2
, tr
, initMove
) {
280 const [x1
, y1
] = [psq1
.x
, psq1
.y
];
281 const color1
= this.turn
;
282 const piece1
= (!!tr
? tr
.p : (psq1
.p
|| this.getPiece(x1
, y1
)));
283 const oppCol
= V
.GetOppCol(color1
);
289 // banana or bomb defines next square, or the move ends there
298 if (this.board
[x1
][y1
] != V
.EMPTY
) {
299 const initP1
= this.getPiece(x1
, y1
);
304 c: this.getColor(x1
, y1
),
308 if ([V
.BANANA
, V
.BOMB
].includes(initP1
)) {
309 const steps
= V
.steps
[initP1
== V
.BANANA
? V
.ROOK : V
.BISHOP
];
310 move.next
= this.getRandomSquare([x1
, y1
], steps
);
313 move.end
= { x: x1
, y: y1
};
316 const [x2
, y2
] = [sq2
[0], sq2
[1]];
317 // The move starts normally, on board:
318 let move = super.getBasicMove([x1
, y1
], [x2
, y2
], tr
);
319 if (!!tr
) move.promoteInto
= tr
.c
+ tr
.p
; //in case of (chomped...)
320 const L
= this.effects
.length
;
322 [V
.PAWN
, V
.KNIGHT
].includes(piece1
) &&
324 (this.subTurn
== 1 || this.effects
[L
-1] == "daisy")
328 const twoSquaresMove
= (Math
.abs(x2
- x1
) == 2);
329 const mushroomX
= x1
+ (twoSquaresMove
? (x2
- x1
) / 2 : 0);
338 if (this.getColor(mushroomX
, y1
) == 'a') {
344 p: this.getPiece(mushroomX
, y1
)
351 const deltaX
= Math
.abs(x2
- x1
);
352 const deltaY
= Math
.abs(y2
- y1
);
354 x1
+ (deltaX
== 2 ? (x2
- x1
) / 2 : 0),
355 y1
+ (deltaY
== 2 ? (y2
- y1
) / 2 : 0)
358 this.board
[eggSquare
[0]][eggSquare
[1]] != V
.EMPTY
&&
359 this.getColor(eggSquare
[0], eggSquare
[1]) != 'a'
372 if (this.getColor(eggSquare
[0], eggSquare
[1]) == 'a') {
378 p: this.getPiece(eggSquare
[0], eggSquare
[1])
386 // For (wa)luigi effect:
387 const changePieceColor
= (color
) => {
389 const oppLastRank
= (color
== 'w' ? 7 : 0);
390 for (let i
=0; i
<8; i
++) {
391 for (let j
=0; j
<8; j
++) {
392 const piece
= this.getPiece(i
, j
);
394 (i
!= move.vanish
[0].x
|| j
!= move.vanish
[0].y
) &&
395 this.board
[i
][j
] != V
.EMPTY
&&
396 piece
!= V
.INVISIBLE_QUEEN
&&
397 this.getColor(i
, j
) == color
399 if (piece
!= V
.KING
&& (piece
!= V
.PAWN
|| i
!= oppLastRank
))
400 pieces
.push({ x: i
, y: j
, p: piece
});
404 // Special case of the current piece (still at its initial position)
406 pieces
.push({ x: move.appear
[0].x
, y: move.appear
[0].y
, p: piece1
});
407 const cp
= pieces
[randInt(pieces
.length
)];
408 if (move.appear
[0].x
!= cp
.x
|| move.appear
[0].y
!= cp
.y
) {
418 else move.appear
.shift();
423 c: V
.GetOppCol(color
),
428 const applyEggEffect
= () => {
429 if (this.subTurn
== 2)
430 // No egg effects at subTurn 2
432 // 1) Determine the effect (some may be impossible)
433 let effects
= ["kingboo", "koopa", "chomp", "bowser", "daisy"];
434 if (Object
.values(this.captured
[color1
]).some(c
=> c
>= 1))
435 effects
.push("toadette");
436 const lastRank
= { 'w': 0, 'b': 7 };
438 this.board
.some((b
,i
) =>
443 (cell
[1] != V
.PAWN
|| i
!= lastRank
[color1
])
448 effects
.push("luigi");
453 (piece1
!= V
.PAWN
|| move.appear
[0].x
!= lastRank
[oppCol
])
455 this.board
.some((b
,i
) =>
460 (cell
[1] != V
.PAWN
|| i
!= lastRank
[oppCol
])
465 effects
.push("waluigi");
467 const effect
= effects
[randInt(effects
.length
)];
468 move.end
.effect
= effect
;
469 // 2) Apply it if possible
470 if (!(["kingboo", "toadette", "daisy"].includes(effect
))) {
474 // Maybe egg effect was applied after others,
475 // so just shift vanish array:
482 move.appear
[0].p
= V
.IMMOBILIZE_CODE
[piece1
];
485 changePieceColor(oppCol
);
488 changePieceColor(color1
);
493 const applyMushroomEffect
= () => {
494 if ([V
.PAWN
, V
.KING
, V
.KNIGHT
].includes(piece1
)) {
495 // Just make another similar step, if possible (non-capturing)
497 move.appear
[0].x
+ (x2
- x1
),
498 move.appear
[0].y
+ (y2
- y1
)
503 this.board
[i
][j
] == V
.EMPTY
||
504 this.getPiece(i
, j
) == V
.INVISIBLE_QUEEN
||
505 this.getColor(i
, j
) == 'a'
508 move.appear
[0].x
= i
;
509 move.appear
[0].y
= j
;
510 if (this.board
[i
][j
] != V
.EMPTY
) {
511 const object
= this.getPiece(i
, j
);
512 const color
= this.getColor(i
, j
);
524 const steps
= V
.steps
[object
== V
.BANANA
? V
.ROOK : V
.BISHOP
];
525 move.next
= this.getRandomSquare([i
, j
], steps
);
531 applyMushroomEffect();
538 // Queen, bishop or rook:
540 (x2
- x1
) / Math
.abs(x2
- x1
) || 0,
541 (y2
- y1
) / Math
.abs(y2
- y1
) || 0
543 const next
= [move.appear
[0].x
+ step
[0], move.appear
[0].y
+ step
[1]];
545 V
.OnBoard(next
[0], next
[1]) &&
546 this.board
[next
[0]][next
[1]] != V
.EMPTY
&&
547 this.getPiece(next
[0], next
[1]) != V
.INVISIBLE_QUEEN
&&
548 this.getColor(next
[0], next
[1]) != 'a'
550 const afterNext
= [next
[0] + step
[0], next
[1] + step
[1]];
551 if (V
.OnBoard(afterNext
[0], afterNext
[1])) {
552 const afterColor
= this.getColor(afterNext
[0], afterNext
[1]);
554 this.board
[afterNext
[0]][afterNext
[1]] == V
.EMPTY
||
557 move.appear
[0].x
= afterNext
[0];
558 move.appear
[0].y
= afterNext
[1];
559 if (this.board
[afterNext
[0]][afterNext
[1]] != V
.EMPTY
) {
560 // object = banana, bomb, mushroom or egg
561 const object
= this.getPiece(afterNext
[0], afterNext
[1]);
574 V
.steps
[object
== V
.BANANA
? V
.ROOK : V
.BISHOP
];
575 move.next
= this.getRandomSquare(
576 [afterNext
[0], afterNext
[1]], steps
);
582 applyMushroomEffect();
591 const color2
= this.getColor(x2
, y2
);
592 const piece2
= this.getPiece(x2
, y2
);
597 const steps
= V
.steps
[piece2
== V
.BANANA
? V
.ROOK : V
.BISHOP
];
598 move.next
= this.getRandomSquare([x2
, y2
], steps
);
601 applyMushroomEffect();
604 if (this.subTurn
== 1)
605 // No egg effect at subTurn 2
613 move.appear
.length
> 0 &&
614 [V
.ROOK
, V
.BISHOP
].includes(piece1
)
616 const finalSquare
= [move.appear
[0].x
, move.appear
[0].y
];
619 this.getColor(finalSquare
[0], finalSquare
[1]) != 'a' ||
620 this.getPiece(finalSquare
[0], finalSquare
[1]) != V
.EGG
623 V
.steps
[piece1
== V
.ROOK
? V
.BISHOP : V
.ROOK
].filter(s
=> {
624 const [i
, j
] = [finalSquare
[0] + s
[0], finalSquare
[1] + s
[1]];
627 // NOTE: do not place a bomb or banana on the invisible queen!
628 (this.board
[i
][j
] == V
.EMPTY
|| this.getColor(i
, j
) == 'a')
631 if (validSteps
.length
>= 1) {
632 const randIdx
= randInt(validSteps
.length
);
634 finalSquare
[0] + validSteps
[randIdx
][0],
635 finalSquare
[1] + validSteps
[randIdx
][1]
642 p: (piece1
== V
.ROOK
? V
.BANANA : V
.BOMB
)
645 if (this.board
[x
][y
] != V
.EMPTY
) {
647 new PiPo({ x: x
, y: y
, c: 'a', p: this.getPiece(x
, y
) }));
655 getBasicMove(psq1
, sq2
, tr
) {
657 if (Array
.isArray(psq1
)) psq1
= { x: psq1
[0], y: psq1
[1] };
658 let m
= this.getBasicMove_aux(psq1
, sq2
, tr
, "initMove");
660 // Last move ended on bomb or banana, direction change
661 V
.PlayOnBoard(this.board
, m
);
663 m
= this.getBasicMove_aux(
664 { x: m
.appear
[0].x
, y: m
.appear
[0].y
}, m
.next
);
666 for (let i
=moves
.length
-1; i
>=0; i
--) V
.UndoOnBoard(this.board
, moves
[i
]);
668 // Now merge moves into one
670 // start is wrong for Toadette moves --> it's fixed later
671 move.start
= { x: psq1
.x
, y: psq1
.y
};
672 move.end
= !!sq2
? { x: sq2
[0], y: sq2
[1] } : { x: psq1
.x
, y: psq1
.y
};
673 if (!!tr
) move.promoteInto
= moves
[0].promoteInto
;
674 let lm
= moves
[moves
.length
-1];
675 if (this.subTurn
== 1 && !!lm
.end
.effect
)
676 move.end
.effect
= lm
.end
.effect
;
677 if (moves
.length
== 1) {
678 move.appear
= moves
[0].appear
;
679 move.vanish
= moves
[0].vanish
;
682 // Keep first vanish and last appear (if any)
683 move.appear
= lm
.appear
;
684 move.vanish
= moves
[0].vanish
;
686 move.vanish
.length
>= 1 &&
687 move.appear
.length
>= 1 &&
688 move.vanish
[0].x
== move.appear
[0].x
&&
689 move.vanish
[0].y
== move.appear
[0].y
691 // Loopback on initial square:
695 for (let i
=1; i
< moves
.length
- 1; i
++) {
696 for (let v
of moves
[i
].vanish
) {
697 // Only vanishing objects, not appearing at init move
701 moves
[0].appear
.length
== 1 ||
702 moves
[0].appear
[1].x
!= v
.x
||
703 moves
[0].appear
[1].y
!= v
.y
710 // Final vanish is our piece, but others might be relevant
711 // (for some egg bonuses at least).
712 for (let i
=1; i
< lm
.vanish
.length
; i
++) {
714 lm
.vanish
[i
].c
!= 'a' ||
715 moves
[0].appear
.length
== 1 ||
716 moves
[0].appear
[1].x
!= lm
.vanish
[i
].x
||
717 moves
[0].appear
[1].y
!= lm
.vanish
[i
].y
719 move.vanish
.push(lm
.vanish
[i
]);
726 getPotentialPawnMoves([x
, y
]) {
727 const color
= this.turn
;
728 const oppCol
= V
.GetOppCol(color
);
729 const [sizeX
, sizeY
] = [V
.size
.x
, V
.size
.y
];
730 const shiftX
= V
.PawnSpecs
.directions
[color
];
731 const firstRank
= (color
== "w" ? sizeX
- 1 : 0);
734 this.board
[x
+ shiftX
][y
] == V
.EMPTY
||
735 this.getColor(x
+ shiftX
, y
) == 'a' ||
736 this.getPiece(x
+ shiftX
, y
) == V
.INVISIBLE_QUEEN
738 this.addPawnMoves([x
, y
], [x
+ shiftX
, y
], moves
);
740 [firstRank
, firstRank
+ shiftX
].includes(x
) &&
742 this.board
[x
+ 2 * shiftX
][y
] == V
.EMPTY
||
743 this.getColor(x
+ 2 * shiftX
, y
) == 'a' ||
744 this.getPiece(x
+ 2 * shiftX
, y
) == V
.INVISIBLE_QUEEN
747 moves
.push(this.getBasicMove({ x: x
, y: y
}, [x
+ 2 * shiftX
, y
]));
750 for (let shiftY
of [-1, 1]) {
753 y
+ shiftY
< sizeY
&&
754 this.board
[x
+ shiftX
][y
+ shiftY
] != V
.EMPTY
&&
755 // Pawns cannot capture invisible queen this way!
756 this.getPiece(x
+ shiftX
, y
+ shiftY
) != V
.INVISIBLE_QUEEN
&&
757 ['a', oppCol
].includes(this.getColor(x
+ shiftX
, y
+ shiftY
))
759 this.addPawnMoves([x
, y
], [x
+ shiftX
, y
+ shiftY
], moves
);
765 getPotentialQueenMoves(sq
) {
766 const normalMoves
= super.getPotentialQueenMoves(sq
);
767 // If flag allows it, add 'invisible movements'
768 let invisibleMoves
= [];
769 if (this.powerFlags
[this.turn
][V
.QUEEN
]) {
770 normalMoves
.forEach(m
=> {
772 m
.appear
.length
== 1 &&
773 m
.vanish
.length
== 1 &&
774 // Only simple non-capturing moves:
777 let im
= JSON
.parse(JSON
.stringify(m
));
778 im
.appear
[0].p
= V
.INVISIBLE_QUEEN
;
779 im
.end
.noHighlight
= true;
780 invisibleMoves
.push(im
);
784 return normalMoves
.concat(invisibleMoves
);
787 getPotentialKingMoves([x
, y
]) {
788 let moves
= super.getPotentialKingMoves([x
, y
]);
789 const color
= this.turn
;
790 // If flag allows it, add 'remote shell captures'
791 if (this.powerFlags
[this.turn
][V
.KING
]) {
792 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]).forEach(step
=> {
793 let [i
, j
] = [x
+ step
[0], y
+ step
[1]];
797 this.board
[i
][j
] == V
.EMPTY
||
798 this.getPiece(i
, j
) == V
.INVISIBLE_QUEEN
||
800 this.getColor(i
, j
) == 'a' &&
801 [V
.EGG
, V
.MUSHROOM
].includes(this.getPiece(i
, j
))
808 if (V
.OnBoard(i
, j
)) {
809 const colIJ
= this.getColor(i
, j
);
810 if (colIJ
!= color
) {
811 // May just destroy a bomb or banana:
814 start: { x: x
, y: y
},
819 x: i
, y: j
, c: colIJ
, p: this.getPiece(i
, j
)
831 getSlideNJumpMoves([x
, y
], steps
, oneStep
) {
833 outerLoop: for (let step
of steps
) {
839 this.board
[i
][j
] == V
.EMPTY
||
840 this.getPiece(i
, j
) == V
.INVISIBLE_QUEEN
||
842 this.getColor(i
, j
) == 'a' &&
843 [V
.EGG
, V
.MUSHROOM
].includes(this.getPiece(i
, j
))
847 moves
.push(this.getBasicMove({ x: x
, y: y
}, [i
, j
]));
848 if (oneStep
) continue outerLoop
;
852 if (V
.OnBoard(i
, j
) && this.canTake([x
, y
], [i
, j
]))
853 moves
.push(this.getBasicMove({ x: x
, y: y
}, [i
, j
]));
858 getAllPotentialMoves() {
859 if (this.subTurn
== 1) return super.getAllPotentialMoves();
861 const color
= this.turn
;
862 const L
= this.effects
.length
;
863 switch (this.effects
[L
-1]) {
866 for (let i
=0; i
<8; i
++) {
867 for (let j
=0; j
<8; j
++) {
868 const colIJ
= this.getColor(i
, j
);
869 const pieceIJ
= this.getPiece(i
, j
);
872 this.board
[i
][j
] != V
.EMPTY
&&
874 pieceIJ
!= V
.INVISIBLE_QUEEN
876 allPieces
.push({ x: i
, y: j
, c: colIJ
, p: pieceIJ
});
880 for (let x
=0; x
<8; x
++) {
881 for (let y
=0; y
<8; y
++) {
882 if (this.getColor(i
, j
) == color
) {
883 // Add exchange with something
884 allPieces
.forEach(pp
=> {
885 if (pp
.x
!= i
|| pp
.y
!= j
) {
886 const movedUnit
= new PiPo({
892 let mMove
= this.getBasicMove({ x: x
, y: y
}, [pp
.x
, pp
.y
]);
893 mMove
.appear
.push(movedUnit
);
903 const x
= V
.size
.x
+ (this.turn
== 'w' ? 0 : 1);
904 for (let y
= 0; y
< 8; y
++)
905 Array
.prototype.push
.apply(moves
, this.getReserveMoves([x
, y
]));
909 moves
= super.getAllPotentialMoves();
926 if (move.effect
== "toadette")
927 this.reserve
= this.captured
;
929 this.reserve
= { w: {}, b: {} };;
930 const color
= this.turn
;
932 move.vanish
.length
== 2 &&
933 move.vanish
[1].c
!= 'a' &&
934 move.appear
.length
== 1 //avoid king Boo!
936 // Capture: update this.captured
937 let capturedPiece
= move.vanish
[1].p
;
938 if (capturedPiece
== V
.INVISIBLE_QUEEN
)
939 capturedPiece
= V
.QUEEN
;
940 else if (Object
.keys(V
.IMMOBILIZE_DECODE
).includes(capturedPiece
))
941 capturedPiece
= V
.IMMOBILIZE_DECODE
[capturedPiece
];
942 this.captured
[move.vanish
[1].c
][capturedPiece
]++;
944 else if (move.vanish
.length
== 0) {
945 if (move.appear
.length
== 0 || move.appear
[0].c
== 'a') return;
946 // A piece is back on board
947 this.captured
[move.appear
[0].c
][move.appear
[0].p
]--;
949 if (move.appear
.length
== 0) {
950 // Three cases: king "shell capture", Chomp or Koopa
951 if (this.getPiece(move.start
.x
, move.start
.y
) == V
.KING
)
952 // King remote capture:
953 this.powerFlags
[color
][V
.KING
] = false;
954 else if (move.end
.effect
== "chomp")
955 this.captured
[color
][move.vanish
[0].p
]++;
957 else if (move.appear
[0].p
== V
.INVISIBLE_QUEEN
)
958 this.powerFlags
[move.appear
[0].c
][V
.QUEEN
] = false;
959 if (this.subTurn
== 2) return;
962 move.appear
.length
== 0 ||
963 !(Object
.keys(V
.IMMOBILIZE_DECODE
).includes(move.appear
[0].p
))
965 // Look for an immobilized piece of my color: it can now move
966 for (let i
=0; i
<8; i
++) {
967 for (let j
=0; j
<8; j
++) {
968 if (this.board
[i
][j
] != V
.EMPTY
) {
969 const piece
= this.getPiece(i
, j
);
971 this.getColor(i
, j
) == color
&&
972 Object
.keys(V
.IMMOBILIZE_DECODE
).includes(piece
)
974 this.board
[i
][j
] = color
+ V
.IMMOBILIZE_DECODE
[piece
];
975 move.wasImmobilized
= [i
, j
];
981 // Also make opponent invisible queen visible again, if any
982 const oppCol
= V
.GetOppCol(color
);
983 for (let i
=0; i
<8; i
++) {
984 for (let j
=0; j
<8; j
++) {
986 this.board
[i
][j
] != V
.EMPTY
&&
987 this.getColor(i
, j
) == oppCol
&&
988 this.getPiece(i
, j
) == V
.INVISIBLE_QUEEN
990 this.board
[i
][j
] = oppCol
+ V
.QUEEN
;
991 move.wasInvisible
= [i
, j
];
999 this.playOnBoard(move);
1000 if (["kingboo", "toadette", "daisy"].includes(move.effect
)) {
1001 this.effect
= move.effect
;
1005 this.turn
= C
.GetOppCol(this.turn
);
1011 filterValid(moves
) {
1015 // TODO + display bonus messages
1016 // + animation + multi-moves for bananas/bombs/mushrooms