- 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})
- ]
- });
- }
- break;
- case "bowser":
- em = new Move({
- appear: [
- new PiPo({
- x: move.end.x,
- y: move.end.y,
- c: color,
- p: V.IMMOBILIZED_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
- })
- ]
- });
- 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;
- }
- return em;
- }
-
- // 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]];
- }
-
- getPotentialMovesOf(piece, [x, y]) {
- const color = this.getColor(x, y);
- const stepSpec = this.pieces(color, x, y)[piece];
- let moves = [];
- const findAddMoves = (type, stepArray) => {
- for (let s of stepArray) {
- outerLoop: for (let step of s.steps) {
- let [i, j] = [x + step[0], y + step[1]];
- let stepCounter = 1;
- while (
- this.onBoard(i, j) &&
- (
- this.board[i][j] == "" ||
- [V.MUSHROOM, V.EGG].includes(this.getPiece(i, j))
- )
- ) {
- if (type != "attack")
- moves.push(this.getBasicMove([x, y], [i, j]));
- if (s.range <= stepCounter++)
- continue outerLoop;
- [i, j] = [i + step[0], j + step[1]];
- }
- if (!this.onBoard(i, j))
- continue;
- const pieceIJ = this.getPiece(i, j);
- if (type != "moveonly" && this.getColor(i, j) != color)
- moves.push(this.getBasicMove([x, y], [i, j]));
- }
- }
- };
- const specialAttack = !!stepSpec.attack;
- if (specialAttack)
- findAddMoves("attack", stepSpec.attack);
- findAddMoves(specialAttack ? "moveonly" : "all", stepSpec.moves);
- return moves;