From: Benjamin Auder Date: Wed, 12 Dec 2018 17:04:40 +0000 (+0100) Subject: Simplify (and almost fix) Ultima rules X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/css/current/img/doc/%3C?a=commitdiff_plain;h=c28265aa3e9d97601af99067b580699a83f4d28b;p=vchess.git Simplify (and almost fix) Ultima rules --- diff --git a/public/javascripts/variants/Magnetic.js b/public/javascripts/variants/Magnetic.js index 7d9d5113..b17bb74a 100644 --- a/public/javascripts/variants/Magnetic.js +++ b/public/javascripts/variants/Magnetic.js @@ -165,8 +165,8 @@ class MagneticRules extends ChessRules { super.updateVariables(move); const c = this.getColor(move.start.x,move.start.y); - if (c != this.getColor(move.end.x,move.end.y) - && this.board[move.end.x][move.end.y] != VariantRules.EMPTY + if (this.board[move.end.x][move.end.y] != VariantRules.EMPTY + && c != this.getColor(move.end.x,move.end.y) && this.getPiece(move.end.x,move.end.y) == VariantRules.KING) { // We took opponent king ! 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) }; diff --git a/views/rules/Ultima.pug b/views/rules/Ultima.pug index 0a3cc7f0..df8571f4 100644 --- a/views/rules/Ultima.pug +++ b/views/rules/Ultima.pug @@ -11,7 +11,7 @@ ul li Non-capturing moves: often like queen. li Special moves: none. li Captures: very special. - li End of game: standard; see below. + li End of game: capture the king. h3 Non-capturing moves @@ -20,10 +20,12 @@ h3 Non-capturing moves h3 Capturing moves // TODO... +// TODO: dire comment suicider une pièce immobilisée (self-capture) h3 End of the game // TODO: show the situation from Wikipedia page +// tell that it's much simpler to go until king capture and not very different in this case h3 Credits