- static get VALUES() {
- return Object.assign(
- {},
- ChessRules.VALUES,
- {
- s: 1,
- u: 5,
- o: 3,
- c: 3,
- t: 9,
- l: 1000,
- e: 0,
- d: 0,
- w: 0,
- m: 0
- }
- );
- }
-
- static get SEARCH_DEPTH() {
- return 1;
- }
-
- getComputerMove() {
- const moves = this.getAllValidMoves();
- // Split into "normal" and "random" moves:
- // (Next splitting condition is OK because cannot take self object
- // without a banana or bomb on the way).
- const deterministicMoves = moves.filter(m => {
- return m.vanish.every(a => a.c != 'a' || a.p == V.MUSHROOM);
- });
- const randomMoves = moves.filter(m => {
- return m.vanish.some(a => a.c == 'a' && a.p != V.MUSHROOM);
- });
- if (Math.random() < deterministicMoves.length / randomMoves.length)
- // Play a deterministic one: capture king or material if possible
- return super.getComputerMove(deterministicMoves);
- // Play a random effect move, at random:
- let move1 = randomMoves[randInt(randomMoves.length)];
- this.play(move1);
- let move2 = undefined;
- if (this.subTurn == 2) {
- const moves2 = this.getAllValidMoves();
- move2 = moves2[randInt(moves2.length)];
- }
- this.undo(move1);
- if (!move2) return move1;
- return [move1, move2];
- }
-
- getNotation(move) {
- if (move.vanish.length == 0 && move.appear.length == 0) return "-";
- if (
- !move.end.effect &&
- move.appear.length > 0 &&
- move.appear[0].p == V.INVISIBLE_QUEEN
- ) {
- return "Q??";
- }
- const finalSquare = V.CoordsToSquare(move.end);
- // Next condition also includes Toadette placements:
- if (move.appear.length > 0 && move.vanish.every(a => a.c == 'a')) {
- const piece =
- move.appear[0].p != V.PAWN ? move.appear[0].p.toUpperCase() : "";
- return piece + "@" + finalSquare;
- }
- else if (move.appear.length == 0) {
- const piece = this.getPiece(move.start.x, move.start.y);
- if (piece == V.KING && !move.end.effect)
- // King remote capture
- return "Kx" + finalSquare;
- // Koopa or Chomp, or loopback after bananas, bombs & mushrooms:
- return (
- piece.toUpperCase() + "x" + finalSquare +
- (
- !!move.end.effect
- ? "*" + (move.end.effect == "koopa" ? "K" : "C")
- : ""
- )
- );
- }
- if (move.appear.length == 1 && move.vanish.length == 1) {
- const moveStart = move.appear[0].p.toUpperCase() + "@";
- if (move.appear[0].c == 'a' && move.vanish[0].c == 'a')
- // Bonus replacement:
- return moveStart + finalSquare;
- if (
- move.vanish[0].p == V.INVISIBLE_QUEEN &&
- move.appear[0].x == move.vanish[0].x &&
- move.appear[0].y == move.vanish[0].y
- ) {
- // Toadette takes invisible queen
- return moveStart + "Q" + finalSquare;
- }
- }
- if (
- move.appear.length == 2 &&
- move.vanish.length == 2 &&
- move.appear.every(a => a.c != 'a') &&
- move.vanish.every(v => v.c != 'a')
- ) {
- // King Boo exchange
- return V.CoordsToSquare(move.start) + finalSquare;
- }
- const piece = move.vanish[0].p;
- let notation = undefined;
- if (piece == V.PAWN) {
- // Pawn move
- if (this.board[move.end.x][move.end.y] != V.EMPTY) {
- // Capture
- const startColumn = V.CoordToColumn(move.start.y);
- notation = startColumn + "x" + finalSquare;
- }
- else notation = finalSquare;
- if (move.appear[0].p != V.PAWN)
- // Promotion
- notation += "=" + move.appear[0].p.toUpperCase();
- }
- else {
- notation =
- piece.toUpperCase() +
- (this.board[move.end.x][move.end.y] != V.EMPTY ? "x" : "") +
- finalSquare;
- }
- if (!!move.end.effect) {
- switch (move.end.effect) {
- case "kingboo":
- notation += "*B";
- break;
- case "toadette":
- notation += "*T";
- break;
- case "daisy":
- notation += "*D";
- break;
- case "bowser":
- notation += "*M";
- break;
- case "luigi":
- case "waluigi":
- const lastAppear = move.appear[move.appear.length - 1];
- const effectOn =
- V.CoordsToSquare({ x: lastAppear.x, y : lastAppear.y });
- notation += "*" + move.end.effect[0].toUpperCase() + effectOn;
- break;
- }
- }
- return notation;
- }