Fix Alice rules (en passant)
authorBenjamin Auder <benjamin.auder@somewhere>
Sat, 24 Nov 2018 00:22:04 +0000 (01:22 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Sat, 24 Nov 2018 00:22:04 +0000 (01:22 +0100)
public/javascripts/base_rules.js
public/javascripts/components/game.js
public/javascripts/variants/Alice.js

index ec5f937..ab197b6 100644 (file)
@@ -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<moves1.length; i++)
                {
                        moves1[i].eval = (color=="w" ? -1 : 1) * 1000; //very low, I'm checkmated
index a7acc10..1f47b60 100644 (file)
@@ -574,8 +574,6 @@ Vue.component('my-game', {
                        this.newGame("computer");
                },
                newGame: function(mode, fenInit, color, oppId, moves, continuation) {
-                       //const fen = "bbrkqnrn/pppppppp/8/8/8/8/PPPPPPPP/NNRKQBBR 1111";
-                       //const fen = "bbrkqnr1/pppppp1p/6o1/6s1/3SS3/8/PPP2PPP/NNRKQBBR 1111"; //first 2 moves == pb
                        const fen = fenInit || VariantRules.GenRandInitFen();
                        console.log(fen); //DEBUG
                        this.score = "*";
index a15c30c..dd023bb 100644 (file)
@@ -95,8 +95,11 @@ class AliceRules extends ChessRules
                let moves = super.getPotentialMovesFrom([x,y]);
                this.board = saveBoard;
 
+               const pieces = Object.keys(VariantRules.ALICE_CODES);
+               const codes = Object.keys(VariantRules.ALICE_PIECES);
+
                // Finally filter impossible moves
-               const mirrorSide = (Object.keys(VariantRules.ALICE_CODES).includes(this.getPiece(x,y)) ? 1 : 2);
+               const mirrorSide = (pieces.includes(this.getPiece(x,y)) ? 1 : 2);
                return moves.filter(m => {
                        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;
                });
        }