X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FUltima.js;h=588968da90c22cf1ee2e8aff439bd367f79f3df4;hb=c28265aa3e9d97601af99067b580699a83f4d28b;hp=b3679f71352b62544208b13698ce7a0652cdb26b;hpb=7aea79424d0c596e0a34e960c83847cc12b89e32;p=vchess.git diff --git a/public/javascripts/variants/Ultima.js b/public/javascripts/variants/Ultima.js index b3679f71..588968da 100644 --- a/public/javascripts/variants/Ultima.js +++ b/public/javascripts/variants/Ultima.js @@ -276,14 +276,17 @@ class UltimaRules extends ChessRules return super.getPotentialQueenMoves(sq).concat(this.getKnightCaptures(sq)); } - getPotentialBishopMoves(sq) + getPotentialBishopMoves([x,y]) { - let moves = super.getPotentialQueenMoves(sq) - .concat(this.getKnightCaptures(sq,"asChameleon")); - // NOTE: no "addKingCaptures" because the king isn't captured + let moves = super.getPotentialQueenMoves([x,y]) + .concat(this.getKnightCaptures([x,y],"asChameleon")); this.addPawnCaptures(moves, "asChameleon"); this.addRookCaptures(moves, "asChameleon"); this.addQueenCaptures(moves, "asChameleon"); + // Add king capture if it's within range + const oppKp = this.kingPos[this.getOppCol(this.turn)]; + if (Math.abs(x-oppKp[0]) <= 1 && Math.abs(y-oppKp[1]) <= 1) + moves.push(this.getBasicMove([x,y],oppKp)); // Post-processing: merge similar moves, concatenating vanish arrays let mergedMoves = {}; const [sizeX,sizeY] = VariantRules.size; @@ -365,153 +368,87 @@ class UltimaRules extends ChessRules V.steps[V.ROOK].concat(V.steps[V.BISHOP]), "oneStep"); } - // isAttacked() is OK because the immobilizer doesn't take - - isAttackedByPawn([x,y], colors) + // TODO: verify this assertion + atLeastOneMove() { - // Square (x,y) must be surrounded by two enemy pieces, - // and one of them at least should be a pawn. - const dirs = [ [1,0],[0,1],[1,1],[-1,1] ]; - const [sizeX,sizeY] = VariantRules.size; - for (let dir of dirs) - { - const [i1,j1] = [x-dir[0],y-dir[1]]; //"before" - const [i2,j2] = [x+dir[0],y+dir[1]]; //"after" - if (i1>=0 && i1=0 && i2=0 && j1=0 && j2=0 && i0=0 && j0=0 && i=0 && j=0 && i=0 && j 0) { - const [i,j] = [x+step[0],y+step[1]]; - if (i>=0 && i=0 && j=0 && sq2[0]=0 && sq2[1] 0) - { - this.kingPos[c][0] = move.appear[0].x; - this.kingPos[c][1] = move.appear[0].y; - } + if (this.checkRepetition()) + return "1/2"; + + const color = this.turn; + // TODO: do we need "atLeastOneMove()"? + if (this.atLeastOneMove() && this.kingPos[color][0] >= 0) + return "*"; + + return this.checkGameEnd(); } checkGameEnd() { - // No valid move: game is lost (stalemate is a win) + // No valid move: our king disappeared return this.turn == "w" ? "0-1" : "1-0"; } @@ -529,6 +466,10 @@ 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) };