コード例 #1
0
ファイル: NeutralAI.cs プロジェクト: rtwm500/SEPR-ASS4
    public void DecideMove()
    {
        // Method called to perform a AI turn

        if (NumberOfFriendlySectors() != 0)
        {
            // Ordered List to aid in determining move
            OrderedList list = new OrderedList(NumberOfFriendlySectors());

            // Global calculations
            int fAvg = AvgFriendlyStrength();

            foreach (Section section in sections)
            {
                // Local calculations
                int eMag = EnemyMagnitudeOnBorder(section);
                int eBor = NumberOfBorderingEnemies(section);
                int eDel = MaxHostileUnitDelta(section);
                int fDel = MaxFriendlyUnitDelta(section);

                // Threat Heuristic
                int threatHeuristic = (5 * eDel) + (4 * eMag) + (3 * eBor);

                // Balance Heuristic
                int balanceHeuristic = 0;

                if (fAvg - fDel > 0)
                {
                    balanceHeuristic = (fAvg - fDel);
                }

                // Poppulate ordered list
                list.AddItem(section, threatHeuristic, eDel, balanceHeuristic, fDel);
            }

            if (Reinforce(list.GetMaxThreat().section))
            {
                Debug.Log("AI Performed Reinforce action");
            }
            else if (Balance(list.GetMaxBalance().section))
            {
                Debug.Log("AI Performed Balance action");
            }
            else
            {
                Debug.Log("AI Performed no action");
            }
        }
        game.NextTurn();
    }