Пример #1
0
        public void Update()
        {
            CleanUpDeadPawns();

            if (m_OrderedPawns.TrueForAll(item => item.GetComponent <PawnStatistics>().m_Priority < 1))
            {
                ApplyPriorityRestore();
            }

            List <float> priorityWorkingCopy = new List <float>();

            foreach (GameObject obj in m_OrderedPawns)
            {
                priorityWorkingCopy.Add(obj.GetComponent <PawnStatistics>().m_Priority);
            }

            m_CurrentIteration = ComputeIteration(0, priorityWorkingCopy);

            m_NextIterations.Clear();
            int       turnCount      = m_CurrentIteration.GetCount();
            const int MAX_TURN_COUNT = 10;

            while (turnCount < MAX_TURN_COUNT)
            {
                for (int i = 0; i < m_OrderedPawns.Count; ++i)
                {
                    priorityWorkingCopy[i] += m_OrderedPawns[i].GetComponent <PawnStatistics>().m_PriorityIncrease;
                }

                GameIteration iteration = ComputeIteration(0, priorityWorkingCopy);
                m_NextIterations.Add(iteration);

                turnCount += iteration.GetCount();
            }
        }
Пример #2
0
        public List <GameObject> Preview(GameObject _previewPawn, PawnStatistics _previewStatistics, int _count)
        {
            Dictionary <GameObject, PawnStatistics> statistics = new Dictionary <GameObject, PawnStatistics>();

            foreach (GameObject obj in m_OrderedPawns)
            {
                if (obj == _previewPawn)
                {
                    statistics.Add(obj, _previewStatistics);
                }
                else
                {
                    statistics.Add(obj, obj.GetComponent <PawnStatistics>());
                }
            }

            List <GameObject> ret = new List <GameObject>();

            List <float> priorityBase = new List <float>();

            foreach (GameObject obj in m_OrderedPawns)
            {
                priorityBase.Add(statistics[obj].m_Priority);
            }

            int turnCount = 0;

            while (turnCount < _count)
            {
                GameIteration iter = ComputeIteration(0, priorityBase);
                for (int i = 0; i < iter.GetCount(); ++i)
                {
                    ret.Add(iter.GetPawn(i));
                }

                turnCount += iter.GetCount();

                for (int i = 0; i < m_OrderedPawns.Count; ++i)
                {
                    priorityBase[i] += statistics[m_OrderedPawns[i]].m_PriorityIncrease;
                }
            }

            return(ret);
        }
Пример #3
0
        private GameIteration ComputeIteration(int _startPawnId, List <float> _priorityBase)
        {
            const int PRIORITY_THRESHOLD = 1;

            GameIteration iteration           = new GameIteration();
            bool          atLeastOneTurnAdded = true;

            while (atLeastOneTurnAdded)
            {
                atLeastOneTurnAdded = false;
                for (int i = _startPawnId; i < m_OrderedPawns.Count; ++i)
                {
                    if (_priorityBase[i] >= PRIORITY_THRESHOLD)
                    {
                        iteration.AddTurn(m_OrderedPawns[i]);
                        _priorityBase[i]   -= PRIORITY_THRESHOLD;
                        atLeastOneTurnAdded = true;
                    }
                }
            }

            return(iteration);
        }