X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FUltima.js;h=7f9531eb82ef281a9f5a899161f8e34c7d05b46e;hb=0279ac93197aa072991bce8f643ca68e99a54bc7;hp=d6676436a24f21641ae57783ebd656a4bad85fff;hpb=a3c86ec9b60326a8ae3d8f237493fb09627aed95;p=vchess.git diff --git a/public/javascripts/variants/Ultima.js b/public/javascripts/variants/Ultima.js index d6676436..7f9531eb 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,46 +368,27 @@ 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) - { - // Square (x,y) must be surrounded by two enemy pieces, - // and one of them at least should be a pawn - return false; - } - - isAttackedByRook(sq, colors) - { - // Enemy king must be on same file and a rook on same row (or reverse) - return false; - } - - isAttackedByKnight(sq, colors) - { - // Square (x,y) must be on same line as a knight, - // and there must be empty square(s) behind. - return false; - } - - isAttackedByBishop(sq, colors) + underCheck(move) { - // switch on piece nature on square sq: a chameleon attack as this piece - // ==> call the appropriate isAttackedBy... (exception of immobilizers) - // Other exception: a chameleon cannot attack a chameleon (seemingly...) - return false; + return false; //there is no check } - isAttackedByQueen(sq, colors) + getCheckSquares(move) { - // 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 +396,53 @@ 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= 0) + return "*"; + + return this.checkGameEnd(); } checkGameEnd() { - // No valid move: game is lost (stalemate is a win) + // Stalemate, or our king disappeared return this.turn == "w" ? "0-1" : "1-0"; } @@ -434,6 +460,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) };