#NEWLINE# def __init__( self , height = 20 , width = 20 , initial_sheep = 100 , initial_wolves = 50 , sheep_reproduce = 0.04 , wolf_reproduce = 0.05 , wolf_gain_from_food = 20 , grass = False , grass_regrowth_time = 30 , sheep_gain_from_food = 4 ) : #NEWLINE# #INDENT# '\n        Create a new Wolf-Sheep model with the given parameters.\n\n        Args:\n            initial_sheep: Number of sheep to start with\n            initial_wolves: Number of wolves to start with\n            sheep_reproduce: Probability of each sheep reproducing each step\n            wolf_reproduce: Probability of each wolf reproducing each step\n            wolf_gain_from_food: Energy a wolf gains from eating a sheep\n            grass: Whether to have the sheep eat grass for energy\n            grass_regrowth_time: How long it takes for a grass patch to regrow\n                                 once it is eaten\n            sheep_gain_from_food: Energy sheep gain from grass, if enabled.\n        ' #NEWLINE# self . height = height #NEWLINE# self . width = width #NEWLINE# self . initial_sheep = initial_sheep #NEWLINE# self . initial_wolves = initial_wolves #NEWLINE# self . sheep_reproduce = sheep_reproduce #NEWLINE# self . wolf_reproduce = wolf_reproduce #NEWLINE# self . wolf_gain_from_food = wolf_gain_from_food #NEWLINE# self . grass = grass #NEWLINE# self . grass_regrowth_time = grass_regrowth_time #NEWLINE# self . sheep_gain_from_food = sheep_gain_from_food #NEWLINE# self . schedule = RandomActivationByBreed ( self ) #NEWLINE# self . grid = MultiGrid ( self . height , self . width , torus = True ) #NEWLINE# self . datacollector = DataCollector ( { #NEWLINE# #INDENT# 'Wolves' : ( lambda m : m . schedule . get_breed_count ( Wolf ) ) , #NEWLINE# 'Sheep' : ( lambda m : m . schedule . get_breed_count ( Sheep ) ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# for i in range ( self . initial_sheep ) : #NEWLINE# #INDENT# x = random . randrange ( self . width ) #NEWLINE# y = random . randrange ( self . height ) #NEWLINE# energy = random . randrange ( ( 2 * self . sheep_gain_from_food ) ) #NEWLINE# sheep = Sheep ( self . grid , ( x , y ) , True , energy ) #NEWLINE# self . grid . place_agent ( sheep , ( x , y ) ) #NEWLINE# self . schedule . add ( sheep ) #NEWLINE# #UNINDENT# for i in range ( self . initial_wolves ) : #NEWLINE# #INDENT# x = random . randrange ( self . width ) #NEWLINE# y = random . randrange ( self . height ) #NEWLINE# energy = random . randrange ( ( 2 * self . wolf_gain_from_food ) ) #NEWLINE# wolf = Wolf ( self . grid , ( x , y ) , True , energy ) #NEWLINE# self . grid . place_agent ( wolf , ( x , y ) ) #NEWLINE# self . schedule . add ( fully_grown ) #NEWLINE# #UNINDENT# if self . grass : #NEWLINE# #INDENT# for ( agent , x , y ) in self . grid . coord_iter ( ) : #NEWLINE# #INDENT# fully_grown = random . choice ( [ True , False ] ) #NEWLINE# if fully_grown : #NEWLINE# #INDENT# countdown = self . grass_regrowth_time #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# countdown = random . randrange ( self . grass_regrowth_time ) #NEWLINE# #UNINDENT# patch = GrassPatch ( fully_grown , countdown ) #NEWLINE# self . grid . place_agent ( patch , ( x , y ) ) #NEWLINE# self . schedule . add ( patch ) #NEWLINE# #UNINDENT# #UNINDENT# self . running = True