X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FLoser.js;h=6731d322f57d8ebc09ec05ea3189dc58b5905ad8;hb=643479f8d7c3622b57fc49c4f10d9950793ebf4f;hp=6a322b9db35730a51a3ead31abbde0b55d868a9b;hpb=2eef6db6cdce30fe785e601b88858c7fc743eee8;p=vchess.git diff --git a/public/javascripts/variants/Loser.js b/public/javascripts/variants/Loser.js index 6a322b9d..6731d322 100644 --- a/public/javascripts/variants/Loser.js +++ b/public/javascripts/variants/Loser.js @@ -1,15 +1,15 @@ class LoserRules extends ChessRules { - initVariables(fen) - { - const epSq = this.moves.length > 0 ? this.getEpSquare(this.lastMove) : undefined; - this.epSquares = [ epSq ]; - } + static get HasFlags() { return false; } - setFlags(fen) + setOtherVariables(fen) { - // No castling, hence no flags; but flags defined for compatibility - this.castleFlags = { "w":[false,false], "b":[false,false] }; + const parsedFen = V.ParseFen(fen); + const epSq = parsedFen.enpassant != "-" + ? V.SquareToCoords(parsedFen.enpassant) + : undefined; + this.epSquares = [ epSq ]; + this.scanKingsRooks(fen); } getPotentialPawnMoves([x,y]) @@ -18,10 +18,8 @@ class LoserRules extends ChessRules // Complete with promotion(s) into king, if possible const color = this.turn; - const V = VariantRules; - const [sizeX,sizeY] = VariantRules.size; const shift = (color == "w" ? -1 : 1); - const lastRank = (color == "w" ? 0 : sizeX-1); + const lastRank = (color == "w" ? 0 : V.size.x-1); if (x+shift == lastRank) { // Normal move @@ -33,7 +31,7 @@ class LoserRules extends ChessRules { moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:color,p:V.KING})); } - if (y 0) @@ -88,7 +85,7 @@ class LoserRules extends ChessRules let moves = this.filterValid( this.getPotentialMovesFrom(sq) ); // This is called from interface: we need to know if a capture is possible if (this.atLeastOneCapture()) - moves = VariantRules.KeepCaptures(moves); + moves = V.KeepCaptures(moves); return moves; } @@ -96,7 +93,7 @@ class LoserRules extends ChessRules { let moves = super.getAllValidMoves(); if (moves.some(m => { return m.vanish.length == 2; })) - moves = VariantRules.KeepCaptures(moves); + moves = V.KeepCaptures(moves); return moves; } @@ -110,22 +107,19 @@ class LoserRules extends ChessRules return []; } - // Unused: + // No variables update because no castling updateVariables(move) { } unupdateVariables(move) { } - getFlagsFen() - { - return "-"; - } - checkGameEnd() { // No valid move: you win! return this.turn == "w" ? "1-0" : "0-1"; } - static get VALUES() { //experimental... + static get VALUES() + { + // Experimental... return { 'p': 1, 'r': 7, @@ -196,6 +190,8 @@ class LoserRules extends ChessRules return pieces["b"].join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" + pieces["w"].join("").toUpperCase() + - " 0000"; //add flags (TODO?!) + " w -"; //no en-passant } } + +const VariantRules = LoserRules;