-
Notifications
You must be signed in to change notification settings - Fork 2
/
animal.py
51 lines (43 loc) · 1.21 KB
/
animal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from random import random, uniform
from numpy.random import normal, randint
from abc import ABC, abstractmethod
class Animal(ABC):
seasons = {'winter': 0, 'spring': 122, 'summer': 183, 'autumn': 304}
def __init__(self, gender, age, probability_death, probability_birth,
movement_speed, hunger, radius, weaning, mating, parents, pregnancy):
self.gender = gender
self.age = age
self.probability_death = probability_death
self.probability_birth = probability_birth
self.movement_speed = movement_speed
self.hunger = hunger
self.radius = radius
self.radius_sq = self.radius ** 2
self.weaning = weaning
self.mating = mating[gender]
self.parents = parents
self.isPregnant=False
self.daysSpentInPregnancy=None
self.pregnancy=randint(pregnancy[0], pregnancy[1])
self.partner=None
self.children = []
self.isInDen=None
@abstractmethod
def check_death(self):
pass
@abstractmethod
def check_birth(self):
pass
@abstractmethod
def move(self):
pass
def restrict(self, n, min_, max_):
n = max(min(max_, n), min_)
if n == 100:
n -= uniform(0, self.movement_speed)
elif n == 0:
n += uniform(0, self.movement_speed)
return n
@abstractmethod
def give_birth(self):
pass