X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2FApocalypse%2Fclass.js;h=1f7cc7aa0533e1a172f84927a7b424914edf879b;hb=HEAD;hp=060099107217db925a464f9b734facd32588cc92;hpb=98d144512e5505f5ef8b702b139ca6ceff92c823;p=xogo.git diff --git a/variants/Apocalypse/class.js b/variants/Apocalypse/class.js index 0600991..3b735b1 100644 --- a/variants/Apocalypse/class.js +++ b/variants/Apocalypse/class.js @@ -40,7 +40,7 @@ export default class ApocalypseRules extends ChessRules { genRandInitBaseFen() { return { - fen: "npppn/p3p/5/P3P/NPPPN w 0", + fen: "npppn/p3p/5/P3P/NPPPN", o: {} }; } @@ -68,7 +68,7 @@ export default class ApocalypseRules extends ChessRules { return { 'p': { "class": "pawn", - moves: [ + both: [ { steps: [[pawnShift, 0], [pawnShift, -1], [pawnShift, 1]], range: 1 @@ -102,7 +102,7 @@ export default class ApocalypseRules extends ChessRules { } } else { - const oppCol = C.GetOppCol(this.getColor(x, y)); + const oppCol = C.GetOppTurn(this.getColor(x, y)); moves = super.getPotentialMovesFrom([x, y]).filter(m => { // Remove pawn push toward own color (absurd) return ( @@ -222,10 +222,13 @@ export default class ApocalypseRules extends ChessRules { if (!res.wm || !res.bm) return; for (let c of ['w', 'b']) { - const myMove = res[c + 'm'], oppMove = res[C.GetOppCol(c) + 'm']; + const myMove = res[c + 'm'], oppMove = res[C.GetOppTurn(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) { @@ -302,14 +306,14 @@ export default class ApocalypseRules extends ChessRules { }; this.playVisual(revFirstMove); } - this.turn = C.GetOppCol(color); + this.turn = C.GetOppTurn(color); this.movesCount++; this.subTurn = 1; this.firstMove = null; 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