From: Benjamin Auder Date: Sat, 24 Nov 2018 00:22:04 +0000 (+0100) Subject: Fix Alice rules (en passant) X-Git-Url: https://git.auder.net/variants/Chakart/%7B%7B%20asset%28%27mixstore/images/scripts/DESCRIPTION?a=commitdiff_plain;h=06ddfe34f6ef5c82d206332245ed4f33a9d92715;p=vchess.git Fix Alice rules (en passant) --- diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index ec5f9372..ab197b62 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -781,10 +781,9 @@ class ChessRules getComputerMove() { const color = this.turn; - - // Rank moves using a min-max at depth 2 let moves1 = this.getAllValidMoves(); + // Rank moves using a min-max at depth 2 for (let i=0; i { if (m.appear.length == 2) //castle { @@ -113,8 +116,8 @@ class AliceRules extends ChessRules { // Attempt to capture const piece = this.getPiece(m.end.x,m.end.y); - if ((mirrorSide==1 && Object.keys(VariantRules.ALICE_PIECES).includes(piece)) - || (mirrorSide==2 && Object.keys(VariantRules.ALICE_CODES).includes(piece))) + if ((mirrorSide==1 && codes.includes(piece)) + || (mirrorSide==2 && pieces.includes(piece))) { return false; } @@ -134,7 +137,17 @@ class AliceRules extends ChessRules } // Fix en-passant captures if (m.vanish.length == 2 && this.board[m.end.x][m.end.y] == VariantRules.EMPTY) + { m.vanish[1].c = this.getOppCol(this.getColor(x,y)); + // In the special case of en-passant, if + // - board1 takes board2 : vanish[1] --> Alice + // - board2 takes board1 : vanish[1] --> normal + let van = m.vanish[1]; + if (mirrorSide==1 && codes.includes(this.getPiece(van.x,van.y))) + van.p = VariantRules.ALICE_CODES[van.p]; + else if (mirrorSide==2 && pieces.includes(this.getPiece(van.x,van.y))) + van.p = VariantRules.ALICE_PIECES[van.p]; + } return true; }); }