コード例 #1
0
ファイル: AntFoodForm.cs プロジェクト: HungryHorse/AntFarm
 /// <summary>
 /// Returns true of false in regards to whether an ant knows about a destroyed food source
 /// </summary>
 /// <param name="ant">The ant that is having its memory checked</param>
 /// <param name="passingVector">The location of the proposed nest</param>
 /// <returns></returns>
 private bool KnowsDestoryedFoodSource(WorkerAntAgent ant, SOFT152Vector passingVector)
 {
     foreach (SOFT152Vector vector in ant.usedUpFoodList)
     {
         if (MatchingVectors(vector, passingVector))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #2
0
ファイル: AntFoodForm.cs プロジェクト: HungryHorse/AntFarm
        /// <summary>
        /// Creates all the ants when the simulation is first executed
        /// </summary>
        private void CreateAnts()
        {
            antList          = new List <WorkerAntAgent>();
            agressiveAntList = new List <AgressiveAntAgent>();
            WorkerAntAgent    tempAgent;
            AgressiveAntAgent tempBadGuy;
            Rectangle         worldLimits;
            int randX;
            int randY;
            int antLimit;

            // create a radnom object to pass to the ants
            randomGenerator = new Random();

            // define some world size for the ants to move around on
            // assume the size of the world is the same size as the panel
            // on which they are displayed
            worldLimits = new Rectangle(0, 0, drawingPanel.Width, drawingPanel.Height);

            // sets the number of ants to make
            // TODO: allow user to delcare
            antLimit = 100;

            // generates ants in random locations and adds them to the dynamic list
            for (int i = 0; i < antLimit; i++)
            {
                randX     = randomGenerator.Next(0, worldLimits.Width + 1);
                randY     = randomGenerator.Next(0, worldLimits.Height + 1);
                tempAgent = new WorkerAntAgent(new SOFT152Vector(randX, randY), randomGenerator, worldLimits);
                antList.Add(tempAgent);
                antList[i].AgentSpeed     = 1.0;
                antList[i].WanderLimits   = 0.25;
                antList[i].usedUpFoodList = new List <SOFT152Vector>();

                // keep the agent within the world
                antList[i].ShouldStayInWorldBounds = true;
            }

            someObject = new SOFT152Vector(250, 250);
        }