bfs #fixed

This commit is contained in:
Michal Zmudzinski 2021-06-15 19:59:23 +02:00
parent 40b2b178f3
commit 66dfb94548
3 changed files with 7 additions and 3 deletions

Binary file not shown.

8
bfs.py
View File

@ -9,6 +9,11 @@ class Node:
self.parent = parent
self.action = action
def __eq__(self, other):
if isinstance(other, Node):
return self.pos[0] == other.pos[0] and self.pos[1] == other.pos[1] and self.direction == other.direction
return False
def successor(pos, direction, houses):
neighbours = []
@ -38,13 +43,12 @@ def bfs(pos, direction, end_pos, houses):
while queue:
curr_node = queue.pop(0)
print(curr_node.pos, curr_node.direction)
if not is_house(curr_node.pos, houses) and curr_node.pos == end_pos:
while curr_node.parent:
print(curr_node.pos, end_pos)
actions.append(curr_node.action)
curr_node = curr_node.parent
actions.append(curr_node.action)
return actions
visited.append(curr_node)

View File

@ -83,9 +83,9 @@ def game_loop():
print('##################################################')
while actions:
action = actions.pop()
print(action)
pygame.event.post(pygame.event.Event(
pygame.KEYDOWN, {'key': action}))
game_keys(truck, trash, houses, True)
update_images(gameDisplay, truck, trash, houses)
else: