I have a problem about writing C function that will make necessary movements. If you help me, I will very happy.
Thank you for now.(Also you can send the answer to my mail
SHARKS AND FISHES In this project you will implement a simple game for an ocean containing sharks and fish. The ocean is rectangular, but the edges are connected together in a donut shape, or Toroidal fashion. This means that the top (North) and bottom (South) edges are considered adjacent, so if you start and the top edge and go up, you'll be at the bottom edge. Similarly, the East and West edges are connected. The Ocean is indexed as follows:
| 0,0 | 0,1 | 0,2 | 0,3 |
| 1,0 | 1,1 | 1,2 | 1,3 |
| 2,0 | 2,1 | 2,2 | 2,3 |
However, you can also refer to locations such as 0,4, which would be the same as 0,0 and -1,-1, which would be the same as 2,3. Any pair of integers will give you a valid position in the grid. There are 2 kinds of entities in this ocean, sharks and fish. The sharks and fish breed, die, and eat in the ocean. Each position on the grid can be occupied by a single shark or fish or it can be empty. In addition to the size of the ocean and the initial placement of sharks and fish in the ocean, the simulation is parameterized by one other value, called the starveTime for a shark; this is the number of simulation timesteps that a shark can live without eating. The simulation proceeds in timesteps. The rules for how the world looks after a timestep depend only on the values in the cells from the previous timestep. Therefore, the easiest (and in this case reasonable) way to get the desired simulation behavior is to have two copies of the ocean, one for the previous timestep which is not being changed, and one for the current timestep that is being updated. In addition, the contents of any particular position in the ocean depends only on the contents of that cells and its neighbors in the previous timesteps. "Neighbors," in this case, means the four surrounding cells to the north, south, east, and west. (Neighbors do not include diagonals.) Here are the rules: 1) If a cell contains a fish, and any of the neighbors are sharks, then the fish is eaten by a shark, and therefore disappears. 2) If a cell contains a fish and all of the neighbors are either empty or are other fish, then the fish stays where it is. 3) If a cell contains a shark, and any of it neighbors are fish, then the shark stays where it is, but it assumed to have eaten in this timestep. (Note that we may have multiple sharks eating the same fish. This is fine, we'll assume they all can get enough to eat.)
4) If a cell contains a shark, and none of its neighbors are fish, it gets hungrier. If the last timestep in which the shark ate was more than starveTime ago, then the shark dies (disappears). 5) If a cell is empty and at least three of its neighbor are fish, then a new fish is born in that cell. 6) If a cell is empty and at least three of its neighbor are sharks, then a new shark is born in that cell. Sharks are assumed to be well-fed at birth, so the can live for starveTime timesteps without eating. Note on starveTime: ------------------ The following example will demonstrate exactly when sharks will die. Assume the starveTime is . At the start of the simulation, call it time 0, all of the sharks have been fed. A shark that does not ever get to eat will exist in timesteps 0 through 3, but at timestep 4, the shark will not exist. Similarly, if a shark is fed at time 3, but not after that, it will live through timestep 6, but will not exist in timestep 7. Time 0 shark A born shark B born Time 1 Time 2 Time 3 shark B eats a fish that was in time 2 Time 4 shark A does not exist Time 5 Time 6 Time 7 shark B does not exit A shark is well-fed at birth, so a shark born in time 3 would also live through time 6 but not exist in time 7 if it did not eat. Create an Ocean of size MxN and run a simulation for a given time unit. Your program should output the contents of the ocean at each step. At each step sharks or fishes may be added to the ocean or die depending on the above rules.
1 post •Page 1 of 1