X-Git-Url: https://git.auder.net/img/rock_paper_scissors_lizard_spock.gif?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FMarseille.js;h=d38d177f8707d49cd33bfdbbc261cb7cfe51a930;hb=7d9e99bc177972c5af8b1b45f4bfb043d8306f30;hp=f372698dd7ef638725918a027bafa938098ec9e8;hpb=edcd679ab1fe609641451586ef1e9484925c4f83;p=vchess.git diff --git a/public/javascripts/variants/Marseille.js b/public/javascripts/variants/Marseille.js index f372698d..d38d177f 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]) @@ -117,7 +114,7 @@ class MarseilleRules extends ChessRules }); if (epSqs.length == 0) return moves; - const oppCol = this.getOppCol(color); + const oppCol = V.GetOppCol(color); for (let sq of epSqs) { if (this.subTurn == 1 || (epSqs.length == 2 && @@ -144,26 +141,21 @@ 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]); } // Does this move give check on subturn 1? If yes, skip subturn 2 - else if (this.subTurn==1 && this.underCheck(this.getOppCol(this.turn))) + else if (this.subTurn==1 && this.underCheck(V.GetOppCol(this.turn))) { - this.turn = this.getOppCol(this.turn); + this.turn = V.GetOppCol(this.turn); this.epSquares.push([epSq]); move.checkOnSubturn1 = true; } @@ -171,7 +163,7 @@ class MarseilleRules extends ChessRules { if (this.subTurn == 2) { - this.turn = this.getOppCol(this.turn); + this.turn = V.GetOppCol(this.turn); let lastEpsq = this.epSquares[this.epSquares.length-1]; lastEpsq.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 = this.getOppCol(this.turn); - this.subTurn = 1; - this.epSquares.pop(); - } - else - { - if (this.subTurn == 1) - { - this.turn = this.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); } @@ -239,7 +213,7 @@ class MarseilleRules extends ChessRules const maxeval = V.INFINITY; const color = this.turn; - const oppCol = this.getOppCol(this.turn); + const oppCol = V.GetOppCol(this.turn); // Search best (half) move for opponent turn const getBestMoveEval = () => { @@ -319,6 +293,7 @@ class MarseilleRules extends ChessRules return selected; } + // TODO: put this generic version elsewhere getPGN(mycolor, score, fenStart, mode) { let pgn = "";