X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FUltima.js;h=04d62b7d016a992083fdfa86af0d890fd6ae4fbb;hb=643479f8d7c3622b57fc49c4f10d9950793ebf4f;hp=57f3e25c6e8cd6fbabfafe7ccc224fde1c1e3c8b;hpb=2f3c845159670ec8bfba8a3999571d6ee1e45320;p=vchess.git diff --git a/public/javascripts/variants/Ultima.js b/public/javascripts/variants/Ultima.js index 57f3e25c..04d62b7d 100644 --- a/public/javascripts/variants/Ultima.js +++ b/public/javascripts/variants/Ultima.js @@ -1,5 +1,9 @@ class UltimaRules extends ChessRules { + static get HasFlags() { return false; } + + static get HasEnpassant() { return false; } + static getPpath(b) { if (b[1] == "m") //'m' for Immobilizer (I is too similar to 1) @@ -7,7 +11,13 @@ class UltimaRules extends ChessRules return b; //usual piece } - initVariables(fen) + static get PIECES() + { + return ChessRules.PIECES.concat([V.IMMOBILIZER]); + } + + // No castling, but checks, so keep track of kings + setOtherVariables(fen) { this.kingPos = {'w':[-1,-1], 'b':[-1,-1]}; const fenParts = fen.split(" "); @@ -33,13 +43,6 @@ class UltimaRules extends ChessRules k++; } } - this.epSquares = []; //no en-passant here - } - - setFlags(fen) - { - // TODO: for compatibility? - this.castleFlags = {"w":[false,false], "b":[false,false]}; } static get IMMOBILIZER() { return 'm'; } @@ -53,70 +56,41 @@ class UltimaRules extends ChessRules // Is piece on square (x,y) immobilized? isImmobilized([x,y]) { - // Final check: is this knight immobilized? - let foundImmobilizer = false; - let neutralized = false; - outerLoop: - for (let step of steps) - { - const [i2,j2] = [i+step[0],j+step[1]]; - if (i2>=0 && i2=0 && j2=0 && i3=0 && j3=0 && i=0 && j=0 && i2=0 && j2=0 && i=0 && j=0 && i=0 - && j { @@ -177,17 +145,16 @@ class UltimaRules extends ChessRules for (let step of steps) { const sq2 = [m.end.x+2*step[0],m.end.y+2*step[1]]; - if (sq2[0]>=0 && sq2[0]=0 && sq2[1]=0 && i=0 && j=sizeX || j<0 || j>=sizeY || this.getColor(i,j)==color + if (!V.OnBoard(i,j) || this.getColor(i,j)==color || (!!byChameleon && this.getPiece(i,j)!=V.KNIGHT)) { continue; @@ -281,7 +246,7 @@ class UltimaRules extends ChessRules let last = [i,j]; let cur = [i+step[0],j+step[1]]; let vanished = [ new PiPo({x:x,y:y,c:color,p:piece}) ]; - while (cur[0]>=0 && cur[0]=0 && cur[1] { - const key = m.end.x + sizeX * m.end.y; + const key = m.end.x + V.size.x * m.end.y; if (!mergedMoves[key]) mergedMoves[key] = m; else @@ -354,16 +318,13 @@ class UltimaRules extends ChessRules if (moves.length == 0) return; const [x,y] = [moves[0].start.x,moves[0].start.y]; - const V = VariantRules; const adjacentSteps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]); let capturingDirections = []; const color = this.turn; const oppCol = this.getOppCol(color); - const [sizeX,sizeY] = V.size; adjacentSteps.forEach(step => { const [i,j] = [x+step[0],y+step[1]]; - if (i>=0 && i=0 && j=0 && i1=0 && i2=0 && j1=0 && j2=0 && i0=0 && j0=0 && i=0 && j=0 && i=0 && j=0 && i=0 && j=0 && sq2[0]=0 && sq2[1] 0) + if (piece == V.KING && move.appear.length > 0) { this.kingPos[c][0] = move.appear[0].x; this.kingPos[c][1] = move.appear[0].y; } } - static get VALUES() { //TODO: totally experimental! + static get VALUES() + { + // TODO: totally experimental! return { 'p': 1, 'r': 2, @@ -623,11 +604,27 @@ class UltimaRules extends ChessRules return pieces["b"].join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" + pieces["w"].join("").toUpperCase() + - " 0000"; //TODO: flags?! + " w"; } - getFlagsFen() + getNotation(move) { - return "0000"; //TODO: or "-" ? + const initialSquare = V.CoordsToSquare(move.start); + const finalSquare = V.CoordsToSquare(move.end); + let notation = undefined; + if (move.appear[0].p == V.PAWN) + { + // Pawn: generally ambiguous short notation, so we use full description + notation = "P" + initialSquare + finalSquare; + } + else if (move.appear[0].p == V.KING) + notation = "K" + (move.vanish.length>1 ? "x" : "") + finalSquare; + else + notation = move.appear[0].p.toUpperCase() + finalSquare; + if (move.vanish.length > 1 && move.appear[0].p != V.KING) + notation += "X"; //capture mark (not describing what is captured...) + return notation; } } + +const VariantRules = UltimaRules;