+ else {
+ // Normal case (including bonus daisy)
+ const piece = this.getPiece(x, y);
+ switch (piece) {
+ case 'p':
+ moves = this.getPawnMovesFrom([x, y]); //apply promotions
+ break;
+ case 'q':
+ moves = this.getQueenMovesFrom([x, y]);
+ break;
+ case 'k':
+ moves = this.getKingMovesFrom([x, y]);
+ break;
+ case 'n':
+ moves = this.getKnightMovesFrom([x, y]);
+ break;
+ case 'b':
+ case 'r':
+ // explicitely listing types to avoid moving immobilized piece
+ moves = this.getRookOrBishopMovesFrom([x, y], piece);
+ break;
+ }
+ }
+ // Set potential random effects, so that play() is deterministic
+ moves.forEach(m => {
+ switch (this.getPiece(m.end.x, m.end.y)) {
+ case V.EGG:
+ m.egg = Random.sample(V.EGG_SURPRISE);
+ m.next = this.getEggEffect(m);
+ break;
+ case V.BANANA:
+ m.next = this.getRandomSquare(
+ [m.end.x, m.end.y], [[1, 1], [1, -1], [-1, 1], [-1, -1]]);
+ break;
+ case V.BOMB:
+ m.next = this.getRandomSquare(
+ [m.end.x, m.end.y], [[1, 0], [-1, 0], [0, 1], [0, -1]]);
+ break;
+ }
+ });
+ return moves;
+ }
+
+ 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})
+ ]
+ });
+ }