I am currently working on an agents project that involves controlling the movement of various agents (dinosaurs in this case). Each "turn" all of the dinosaurs will determine what 'food' source they need to eat and where they need to move to get it. I already have the methods to determine what it is going to move towards next-
public Object wut2Eat(ArrayList<Dinosaur> dinosaurs, ArrayList<Grass> grasses, ArrayList<Water> waters) { //0=dino 1=grass for food type if(foodStorage >= waterStorage) { //i need 2 eets da foodies if(isHerbivore()) { //i eet grassies return closestGrass(grasses); } else { //i eet dinoes return closestDinosaur(dinosaurs); } } else { //i'm a thirsty mofo return closestWater(waters); } } The three methods closestDinosaur/Grass/Water each look exactly like the following:
public Water closestWater(ArrayList<Water> waters) { Water closestWater = null; double distance; double minDistance = MAX_VALUE; for (Water water : waters) { distance = calculateDistance(this.getxLoc(), this.getyLoc(), water.getxLoc(), water.getyLoc()); if(distance < minDistance) { closestWater = water; minDistance = Double.min(minDistance, distance); } } return closestWater; } Now I have to determine which direction the current dinosaur has to move, and based off of that where it will move to.
public void move(ArrayList<Dinosaur> dinosaurs, ArrayList<Grass> grasses, ArrayList<Water> waters) { Object food = wut2Eat(dinosaurs, grasses, waters); } Each of the three objects (Dinosaur, Grass, Water) have an xLoc and yLoc that determine their position on a field. How do I get those values so that I can determine where the current dinosaur should move? I know that whatever wut2Eat returns is going to be an object with xLoc and yLoc variables with the setters and getters to go along with it. Should I put wut2Eat inside of move?