naprawiony bfs
This commit is contained in:
parent
2aab028009
commit
bec25a4e4a
@ -14,16 +14,19 @@ class BFS:
|
||||
def successor(self, current_position):
|
||||
new_nodes = []
|
||||
neighbours_list = self.agent.sensor(current_position[0], current_position[1])
|
||||
print(neighbours_list[0])
|
||||
print(neighbours_list[1])
|
||||
print(neighbours_list[2])
|
||||
|
||||
|
||||
if neighbours_list[1][0] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
|
||||
new_nodes.append([1 + current_position[0] - 1, 0 + current_position[1] - 1])
|
||||
new_nodes.append([current_position[0] - 1, current_position[1]])
|
||||
if neighbours_list[2][1] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
|
||||
new_nodes.append([2 + current_position[0] - 1, 1 + current_position[1] - 1])
|
||||
new_nodes.append([current_position[0], current_position[1] + 1])
|
||||
if neighbours_list[1][2] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
|
||||
new_nodes.append([1 + current_position[0] - 1, 2 + current_position[1] -1])
|
||||
new_nodes.append([current_position[0] + 1, current_position[1]])
|
||||
if neighbours_list[0][1] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
|
||||
new_nodes.append([0 + current_position[0] - 1, 1 + current_position[1] - 1])
|
||||
new_nodes.append([current_position[0],current_position[1] - 1])
|
||||
|
||||
return new_nodes
|
||||
|
||||
@ -70,7 +73,7 @@ class BFS:
|
||||
#break
|
||||
while tmp_node[1].get_parent() is not None:
|
||||
#print('sdfhdfg')
|
||||
#print(tmp_node[1].get_parent())
|
||||
#print(tmp_node[1].get_parent()[1].get_position())
|
||||
final_action_list.append(tmp_node[1].get_action())
|
||||
tmp_node = tmp_node[1].get_parent()
|
||||
final_action_list.reverse()
|
||||
@ -81,11 +84,12 @@ class BFS:
|
||||
explored.append(tmp_node)
|
||||
|
||||
neighbours_list_of_our_node = self.successor(tmp_node_position[:2])
|
||||
# print(neighbours_list_of_our_node)
|
||||
print(neighbours_list_of_our_node)
|
||||
for node_ in neighbours_list_of_our_node:
|
||||
# jesli pozucja wezla nie jest w fringe i nie jest w explored
|
||||
if [node_[0], node_[1]] not in visited_position and node_[0] >= 0 and node_[1] >=0:
|
||||
counter += 1
|
||||
print([node_[0], node_[1]])
|
||||
x = node.Node(tmp_node, None, [node_[0], node_[1]]) # action
|
||||
heapq.heappush(fringe, (counter, x))
|
||||
# time.sleep(0.5)
|
||||
|
Loading…
Reference in New Issue
Block a user