diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e99e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc \ No newline at end of file diff --git a/__pycache__/adult_animal.cpython-311.pyc b/__pycache__/adult_animal.cpython-311.pyc deleted file mode 100644 index aa04f9e..0000000 Binary files a/__pycache__/adult_animal.cpython-311.pyc and /dev/null differ diff --git a/__pycache__/agent.cpython-311.pyc b/__pycache__/agent.cpython-311.pyc deleted file mode 100644 index ffcb503..0000000 Binary files a/__pycache__/agent.cpython-311.pyc and /dev/null differ diff --git a/__pycache__/animal.cpython-311.pyc b/__pycache__/animal.cpython-311.pyc deleted file mode 100644 index b4b1e5e..0000000 Binary files a/__pycache__/animal.cpython-311.pyc and /dev/null differ diff --git a/__pycache__/bear.cpython-311.pyc b/__pycache__/bear.cpython-311.pyc deleted file mode 100644 index 524e534..0000000 Binary files a/__pycache__/bear.cpython-311.pyc and /dev/null differ diff --git a/__pycache__/combined_animal.cpython-311.pyc b/__pycache__/combined_animal.cpython-311.pyc deleted file mode 100644 index fd6781a..0000000 Binary files a/__pycache__/combined_animal.cpython-311.pyc and /dev/null differ diff --git a/__pycache__/elephant.cpython-311.pyc b/__pycache__/elephant.cpython-311.pyc deleted file mode 100644 index aa0a8cb..0000000 Binary files a/__pycache__/elephant.cpython-311.pyc and /dev/null differ diff --git a/__pycache__/enclosure.cpython-311.pyc b/__pycache__/enclosure.cpython-311.pyc deleted file mode 100644 index c492895..0000000 Binary files a/__pycache__/enclosure.cpython-311.pyc and /dev/null differ diff --git a/__pycache__/giraffe.cpython-311.pyc b/__pycache__/giraffe.cpython-311.pyc deleted file mode 100644 index 6b943d4..0000000 Binary files a/__pycache__/giraffe.cpython-311.pyc and /dev/null differ diff --git a/__pycache__/parrot.cpython-311.pyc b/__pycache__/parrot.cpython-311.pyc deleted file mode 100644 index 5748723..0000000 Binary files a/__pycache__/parrot.cpython-311.pyc and /dev/null differ diff --git a/__pycache__/penguin.cpython-311.pyc b/__pycache__/penguin.cpython-311.pyc deleted file mode 100644 index bae0869..0000000 Binary files a/__pycache__/penguin.cpython-311.pyc and /dev/null differ diff --git a/__pycache__/spawner.cpython-311.pyc b/__pycache__/spawner.cpython-311.pyc deleted file mode 100644 index 5382987..0000000 Binary files a/__pycache__/spawner.cpython-311.pyc and /dev/null differ diff --git a/__pycache__/state_space_search.cpython-311.pyc b/__pycache__/state_space_search.cpython-311.pyc deleted file mode 100644 index b003292..0000000 Binary files a/__pycache__/state_space_search.cpython-311.pyc and /dev/null differ diff --git a/agent.py b/agent.py index 311fcb5..94b4d8b 100644 --- a/agent.py +++ b/agent.py @@ -27,19 +27,15 @@ class Agent: def handle_event(self, event, max_x, max_y, animals, obstacles): if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: - self.move('Go Forward', max_x, max_y, obstacles) + self.move('Go Forward', max_x, max_y, obstacles, animals) elif event.key == pygame.K_LEFT: - self.move('Turn Left', max_x, max_y, obstacles) + self.move('Turn Left', max_x, max_y, obstacles, animals) elif event.key == pygame.K_RIGHT: - self.move('Turn Right', max_x, max_y, obstacles) + self.move('Turn Right', max_x, max_y, obstacles, animals) - for animal in animals: - if self.x == animal.x and self.y == animal.y: - if animal.feed() == 'True': - animal._feed = 0 - print(animal.name, "fed with", animal.food) + feed_animal(self, animals) - def move(self, action, max_x, max_y, obstacles): + def move(self, action, max_x, max_y, obstacles, animals): if action == 'Go Forward': new_x, new_y = self.x, self.y if self.direction == 'N': @@ -59,4 +55,13 @@ class Agent: self.direction = {'N': 'W', 'W': 'S', 'S': 'E', 'E': 'N'}[self.direction] elif action == 'Turn Right': - self.direction = {'N': 'E', 'E': 'S', 'S': 'W', 'W': 'N'}[self.direction] \ No newline at end of file + self.direction = {'N': 'E', 'E': 'S', 'S': 'W', 'W': 'N'}[self.direction] + + feed_animal(self, animals) + +def feed_animal(self, animals): + for animal in animals: + if self.x == animal.x and self.y == animal.y: + if animal.feed() == 'True': + animal._feed = 0 + print(animal.name, "fed with", animal.food) \ No newline at end of file diff --git a/main.py b/main.py index 3eb6673..e5c417b 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import random import pygame import sys from elephant import Elephant @@ -8,7 +9,6 @@ from bear import Bear from agent import Agent from enclosure import Enclosure from spawner import Spawner -from state_space_search import succ from state_space_search import graphsearch BLACK = (0, 0, 0) @@ -159,12 +159,9 @@ def main(): obstacles = generate_obstacles() actions = [] - spawn_all_animals() - actions = graphsearch(agent.istate, (an1.x, an1.y), GRID_WIDTH, GRID_HEIGHT, obstacles) - # actions = graphsearch(agent.istate, (25,1), GRID_WIDTH, GRID_HEIGHT, obstacles) - clock = pygame.time.Clock() - + + spawned = False while True: for event in pygame.event.get(): if event.type == pygame.QUIT: @@ -172,12 +169,20 @@ def main(): sys.exit() agent.handle_event(event, GRID_WIDTH, GRID_HEIGHT, Animals, obstacles) - - screen.blit(background_image,(0,0)) draw_grid() draw_enclosures() draw_gates() + if not spawned: + spawn_all_animals() + + # region Test szukania ścieżki + animal = random.choice(Animals) + actions = graphsearch(agent.istate, (animal.x, animal.y), GRID_WIDTH, GRID_HEIGHT, obstacles) + animal._feed = 2 # Ustawienie aby zwierzę było głodne + # endregion + + spawned = True draw_Animals() opengates() agent.draw(screen) @@ -186,7 +191,7 @@ def main(): if actions: action = actions.pop(0) - agent.move(action, GRID_WIDTH, GRID_HEIGHT, obstacles) + agent.move(action, GRID_WIDTH, GRID_HEIGHT, obstacles, Animals) pygame.time.wait(200) if __name__ == "__main__":