X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fbase_rules.js;h=48a5602c33c32688762c998d13fd9ab4d54b2261;hb=16984853e12058bd51b2e5ac065ed84febebc162;hp=fdfcda3510aab264a758ccdb5198b35840e8a577;hpb=11a31682261b2bb40b06e1c026b07a3c5b2285e1;p=vchess.git diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index fdfcda35..48a5602c 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -331,21 +331,22 @@ class ChessRules if (x+shift == lastRank) { // Promotion + const pawnColor = this.getColor(x,y); //can be different for checkered let promotionPieces = [V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN]; promotionPieces.forEach(p => { // Normal move if (this.board[x+shift][y] == V.EMPTY) - moves.push(this.getBasicMove([x,y], [x+shift,y], {c:color,p:p})); + moves.push(this.getBasicMove([x,y], [x+shift,y], {c:pawnColor,p:p})); // Captures if (y>0 && this.canTake([x,y], [x+shift,y-1]) && this.board[x+shift][y-1] != V.EMPTY) { - moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:color,p:p})); + moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:pawnColor,p:p})); } if (y eval2)) - eval2 = evalPos; - this.undo(moves2[j]); + eval2 = (color=="w" ? 1 : -1) * maxeval; //initialized with checkmate value + // Second half-move: + let moves2 = this.getAllValidMoves(); + for (let j=0; j eval2)) + eval2 = evalPos; + this.undo(moves2[j]); + } + } + else + { + const score = this.checkGameEnd(); + eval2 = (score=="1/2" ? 0 : (score=="1-0" ? 1 : -1) * maxeval); } if ((color=="w" && eval2 > moves1[i].eval) || (color=="b" && eval2 < moves1[i].eval)) moves1[i].eval = eval2; @@ -884,7 +896,7 @@ class ChessRules } else return currentBest; - //console.log(moves1.map(m => { return [this.getNotation(m)[0], m.eval]; })); + //console.log(moves1.map(m => { return [this.getNotation(m), m.eval]; })); candidates = [0]; for (let j=1; j { return (x<10 ? "0" : "") + x; }; let pgn = ""; pgn += '[Site "vchess.club"]
'; const d = new Date(); const opponent = mode=="human" ? "Anonymous" : "Computer"; pgn += '[Variant "' + variant + '"]
'; - pgn += '[Date "' + d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate() + '"]
'; + pgn += '[Date "' + d.getFullYear() + '-' + (d.getMonth()+1) + '-' + zeroPad(d.getDate()) + '"]
'; pgn += '[White "' + (mycolor=='w'?'Myself':opponent) + '"]
'; pgn += '[Black "' + (mycolor=='b'?'Myself':opponent) + '"]
'; - pgn += '[Fen "' + fenStart + '"]
'; + pgn += '[FenStart "' + fenStart + '"]
'; + pgn += '[Fen "' + this.getFen() + '"]
'; pgn += '[Result "' + score + '"]

'; // Standard PGN @@ -1137,7 +1154,7 @@ class ChessRules pgn += ((i/2)+1) + "."; pgn += this.moves[i].notation[0] + " "; } - pgn += score + "

"; + pgn += "

"; // "Complete moves" PGN (helping in ambiguous cases) for (let i=0; i