# Supplemental Example: Fast Fish

## Problem Specification

The marine biologists decided that they would also like faster-moving fish in the simulation. In particular, the biologists decided that:

• A fast fish can move one or two cells away in a single timestep, in any of the four directions. It can only move to an empty location two cells away if the first cell in the two-step sequence is empty also. In other words, if an immediately adjacent location is empty, the fast fish looks at the cell beyond it in the same direction to see if it is empty also. The left diagram below shows all the possible neighboring locations (~) of a fast fish (F). The diagram on the right shows how neighboring fish (N) can block the fast fish from moving to some of its empty neighboring locations (the ones marked X). Fast fish, like other fish, move only if they do not breed.
```           ~                   X
~                   N
~ ~ F ~ ~           X N F ~ ~
~                   ~
~                   ~
```

The key to the movement of fast fish is the way they choose the empty neighboring locations to which they could move.  Fast fish move within a wider neighborhood than just their immediately adjacent neighbors. You may want to create a new method, `findMoveLocs`, that would find the possible move locations in the wider neighborhood, and then redefine the `nextLocation` method to call `findMoveLocs` rather than calling `emptyNeighbors`.

#### Analysis Question:

• Why would it be a good idea to introduce the `findMoveLocs` method instead of redefining the behavior of the `emptyNeighbors` method?

As you design your implementation of the fast fish subclass, be sure to consider fast fish in different locations and with neighbors in different locations, as in the two examples above or the example below.  For each configuration, identify the locations to which the fast fish might move.  Then develop test cases and expected results to test your new fast fish subclass.

```       F  ~  ~  ~
~  ~  ~  ~
~  ~  ~  ~
~  ~  ~  ~```

You might want to make all fast fish one color (such as cyan) to help them show up as you run the simulation, just as Pat did for darters and slow fish.  Then develop an initial configuration file that contains fast fish (or a mixture of fast fish and your other `Fish` subclasses).  Test your new subclass using the test cases you developed earlier.

## Refactoring Variant

Sometimes when adding functionality to a program, you realize that you could have designed it differently in the first place in a way that would make it easier to modify now. You might even decide that it's worth going back and changing the original before making your new changes. This is called refactoring.

Modify the `Fish` class to break up the `nextLocation` method and create a `findMoveLocs` method there. Which pieces of the current `nextLocation` method in `Fish` should stay in `nextLocation` and which should move to `findMoveLocs`? If you design this correctly, neither `DarterFish` nor `SlowFish` will have to change at all, and your new fast fish subclass will only have to redefine `findMoveLocs`, not `nextLocation`.

#### Analysis Question:

• What are the advantages or disadvantages of refactoring the `Fish` class in this way?