From: Benjamin Auder Date: Thu, 7 Jul 2022 09:05:01 +0000 (+0200) Subject: Fix some bugs X-Git-Url: https://git.auder.net/variants/img/pieces/css/%7B%7B%20pkg.url%20%7D%7D?a=commitdiff_plain;h=b9877ed29697640d72b8f3d89848863fc87bd7e8;p=xogo.git Fix some bugs --- diff --git a/base_rules.js b/base_rules.js index dc25e54..11b8b30 100644 --- a/base_rules.js +++ b/base_rules.js @@ -2476,32 +2476,37 @@ export default class ChessRules { buildMoveStack(move, r) { this.moveStack.push(move); this.computeNextMove(move); - this.play(move); - const newTurn = this.turn; - if (this.moveStack.length == 1 && !this.hideMoves) - this.playVisual(move, r); - if (move.next) { - this.gameState = { - fen: this.getFen(), - board: JSON.parse(JSON.stringify(this.board)) //easier - }; - this.buildMoveStack(move.next, r); - } - else { - if (this.moveStack.length == 1) { - // Usual case (one normal move) - this.afterPlay(this.moveStack, newTurn, {send: true, res: true}); - this.moveStack = [] + const then = () => { + const newTurn = this.turn; + if (this.moveStack.length == 1 && !this.hideMoves) + this.playVisual(move, r); + if (move.next) { + this.gameState = { + fen: this.getFen(), + board: JSON.parse(JSON.stringify(this.board)) //easier + }; + this.buildMoveStack(move.next, r); } else { - this.afterPlay(this.moveStack, newTurn, {send: true, res: false}); - this.re_initFromFen(this.gameState.fen, this.gameState.board); - this.playReceivedMove(this.moveStack.slice(1), () => { - this.afterPlay(this.moveStack, newTurn, {send: false, res: true}); - this.moveStack = [] - }); + if (this.moveStack.length == 1) { + // Usual case (one normal move) + this.afterPlay(this.moveStack, newTurn, {send: true, res: true}); + this.moveStack = []; + } + else { + this.afterPlay(this.moveStack, newTurn, {send: true, res: false}); + this.re_initFromFen(this.gameState.fen, this.gameState.board); + this.playReceivedMove(this.moveStack.slice(1), () => { + this.afterPlay(this.moveStack, newTurn, {send: false, res: true}); + this.moveStack = []; + }); + } } - } + }; + // If hiding moves, then they are revealed in play() with callback + this.play(move, this.hideMoves ? then : null); + if (!this.hideMoves) + then(); } // Implemented in variants using (automatic) moveStack @@ -2632,8 +2637,9 @@ export default class ChessRules { launchAnimation(moves, container, callback) { if (this.hideMoves) { - moves.forEach(m => this.play(m)); - callback(); + for (let i=0; i {}); return; } const r = container.querySelector(".chessboard").getBoundingClientRect(); diff --git a/variants/Align4/class.js b/variants/Align4/class.js index ce5700d..09a79ed 100644 --- a/variants/Align4/class.js +++ b/variants/Align4/class.js @@ -26,13 +26,10 @@ export default class Align4Rules extends ChessRules { genRandInitBaseFen() { let baseFen = super.genRandInitBaseFen(); - return { fen: baseFen.fen.replace("rnbqkbnr/pppppppp", "4k3/8"), o: {} }; - } - - getPartFen(o) { - let parts = super.getPartFen(o); - parts["flags"] = parts["flags"].substr(0, 2) + "88"; - return parts; + return { + fen: baseFen.fen.replace("rnbqkbnr/pppppppp", "4k3/8"), + o: {flags: baseFen.o.flags.substr(0, 2) + "88"} + }; } initReserves() { diff --git a/variants/Apocalypse/class.js b/variants/Apocalypse/class.js index 5f1e7e2..1f7cc7a 100644 --- a/variants/Apocalypse/class.js +++ b/variants/Apocalypse/class.js @@ -224,8 +224,11 @@ export default class ApocalypseRules extends ChessRules { for (let c of ['w', 'b']) { const myMove = res[c + 'm'], oppMove = res[C.GetOppCol(c) + 'm']; if ( - myMove.end.x == oppMove.start.x && - myMove.end.y == oppMove.start.y + // More general test than checking moves ends, + // because of potential pawn relocation + myMove.vanish.length == 2 && + myMove.vanish[1].x == oppMove.start.x && + myMove.vanish[1].y == oppMove.start.y ) { // Whatever was supposed to vanish, finally doesn't vanish myMove.vanish.pop(); @@ -235,8 +238,8 @@ export default class ApocalypseRules extends ChessRules { // Collision (necessarily on empty square) if (!res.wm.illegal && !res.bm.illegal) { if (res.wm.vanish[0].p != res.bm.vanish[0].p) { - const c = (res.wm.vanish[0].p == 'n' ? 'w' : 'b'); - res[c + 'm'].vanish.push(res[C.GetOppCol(c) + 'm'].appear.shift()); + const vanishColor = (res.wm.vanish[0].p == 'n' ? 'b' : 'w'); + res[vanishColor + 'm'].appear.shift(); } else { // Collision of two pieces of same nature: both disappear @@ -271,7 +274,7 @@ export default class ApocalypseRules extends ChessRules { return res; } - play(move) { + play(move, callback) { const color = this.turn; if (color == 'w') this.whiteMove.push(move); @@ -289,6 +292,7 @@ export default class ApocalypseRules extends ChessRules { this.playOnBoard(move); this.playVisual(move); } + callback(); return; } if (color == this.playerColor && this.firstMove) { @@ -309,7 +313,7 @@ export default class ApocalypseRules extends ChessRules { if (color == 'b') { // A full turn just ended const res = this.resolveSynchroneMove(move); - const callback = () => { + const afterAnimate = () => { // start + end don't matter for playOnBoard() and playVisual(). // Merging is necessary because moves may overlap. let toPlay = {appear: [], vanish: []}; @@ -321,11 +325,12 @@ export default class ApocalypseRules extends ChessRules { } this.playOnBoard(toPlay); this.playVisual(toPlay); + callback(); }; if (res.wm) - this.animate(res.wm, () => {if (!res.bm) callback();}); + this.animate(res.wm, () => {if (!res.bm) afterAnimate();}); if (res.bm) - this.animate(res.bm, callback); + this.animate(res.bm, afterAnimate); if (!res.wm && !res.bm) { this.displayIllegalInfo("both illegal"); ['w', 'b'].forEach(c => this.penalties[c]++); @@ -340,6 +345,8 @@ export default class ApocalypseRules extends ChessRules { } this.whiteMove = []; } + else + callback(); } displayIllegalInfo(msg) { @@ -370,9 +377,9 @@ export default class ApocalypseRules extends ChessRules { return "*"; } // Count footmen: if a side has none, it loses - let fmCount = { 'w': 0, 'b': 0 }; - for (let i=0; i<5; i++) { - for (let j=0; j<5; j++) { + let fmCount = {w: 0, b: 0}; + for (let i=0; i { let [mx, my] = [x, y]; @@ -472,8 +472,7 @@ export default class ChakartRules extends ChessRules { ) ) { // "Forgotten" promotion, which occurred after some effect - let moves = [move]; - super.pawnPostProcess(moves, color, C.GetOppCol(color)); + let moves = super.pawnPostProcess([move], color, C.GetOppCol(color)); super.showChoices(moves, r); } else @@ -481,6 +480,8 @@ export default class ChakartRules extends ChessRules { } 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); @@ -641,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 diff --git a/variants/Chakart/style.css b/variants/Chakart/style.css index f1a38bc..6f45bed 100644 --- a/variants/Chakart/style.css +++ b/variants/Chakart/style.css @@ -41,7 +41,7 @@ piece.black.mystery { div.bonus-text { position: relative; - margin-top: 5%; + margin-top: 15px; width: 100%; text-align: center; background-color: transparent;