X-Git-Url: https://git.auder.net/pieces/Checkered/cp.svg?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FUltima.js;h=c98822dcbf0e85aa68889faf0f4c338194dd79ef;hb=9d218497ab97bc0e94ec4c1f0a40cf02df3ea0d4;hp=d6676436a24f21641ae57783ebd656a4bad85fff;hpb=a3c86ec9b60326a8ae3d8f237493fb09627aed95;p=vchess.git diff --git a/public/javascripts/variants/Ultima.js b/public/javascripts/variants/Ultima.js index d6676436..c98822dc 100644 --- a/public/javascripts/variants/Ultima.js +++ b/public/javascripts/variants/Ultima.js @@ -53,13 +53,13 @@ class UltimaRules extends ChessRules getPotentialMovesFrom([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,15 +67,23 @@ 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 []; + 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 call the appropriate isAttackedBy... (exception of immobilizers) - // Other exception: a chameleon cannot attack a chameleon (seemingly...) - return false; - } - - isAttackedByQueen(sq, colors) - { - // Square (x,y) must be adjacent to a queen, and the queen must have - // some free space in the opposite direction from (x,y) - return false; + const c = this.getOppCol(this.turn); //opponent + const saveKingPos = this.kingPos[c]; //king might be taken + this.play(move); + // The only way to be "under check" is to have lost the king (thus game over) + let res = this.kingPos[c][0] < 0 + ? [ JSON.parse(JSON.stringify(saveKingPos)) ] + : [ ]; + this.undo(move); + return res; } updateVariables(move) { - // Just update king position + // 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) @@ -412,11 +411,41 @@ class UltimaRules extends ChessRules this.kingPos[c][0] = move.appear[0].x; this.kingPos[c][1] = move.appear[0].y; } + // Does this move takes opponent's king? + const oppCol = this.getOppCol(c); + for (let i=1; i