import java.util.ArrayList; import java.util.Random; import java.awt.Color; //Anchovy school leader public class Anchovy extends Fish{ static Environment theEnv = env; static Location myLoc = loc; static Location st = randomSchoolTarget(); static Direction myDir; public Anchovy(Environment env, Location loc) { // Construct and initialize the attributes inherited from Fish. super(env, loc, env.randomDirection(), Color.yellow); } public boolean isInEnv(){ return environment().objectAt(location()) == this; } public void act(){ if(isInEnv(){ move(); } } protected void move(){ // Find a location to move to. Debug.print("Fish " + toString() + " attempting to move. "); Location nextLoc = nextLocation(); // If the next location is different, move there. if ( ! nextLoc.equals(location()) ) { // Move to new location. Location oldLoc = location(); changeLocation(nextLoc); // Update direction in case fish had to turn to move. Direction newDir = environment().getDirection(oldLoc, nextLoc); changeDirection(newDir); Debug.println(" Moves to " + location() + direction()); } else Debug.println(" Does not move."); } protected Location nextLocation(){ return st; } protected ArrayList emptyNeighbors(){ ArrayLits nbrs = environment().neighborsOf(location()); ArrayList emptyNbrs = new ArrayList(); for ( int index = 0; index < nbrs.size(); index++ ) { Location loc = (Location) nbrs.get(index); if ( environment().isEmpty(loc) ) emptyNbrs.add(loc); } return emptyNbrs; } public Location randomSchoolTarget(){ int r; int c; Random randomNumGen = RandumNumGenerator.getInstance(); r = randomNumGen.nextInt(theEnv.numRows()); c = randomNumGen.nextInt(theEnv.numCols()); Location temploc = new Location(r,c) return temploc; } }