Question: Question 1: Scattering sheep (3 points) Write a function that randomly places the sheep in the field above the fence. It should take as an

Question 1: Scattering sheep (3 points) Write a function that randomly places the sheep in the field above the fence. It should take as an argument the system_state, the number of sheep to place (N), and a fenceline parameter that describes the y-position of the fence. It should return a new state with the sheep Importantly, the sheep cannot overlap with anything that is not empty space (i.e. stateltry_y, try_x] must equal zero), and the sheep must be placed above the fencelinel In from copy import copy def place_sheep (state, N, fenceline): newstate-copy (state) sheep_placed- while sheep_placedN: # suggest somewhere for a sheep to be placed try_T- # hint: use np. random. randint try-x- # # check if this is appropriate # if yes, set good-place to True. if no, set good-place to False. # if good, place the sheep, if not try again if good_place is True: sheep-placed 1 newstateltry-y, try-x) 2 = return newstate Let's call this state initial_state since we'll use it to start our agent-based model simulations. The following should plot your new system. Run it a few times and make sure it always gives you something appropriate. In initial state place_sheep (system_state, 20, fenceline) plt. figure(figsize= (10, 10)) plotstate initialstate)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
