+ // Helper to set and apply banana/bomb effect
+ getRandomSquare([x, y], steps, freeSquare) {
+ let validSteps = steps.filter(s => this.onBoard(x + s[0], y + s[1]));
+ if (freeSquare) {
+ // Square to put banana/bomb cannot be occupied by a piece
+ validSteps = validSteps.filter(s => {
+ return ["", 'a'].includes(this.getColor(x + s[0], y + s[1]))
+ });
+ }
+ if (validSteps.length == 0)
+ return null;
+ const step = validSteps[Random.randInt(validSteps.length)];
+ return [x + step[0], y + step[1]];
+ }
+
+ getEggEffect(move) {
+ const getRandomPiece = (c) => {
+ let bagOfPieces = [];
+ for (let i=0; i<this.size.x; i++) {
+ for (let j=0; j<this.size.y; j++) {
+ if (this.getColor(i, j) == c && this.getPiece(i, j) != 'k')
+ bagOfPieces.push([i, j]);
+ }
+ }
+ if (bagOfPieces.length >= 1)
+ return Random.sample(bagOfPieces);
+ return null;
+ };
+ const color = this.turn;
+ let em = null;
+ switch (move.egg) {
+ case "luigi":
+ case "waluigi":
+ // Change color of friendly or enemy piece, king excepted
+ const oldColor = (move.egg == "waluigi" ? color : C.GetOppCol(color));
+ const newColor = C.GetOppCol(oldColor);
+ const coords = getRandomPiece(oldColor);
+ if (coords) {
+ const piece = this.getPiece(coords[0], coords[1]);
+ em = new Move({
+ appear: [
+ new PiPo({x: coords[0], y: coords[1], c: newColor, p: piece})
+ ],
+ vanish: [
+ new PiPo({x: coords[0], y: coords[1], c: oldColor, p: piece})
+ ]
+ });
+ em.luigiEffect = true; //avoid dropping bomb/banana by mistake
+ }
+ break;
+ case "bowser":
+ em = new Move({
+ appear: [
+ new PiPo({
+ x: move.end.x,
+ y: move.end.y,
+ c: color,
+ p: V.IMMOBILIZE_CODE[move.appear[0].p]
+ })
+ ],
+ vanish: [
+ new PiPo({
+ x: move.end.x,
+ y: move.end.y,
+ c: color,
+ p: move.appear[0].p
+ })
+ ]
+ });
+ break;
+ case "koopa":
+ // Reverse move
+ em = new Move({
+ appear: [
+ new PiPo({
+ x: move.start.x, y: move.start.y, c: color, p: move.appear[0].p
+ })
+ ],
+ vanish: [
+ new PiPo({
+ x: move.end.x, y: move.end.y, c: color, p: move.appear[0].p
+ })
+ ]
+ });
+ if (this.board[move.start.x][move.start.y] != "") {
+ // Pawn or knight let something on init square
+ em.vanish.push(new PiPo({
+ x: move.start.x,
+ y: move.start.y,
+ c: 'a',
+ p: this.getPiece(move.start.x, move.start.y)
+ }));
+ }
+ break;
+ case "chomp":
+ // Eat piece
+ em = new Move({
+ appear: [],
+ vanish: [
+ new PiPo({
+ x: move.end.x, y: move.end.y, c: color, p: move.appear[0].p
+ })
+ ],
+ end: {x: move.end.x, y: move.end.y}
+ });
+ break;
+ }
+ if (em && move.egg != "koopa")
+ em.noAnimate = true; //static move
+ return em;