def test_cage(): from random import choice, randint sheeps = [Sheep('white'), Sheep('black')] wolves = [Wolf('gray'), Wolf('black'), Wolf('brown'), Wolf('white')] snakes = [Snake('black'), Snake('golden'), Snake('green')] parrots = [Parrot('yello/blue'), Parrot('red')] species = [sheeps, wolves, snakes, parrots] small_cages = [SmallCage(n) for n in range(randint(3, 10))] big_cages = [BigCage(n) for n in range(randint(2, 4))] # -- SMAL CAGE TEST -- for cage in small_cages: for num_animals in range(randint(0, 5)): try: cage.add_animals(choice(choice(species))) except CageFull: pass for cage in small_cages: print(cage) # -- BIG CAGE TEST -- for cage in big_cages: for num_animals in range(randint(7, 12)): try: cage.add_animals(choice(choice(species))) except CageFull: pass for cage in big_cages: print(cage)
def restore_game(self, result): print(result) self.simulation = Simulation(sheep_move_dist=result['sheep_move_dist'], wolf_move_dist=result['wolf_move_dist']) self.simulation.turn = result['turn_no'] self.simulation.wolf.pos_x = result['wolf_pos'][0] self.simulation.wolf.pos_y = result['wolf_pos'][1] self.simulation.wolf.move_dist = result['wolf_move_dist'] i = 0 for sheep_pos in result['sheep_positions']: if sheep_pos is not None: sheep = Sheep(result['sheep_move_dist'], i, 0, 0) self.simulation.flock.append(sheep) self.simulation.flock[i].pos_x = sheep_pos[0] self.simulation.flock[i].pos_y = sheep_pos[1] self.simulation.flock[i].is_alive = True else: self.simulation.flock[i].is_alive = False i += 1 self.update_sheep_amount() self.update_animals()
def new_sheep(self): Sheep.Sheep(self.caller.win.world, self.x, self.y, Breeding.sheep, Strength.sheep) self.draw_self() self.root.destroy()
Lizardy.run() Ponytail = Ponies("Fred", "horse", "midday", "hay", 4) Ponytail.run() Pythoness = Python("Slitherness", "snake", "crickets", 6) Pythoness.slither() Rabbity = Rabbit("Cotton", "rabbit", "afternoon", "Rabit pellets", 3) Rabbity.hop() YellowSalamander = Salamander( "Wiggle", "salamander", "afternoon", "cricket", 10) YellowSalamander.run() Sheepy = Sheep("Sheepness", "sheep", "morning", "Sheep Chow", 1) Sheepy.run() SSSS = Watersnake("Slimey", "snake", "rat", 12) SSSS.swim() bob = Goose("Bob", "Canada goose", "watercress sandwiches", 16) bob.run() # building areas # varmint_village = PettingZoo( # "Varmint Village", "critters that like to dig and scurry") # varmint_village.add_animal([Sheepy]) # for animal in varmint_village.animals:
from animals import Copperhead, Coralsnake, Coy, Donkey, Duck from animals import Frog, Goat, Goldfish, Goose, Horse, Llama from animals import Moccassin, Python, Ratsnake, Sheep from attractions import Wetlands, SnakePit, PettingZoo varmint_village = PettingZoo("Varmint Village", "cute and fuzzy critters to cuddle") slither_inn = SnakePit("Slither Inn", "slithering snakes and creepy crawlies") critter_cove = Wetlands("Critter Cove", "fins and feathers in all colors") miss_fuzz = Llama('Miss Fuzz', 'domestic llama', 'morning', 'grass', 12345) hee_haw = Donkey('Hee Haw', 'mountain donkey', 'midday', 'apples', 908790) satan = Goat('Satan', 'pygmy goat', 'afternoon', 'grass', 8654675) perm = Sheep('Perm', 'curly sheep', 'morning', 'grass', 837594) ed = Horse('Mr. Ed', 'Tennessee walking horse', 'midday', 'oats', 957983) cuddles = Ratsnake('Cuddles', 'Ratsnake', 'mice', 87676) kissy = Copperhead('Kissy', 'Copperhead', 'mice', 4657) monty = Python('Monty', 'python', 'rats', 665679) cotton = Moccassin('Cotton', 'cotton mouth', 'frogs', 356554) rainbow = Coralsnake('Rainbow', 'coral snake', 'roaches', 108375) tangerine = Goldfish('Tangerine', 'goldfish', 'fish flakes', 23987) waddle = Duck('Waddle', 'mallard', 'corn kernels', 487589) ki = Coy('Ki', 'coy', 'fish flakes', 87984) ribbit = Frog('Ribbit', 'bull frog', 'flies', 58769) the_devil = Goose('The Devil', 'goose', 'corn kernels', 63495) varmint_village.add(miss_fuzz) varmint_village.add(hee_haw) varmint_village.add(satan) varmint_village.add(perm) varmint_village.add(ed)
from animals import Goldfish from animals import RedFish from animals import BlueFish from animals import Catfish from animals import KoiFish from attractions import PettingZoo from attractions import SnakePit from attractions import Wetlands varmint_village = PettingZoo("Varmint Village") the_slither_inn = SnakePit("The Slither Inn") critter_cove = Wetlands("Critter Cove") JA = Donkey("JA", "donkey", "morning", "straw", 334) Black = Sheep("Black", "sheep", "afternoon", "hay", 123) Billy = Goat("Billy", "goat", "midday", "pellets", 456) Milkshake = Cow("Milkshake", "Cow", "morning", "grass", 765) RedRum = Horse("RedRum", "horse", "midday", "apples", 678) varmint_village.animals.extend([JA, Black, Billy, Milkshake, RedRum]) Noodles = Watersnake("Noodles", "watersnake", "fish", 198) Zoe = Rattlesnake("Zoe", "rattlesnake", "rabbit", 444) Snape = Cottonmouth("Snape", "cottonmouth", "salamander", 111) Buttercup = Ratsnake("Buttercup", "ratsnake", "shrew", 222) Sssssam = Copperhead("Sssssam", "copperhead", "mice", 555) the_slither_inn.animals.extend([Noodles, Zoe, Snape, Buttercup, Sssssam]) Goldie = Goldfish("Goldie", "goldfish", "shelled peas", 989)
def add_sheep(self, x, y): sheep = Sheep(cfg.config["sheep_move_dist"] * self.step, len(self.flock), x, y) self.flock.append(sheep)
from animals import Barreleye, Bird, Catfish, Donkey, Duck, Goat, Goldfish, Insect, King_Cobra, Kingsnake, Llama, Pig, Sheep, Snake, Whale from attractions import Petting_Zoo, Snake_Pit, Wetlands bassy = Barreleye('Bassy', 'fish', 'Morning', 'Fish chips', 12345) cotters = Bird('Cotters', 'shoebill', 'Evening', 'Bird Food') catty = Catfish('Catty', 'catfish', 'Afternoon', 'Fish Chips') dokay = Donkey('Dokay', 'amiatina', 'Morning', 'Donkey food') malaard = Duck('Malaard', 'mallard', 'Evening', 'Duck food') lebron = Goat('Lebron', 'goat', 'Afternoon', 'Goat food') goldie = Goldfish('Goldie', 'goldfish', 'Evening', 'Fish chips') scorpie = Insect('Scorpie', 'scorpion', 'Morning', 'Insect food') moonshine = King_Cobra('Moonshine', 'snake', 'Afternoon', 'Snake food') kingsby = Kingsnake('Kingsby', 'snake', 'Morning', 'Snake food') llavya = Llama('Llavya', 'llama', 'Evening', 'Llama food') pinky = Pig('Pinky', 'Duroc pig', 'Afternoon', 'Pig food') shep = Sheep('Shep', 'sheep', 'Morning', 'Sheep food') anex = Snake('Anex', 'anaconda', 'Evening', 'Snake food') swain = Whale('Swain', 'Humpback', 'Afternoon', 'Whale food') varmint_village = Petting_Zoo("Varmint Village", "Pet all you can!") reptilian_corner = Snake_Pit("Reptilian Corner", "Lots and Lots and Lots of Reptiles") the_wet_place = Wetlands("The Wet Place", "It's wet here.") varmint_village.add_animals( [dokay, cotters, malaard, lebron, llavya, pinky, shep, swain]) reptilian_corner.add_animals([scorpie, moonshine, kingsby, anex]) the_wet_place.add_animals([catty, goldie, swain]) print(the_wet_place)
def __spawn(self): tiles = self.width * self.height x = 0 while x < tiles * Antelope.Antelope.density: f = self.empty_field() Antelope.Antelope(self, f.x, f.y, Breeding.antelope, Strength.antelope) x += 1 x = 0 while x < tiles * Cyber_sheep.Cyber_sheep.density: f = self.empty_field() Cyber_sheep.Cyber_sheep(self, f.x, f.y, Breeding.cyber_sheep, Strength.cyber_sheep) x += 1 x = 0 while x < tiles * Fox.Fox.density: f = self.empty_field() Fox.Fox(self, f.x, f.y, Breeding.fox, Strength.fox) x += 1 x = 0 while x < tiles * Sheep.Sheep.density: f = self.empty_field() Sheep.Sheep(self, f.x, f.y, Breeding.sheep, Strength.sheep) x += 1 x = 0 while x < tiles * Turtle.Turtle.density: f = self.empty_field() Turtle.Turtle(self, f.x, f.y, Breeding.turtle, Strength.turtle) x += 1 x = 0 while x < tiles * Wolf.Wolf.density: f = self.empty_field() Wolf.Wolf(self, f.x, f.y, Breeding.wolf, Strength.wolf) x += 1 x = 0 while x < tiles * Belladonna.Belladonna.density: f = self.empty_field() Belladonna.Belladonna(self, f.x, f.y, Breeding.belladonna, Strength.belladonna) x += 1 x = 0 while x < tiles * Grass.Grass.density: f = self.empty_field() Grass.Grass(self, f.x, f.y, Breeding.grass, Strength.grass) x += 1 x = 0 while x < tiles * Dandelion.Dandelion.density: f = self.empty_field() Dandelion.Dandelion(self, f.x, f.y, Breeding.dandelion, Strength.dandelion) x += 1 x = 0 while x < tiles * Guarana.Guarana.density: f = self.empty_field() Guarana.Guarana(self, f.x, f.y, Breeding.guarana, Strength.guarana) x += 1 x = 0 while x < tiles * Hogweed.Hogweed.density: f = self.empty_field() Hogweed.Hogweed(self, f.x, f.y, Breeding.hogweed, Strength.hogweed) x += 1 f = self.empty_field() Human.Human(self, f.x, f.y, Breeding.human, Strength.human)
#%% from animals import Wolf, Sheep from space import Grid import seaborn as sns import matplotlib.pyplot as plt import numpy as np import random from celluloid import Camera import custom_utils as utils np.random.seed(1234) grid = Grid(100, 100) ## initialize agents for i in range(5): new_wolf = Wolf(grid) for i in range(20): new_sheep = Sheep(grid) ## run simulation and get GIF saved print("AGENTS before running") print(len(grid.agent_population.values())) utils.simulate(grid, output_path='test2.gif') print("AGENTS after running") print(len(grid.agent_population.values()))