Пример #1
0
        /// <summary>
        /// Conduct the events a normal ant AntAgent object.
        /// The action will be determined based on it's current status (e.g. if it is moving to a food source,
        /// if it is depositing food at a nest).
        /// </summary>
        /// <param name="ant">The AntAgent for which to conduct the appropriate action for (based on it's current status).</param>
        private void AntAction(AntAgent ant)
        {
            // Based on if the ant is at or moving to food or nest.
            // The ant can be forgetful, so we need to make sure it knows where food is as it moves.
            if (ant.IsMovingToFood && ant.IsFoodKnown)
            {
                ant.Approach(ant.FoodLocation);

                // See if the ant is at the nest or food source currently.
                if (ant.AgentPosition.Distance(ant.FoodLocation) < 1)
                {
                    FoodAntAction(ant);
                }
            }
            else if (ant.IsMovingToNest && ant.IsNestKnown)
            {
                ant.Approach(ant.NestLocation);

                // If the ant is currently at the nest.
                if (ant.AgentPosition.Distance(ant.NestLocation) < 1)
                {
                    NestAntAction(ant);
                }
            }
            else
            {
                GenericAntAction(ant);
            }
        }
Пример #2
0
        /// <summary>
        /// Conduct the events that a robber AntAgent object undertakes in the ant world.
        /// </summary>
        /// <param name="robberAnt">The robber AntAgent object to undertake the appropriate action in the current condition.</param>
        private void RobberAntAction(AntAgent robberAnt)
        {
            if (robberAnt.IsMovingToFood)
            {
                // Approach location of the target ant with possible food.
                robberAnt.Approach(robberAnt.FoodLocation);

                if (robberAnt.AgentPosition.Distance(robberAnt.FoodLocation) < 5)
                {
                    RobberFoodAntAction(robberAnt);
                }
            }
            else if (robberAnt.IsMovingToNest)
            {
                robberAnt.Approach(robberAnt.NestLocation);

                // If the robber ant is currently at the nest.
                if (robberAnt.AgentPosition.Distance(robberAnt.NestLocation) < 1)
                {
                    RobberNestAntAction(robberAnt);
                }
            }
            else
            {
                GenericAntAction(robberAnt);
            }
        }
Пример #3
0
        private void timer_Tick(object sender, EventArgs e)
        {
            SOFT152Vector tempPosition;

            // one each time tick each of the two agents makes one movment

            // set some values for agent1
            // before it moves
            agent1.AgentSpeed   = 1.0;
            agent1.WanderLimits = 0.25;

            // keep the agent within the world
            agent1.ShouldStayInWorldBounds = true;

            // let agent1 wander
            agent1.Wander();


            // again set some values for agent2 before moving
            // agent2 is slower than agent1 to show some following behaviour
            agent2.AgentSpeed = 0.9;

            agent2.AvoidDistance           = 100;
            agent2.ShouldStayInWorldBounds = true;

            agent3.AgentSpeed              = 1.0;
            agent3.WanderLimits            = 0.25;
            agent3.ShouldStayInWorldBounds = true;

            agent3.Wander();

            // get agent1 position
            tempPosition = agent1.AgentPosition;

            // agent2.FleeFrom(tempPosition);

            agent2.Approach(tempPosition);


            // or get the agent to approach or flee from the stationary object

            //    agent2.Approach(someObject);


            // after making a movement, now draw the agents
            // DrawAgents();

            DrawAgentsDoubleBuffering();
        }