X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FUltima.js;h=ac0cf9579142b761b1530537d67a00192c43c2f0;hb=e1cce11566b1fe6f0cfd85517617c1c0c6249761;hp=1db369199aee089aad9172e72f1fccb28f788a25;hpb=96f8422ec4d5e3cee43e25e749e3cdc4547e0ed2;p=vchess.git diff --git a/public/javascripts/variants/Ultima.js b/public/javascripts/variants/Ultima.js index 1db36919..ac0cf957 100644 --- a/public/javascripts/variants/Ultima.js +++ b/public/javascripts/variants/Ultima.js @@ -50,16 +50,16 @@ class UltimaRules extends ChessRules // - a "bishop" is a chameleon, capturing as its prey // - a "queen" is a withdrawer, capturing by moving away from pieces - getPotentialMovesFrom([x,y]) + // Is piece on square (x,y) immobilized? + isImmobilized([x,y]) { - // Pre-check: is thing on this square immobilized? - // In this case add potential suicide as a move "taking the immobilizer" const piece = this.getPiece(x,y); const color = this.getColor(x,y); const oppCol = this.getOppCol(color); const V = VariantRules; const adjacentSteps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]); const [sizeX,sizeY] = V.size; + outerLoop: for (let step of adjacentSteps) { const [i,j] = [x+step[0],y+step[1]]; @@ -67,18 +67,33 @@ class UltimaRules extends ChessRules && this.getColor(i,j) == oppCol) { const oppPiece = this.getPiece(i,j); - if (oppPiece == V.IMMOBILIZER - || (oppPiece == V.BISHOP && piece == V.IMMOBILIZER)) + if (oppPiece == V.BISHOP && piece == V.IMMOBILIZER) + return true; + if (oppPiece == V.IMMOBILIZER && ![V.BISHOP,V.IMMOBILIZER].includes(piece)) { - return [ new Move({ - appear: [], - vanish: [new PiPo({x:x,y:y,p:piece,c:color})], - start: {x:x,y:y}, - end: {x:i,y:j} - }) ]; + // Moving is impossible only if this immobilizer is not neutralized + for (let step2 of adjacentSteps) + { + const [i2,j2] = [i+step2[0],j+step2[1]]; + if (i2>=0 && i2=0 && j2=0 && i1=0 && i2=0 && j1=0 && j2=0 && i3=0 && j3=0 && i3=0 && j3 0) + // Square (x,y) must be on same line as a knight, + // and there must be empty square(s) behind. + const V = VariantRules; + const steps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]); + const [sizeX,sizeY] = V.size; + outerLoop: + for (let step of steps) { - this.kingPos[c][0] = move.appear[0].x; - this.kingPos[c][1] = move.appear[0].y; + const [i0,j0] = [x+step[0],y+step[1]]; + if (i0>=0 && i0=0 && j0=0 && i=0 && j=0 && i=0 && j=0 && i=0 && j=0 && i=0 && j=0 && sq2[0]=0 && sq2[1]= 0) - return "*"; - - return this.checkGameEnd(); - } - - checkGameEnd() + updateVariables(move) { - // No valid move: our king disappeared - return this.turn == "w" ? "0-1" : "1-0"; + // Just update king(s) position(s) + const piece = this.getPiece(move.start.x,move.start.y); + const c = this.getColor(move.start.x,move.start.y); + if (piece == VariantRules.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! @@ -467,10 +578,6 @@ class UltimaRules extends ChessRules static get SEARCH_DEPTH() { return 2; } //TODO? - static get THRESHOLD_MATE() { - return 500; //checkmates evals may be slightly below 1000 - } - static GenRandInitFen() { let pieces = { "w": new Array(8), "b": new Array(8) }; @@ -531,12 +638,22 @@ class UltimaRules extends ChessRules getNotation(move) { - if (move.appear.length == 0) + const initialSquare = + String.fromCharCode(97 + move.start.y) + (VariantRules.size[0]-move.start.x); + const finalSquare = + String.fromCharCode(97 + move.end.y) + (VariantRules.size[0]-move.end.x); + let notation = undefined; + if (move.appear[0].p == VariantRules.PAWN) { - const startSquare = - String.fromCharCode(97 + move.start.y) + (VariantRules.size[0]-move.start.x); - return "^" + startSquare; //suicide + // Pawn: generally ambiguous short notation, so we use full description + notation = "P" + initialSquare + finalSquare; } - return super.getNotation(move); + else if (move.appear[0].p == VariantRules.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 != VariantRules.KING) + notation += "X"; //capture mark (not describing what is captured...) + return notation; } }