Beispiel #1
0
    public override void ActivateTurn()
    {
        base.ActivateTurn();
        int[,] dummyArray = TicTacToeFunctions.GetDummyBoard(manager.tiles);

        NodesTaken = 0;
        BestMove(dummyArray);
        Debug.Log("Nodes Taken: " + NodesTaken);
    }
Beispiel #2
0
    TicTacState VictoryCheck()
    {
        switch (TicTacToeFunctions.VictoryCheck(TicTacToeFunctions.GetDummyBoard(tiles), currentPlayer))
        {
        case TicTacState.Win:
            Victory();
            return(TicTacState.Win);

        case TicTacState.Lose:
            Victory();
            return(TicTacState.Win);

        case TicTacState.Tie:
            Tie();
            return(TicTacState.Tie);

        default:
            return(TicTacState.None);
        }
    }
Beispiel #3
0
    int MiniMax(int[,] dummyArray, int depth, bool maximizing, int alpha, int beta)
    {
        NodesTaken++;
        TicTacState currentState = TicTacToeFunctions.VictoryCheck(dummyArray, depth, false, playerNummber);

        if (currentState != TicTacState.None)
        {
            return(ScoreCheck(currentState, depth));
        }

        int score;

        if (maximizing)
        {
            //score = int.MinValue;
            for (int x = 0; x < dummyArray.GetLength(0); x++)
            {
                for (int y = 0; y < dummyArray.GetLength(1); y++)
                {
                    if (dummyArray[x, y] == 0)
                    {
                        dummyArray[x, y] = playerNummber;
                        score            = MiniMax(dummyArray, depth++, false, alpha, beta);
                        dummyArray[x, y] = 0;
                        // score = Math.Max(newScore, score);
                        alpha = Math.Max(alpha, score);
                        if (beta <= alpha)
                        {
                            break;
                        }
                    }
                    if (beta <= alpha)
                    {
                        break;
                    }
                }
            }
            return(alpha);
        }
        else
        {
            // score = int.MaxValue;
            for (int x = 0; x < dummyArray.GetLength(0); x++)
            {
                for (int y = 0; y < dummyArray.GetLength(1); y++)
                {
                    if (dummyArray[x, y] == 0)
                    {
                        dummyArray[x, y] = 1;
                        score            = MiniMax(dummyArray, depth++, true, alpha, beta);
                        dummyArray[x, y] = 0;
                        //score = Math.Min(score, newScore);
                        beta = Math.Min(beta, score);
                        if (beta <= alpha)
                        {
                            break;
                        }
                    }
                    if (beta <= alpha)
                    {
                        break;
                    }
                }
            }
            return(beta);
        }
    }