Fix Ultima when no moves are available
[vchess.git] / public / javascripts / variants / Ultima.js
index 588968d..7f9531e 100644 (file)
@@ -368,12 +368,6 @@ class UltimaRules extends ChessRules
                        V.steps[V.ROOK].concat(V.steps[V.BISHOP]), "oneStep");
        }
 
-       // TODO: verify this assertion
-       atLeastOneMove()
-       {
-               return true; //always at least one possible move
-       }
-
        underCheck(move)
        {
                return false; //there is no check
@@ -404,9 +398,9 @@ class UltimaRules extends ChessRules
                }
                // Does this move takes opponent's king?
                const oppCol = this.getOppCol(c);
-               for (let psq of move.vanish)
+               for (let i=1; i<move.vanish.length; i++)
                {
-                       if (psq.p == VariantRules.KING)
+                       if (move.vanish[i].p == VariantRules.KING)
                        {
                                this.kingPos[oppCol] = [-1,-1];
                                break;
@@ -422,8 +416,9 @@ class UltimaRules extends ChessRules
                if (this.kingPos[oppCol][0] < 0)
                {
                        // Last move took opponent's king
-                       for (let psq of move.vanish)
+                       for (let i=1; i<move.vanish.length; i++)
                        {
+                               const psq = move.vanish[i];
                                if (psq.p == 'k')
                                {
                                        this.kingPos[oppCol] = [psq.x, psq.y];
@@ -439,7 +434,6 @@ class UltimaRules extends ChessRules
                        return "1/2";
 
                const color = this.turn;
-               // TODO: do we need "atLeastOneMove()"?
                if (this.atLeastOneMove() && this.kingPos[color][0] >= 0)
                        return "*";
 
@@ -448,7 +442,7 @@ class UltimaRules extends ChessRules
 
        checkGameEnd()
        {
-               // No valid move: our king disappeared
+               // Stalemate, or our king disappeared
                return this.turn == "w" ? "0-1" : "1-0";
        }