Exemplo n.º 1
0
    void ChooseBestMove()
    {
        int indexOfHighestValue = Array.IndexOf(movesTree.chancesOfChildren, movesTree.chancesOfChildren.Max());

        gameUIScript.SetComputerProbability(movesTree.chancesOfChildren[indexOfHighestValue]);

        switch (indexOfHighestValue)
        {
        case 0:
            movesTree = movesTree.leftBranch;
            levelScript.ChoosingForAI(movesTree.takenMatchesCount);
            break;

        case 1:
            movesTree = movesTree.centerBranch;
            levelScript.ChoosingForAI(movesTree.takenMatchesCount);
            break;

        case 2:
            movesTree = movesTree.rightBranch;
            levelScript.ChoosingForAI(movesTree.takenMatchesCount);
            break;

        default:
            print("Error in choosing best move");
            break;
        }
    }
Exemplo n.º 2
0
    void CreateMovesTree(int matchesCount, int matchesTakenLastMove)
    {
        millisecondsTimer.Start();
        movesTree = new branchBehaviour(matchesCount, matchesTakenLastMove, true);
        millisecondsTimer.Stop();
        print("Create tree time: " + millisecondsTimer.ElapsedMilliseconds);

        millisecondsTimer.Reset();
        millisecondsTimer.Start();
        movesTree.CalculateProbability();
        millisecondsTimer.Stop();
        print("Calculating probability time: " + millisecondsTimer.ElapsedMilliseconds);
    }
Exemplo n.º 3
0
    public branchBehaviour(int matchesCount, int takenMatchesCount, bool wasHumanMove)
    {
        this.matchesCount      = matchesCount;
        this.takenMatchesCount = takenMatchesCount;
        this.isComputerMove    = !wasHumanMove;

        if (matchesCount > 0)
        {
            if (takenMatchesCount - 1 > 0)
            {
                leftBranch = new branchBehaviour((matchesCount - takenMatchesCount + 1), (takenMatchesCount - 1), isComputerMove);
            }
            else
            {
                leftBranch = null;
            }
            centerBranch = new branchBehaviour(matchesCount - takenMatchesCount, takenMatchesCount, isComputerMove);
            rightBranch  = new branchBehaviour((matchesCount - takenMatchesCount - 1), (takenMatchesCount + 1), isComputerMove);
        }
    }
Exemplo n.º 4
0
    void PlayerMadeMove(int matchesTakenLastMove)
    {
        if (movesTree.leftBranch != null && matchesTakenLastMove == movesTree.leftBranch.takenMatchesCount)
        {
            movesTree = movesTree.leftBranch;
        }
        else if (matchesTakenLastMove == movesTree.centerBranch.takenMatchesCount)
        {
            movesTree = movesTree.centerBranch;
        }
        else if (matchesTakenLastMove == movesTree.rightBranch.takenMatchesCount)
        {
            movesTree = movesTree.rightBranch;
        }
        else
        {
            print("Error in player move (AI message)");
        }

        gameUIScript.SetComputerProbability(movesTree.chancesOfChildren.Max());
    }