Get minimax to output just one spot?
<p>I have this minimax function for a numbers game.  The goal is to get to [11][30] in an array.  And each player can only change x or y, not both.  So if player one picks 5 16, then player2(AI) can pick 5 17, 5 18, 5 19, or 6 16, 7 16, 8 16...etc.  My problem is that when its the AI's turn it just picks every valid spot until the end.  I just want one spot.</p>

<pre><code> public Space MiniMax(GameBoard board, Player comPlayer)
    {
        Space BestValue = new Space();
        GameBoard tempBoard;

        Space Position = GetPlayerPosition(board, ((Player)(-(int)comPlayer)));

         if (comPlayer == Player.Player1)
             BestValue.Rank = -INFINITY;
         else
             BestValue.Rank = INFINITY;

        List&lt;Space&gt; validspot = GetValidSpot(board, Position);

        for (int i = 0; i &lt; validspot.Count; i++)
        {
            Space value = validspot[i];
            tempBoard = board.Clone();


            tempBoard[value.X, value.Y] = comPlayer;//make move

            if (tempBoard.Winner == Player.openspot)
            {
                value = MiniMax(tempBoard, ((Player)(-(int)comPlayer)));

            }
            else
            {
                if (tempBoard.Winner == Player.openspot)
                    value.Rank = 0;
                else if (tempBoard.Winner == Player.Player1)
                    value.Rank = 1;
                else if (tempBoard.Winner == Player.Player2)
                    value.Rank = -1;
            }

            if (comPlayer == Player.Player1)
                BestValue = MAX(value, BestValue);
            else
                BestValue = MIN(value, BestValue);
        }

        return BestValue;
    }
</code></pre>

<p>and here is where its called and changed.</p>

<pre><code>public void Move(GameBoard board, Player comPlayer)
    {

        Space BestPos = MiniMax(board, comPlayer);

        board[BestPos.X, BestPos.Y] = Player.Player2;
    }
</code></pre>
