Fix Berolina notation + Marseille PGN
authorBenjamin Auder <benjamin.auder@somewhere>
Wed, 26 Dec 2018 12:41:59 +0000 (13:41 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Wed, 26 Dec 2018 12:41:59 +0000 (13:41 +0100)
public/javascripts/variants/Berolina.js
public/javascripts/variants/Marseille.js
views/rules/Berolina/en.pug
views/rules/Marseille/en.pug

index be72e2d..8ea3c9c 100644 (file)
@@ -119,14 +119,15 @@ class BerolinaRules extends ChessRules
                if (piece == V.PAWN)
                {
                        // Pawn move
+                       const finalSquare = V.CoordsToSquare(move.end);
                        let notation = "";
                        if (move.vanish.length == 2) //capture
-                               notation = finalSquare;
+                               notation = "Px" + finalSquare;
                        else
                        {
-                               // No capture
-                               const startColumn = V.CoordToColumn(move.start.y);
-                               notation = startColumn + "x" + finalSquare;
+                               // No capture: indicate the initial square for potential ambiguity
+                               const startSquare = V.CoordsToSquare(move.start);
+                               notation = startSquare + finalSquare;
                        }
                        if (move.appear[0].p != V.PAWN) //promotion
                                notation += "=" + move.appear[0].p.toUpperCase();
index 02daa22..6e72a23 100644 (file)
@@ -148,10 +148,12 @@ class MarseilleRules extends ChessRules
 
        play(move, ingame)
        {
-//             console.log("play " + this.getNotation(move));
-//             console.log(this.turn + " "+ this.subTurn);
                if (!!ingame)
+               {
                        move.notation = [this.getNotation(move), this.getLongNotation(move)];
+                       // In this special case, we also need the "move color":
+                       move.color = this.turn;
+               }
                move.flags = JSON.stringify(this.aggregateFlags());
                let lastEpsq = this.epSquares[this.epSquares.length-1];
                const epSq = this.getEpSquare(move);
@@ -185,7 +187,6 @@ class MarseilleRules extends ChessRules
                this.updateVariables(move);
                if (!!ingame)
                        move.hash = hex_md5(this.getFen());
-               //console.log(move.checkOnSubturn1 + " " +this.turn + " "+ this.subTurn);
        }
 
        undo(move)
@@ -220,8 +221,6 @@ class MarseilleRules extends ChessRules
                }
                this.moves.pop();
                this.unupdateVariables(move);
-//             console.log("UNDO " + this.getNotation(move));
-//             console.log(this.turn + " "+ this.subTurn);
        }
 
        // NOTE:  GenRandInitFen() is OK,
@@ -315,6 +314,55 @@ class MarseilleRules extends ChessRules
                        return selected[0];
                return selected;
        }
+
+       getPGN(mycolor, score, fenStart, mode)
+       {
+               let pgn = "";
+               pgn += '[Site "vchess.club"]<br>';
+               const opponent = mode=="human" ? "Anonymous" : "Computer";
+               pgn += '[Variant "' + variant + '"]<br>';
+               pgn += '[Date "' + getDate(new Date()) + '"]<br>';
+               pgn += '[White "' + (mycolor=='w'?'Myself':opponent) + '"]<br>';
+               pgn += '[Black "' + (mycolor=='b'?'Myself':opponent) + '"]<br>';
+               pgn += '[FenStart "' + fenStart + '"]<br>';
+               pgn += '[Fen "' + this.getFen() + '"]<br>';
+               pgn += '[Result "' + score + '"]<br><br>';
+
+               let counter = 1;
+               let i = 0;
+               while (i < this.moves.length)
+               {
+                       pgn += (counter++) + ".";
+                       for (let color of ["w","b"])
+                       {
+                               let move = "";
+                               while (i < this.moves.length && this.moves[i].color == color)
+                                       move += this.moves[i++].notation[0] + ",";
+                               move = move.slice(0,-1); //remove last comma
+                               pgn += move + (i < this.moves.length-1 ? " " : "");
+                       }
+               }
+               pgn += "<br><br>";
+
+               // "Complete moves" PGN (helping in ambiguous cases)
+               counter = 1;
+               i = 0;
+               while (i < this.moves.length)
+               {
+                       pgn += (counter++) + ".";
+                       for (let color of ["w","b"])
+                       {
+                               let move = "";
+                               while (i < this.moves.length && this.moves[i].color == color)
+                                       move += this.moves[i++].notation[1] + ",";
+                               move = move.slice(0,-1); //remove last comma
+                               pgn += move + (i < this.moves.length-1 ? " " : "");
+                       }
+               }
+
+               return pgn;
+       }
+
 }
 
 const VariantRules = MarseilleRules;
index 60080ea..5cdfff9 100644 (file)
@@ -14,7 +14,14 @@ ul
 h3 Basics
 
 p.
-       TODO: explain...
+       Only the pawn movements change, but since there are many on the board it's a
+       consequent change. They move diagonally instead of moving forward, and capture by
+       advancing to the next square vertically. The initial 2-squares jump is allowed,
+       as well as en-passant captures: after 1.d2b4 on the diagram,
+       1...Pxc3 e.p. is possible.
+
+p.
+       Note about notation: pawns
 
 figure.diagram-container
        .diagram
index f2a5e18..5c66e78 100644 (file)
@@ -29,6 +29,7 @@ p.
        a double move in the game is indicated as two comma-separated (ordered) moves,
        as in 3.Na5,Bd3 e6,f4 (the two first are white moves,
        the two others are black moves).
+       Sometimes a move gives check, or stalemate occurs after subTurn 1 :: just one move
 
 figure.diagram-container
        .diagram