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.parent = parent
|
||||||
self.action = action
|
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):
|
def successor(pos, direction, houses):
|
||||||
neighbours = []
|
neighbours = []
|
||||||
@ -38,13 +43,12 @@ def bfs(pos, direction, end_pos, houses):
|
|||||||
|
|
||||||
while queue:
|
while queue:
|
||||||
curr_node = queue.pop(0)
|
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:
|
if not is_house(curr_node.pos, houses) and curr_node.pos == end_pos:
|
||||||
while curr_node.parent:
|
while curr_node.parent:
|
||||||
print(curr_node.pos, end_pos)
|
print(curr_node.pos, end_pos)
|
||||||
actions.append(curr_node.action)
|
actions.append(curr_node.action)
|
||||||
curr_node = curr_node.parent
|
curr_node = curr_node.parent
|
||||||
actions.append(curr_node.action)
|
|
||||||
return actions
|
return actions
|
||||||
|
|
||||||
visited.append(curr_node)
|
visited.append(curr_node)
|
||||||
|
2
main.py
2
main.py
@ -83,9 +83,9 @@ def game_loop():
|
|||||||
print('##################################################')
|
print('##################################################')
|
||||||
while actions:
|
while actions:
|
||||||
action = actions.pop()
|
action = actions.pop()
|
||||||
print(action)
|
|
||||||
pygame.event.post(pygame.event.Event(
|
pygame.event.post(pygame.event.Event(
|
||||||
pygame.KEYDOWN, {'key': action}))
|
pygame.KEYDOWN, {'key': action}))
|
||||||
|
|
||||||
game_keys(truck, trash, houses, True)
|
game_keys(truck, trash, houses, True)
|
||||||
update_images(gameDisplay, truck, trash, houses)
|
update_images(gameDisplay, truck, trash, houses)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user