THE LIFE of a fish

The game is “Fishies in the ocean”. I made up this game. Thank you. Imagine there is an ocean. This ocean has a lot of fish. There are fishes of many different sizes. In this game, there are only 3 sizes of fish: Large (“L”), Medium(“M”), Small(“S”). Fish need to eat. So, L fish can eat a M or S fish. M fish can eat a S fish. S fish basically doesn't eat because its mouth is too small.

THE OCEAN

Imagine that each fish occupies a space in the ocean. Imagine that you are viewing this ocean sideways. So, the ocean is a two-dimensional array. Each space in this ocean is an element in this array. Each element can be empty or it can contain a maximum of one fish. The Ocean is a square: X by X dimensions. You'll need to randomly place fish in the ocean.

THE FISH

Because you know that fish like to eat each other (Sorry, vegetarians!) according to the the rules above, when a L fish eats a M fish, the M fish disappears off the ocean; M fish gets eaten! Likewise, when a S fish gets eaten, it disappears from the ocean. An L fish can't grow any bigger even if it eats many fish. However, a M fish must become a L fish if it eats AT LEAST 3 fish. You must therefore, keep track of the number of fish that each fish eats. When a fish becomes into a bigger fish, remember to RESET the value of the number of fish it has eaten before.

A fish can eat another fish if it is adjacent to it. Adjacent meaning if it is on the TOP, RIGHT, LEFT, BOTTOM of it in the array, but NOT DIAGONAL. The fish is REQUIRED to eat in this ORDER: LEFT, TOP, RIGHT, BOTTOM. It can only eat one fish at a time per turn. The bigger fish will move to that new space where the eaten fish was. If there are no fish around to eat, then the fish will move ONE SPACE DOWN if that space is not occupied. If the space is occupied, then it needs to move ONE SPACE TO THE RIGHT, if not occupied. If both are occupied, then stay still.

THE SIMULATION

So, as you've probably figured out by now, this is a simulation. Here's how the simulation works: Say you have an X by X array.

**while ( ALL FISHES are not Large or there are no more steps to do) {
for each element in the array (start with [0][0], and go row by row down to [X-1][X-1] *)
if empty: do nothing
if fish exists, then look around to see if it can eat anything
if it can't eat anything, ok move down or move right.
If it can eat something, ok, eat it and move it to that space.
}
* start with the first row and iterate through each column in that row. When you're done with that row,
continue to the next row, starting with the first column of that row. And so on. This structure should be
two nested for loops.
** Inside the while loop is where you place the two for loops. This could be an infinite loop if you are
not careful... I would use a counter with value = 2, and then work my way to a better condition.

At the end of the simulation, you'll only be left with L fishes. So keep on iterating through this two dimensional array until only L fishes remain.

Here's how i'll run your project:

> javac BigFishGame.java
> java BigFishGame X Y Z A

where X is the number of L fish in the ocean where Y is the number of M fish in the ocean where Z is the number of S fish in the ocean where A is the dimension of the ocean. So it would be an A by A size array.

I recommend testing your program on very small numbers for X,Y,Z, and 10x10 array.

OUTPUT of your program: I'll be looking for TWO outputs: THE BEGINNING of the ocean, and the END of the ocean. So, this 5x5 array would print like this:

BEGINNING:
| L | __ | M* | __ | S |
| S | M | M | __ | S |
| L | __ | __ | __ | S |
| L | __ | __ | __ | M |
| M | __ | M | __ | S |
END:
| __ | __ | __ | _ | _ |
| __ | __ | __ | _ | _ |
| __ | __ | __ | _ | _ |
| __ | __ | __ | _ | _ |
| __ | L | L | L | L |

* that M becomes an L because it ate all 3 of the S fish.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.