X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FUltima.js;h=229910c2ec13fb9545413a7143c576944f93b14d;hb=d62554ed2e2309126e42d5db87eddf50ce11aba0;hp=b3679f71352b62544208b13698ce7a0652cdb26b;hpb=7aea79424d0c596e0a34e960c83847cc12b89e32;p=vchess.git diff --git a/public/javascripts/variants/Ultima.js b/public/javascripts/variants/Ultima.js index b3679f71..229910c2 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 && j1=0 && j2=0 && i3=0 && j3=0 && i3=0 && j3=0 && i=0 && j=0 && i=0 && j 0) @@ -509,12 +553,6 @@ class UltimaRules extends ChessRules } } - checkGameEnd() - { - // No valid move: game is lost (stalemate is a win) - return this.turn == "w" ? "0-1" : "1-0"; - } - static get VALUES() { //TODO: totally experimental! return { 'p': 1, @@ -589,12 +627,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; } }