Attempt to fix Alice chess
[vchess.git] / public / javascripts / base_rules.js
index c24c84c..8568936 100644 (file)
@@ -479,8 +479,7 @@ class ChessRules
        {
                if (moves.length == 0)
                        return [];
-               let color = this.turn;
-               return moves.filter(m => { return !this.underCheck(m, color); });
+               return moves.filter(m => { return !this.underCheck(m); });
        }
 
        // Search for all valid moves considering current turn (for engine and game end)
@@ -699,6 +698,10 @@ class ChessRules
 
        play(move, ingame)
        {
+               // DEBUG:
+//             if (!this.states) this.states = [];
+//             if (!ingame) this.states.push(JSON.stringify(this.board));
+
                if (!!ingame)
                        move.notation = this.getNotation(move);
 
@@ -716,6 +719,11 @@ class ChessRules
                this.moves.pop();
                this.unupdateVariables(move);
                this.parseFlags(JSON.parse(move.flags));
+
+               // DEBUG:
+//             let state = this.states.pop();
+//             if (JSON.stringify(this.board) != state)
+//                     debugger;
        }
 
        //////////////
@@ -781,10 +789,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
@@ -1047,6 +1054,7 @@ class ChessRules
                pgn += '[Site "vchess.club"]<br>';
                const d = new Date();
                const opponent = mode=="human" ? "Anonymous" : "Computer";
+               pgn += '[Variant "' + variant + '"]<br>';
                pgn += '[Date "' + d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate() + '"]<br>';
                pgn += '[White "' + (mycolor=='w'?'Myself':opponent) + '"]<br>';
                pgn += '[Black "' + (mycolor=='b'?'Myself':opponent) + '"]<br>';