bfs #fixed
This commit is contained in:
parent
40b2b178f3
commit
66dfb94548
Binary file not shown.
8
bfs.py
8
bfs.py
@ -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)
|
||||
|
2
main.py
2
main.py
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user