private void CreateAnts() { Rectangle worldLimits; // 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); // create a couple of agents at some postions agent1 = new AntAgent(new SOFT152Vector(100, 150), randomGenerator, worldLimits); agent2 = new AntAgent(new SOFT152Vector(200, 150), randomGenerator, worldLimits); agent3 = new AntAgent(new SOFT152Vector(300, 150), randomGenerator, worldLimits); // create an object at a arbitary position someObject = new SOFT152Vector(250, 250); //create a 2nd object at an arbitrary position foodObject = new SOFT152Vector(50, 50); //create a nest object at an arbitrary position nest1 = new NestObject(new SOFT152Vector(50, 100)); //create a food object at an arbitrary position food1 = new FoodObject(new SOFT152Vector(100, 50), 100); }
private void CreateAgressiveAnts(SOFT152Vector position) { AgressiveAntAgent tempBadGuy; Rectangle worldLimits; 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 = 10; //Creates all aggressive ants and adds them to the correct list for (int i = 0; i < antLimit; i++) { tempBadGuy = new AgressiveAntAgent(position, randomGenerator, worldLimits); agressiveAntList.Add(tempBadGuy); agressiveAntList[i].AgentSpeed = 1.5; agressiveAntList[i].WanderLimits = 0.25; } }
/// <summary> /// Creates a worker ant nest /// </summary> /// <param name="position">The position that the nest should be placed in</param> private void CreateWorkerNest(SOFT152Vector position) { WorkerAntNest tempNest; tempNest = new WorkerAntNest(position); workerNestList.Add(tempNest); }
/// <summary> /// Creates a nest for the aggressive ants /// </summary> /// <param name="position">The position for the nest to be placed at</param> private void CreateAgressiveNest(SOFT152Vector position) { AgressiveAntNest tempNest; tempNest = new AgressiveAntNest(position); agressiveNestList.Add(tempNest); }
/// <summary> /// Creates a food source for the worker ants to collect from /// </summary> /// <param name="position"> The position at which the food source should be created </param> private void CreateFoodSource(SOFT152Vector position) { Food tempFood; tempFood = new Food(position); foodList.Add(tempFood); }
/// <summary> /// Returns the Distance between the ant and a given SOFT152Vector /// </summary> /// <param name="objectPosition">Current position of SOFT152Vector that you want to work out the distance to</param> /// <returns>The distance between the ant agent and the SOFT152Vector</returns> public double DistanceTo(SOFT152Vector objectPosition) { double distance; distance = Math.Sqrt(Math.Pow((agentPosition.X - objectPosition.X), 2) + Math.Pow((agentPosition.Y - objectPosition.Y), 2)); return(distance); }
public AntAgent(SOFT152Vector position, Random random) { agentPosition = new SOFT152Vector(position.X, position.Y); randomNumberGenerator = random; InitialiseAgent(); }
/// <summary> /// Checks to see whether two vectors are the same /// </summary> /// <param name="primaryVector">The first value</param> /// <param name="secondaryVector">And the value that the first one is being compared to</param> /// <returns></returns> private bool MatchingVectors(SOFT152Vector primaryVector, SOFT152Vector secondaryVector) { if (primaryVector.X == secondaryVector.X && primaryVector.Y == secondaryVector.Y) { return(true); } return(false); }
/// <summary> /// Food constructor to initialise the food source object /// with a given SOFT152Vector position and the food pieces /// available at the food source. /// </summary> /// <param name="foodPosition">The SOFT152Vector with X and Y coordinates of where to create the food source.</param> /// <param name="foodPieces">The number of pieces of food to create.</param> public Food(SOFT152Vector foodPosition, int foodPieces) { FoodPosition = new SOFT152Vector(foodPosition.X, foodPosition.Y); foodAvailable = foodPieces; isFoodDepleted = false; }
/// <summary> /// Nest constructor to initialise the nest object, /// providing the SOFT152Vector position to create the object. /// </summary> /// <param name="nestPosition">The SOFT152Vector with X and Y coordinates of where to create the nest.</param> public Nest(SOFT152Vector nestPosition) { // Initialise the position of the nest as a vector. NestPosition = new SOFT152Vector(nestPosition.X, nestPosition.Y); // Keep track of the total food pieces deposited at the nest object. foodDeposited = 0; }
public FoodPile(SOFT152Vector position) { //the units of the food object Quantity = 30; //the position of the food object foodPosition = new SOFT152Vector(position.X, position.Y); }
public AntAgent(SOFT152Vector position, Random random, Rectangle bounds) { agentPosition = new SOFT152Vector(position.X, position.Y); worldBounds = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height); randomNumberGenerator = random; InitialiseAgent(); }
/// <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); }
/// <summary> /// Food constructor to initialise the food source object, /// providing the SOFT152Vector position to create the object. /// </summary> /// <param name="foodPosition">The SOFT152Vector with X and Y coordinates of where to create the food source.</param> public Food(SOFT152Vector foodPosition) { FoodPosition = new SOFT152Vector(foodPosition.X, foodPosition.Y); // An initial size of a 200 pieces in each food source. foodAvailable = 200; // A Boolean value as a state which can change when // the food source is empty. isFoodDepleted = false; }
/// <summary> /// Initialises the Agents various fields /// with default values /// </summary> private void InitialiseAgent() { wanderPosition = new SOFT152Vector(); ApproachRadius = 15; AvoidDistance = 15; AgentSpeed = 1.0; ShouldStayInWorldBounds = true; WanderLimits = 0.5; }
/// <summary> /// Initialises the Agents various fields /// with default values /// </summary> private void InitialiseAgent() { wanderPosition = new SOFT152Vector(); ShouldStayInWorldBounds = true; ApproachRadius = 10; AvoidDistance = 25; AgentSpeed = 1.0; WanderLimits = 0.5; Forgetfulness = 20; // out of 10000 }
/// <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); }
/// <summary> /// Initialises the Agents various fields /// with default values. /// </summary> private void InitialiseAgent() { wanderPosition = new SOFT152Vector(); ApproachRadius = 10; AvoidDistance = 25; AgentSpeed = 1.0; ShouldStayInWorldBounds = true; WanderLimits = 0.5; IsNewClosestAnt = false; IsFoodKnown = false; IsNestKnown = false; IsCarryingFood = false; }
private void drawingPanel_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { SOFT152Vector position; position = new SOFT152Vector(e.Location.X, e.Location.Y); CreateFoodSource(position); } else if (e.Button == MouseButtons.Right) { SOFT152Vector position; position = new SOFT152Vector(e.Location.X, e.Location.Y); CreateWorkerNest(position); } else if (e.Button == MouseButtons.Middle) { SOFT152Vector position; position = new SOFT152Vector(e.Location.X, e.Location.Y); CreateAgressiveNest(position); CreateAgressiveAnts(position); } }
private void CreateAnts() { Rectangle worldLimits; // 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); for (int i = 0; i < noOfAnts; i++) { antGroup[i] = new AntAgent(new SOFT152Vector(randomGenerator.NextDouble() * drawingPanel.Width, randomGenerator.NextDouble() * drawingPanel.Height), randomGenerator, worldLimits); antGroup[i].HasFood = false; antGroup[i].KnowsFood = false; antGroup[i].KnowsNest = false; //set moving values for all the ants in the antGroup antGroup[i].AgentSpeed = 1.0; antGroup[i].WanderLimits = 0.25; //keep all the antAgents in the antGroup in the world antGroup[i].ShouldStayInWorldBounds = true; } // create an object at a arbitary position someObject = new SOFT152Vector(250, 250); anotherObject = new SOFT152Vector(50, 50); }
public NestObject(SOFT152Vector position) { nestPosition = new SOFT152Vector(position.X, position.Y); }
public Food(SOFT152Vector postion, int amount) { location = postion; quantity = amount; isEmpty = false; }
public Food(SOFT152Vector position) { location = position; quantity = 100; isEmpty = false; }
public AgressiveAntNest(SOFT152Vector position) : base(position) { location = position; }
public FoodObject(SOFT152Vector position, int value) { foodPosition = new SOFT152Vector(position.X, position.Y); foodValue = 100; }
public FoodObject(SOFT152Vector position) { foodPosition = new SOFT152Vector(position.X, position.Y); }
public RobberNest(SOFT152Vector position) { NestPosition = new SOFT152Vector(position.X, position.Y); NestSize = 20; }
/// <summary> /// Causes the agent to make one step towards the object at objectPosition /// The speed of approach will reduce one this agent is within /// an ApproachRadius of the objectPosition /// </summary> /// <param name="agentToApproach"></param> public void Approach(SOFT152Vector objectPosition) { Steering.MoveTo(agentPosition, objectPosition, AgentSpeed, ApproachRadius); StayInWorld(); }
/// <summary> /// Causes the agent to make one step away from the objectPosition /// The speed of avoid is goverened by this agents speed /// </summary> public void FleeFrom(SOFT152Vector objectPosition) { Steering.MoveFrom(agentPosition, objectPosition, AgentSpeed, AvoidDistance); StayInWorld(); }
public Food(SOFT152Vector position) { FoodPosition = new SOFT152Vector(position.X, position.Y); FoodSize = 20; }