how do you have it so that if a fish sees a peise of food it swims to it.


public void find() { java.util.List zom = getObjectsInRange(50,food.class); int z = zom.size(); if( z>=1) { java.util.List foodList = getNeighbours(100, true, food.class); turnTowards(foodList.get(0)); } }
public void find() { // find the closest piece of food within 50 of 'this' int distance = 1; while (distance < 51 && getObjectsInRange(distance, food.class).isEmpty()) distance++; if (distance == 51) return; // no food found in range turnTowards(getObjectsInRange(distance, food.class).get(0)); // closest piece found }