Freedom of Movement programmign assignment

The biologists ask if we can modify the simulation program so that the fish have more freedom of movement. We propose a hexagonal grid, which gives each fish six neighboring cells into which they can move, or the original rectangular grid with movement along the diagonals added, giving eight directions of movement. The biologists opt for the hexagonal grid. They believe that this will better reflect the variety of fish movement and they like keeping the relationships among the neighboring cells symmetric, which would not be the case for a rectangular grid with diagonal movement.

Download the following files and place them in a folder called Movement

Create new LJHS project called HexGrid and store the project in the Movement folder. Move fish.dat into the HexGrid folder. Add all *.cpp files to your project then run the project. If you have warnings with RandGen, remove randGen.cpp from your project. You should get a two-dimensional array display.

Instead of displaying spaces between the fishes in the output, display a dot ('.') for the space. Determine which class needs to be editied and then edit the file so that dots '.''s are output instead of blank spaces.

In order to change the behavior of each fish as requested by the biologists, we need to modify the relationships among the positions. We also need to determine how we can compactly represent a hexagonal grid, where each position has six neighbors. It turns out that the idea of the representation is easy. We store the positions in a two dimensional array as we did before, but we interpret each position in the array differently. If we orient the hexagonal grid as shown below, then each position has one neighbor to the right and one to the left in its own row, but two neighbors in the row above and two neighbors in the row below in directions naturally designated Northeast, Northwest, Southeast and Southwest. For example, the 5 x 4 grid shown below has the odd numbered columns shaded for clarity. Notice how the indexing of the Northeast, Northwest, Southeast and Southwest neighbors of a position depends on whether that position is an even or an odd numbered row. The diagram has the position (2, 2) indicated by an X and its six neighbors designated by NE, E, SE, SW, W, NW.

If we examine the classes making up the fish simulation program, we see the the relationship between neighbors in the two dimensional grid is effectively defined by the four Position member functions North, East, South, West. These functions are called in the Fish class member function EmptyNeighbors, which constructs a Neighborhood containing the positions to which the fish can move. Consequently, we can change the internal representation of the fish grid to a hexagonal grid by simply changing these functions appropriately. In the course of doing this we note that a small change must be made in the Neighborhood class implementation to accomodate the larger number of neighbors now possible and an adjustment to the Display class is needed to represent the new grid on screen.

  1. Prepare a plan for your modifications, as outlined below. Modify the Fish and Position class diagrams and show them to me before starting any of the below programming!
  2. Replace the four direction functions in the Position class with six functions representing the six hexagonal grid directions.
  3. Modify the Fish member function EmptyNeighbors to create a Neighborhood containing all the empty neighbors of this Fish, according to the six directions specified by the Position functions.
  4. Change the maximum number of Positions that can be stored in a Neighborhood so that all the neighbors can be accommodated. The current implementation of Neighborhood uses an explicit constant (4) in the Neighborhood constructor. In general, this is a poor design. It is better to use a named constant or to pass the value as a parameter to the Neighborhood constructor. Where would a constant specifying the number of neighbors naturally occur? Declare such a constant with value 6 and use it in place of the explicit 4.
  5. The display can approximate a hexagonal grid by indenting the odd rows half the width used for a cell. This means that for the character-based Display class that is part of thte MBCS, the WIDTH constant should be set to an even value (2 works well), and when displaying an odd row of the hexagonal grid, WIDTH/2 spaces should be inserted into the cout stream. Modify the Display class so that it displays a hexagonal grid.

You will give me a oral presentation of your project. I will not being asking any questions, unless I have a question about your presentation.

Your presentation must prove that your program works. You need to explain how you set the the fish data, what specific fish positions were testing for, the expected output, and show me that the fish movement proves your expectations.

You will also need to show me all changes in all classes that you made, and how they affected the design and outcome of the project.