예제 #1
0
        /// <summary>
        /// This method is called in every simulation round, regardless of additional
        /// conditions. It is ideal for actions that must be executed but that are not
        /// addressed by other methods.
        /// Read more: "http://wiki.antme.net/en/API1:Tick"
        /// </summary>
        public virtual void Tick()
        {
            // Initialize if not yet done
            if (!initialized)
            {
                Init();
            }

            // Clean up cache
            _cache.Cleanup();

            // Return to anthill if remaining distance is barely enough to reach anthill or ant low on health
            if (MaximumRange - WalkedRange - MaximumRange * 0.02 < GetDistanceTo(Anthill) ||
                _ant.CurrentEnergy < _ant.MaximumEnergy * 0.15)
            {
                GoToAnthill();
                return;
            }

            // Calculate next target and move to it if set
            Target nextTarget = GetNextTarget();

            if (nextTarget != null)
            {
                GoTo(nextTarget);
            }

            // Calculate next signal and emit it if set
            Signal nextSignal = GetNextSignal();

            if (nextSignal != null)
            {
                EmitSignal(nextSignal);
            }
        }