X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FChakart%2Fclass.js;h=5202b489dfeaad00f5a74cac6f4a678a87a7cc94;hb=b9877ed29697640d72b8f3d89848863fc87bd7e8;hp=59e44b1ec9365956e1acca259820f235346d5eb1;hpb=ca8a399316d2496c069ea9c6ccf2dc241aeb70ef;p=xogo.git diff --git a/variants/Chakart/class.js b/variants/Chakart/class.js index 59e44b1..5202b48 100644 --- a/variants/Chakart/class.js +++ b/variants/Chakart/class.js @@ -1,7 +1,7 @@ import ChessRules from "/base_rules.js"; import GiveawayRules from "/variants/Giveaway/class.js"; -import { ArrayFun } from "/utils/array.js"; -import { Random } from "/utils/alea.js"; +import {ArrayFun} from "/utils/array.js"; +import {Random} from "/utils/alea.js"; import PiPo from "/utils/PiPo.js"; import Move from "/utils/Move.js"; @@ -127,18 +127,16 @@ export default class ChakartRules extends ChessRules { ] } }, - specials, bowsered, super.pieces(color, x, y)); + specials, bowsered, super.pieces(color, x, y) + ); } - genRandInitFen(seed) { + genRandInitBaseFen() { const options = Object.assign({mode: "suicide"}, this.options); const gr = new GiveawayRules({options: options, genFenOnly: true}); - const baseFen = gr.genRandInitFen(seed); - const fenParts = baseFen.split(" "); - let others = JSON.parse(fenParts[3]); - delete others["enpassant"]; - others["flags"] = "1111"; //Peach + Mario flags - return fenParts.slice(0, 3).join(" ") + " " + JSON.stringify(others); + let res = gr.genRandInitBaseFen(); + res.o["flags"] = "1111"; //Peach + Mario flags + return res; } fen2board(f) { @@ -269,7 +267,7 @@ export default class ChakartRules extends ChessRules { case 'b': case 'r': // Explicitely listing types to avoid moving immobilized piece - moves = this.getPotentialMovesOf(piece, [x, y]); + moves = super.getPotentialMovesOf(piece, [x, y]); break; } } @@ -314,7 +312,7 @@ export default class ChakartRules extends ChessRules { moves.push(this.getBasicMove([x, y], [x + shiftX, nextY])); } } - this.pawnPostProcess(moves, color, oppCol); + moves = super.pawnPostProcess(moves, color, oppCol); // Add mushroom on before-last square (+ potential segments) moves.forEach(m => { let [mx, my] = [x, y]; @@ -341,14 +339,14 @@ export default class ChakartRules extends ChessRules { getKnightMovesFrom([x, y]) { // Add egg on initial square: - return this.getPotentialMovesOf('n', [x, y]).map(m => { + return super.getPotentialMovesOf('n', [x, y]).map(m => { m.appear.push(new PiPo({p: "e", c: "a", x: x, y: y})); return m; }); } getQueenMovesFrom(sq) { - const normalMoves = this.getPotentialMovesOf('q', sq); + const normalMoves = super.getPotentialMovesOf('q', sq); // If flag allows it, add 'invisible movements' let invisibleMoves = []; if (this.powerFlags[this.turn]['q']) { @@ -370,10 +368,10 @@ export default class ChakartRules extends ChessRules { } getKingMovesFrom([x, y]) { - let moves = this.getPotentialMovesOf('k', [x, y]); + let moves = super.getPotentialMovesOf('k', [x, y]); // If flag allows it, add 'remote shell captures' if (this.powerFlags[this.turn]['k']) { - let shellCaptures = this.getPotentialMovesOf('y', [x, y]); + let shellCaptures = super.getPotentialMovesOf('y', [x, y]); shellCaptures.forEach(sc => { sc.shell = true; //easier play() sc.choice = 'z'; //to display in showChoices() @@ -389,25 +387,6 @@ export default class ChakartRules extends ChessRules { play(move) { const color = this.turn; const oppCol = C.GetOppCol(color); - if ( - move.appear.length > 0 && - move.appear[0].p == 'p' && - ( - (color == 'w' && move.end.x == 0) || - (color == 'b' && move.end.x == this.size.x - 1) - ) - ) { - // "Forgotten" promotion, which occurred after some effect - let moves = [move]; - super.pawnPostProcess(moves, color, oppCol); - super.showChoices(moves); - return false; - } - this.postPlay(move, color, oppCol); - return true; - } - - postPlay(move, color, oppCol) { this.egg = move.egg; if (move.egg == "toadette") { this.reserve = { w: {}, b: {} }; @@ -458,7 +437,11 @@ export default class ChakartRules extends ChessRules { this.getColor(i, j) == oppCol ) { const pieceIJ = this.getPiece(i, j); - if (pieceIJ == 'i') { + if ( + pieceIJ == 'i' && + // Ensure that current move doesn't erase invisible queen + move.appear.every(a => a.x != i || a.y != j) + ) { move.vanish.push(new PiPo({x: i, y: j, c: oppCol, p: 'i'})); move.appear.push(new PiPo({x: i, y: j, c: oppCol, p: 'q'})); } @@ -478,7 +461,27 @@ export default class ChakartRules extends ChessRules { this.displayBonus(move); } + buildMoveStack(move, r) { + const color = this.turn; + if ( + move.appear.length > 0 && + move.appear[0].p == 'p' && + ( + (color == 'w' && move.end.x == 0) || + (color == 'b' && move.end.x == this.size.x - 1) + ) + ) { + // "Forgotten" promotion, which occurred after some effect + let moves = super.pawnPostProcess([move], color, C.GetOppCol(color)); + super.showChoices(moves, r); + } + else + super.buildMoveStack(move, r); + } + computeNextMove(move) { + if (move.koopa) + return null; // Set potential random effects, so that play() is deterministic // from opponent viewpoint: const endPiece = this.getPiece(move.end.x, move.end.y); @@ -557,8 +560,17 @@ export default class ChakartRules extends ChessRules { let bagOfPieces = []; for (let i=0; i 0) + ) + ) { bagOfPieces.push([i, j]); + } } } if (bagOfPieces.length >= 1) @@ -630,6 +642,7 @@ export default class ChakartRules extends ChessRules { p: this.getPiece(move.start.x, move.start.y) })); } + em.koopa = true; //avoid applying effect break; case "chomp": // Eat piece @@ -688,12 +701,7 @@ export default class ChakartRules extends ChessRules { } displayBonus(move) { - let divBonus = document.createElement("div"); - divBonus.classList.add("bonus-text"); - divBonus.innerHTML = move.egg; - let container = document.getElementById(this.containerId); - container.appendChild(divBonus); - setTimeout(() => container.removeChild(divBonus), 2000); + super.displayMessage(null, move.egg, "bonus-text", 2000); } atLeastOneMove() {