Przeszukiwanie-stanów-A_star #2

Merged
s481832 merged 12 commits from Przeszukiwanie-stanów-A_star into master 2024-05-08 12:00:16 +02:00
2 changed files with 9 additions and 7 deletions
Showing only changes of commit 539a08af0d - Show all commits

View File

@ -31,9 +31,9 @@ class Agent:
elif event.key == pygame.K_RIGHT:
self.move('Turn Right', max_x, max_y, obstacles, animals)
feed_animal(self, animals)
# feed_animal(self, animals)
def move(self, action, max_x, max_y, obstacles, animals):
def move(self, action, max_x, max_y, obstacles, animals, goal):
if action == 'Go Forward':
new_x, new_y = self.x, self.y
if self.direction == 'N':
@ -56,11 +56,13 @@ class Agent:
self.direction = {'N': 'E', 'E': 'S', 'S': 'W', 'W': 'N'}[self.direction]
self.istate = (self.x, self.y, self.direction)
feed_animal(self, animals)
feed_animal(self, animals, goal)
def feed_animal(self, animals):
for animal in animals:
if self.x == animal.x and self.y == animal.y:
def feed_animal(self, animals, goal):
goal_x, goal_y = 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() == 'True':
animal._feed = 0
print(animal.name, "fed with", animal.food)

View File

@ -260,7 +260,7 @@ def main():
if actions:
action = actions.pop(0)
agent.move(action, GRID_WIDTH, GRID_HEIGHT, obstacles, Animals)
agent.move(action, GRID_WIDTH, GRID_HEIGHT, obstacles, Animals, goal)
pygame.time.wait(200)
else:
animal = random.choice(Animals)