From bec25a4e4a5c8efb41fde106079fd24b772c6106 Mon Sep 17 00:00:00 2001 From: s464859 <@> Date: Thu, 7 Apr 2022 16:43:11 +0200 Subject: [PATCH] naprawiony bfs --- classes/bfs.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/classes/bfs.py b/classes/bfs.py index d06cf0a..a02c4c3 100644 --- a/classes/bfs.py +++ b/classes/bfs.py @@ -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)