X-Git-Url: https://git.auder.net/?a=blobdiff_plain;ds=sidebyside;f=public%2Fjavascripts%2Fvariants%2FUltima.js;h=57f3e25c6e8cd6fbabfafe7ccc224fde1c1e3c8b;hb=2f3c845159670ec8bfba8a3999571d6ee1e45320;hp=d6676436a24f21641ae57783ebd656a4bad85fff;hpb=a3c86ec9b60326a8ae3d8f237493fb09627aed95;p=vchess.git diff --git a/public/javascripts/variants/Ultima.js b/public/javascripts/variants/Ultima.js index d6676436..57f3e25c 100644 --- a/public/javascripts/variants/Ultima.js +++ b/public/javascripts/variants/Ultima.js @@ -50,16 +50,46 @@ 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" + // 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 && i2=0 && j2=0 && i1=0 && i2=0 && j1=0 && j2=0 && i0=0 && j0=0 && i=0 && j=0 && i=0 && j call the appropriate isAttackedBy... (exception of immobilizers) - // Other exception: a chameleon cannot attack a chameleon (seemingly...) + // We cheat a little here: since this function is used exclusively for king, + // it's enough to check the immediate surrounding of the square. + const V = VariantRules; + const adjacentSteps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]); + const [sizeX,sizeY] = V.size; + for (let step of adjacentSteps) + { + const [i,j] = [x+step[0],y+step[1]]; + if (i>=0 && i=0 && j=0 && sq2[0]=0 && sq2[1] 0) @@ -414,12 +559,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, @@ -491,15 +630,4 @@ class UltimaRules extends ChessRules { return "0000"; //TODO: or "-" ? } - - getNotation(move) - { - if (move.appear.length == 0) - { - const startSquare = - String.fromCharCode(97 + move.start.y) + (VariantRules.size[0]-move.start.x); - return "^" + startSquare; //suicide - } - return super.getNotation(move); - } }