Advertisement
Guest User

Untitled

a guest
Nov 29th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import random
  3.  
  4.  
  5. class Fish:
  6.     type = 'Fish'
  7.  
  8.     def __init__(self):
  9.         self.weight = random.randint(1, 9)
  10.  
  11.  
  12. class PredatoryFish(Fish):
  13.     type = 'PredatoryFish'
  14.  
  15.     def __init__(self):
  16.         super().__init__()
  17.         self.weight = 10
  18.  
  19.  
  20. class Aquarium:
  21.     type = 'Aquarium'
  22.  
  23.     def __init__(self):
  24.         self.peaceful_fishes = {}
  25.         self.predatory_fishes = {}
  26.  
  27.     def add_peaceful_fishes(self, fish_count):
  28.         self.peaceful_fishes = {'fish'+str(fish):Fish().weight for fish in range(fish_count)}
  29.  
  30.     def add_predators(self):
  31.         names = ('predator1', 'predator2')
  32.         self.predatory_fishes = {name:PredatoryFish().weight for name in names}
  33.  
  34.     def simulate_hunting(self):
  35.         for fish in list(self.peaceful_fishes):
  36.             kg = self.peaceful_fishes.pop(fish)
  37.             rand = random.choice(list(self.predatory_fishes))
  38.             self.predatory_fishes[rand] += kg
  39.  
  40.             # uncomment line bellow to see logs hunting
  41.             # print('{0}(weight = {1}kg) was eaten by {2}(weight = {3})'.format(fish, kg, rand, self.predatory_fishes.get(rand)))
  42.  
  43.     def get_winner(self):
  44.  
  45.         pass # TODO    
  46.  
  47.  
  48. if __name__ == '__main__':
  49.  
  50.     aquarium = Aquarium()
  51.  
  52.     aquarium.add_peaceful_fishes(random.randint(10, 50))
  53.     print(aquarium.peaceful_fishes)
  54.  
  55.     aquarium.add_predators()
  56.     print(aquarium.predatory_fishes)
  57.  
  58.     aquarium.simulate_hunting()
  59.     print(aquarium.peaceful_fishes)
  60.  
  61.     print(aquarium.predatory_fishes)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement