The theme of this assignment has been interrupted by the evil Ice King who has sent his penguin army to attack the gentle citizens of the Candy Kingdom. Princess Bubblegum, having worked tirelessly in her science lab for a week, has developed a new weapon to combat the penguin menace: the Fish-A-Pult. The Fish-A-Pult can lob a helping of fish onto the battlefield, distracting nearby penguins from their attack long enough to eat all the fish. After a satisfying meal, the affected penguins will go to sleep, and cease their attack.
Princess Bubblegum wants you to run a battlefield simulation to optimize the effectiveness of her Fish-A-Pult. The battlefield will be represented by a 2D array representing a grid of square regions of land. This "battle grid" will have 30 columns and 15 rows (each cell represents a square of land). The Fish-A-Pult can fire between one and three pounds of fish, targeting any grid square of the battlefield.
Firing one pound of fish will cover only the target grid square with fish, halting any penguin therein.
Firing two pounds of fish will cover the grid square and all of its immediate horizontal, vertical and diagonal neighbours with fish, halting all penguins in those squares.
Firing three pounds of fish will cover the same squares around the target square as 2 pounds of fish and also all squares horizontally, vertically, and diagonally adjacent tothose squares.
FishAPult.png
We will represent the battle grid with a two dimensional array of characters.
Your Tasks
Write a function called populatePenguins() that initializes a 15 row by 30 column character array as a battle grid. This function should take one parameter, the battle grid array to be initialized. Each element of the array has a 20% chance of containing a penguin. To do this, use the randFloat()function found in the provided cpp file, which returns a random floating point value between 0.0 and 1.0. If the value returned by randFloat() is less than 0.2, the grid square should contain a penguin: set the element equal to the character 'p'. Otherwise, set the element to the space character ' '. Design and test this function before going on.
Write a function called cover() that places some fish in a single given square of the battle grid; we will use this function multiple times in task 3 (below). This function takes three parameters: a battle grid array, a row offset, and a column offset. This function should check whether the given row and column offsets are valid for the battle grid array as follows:
If either one of the given offsets is not valid, the function should return without modifying the battle grid array.
If the row and column offsets are both valid, then use them to look at the element at the given row and column of the battle grid array, as follows:
If there is a penguin 'p' there, replace it with the 'X' character to represent that this penguin has been hit by fish and therefore that it has stopped attacking.
If the element was a space (no penguin) replace the space character with an 'f' character to represent that the area has been hit by fish.
If the element already contains an 'f' or an 'X' (previously hit by fish), do nothing. Design and test this function before going on.
Write a function called fishAPult() that simulates a single shot of the Fish-A-Pult. This function takes four parameters: a battle grid array, a row offset, a column offset, and the number of pounds of fish to fire. This function must first check whether the number of pounds of fish to fire is between 1 and 3. If it is not, output an error message and return. Otherwise, make the appropriate calls to the cover() function to cover the grid square specified by the given row and column offsets with fish, as well as any surrounding grid squares (depending on the number of pounds of fish) as determined by the rules given above. Design and test this function before going on.
Write a function called runSimulation() which takes two parameters: a battle grid array, and the number of pounds of fish to fire per shot (expected to be 1, 2, or 3). The function will return the theoretical effectiveness of the amount of fish per shot, as described in part (e) below. This function should do the following to simulate the effects of firing fish at the battlefield:
a) Use the populatePenguins() function to initialize the given battle grid array.
b) Determine the number of shots that can be fired: Princess Bubblegum only has 300 pounds of fish, so given the number of pounds to fire per shot, determine how many shots can be fired (it will be either 300, 150, or 100 depending on the pounds per fish given).
c) For each shot that can be fired, make an appropriate call to fishAPult() to simulate the results of the shot. Unfortunately, and much to Princess Bubblegum's annoyance, she had to resort to unscientific and ethically questionable dark magics to make the Fish-A-Pult work, so no matter how well the Candy Kingdom soldiers aim the Fish-A-Pult, each shot lands on a random square on the battlefield! Use the randRow() and randCol() functions (from the provided cpp file) to generate random row and column offsets to pass to fishAPult(). Use a different random row and column for each shot fired.
d) Determine the total number of penguins that were stopped (by counting the number of X's now in the battle grid array). You could write a function for this. You probably should.
e) Determine how many penguins were hit per pound of fish used up (i.e. divide the number of X's in the battle grid array by 300). Have the function return this value!
In your main() program, use a loop to call runSimulation(battleGrid, 1) one thousand times, and take the average of all of the returned values. Display this value to the console as the average number of penguins stopped per pound of fish when firing one-pound shots. Repeat this process for two-pound shots, and again for three-pound shots. Sample output is given below.
Ok this is the hardest question i have to do s far and i have no idea whats going on..... Please help...
I see a lot of text and no code. You can't expect us to read this 1055 word wall of text. Get started on your stuff by using google and youtube to help you out. Write code, come back with the code and ask specific questions.