Question: Python 3 code pleasw The evil Ice King has sent his army of penguins (all named Gunther) to attack the Candy Kingdom. The Candy Kingdom's

Python 3 code pleasw  Python 3 code pleasw The evil Ice King has sent his

The evil Ice King has sent his army of penguins (all named Gunther) to attack the Candy Kingdom. The Candy Kingdom's wise ruler, Princess Bubblegum, has devised a defence to ward off the invading penguin army. Princess Bubblegum's "Fish-a-pult" will lob barrels of fish onto the battlefield. This will cover an area of the battlefield with fish within which the penguins will stop to feed, and then, too full to fight, will retreat for an afternoon nap. Suppose we have a 2D integer array representing the battlefield. Each array value represents the number of penguins currently in a 1 square meter area of the battlefield. Thus, a 100 by 100 array would represent a 100m by 100m battlefield, and each value in the array is the number of penguins in the corresponding one square meter. The Fish-a-pult can fire barrels of fish of different weights. The weight of the fish barrel determines the size of the square area that will be covered by fish when the barrel explodes on impact If a barrel weighs n pounds, then it covers a square area 2n 1 meters on each side. Thus, a 1-pound barrel of fish will cover a 3m square area (corresponding to a 3 by 3 slice of the array!) Your Task Your job is to write a part of the targeting software for the Fish-a-pult. Write a function called find target_location which has the following parameters: battlefield: a 2D integer array representing the current state of the battlefield (containing the num ber of penguins at each location, as above) . fish_weight: an integer representing the weight of the barrel of fish to be fired. The weight also determines the size of the area covered by fish, as above Your function should return the optimal target location (as described below) as a tuple, e, the pair of array offsets corresponding to the location. If there is more than one location tied for the most number of penguins, it does not matter which one you return. Your task is to determine the optimal target location for a given quantity of fish. The optimal location is the battlefietd target location which, if hit with a barrel weighing fish_weight pounds, will distract the most penguins. In other words, if the fish veight is n pounds, then find the center of the 2n+1 by 2n +1 square on the battlefield containing the most penguins. This can be done fairly easily using loops and slicing. You will also find the numpy. sum) function useful You need not consider locations where the fish would land outside of the battlefield - these cannot be optimal locations. A target location where the entire detonation area lies within the battlefield grid will always be as good as or better than a target location where the detonation area falls off the grid because we know there are zero penguins outside the grid. If fish weight equals or exceeds either half of the battlefield width (not rounded), or half of the battlefield height (not rounded), then this means that the detonation area is larger than the entire battlefield. Thus there are no target locations where the detonation area falls entirely within the battlefield grid. In such a case, return None. Firing more fish than needed to cover the entire battlefield is a waste of tasty fish! The evil Ice King has sent his army of penguins (all named Gunther) to attack the Candy Kingdom. The Candy Kingdom's wise ruler, Princess Bubblegum, has devised a defence to ward off the invading penguin army. Princess Bubblegum's "Fish-a-pult" will lob barrels of fish onto the battlefield. This will cover an area of the battlefield with fish within which the penguins will stop to feed, and then, too full to fight, will retreat for an afternoon nap. Suppose we have a 2D integer array representing the battlefield. Each array value represents the number of penguins currently in a 1 square meter area of the battlefield. Thus, a 100 by 100 array would represent a 100m by 100m battlefield, and each value in the array is the number of penguins in the corresponding one square meter. The Fish-a-pult can fire barrels of fish of different weights. The weight of the fish barrel determines the size of the square area that will be covered by fish when the barrel explodes on impact If a barrel weighs n pounds, then it covers a square area 2n 1 meters on each side. Thus, a 1-pound barrel of fish will cover a 3m square area (corresponding to a 3 by 3 slice of the array!) Your Task Your job is to write a part of the targeting software for the Fish-a-pult. Write a function called find target_location which has the following parameters: battlefield: a 2D integer array representing the current state of the battlefield (containing the num ber of penguins at each location, as above) . fish_weight: an integer representing the weight of the barrel of fish to be fired. The weight also determines the size of the area covered by fish, as above Your function should return the optimal target location (as described below) as a tuple, e, the pair of array offsets corresponding to the location. If there is more than one location tied for the most number of penguins, it does not matter which one you return. Your task is to determine the optimal target location for a given quantity of fish. The optimal location is the battlefietd target location which, if hit with a barrel weighing fish_weight pounds, will distract the most penguins. In other words, if the fish veight is n pounds, then find the center of the 2n+1 by 2n +1 square on the battlefield containing the most penguins. This can be done fairly easily using loops and slicing. You will also find the numpy. sum) function useful You need not consider locations where the fish would land outside of the battlefield - these cannot be optimal locations. A target location where the entire detonation area lies within the battlefield grid will always be as good as or better than a target location where the detonation area falls off the grid because we know there are zero penguins outside the grid. If fish weight equals or exceeds either half of the battlefield width (not rounded), or half of the battlefield height (not rounded), then this means that the detonation area is larger than the entire battlefield. Thus there are no target locations where the detonation area falls entirely within the battlefield grid. In such a case, return None. Firing more fish than needed to cover the entire battlefield is a waste of tasty fish

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!