Algorytm_genetyczny #3

Merged
s481832 merged 18 commits from Algorytm_genetyczny into master 2024-06-10 13:30:20 +02:00
13 changed files with 38 additions and 59 deletions
Showing only changes of commit 3baf0209a0 - Show all commits

View File

@ -30,9 +30,9 @@ class Animal:
exclamation_image = pygame.transform.scale(exclamation_image, (int(grid_size * 0.45), int(grid_size * 0.45)))
screen.blit(exclamation_image, (x * grid_size, y * grid_size))
def draw_food(self, screen, grid_size, x, y):
def draw_food(self, screen, grid_size, x, y,food_image):
scale = 0.45
food_image = pygame.image.load(self.food_image)
food_image = pygame.image.load(food_image)
if(self.adult):
y = y + 1
@ -40,9 +40,6 @@ class Animal:
food_image = pygame.transform.scale(food_image, (int(grid_size * scale), int(grid_size * scale)))
screen.blit(food_image, (x * grid_size, (y + 1) * grid_size - int(grid_size * scale)))
@abstractmethod
def feed(self):
pass
@abstractmethod
def getting_hungry(self):

View File

@ -41,7 +41,13 @@ def create_animals():
def draw_Animals(Animals, const):
for Animal in Animals:
Animal.draw(const.screen, const.GRID_SIZE)
if Animal.feed() == 'True':
if Animal.getting_hungry() == 5:
Animal.draw_exclamation(const.screen, const.GRID_SIZE, Animal.x, Animal.y)
else:
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y)
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/empty_bowl.png')
if Animal.getting_hungry() >= 4 and Animal.getting_hungry() < 5:
Animal.draw_exclamation(const.screen, const.GRID_SIZE, Animal.x, Animal.y)
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/almost_empty.png')
if Animal.getting_hungry() >= 2 and Animal.getting_hungry() < 4:
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/half_bowl.png')
if Animal.getting_hungry() < 2:
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/full_bowl.png')

View File

@ -13,13 +13,6 @@ class Bear(Animal):
self._starttime = datetime.now()
def feed(self):
self.getting_hungry()
if self._feed < 2:
return 'False'
else:
return 'True'
def getting_hungry(self):
@ -27,4 +20,7 @@ class Bear(Animal):
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 60
self._feed += minutes_passed
self._starttime = checktime
self._starttime = checktime
if self._feed > 5:
self._feed = 5
return self._feed

View File

@ -21,17 +21,12 @@ class Elephant(Animal):
def feed(self):
self.getting_hungry()
if self._feed < 0.3:
return 'False'
else:
return 'True'
def getting_hungry(self):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 60
minutes_passed = delta.total_seconds() / 50
self._feed += minutes_passed
self._starttime = checktime
self._starttime = checktime
if self._feed > 5:
self._feed = 5
return self._feed

View File

@ -14,19 +14,14 @@ class Giraffe(Animal):
super().__init__(x, y,name, Giraffe_image, food_image,giraffe_food, environment, adult)
self._starttime = datetime.now()
def feed(self):
self.getting_hungry()
if self._feed < 0.8:
return 'False'
else:
return 'True'
def getting_hungry(self):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 60
minutes_passed = delta.total_seconds() / 30
self._feed += minutes_passed
self._starttime = checktime
self._starttime = checktime
if self._feed > 5:
self._feed = 5
return self._feed

View File

@ -16,17 +16,12 @@ class Parrot(Animal):
def feed(self):
self.getting_hungry()
if self._feed < 1.5:
return 'False'
else:
return 'True'
def getting_hungry(self):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 60
minutes_passed = delta.total_seconds() / 20
self._feed += minutes_passed
self._starttime = checktime
self._starttime = checktime
if self._feed > 5:
self._feed = 5
return self._feed

View File

@ -14,19 +14,14 @@ class Penguin(Animal):
super().__init__(x, y,name, Penguin_image, food_image,penguin_food,environment, adult)
self._starttime = datetime.now()
def feed(self):
self.getting_hungry()
if self._feed < 2:
return 'False'
else:
return 'True'
def getting_hungry(self):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 60
minutes_passed = delta.total_seconds() / 15
self._feed += minutes_passed
self._starttime = checktime
self._starttime = checktime
if self._feed > 5:
self._feed = 5
return self._feed

View File

@ -63,7 +63,7 @@ def feed_animal(self, animals, goal):
if self.x == goal_x and self.y == goal_y:
for animal in animals:
if animal.x == goal_x and animal.y == goal_y:
if animal._feed < self._food :
if animal.getting_hungry() < self._food :
self._food -= animal._feed
animal._feed = 0
print(animal.name, "fed with", animal.food)
@ -79,5 +79,5 @@ def take_food(self):
house_y = 1
if self.x == house_x and self.y == house_y:
if self._food == 0:
self._food = 15
self._food = 25
print("Agent took food and current food level is", self._food)

BIN
images/almost_empty.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
images/empty_bowl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
images/full_bowl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
images/half_bowl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

View File

@ -97,7 +97,7 @@ def main():
spawn_obstacles()
cost_map = generate_cost_map(Animals, Terrain_Obstacles)
for animal in Animals:
animal._feed = 2 # Ustawienie, aby zwierzę było głodne
animal._feed = 3
spawned = True
draw_Animals(Animals, const)