X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FUltima.js;h=d6fecb70d49d5c74eb7f1509ee7358190176393c;hb=7931e479adf93c87771ded1892a0873af72ae46d;hp=c98822dcbf0e85aa68889faf0f4c338194dd79ef;hpb=9d218497ab97bc0e94ec4c1f0a40cf02df3ea0d4;p=vchess.git diff --git a/public/javascripts/variants/Ultima.js b/public/javascripts/variants/Ultima.js index c98822dc..d6fecb70 100644 --- a/public/javascripts/variants/Ultima.js +++ b/public/javascripts/variants/Ultima.js @@ -7,6 +7,15 @@ class UltimaRules extends ChessRules return b; //usual piece } + static get PIECES() { + return ChessRules.PIECES.concat([V.IMMOBILIZER]); + } + + static IsGoodFlags(flags) + { + return true; //anything is good: no flags + } + initVariables(fen) { this.kingPos = {'w':[-1,-1], 'b':[-1,-1]}; @@ -50,46 +59,54 @@ 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? 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]]; - if (i>=0 && i=0 && j=0 && i2=0 && j2=0 && i=0 && j=0 && i=0 - && j { @@ -140,17 +151,16 @@ class UltimaRules extends ChessRules for (let step of steps) { const sq2 = [m.end.x+2*step[0],m.end.y+2*step[1]]; - if (sq2[0]>=0 && sq2[0]=0 && sq2[1]=0 && i=0 && j=sizeX || j<0 || j>=sizeY || this.getColor(i,j)==color + if (!V.OnBoard(i,j) || this.getColor(i,j)==color || (!!byChameleon && this.getPiece(i,j)!=V.KNIGHT)) { continue; @@ -244,7 +252,7 @@ class UltimaRules extends ChessRules let last = [i,j]; let cur = [i+step[0],j+step[1]]; let vanished = [ new PiPo({x:x,y:y,c:color,p:piece}) ]; - while (cur[0]>=0 && cur[0]=0 && cur[1] { - const key = m.end.x + sizeX * m.end.y; + const key = m.end.x + V.size.x * m.end.y; if (!mergedMoves[key]) mergedMoves[key] = m; else @@ -320,16 +324,13 @@ class UltimaRules extends ChessRules if (moves.length == 0) return; const [x,y] = [moves[0].start.x,moves[0].start.y]; - const V = VariantRules; const adjacentSteps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]); let capturingDirections = []; const color = this.turn; const oppCol = this.getOppCol(color); - const [sizeX,sizeY] = V.size; adjacentSteps.forEach(step => { const [i,j] = [x+step[0],y+step[1]]; - if (i>=0 && i=0 && j 0) + // Square (x,y) must be on same line as a knight, + // and there must be empty square(s) behind. + const steps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]); + outerLoop: + for (let step of steps) { - this.kingPos[c][0] = move.appear[0].x; - this.kingPos[c][1] = move.appear[0].y; + const [i0,j0] = [x+step[0],y+step[1]]; + if (V.OnBoard(i0,j0) && this.board[i0][j0] == V.EMPTY) + { + // Try in opposite direction: + let [i,j] = [x-step[0],y-step[1]]; + while (V.OnBoard(i,j)) + { + while (V.OnBoard(i,j) && this.board[i][j] == V.EMPTY) + { + i -= step[0]; + j -= step[1]; + } + if (V.OnBoard(i,j)) + { + if (colors.includes(this.getColor(i,j))) + { + if (this.getPiece(i,j) == V.KNIGHT && !this.isImmobilized([i,j])) + return true; + continue outerLoop; + } + // [else] Our color, could be captured *if there was an empty space* + if (this.board[i+step[0]][j+step[1]] != V.EMPTY) + continue outerLoop; + i -= step[0]; + j -= step[1]; + } + } + } } - // Does this move takes opponent's king? - const oppCol = this.getOppCol(c); - for (let i=1; i 0) + { + this.kingPos[c][0] = move.appear[0].x; + this.kingPos[c][1] = move.appear[0].y; + } } static get VALUES() { //TODO: totally experimental! @@ -463,10 +558,6 @@ 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) }; @@ -524,4 +615,24 @@ class UltimaRules extends ChessRules { return "0000"; //TODO: or "-" ? } + + getNotation(move) + { + const initialSquare = + String.fromCharCode(97 + move.start.y) + (V.size.x-move.start.x); + const finalSquare = String.fromCharCode(97 + move.end.y) + (V.size.x-move.end.x); + let notation = undefined; + if (move.appear[0].p == V.PAWN) + { + // Pawn: generally ambiguous short notation, so we use full description + notation = "P" + initialSquare + finalSquare; + } + else if (move.appear[0].p == V.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 != V.KING) + notation += "X"; //capture mark (not describing what is captured...) + return notation; + } }