X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FMarseille.js;h=0d228b0c0407a40baf7a0f903d06138f4d61c80d;hb=3fa426b632d92a65843038a161677069de5db27e;hp=6e72a23609152ec29d1475a5a03ac47c0ce5bbfc;hpb=1b61a94dbd13f6a37a89e62216615d2496c760a2;p=vchess.git diff --git a/public/javascripts/variants/Marseille.js b/public/javascripts/variants/Marseille.js index 6e72a236..0d228b0c 100644 --- a/public/javascripts/variants/Marseille.js +++ b/public/javascripts/variants/Marseille.js @@ -73,40 +73,37 @@ class MarseilleRules extends ChessRules const startRank = (color == "w" ? sizeX-2 : 1); const lastRank = (color == "w" ? 0 : sizeX-1); const pawnColor = this.getColor(x,y); //can be different for checkered + const finalPieces = x + shiftX == lastRank + ? [V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN] + : [V.PAWN]; - if (x+shiftX >= 0 && x+shiftX < sizeX) //TODO: always true + // One square forward + if (this.board[x+shiftX][y] == V.EMPTY) { - const finalPieces = x + shiftX == lastRank - ? [V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN] - : [V.PAWN] - // One square forward - if (this.board[x+shiftX][y] == V.EMPTY) + for (let piece of finalPieces) { - for (let piece of finalPieces) - { - moves.push(this.getBasicMove([x,y], [x+shiftX,y], - {c:pawnColor,p:piece})); - } - // Next condition because pawns on 1st rank can generally jump - if ([startRank,firstRank].includes(x) - && this.board[x+2*shiftX][y] == V.EMPTY) - { - // Two squares jump - moves.push(this.getBasicMove([x,y], [x+2*shiftX,y])); - } + moves.push(this.getBasicMove([x,y], [x+shiftX,y], + {c:pawnColor,p:piece})); + } + // Next condition because pawns on 1st rank can generally jump + if ([startRank,firstRank].includes(x) + && this.board[x+2*shiftX][y] == V.EMPTY) + { + // Two squares jump + moves.push(this.getBasicMove([x,y], [x+2*shiftX,y])); } - // Captures - for (let shiftY of [-1,1]) + } + // Captures + for (let shiftY of [-1,1]) + { + if (y + shiftY >= 0 && y + shiftY < sizeY + && this.board[x+shiftX][y+shiftY] != V.EMPTY + && this.canTake([x,y], [x+shiftX,y+shiftY])) { - if (y + shiftY >= 0 && y + shiftY < sizeY - && this.board[x+shiftX][y+shiftY] != V.EMPTY - && this.canTake([x,y], [x+shiftX,y+shiftY])) + for (let piece of finalPieces) { - for (let piece of finalPieces) - { - moves.push(this.getBasicMove([x,y], [x+shiftX,y+shiftY], - {c:pawnColor,p:piece})); - } + moves.push(this.getBasicMove([x,y], [x+shiftX,y+shiftY], + {c:pawnColor,p:piece})); } } } @@ -127,6 +124,7 @@ class MarseilleRules extends ChessRules { if (this.subTurn == 1 || (epSqs.length == 2 && // Was this en-passant capture already played at subturn 1 ? + // (Or maybe the opponent filled the en-passant square with a piece) this.board[epSqs[0].x][epSqs[0].y] != V.EMPTY)) { if (sq.x == x+shiftX && Math.abs(sq.y - y) == 1) @@ -235,7 +233,9 @@ class MarseilleRules extends ChessRules const maxeval = V.INFINITY; const color = this.turn; const oppCol = this.getOppCol(this.turn); - +//if (this.moves.length == 25) +// debugger; +console.log("turn before " + this.turn + " " + this.subTurn); // Search best (half) move for opponent turn const getBestMoveEval = () => { let moves = this.getAllValidMoves(); @@ -273,11 +273,16 @@ class MarseilleRules extends ChessRules }; let moves11 = this.getAllValidMoves(); +console.log("turn after " + this.turn + " " + this.subTurn); + +if (this.moves.length == 25) + debugger; + + let doubleMoves = []; // Rank moves using a min-max at depth 2 for (let i=0; i { return (color=="w" ? 1 : -1) * (b.eval - a.eval); }); @@ -308,6 +369,7 @@ class MarseilleRules extends ChessRules { candidates.push(i); } +console.log("turn END " + this.turn + " " + this.subTurn); const selected = doubleMoves[_.sample(candidates, 1)].moves; if (selected.length == 1) @@ -362,7 +424,6 @@ class MarseilleRules extends ChessRules return pgn; } - } const VariantRules = MarseilleRules;