From: Benjamin Auder Date: Sat, 4 Apr 2020 20:15:02 +0000 (+0200) Subject: Fix games download/upload + Dynamo variant X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/images/scripts/current/git-favicon.png?a=commitdiff_plain;h=6e0c0bcba5c9e76a50a2676aa3e63bc317123bcb;p=vchess.git Fix games download/upload + Dynamo variant --- diff --git a/client/src/components/BaseGame.vue b/client/src/components/BaseGame.vue index 9c8cadf3..1e1a2149 100644 --- a/client/src/components/BaseGame.vue +++ b/client/src/components/BaseGame.vue @@ -205,13 +205,12 @@ export default { this.vr = new V(game.fenStart); const parsedFen = V.ParseFen(game.fenStart); const firstMoveColor = parsedFen.turn; - this.firstMoveNumber = Math.floor(parsedFen.movesCount / 2); + this.firstMoveNumber = Math.floor(parsedFen.movesCount / 2) + 1; let L = this.moves.length; this.moves.forEach(move => { // Strategy working also for multi-moves: if (!Array.isArray(move)) move = [move]; move.forEach((m,idx) => { - m.index = this.vr.movesCount; m.notation = this.vr.getNotation(m); m.unambiguous = V.GetUnambiguousNotation(m); this.vr.play(m); @@ -222,7 +221,6 @@ export default { if (firstMoveColor == "b") { // 'start' & 'end' is required for Board component this.moves.unshift({ - index: parsedFen.movesCount, notation: "...", unambiguous: "...", start: { x: -1, y: -1 }, @@ -289,13 +287,13 @@ export default { // Adjust dots notation for a better display: let fullNotation = getFullNotation(this.moves[i]); if (fullNotation == "...") fullNotation = ".."; - pgn += (this.moves[i].index / 2 + 1) + "." + fullNotation; + pgn += (i / 2 + this.firstMoveNumber) + "." + fullNotation; if (i+1 < this.moves.length) pgn += " " + getFullNotation(this.moves[i+1]); } pgn += "\n\n"; for (let i = 0; i < this.moves.length; i += 2) { - const moveNumber = this.moves[i].index / 2 + 1; + const moveNumber = i / 2 + this.firstMoveNumber; // Skip "dots move", useless for machine reading: if (this.moves[i].notation != "...") { pgn += moveNumber + ".w " + diff --git a/client/src/variants/Dynamo.js b/client/src/variants/Dynamo.js index c299f84a..5955f641 100644 --- a/client/src/variants/Dynamo.js +++ b/client/src/variants/Dynamo.js @@ -158,7 +158,6 @@ export class DynamoRules extends ChessRules { } // There was something on x2,y2, maybe our color, pushed/pulled. - // Also, the pushed/pulled piece must exit the board. isAprioriValidExit([x1, y1], [x2, y2], color2) { const color1 = this.getColor(x1, y1); const pawnShift = (color1 == 'w' ? -1 : 1); @@ -338,6 +337,8 @@ export class DynamoRules extends ChessRules { // Piece at subTurn 1 just exited the board. // Can I be a piece which caused the exit? if ( + // Only "turn" color can do actions + sqCol == color && this.isAprioriValidExit( [x, y], [fm.start.x, fm.start.y], @@ -347,7 +348,9 @@ export class DynamoRules extends ChessRules { // Seems so: const dir = this.getNormalizedDirection( [fm.start.x - x, fm.start.y - y]); - return this.getMovesInDirection([x, y], dir); + const nbSteps = + ([V.PAWN,V.KING,V.KNIGHT].includes(this.getPiece(x, y)) ? 1 : null); + return this.getMovesInDirection([x, y], dir, nbSteps); } } else {