X-Git-Url: https://git.auder.net/assets/icon_close.svg?a=blobdiff_plain;f=public%2Fjavascripts%2Fbase_rules.js;h=42775dab1553cae4d181eb522f28353cada25f1b;hb=efb20746c30ac26f258f9c5de6dfb70b91980de4;hp=f466624d653ebc5ec50e46036c7c3785ecb4b82d;hpb=a37076f1ac8f4c19d9b34a60cbe89df86b88fa0b;p=vchess.git diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index f466624d..42775dab 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -284,7 +284,7 @@ class ChessRules i += step[0]; j += step[1]; } - if (i>=0 && i<8 && j>=0 && j<8 && this.canTake([x,y], [i,j])) + if (i>=0 && i=0 && j=0 && x+pawnShift<8) + if (x+pawnShift>=0 && x+pawnShift=0 && y+i<8 && this.getPiece(x+pawnShift,y+i)==VariantRules.PAWN + if (y+i>=0 && y+i=0 && rx<8 && ry>=0 && ry<8 && this.board[rx][ry] == VariantRules.EMPTY - && !oneStep) + while (rx>=0 && rx=0 && ry=0 && rx<8 && ry>=0 && ry<8 && this.board[rx][ry] != VariantRules.EMPTY + if (rx>=0 && rx=0 && ry 0) @@ -677,7 +682,7 @@ class ChessRules return; } const oppCol = this.getOppCol(c); - const oppFirstRank = 7 - firstRank; + const oppFirstRank = (sizeX-1) - firstRank; if (move.start.x == firstRank //our rook moves? && this.INIT_COL_ROOK[c].includes(move.start.y)) { @@ -798,9 +803,14 @@ class ChessRules return VariantRules.INFINITY; } + static get SEARCH_DEPTH() { + return 3; //2 for high branching factor, 4 for small (Loser chess) + } + // Assumption: at least one legal move getComputerMove(moves1) //moves1 might be precomputed (Magnetic chess) { + this.shouldReturn = false; const maxeval = VariantRules.INFINITY; const color = this.turn; if (!moves1) @@ -832,21 +842,32 @@ class ChessRules } moves1.sort( (a,b) => { return (color=="w" ? 1 : -1) * (b.eval - a.eval); }); + let candidates = [0]; //indices of candidates moves + for (let j=1; j= 3 + && Math.abs(moves1[0].eval) < VariantRules.THRESHOLD_MATE) { // 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); }); } + else + return currentBest; - let candidates = [0]; //indices of candidates moves + candidates = [0]; for (let j=1; j { return [this.getNotation(m), m.eval]; }));