public void Eval(WObject o) { if (o.getPos() == destination || o.getPos() == waypoint) { Use(o.getUtil()); } }
public void AddKnowledge(WObject o) { if (knowledge.Contains(o)) { knowledge.Remove(o); } knowledge.Add(o); }
public void resolveUD(WObject wobject) { if (position.X > wobject.getPos().X) //horizontal position reset to right of object { newPos(wobject.getPos().X + wobject.sprite.Width, position.Y); } else //horizontal position reset to left of object { newPos(wobject.getPos().X - sprite.Width, position.Y); } }
public void resolveLR(WObject wobject) { CDresolved = false; if (position.Y > wobject.getPos().Y) //vertical position reset to under object { newPos(position.X, wobject.getPos().Y + wobject.sprite.Height); } else //vertical position reset to above object { newPos(position.X, wobject.getPos().Y - sprite.Height); } }
public Agent(Texture2D spriteSheet, Vector2 startPos, int logicNum, int id) : base(spriteSheet, startPos) { agentID = id; setLogicType = logicNum; energy = 100; setDest(D1); waypoints = new Stack<Vector2>(); util = new Utility(1000,1000,0); util.setDecay(HUNGER_DECAY, ENERGY_DECAY, FOOD_DECAY); util.setRecover(0,0,0); plan = new List<int>(); knowledge = new List<WObject>(); property = new List<WObject>(); people = new List<Agent>(); goal = new Utility(0,0,0); goalObject = null; home = null; }
public void resolveLR(WObject wobject) { CDresolved = false; if (position.Y > wobject.getPos().Y) //vertical position reset to under object { newPos(position.X, wobject.getPos().Y + wobject.sprite.Height); } else //vertical position reset to above object { newPos(position.X, wobject.getPos().Y - sprite.Height); } if (destination.X < wobject.getPos().X) //waypoint set to the left { waypoint = new Vector2(wobject.getPos().X - sprite.Width, position.Y); } else { waypoint = new Vector2(wobject.getPos().X + wobject.sprite.Width, position.Y); } _addWP(waypoint); WPSet = true; }
public void resolveUD(WObject wobject) { if (position.X > wobject.getPos().X) //horizontal position reset to right of object { newPos(wobject.getPos().X + wobject.sprite.Width, position.Y); } else //horizontal position reset to left of object { newPos(wobject.getPos().X - sprite.Width, position.Y); } if (destination.Y < wobject.getPos().Y) //waypoint set to above object { waypoint = new Vector2(position.X, wobject.getPos().Y - sprite.Height); } else //waypoint set below object { waypoint = new Vector2(position.X, wobject.getPos().Y + wobject.sprite.Height); } _addWP(waypoint); WPSet = true; }
public void AddProperty(WObject o) { if (property.Contains(o)) { property.Remove(o); } property.Add(o); }
private void nearestRest() { WObject choice = null; //searches property first, since all options are safer. //Will only use unowned sources if no property in range. double range = (util.energy * speed); if (distanceTo(home) < range) { choice = home; } else { foreach (WObject o in property) { if (distanceTo(o) < range) { if (choice == null) choice = o; else { if (choice.getUtil().energy < o.getUtil().energy) { if (distanceTo(o) < distanceTo(choice)) choice = o; } } } } if (choice == null) //No food owned, look for any food { foreach (WObject o in knowledge) { if (distanceTo(o) < range) { if (choice == null) choice = o; else { if (choice.getUtil().energy < o.getUtil().energy) { if (distanceTo(o) < distanceTo(choice)) choice = o; } } } } } } if (choice == null) { //Rest where they lie setDest(getPos()); sleepHere = true; } else { setDest(choice.getPos()); goalObject = choice; destSet = true; action = SLEEP; } }
private void nearestFood() { WObject choice = null; //searches property first, since all options are safer. //Will only use unowned sources if no property in range. double range = (util.hunger * speed); foreach (WObject o in property) { if (distanceTo(o) < range && o.getUtil().foodStores > 0) { if (choice == null) choice = o; else { if (choice.getUtil().hunger < o.getUtil().hunger && o.getUtil().foodStores > 0) { if(distanceTo(o) < distanceTo(choice)) choice = o; } } } } if (choice == null) //No food owned, look for any food { foreach (WObject o in knowledge) { if (distanceTo(o) < range && o.getUtil().foodStores > 0) { if (choice == null) choice = o; else { if (choice.getUtil().hunger < o.getUtil().hunger && o.getUtil().foodStores > 0) { if (distanceTo(o) < distanceTo(choice)) choice = o; } } } } } if (choice == null) { //Wait to die. So sad :( setDest(getPos()); } else { setDest(choice.getPos()); goalObject = choice; destSet = true; action = EAT; } }
private Boolean getFoodSource() { //Console.WriteLine("getFoodSourceCalled"); WObject choice = null; int i = 1; foreach (WObject o in property) { //Console.WriteLine("Iteration " + i); i++; if (o.getUtil().foodStores > 0) { if (choice == null) choice = o; else { if (o.getUtil().foodStores > choice.getUtil().foodStores) { choice = o; } } } } if (choice != null) { setDest(choice.getPos()); destSet = true; goalObject = choice; action = WORK; return true; } return false; }
private void feedSelf() { WObject choice = null; //Only searches property to find food. Distance does not matter. foreach (WObject o in property) { if (choice == null && o.getUtil().foodStores > 0) choice = o; else if (choice != null) { if (choice.getUtil().hunger < o.getUtil().hunger && o.getUtil().foodStores > 0) { if (distanceTo(o) < distanceTo(choice)) choice = o; } } } if (choice != null) { setDest(choice.getPos()); goalObject = choice; destSet = true; action = EAT; } }
private double distanceTo(WObject o) { double f = Math.Sqrt(Math.Pow(o.getPos().X - getPos().X, 2) + Math.Pow(o.getPos().Y - getPos().Y, 2)); return f; }
public Boolean Use(WObject o) { //Console.WriteLine("Goal stores = " + goalObject.util.foodStores); //Console.WriteLine("Goal hunger = " + goalObject.util.hunger); //Console.WriteLine("Goal energy = " + goalObject.util.energy); if (action.CompareTo(EAT) == 0) { util.Add(o.Eat()); util.foodStores = home.util.foodStores; } else if (action.CompareTo(SLEEP) == 0) { util.Add(o.Sleep()); home.util.foodStores = util.foodStores; } else if (action.CompareTo(WORK) == 0) { util.Add(o.Work()); home.util.foodStores = util.foodStores; } if (o.util.foodStores <= 0) return true; return false; }
public void resolveCollide(WObject o) { }