X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Fbase_rules.js;h=9a4ef9120ca8463a9e4e36d4197aead688c94299;hp=de1a0d0fa4ec4eab521532cafa123f3b5f71c113;hb=e64a4effa6b357addc3253504870cf1a6fc29977;hpb=52b1e238e0c85d5554d8edc07b728f83598a4a78 diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index de1a0d0f..9a4ef912 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -517,6 +517,32 @@ class ChessRules // No: if happen on last 1/2 move, could lead to forbidden moves, wrong evals return this.filterValid(potentialMoves); } + + // Stop at the first move found + atLeastOneMove(color) + { + const oppCol = this.getOppCol(color); + let [sizeX,sizeY] = VariantRules.size; + for (var i=0; i 0) + { + for (let i=0; i 0) + return true; + } + } + } + } + } + return false; + } // Check if pieces of color 'color' are attacking square x,y isAttacked(sq, color) @@ -676,12 +702,15 @@ class ChessRules this.movesCount++; } - undo(move) + undo(move, ingame) { VariantRules.UndoOnBoard(this.board, move); this.epSquares.pop(); this.movesCount--; + if (!!ingame) + this.moves.pop(); + // Update king position, and reset stored/computed flags const c = this.getColor(move.start.x,move.start.y); if (this.getPiece(move.start.x,move.start.y) == VariantRules.KING) @@ -709,8 +738,7 @@ class ChessRules } } - // TODO: not required to generate ALL: just need one (callback ? hook ? ...) - if (this.getAllValidMoves(color).length > 0) + if (this.atLeastOneMove(color)) { // game not over return "*"; @@ -779,14 +807,14 @@ class ChessRules moves1.sort( (a,b) => { return (color=="w" ? 1 : -1) * (b.eval - a.eval); }); // TODO: show current analyzed move for depth 3, allow stopping eval (return moves1[0]) -// for (let i=0; i { return (color=="w" ? 1 : -1) * (b.eval - a.eval); }); + for (let i=0; i { return (color=="w" ? 1 : -1) * (b.eval - a.eval); }); let candidates = [0]; //indices of candidates moves for (let j=1; j