X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fbase_rules.js;h=79b6a7a3ce468e6f23e64dd798317ff29eb2aaad;hb=dda21a71b6245832a78ca987b14c77176bd15dd6;hp=f1188ab5b1c544ca14b6d17c64d9e1a3ded05f8a;hpb=a6abf094c35a26019e47fea21302c4be32ff030b;p=vchess.git diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index f1188ab5..79b6a7a3 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -124,7 +124,7 @@ class ChessRules return board; } - // Overridable: flags can change a lot + // Extract (relevant) flags from fen setFlags(fen) { // white a-castle, h-castle, black a-castle, h-castle @@ -137,7 +137,6 @@ class ChessRules /////////////////// // GETTERS, SETTERS - // Simple useful getters static get size() { return [8,8]; } // Two next functions return 'undefined' if called on empty square getColor(i,j) { return this.board[i][j].charAt(0); } @@ -199,7 +198,7 @@ class ChessRules return undefined; //default } - // can thing on square1 take thing on square2 + // Can thing on square1 take thing on square2 canTake([x1,y1], [x2,y2]) { return this.getColor(x1,y1) != this.getColor(x2,y2); @@ -276,7 +275,8 @@ class ChessRules { let i = x + step[0]; let j = y + step[1]; - while (i>=0 && i=0 && j=0 && i=0 && j0 && this.canTake([x,y], [x+shift,y-1]) && this.board[x+shift][y-1] != V.EMPTY) + 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])); - if (y0 && this.canTake([x,y], [x+shift,y-1]) && this.board[x+shift][y-1] != V.EMPTY) + 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})); - if (y= 8) { - // NOTE: crude detection, only moves repetition const L = this.moves.length; if (_.isEqual(this.moves[L-1], this.moves[L-5]) && _.isEqual(this.moves[L-2], this.moves[L-6]) && @@ -756,6 +761,7 @@ class ChessRules return false; } + // Is game over ? And if yes, what is the score ? checkGameOver() { if (this.checkRepetition()) @@ -883,6 +889,7 @@ class ChessRules return moves1[_.sample(candidates, 1)]; } + // TODO: some optimisations, understand why CH get mated in 2 alphabeta(depth, alpha, beta) { const maxeval = VariantRules.INFINITY; @@ -948,7 +955,7 @@ class ChessRules //////////// // FEN utils - // Overridable.. + // Setup the initial random (assymetric) position static GenRandInitFen() { let pieces = [new Array(8), new Array(8)]; @@ -1008,6 +1015,7 @@ class ChessRules return this.getBaseFen() + " " + this.getFlagsFen(); } + // Position part of the FEN string getBaseFen() { let fen = ""; @@ -1041,7 +1049,7 @@ class ChessRules return fen; } - // Overridable.. + // Flags part of the FEN string getFlagsFen() { let fen = ""; @@ -1096,6 +1104,16 @@ class ChessRules } } + // Complete the usual notation, may be required for de-ambiguification + getLongNotation(move) + { + const startSquare = + String.fromCharCode(97 + move.start.y) + (VariantRules.size[0]-move.start.x); + const finalSquare = + String.fromCharCode(97 + move.end.y) + (VariantRules.size[0]-move.end.x); + return startSquare + finalSquare; //not encoding move. But short+long is enough + } + // The score is already computed when calling this function getPGN(mycolor, score, fenStart, mode) { @@ -1110,14 +1128,24 @@ class ChessRules pgn += '[Fen "' + fenStart + '"]
'; pgn += '[Result "' + score + '"]

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