X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FMarseille.js;h=7d83bd556b1b168a3bf56637859fff0c2d280d5f;hb=b955c65b942d09d24b5c3bed0d755d4f2f8f71f1;hp=1adb83f4642ee28f41c9d4482fe29de8ca550a80;hpb=26b8e4f7c71030d49e44fe1d89632ef91b886d67;p=vchess.git diff --git a/public/javascripts/variants/Marseille.js b/public/javascripts/variants/Marseille.js index 1adb83f4..7d83bd55 100644 --- a/public/javascripts/variants/Marseille.js +++ b/public/javascripts/variants/Marseille.js @@ -19,8 +19,6 @@ class MarseilleRules extends ChessRules getTurnFen() { - if (this.startAtFirstMove && this.moves.length==0) - return "w"; return this.turn + this.subTurn; } @@ -56,9 +54,8 @@ class MarseilleRules extends ChessRules // Extract subTurn from turn indicator: "w" (first move), or // "w1" or "w2" white subturn 1 or 2, and same for black const fullTurn = V.ParseFen(fen).turn; - this.startAtFirstMove = (fullTurn == "w"); this.turn = fullTurn[0]; - this.subTurn = (fullTurn[1] || 1); + this.subTurn = (fullTurn[1] || 0); //"w0" = special code for first move in game } getPotentialPawnMoves([x,y]) @@ -144,18 +141,13 @@ class MarseilleRules extends ChessRules return moves; } - play(move, ingame) + play(move) { - 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()); + move.turn = this.turn + this.subturn; V.PlayOnBoard(this.board, move); const epSq = this.getEpSquare(move); - if (this.startAtFirstMove && this.moves.length == 0) + if (this.subTurn == 0) //first move in game { this.turn = "b"; this.epSquares.push([epSq]); @@ -179,40 +171,22 @@ class MarseilleRules extends ChessRules this.epSquares.push([epSq]); this.subTurn = 3 - this.subTurn; } - this.moves.push(move); this.updateVariables(move); - if (!!ingame) - move.hash = hex_md5(this.getFen()); } undo(move) { this.disaggregateFlags(JSON.parse(move.flags)); V.UndoOnBoard(this.board, move); - if (this.startAtFirstMove && this.moves.length == 1) - { - this.turn = "w"; + if (move.turn[1] == '0' || move.checkOnSubturn1 || this.subTurn == 2) this.epSquares.pop(); - } - else if (move.checkOnSubturn1) + else //this.subTurn == 1 { - this.turn = V.GetOppCol(this.turn); - this.subTurn = 1; - this.epSquares.pop(); - } - else - { - if (this.subTurn == 1) - { - this.turn = V.GetOppCol(this.turn); - let lastEpsq = this.epSquares[this.epSquares.length-1]; - lastEpsq.pop(); - } - else - this.epSquares.pop(); - this.subTurn = 3 - this.subTurn; + let lastEpsq = this.epSquares[this.epSquares.length-1]; + lastEpsq.pop(); } - this.moves.pop(); + this.turn = move.turn[0]; + this.subTurn = parseInt(move.turn[1]); this.unupdateVariables(move); } @@ -318,60 +292,4 @@ class MarseilleRules extends ChessRules return selected[0]; return selected; } - - getPGN(mycolor, score, fenStart, mode) - { - let pgn = ""; - pgn += '[Site "vchess.club"]\n'; - const opponent = mode=="human" ? "Anonymous" : "Computer"; - pgn += '[Variant "' + variant + '"]\n'; - pgn += '[Date "' + getDate(new Date()) + '"]\n'; - const whiteName = ["human","computer"].includes(mode) - ? (mycolor=='w'?'Myself':opponent) - : "analyze"; - const blackName = ["human","computer"].includes(mode) - ? (mycolor=='b'?'Myself':opponent) - : "analyze"; - pgn += '[White "' + whiteName + '"]\n'; - pgn += '[Black "' + blackName + '"]\n'; - pgn += '[FenStart "' + fenStart + '"]\n'; - pgn += '[Fen "' + this.getFen() + '"]\n'; - pgn += '[Result "' + score + '"]\n\n'; - - 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 += "\n\n"; - - // "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 + "\n"; - } } - -const VariantRules = MarseilleRules;