def test_successor_space_lower_right_corner(self): initial_node = "31452786_" expected_node_list = {self.left: "3145278_6", self.up: "31452_867"} successors_dict = get_successor_states(initial_node) self.assertDictEqual(expected_node_list, successors_dict)
def test_successor_space_lower_left_corner(self): initial_node = "531824_67" expected_node_list = {self.right: "5318246_7", self.up: "531_24867"} successors_dict = get_successor_states(initial_node) self.assertDictEqual(expected_node_list, successors_dict)
def test_successor_space_upper_right_corner(self): initial_node = "31_524867" expected_node_list = {self.left: "3_1524867", self.down: "31452_867"} successors_dict = get_successor_states(initial_node) self.assertDictEqual(expected_node_list, successors_dict)
def run_successor_states_function(arguments: Arguments): successor_states = get_successor_states(arguments.initial_state) to_print = "" for successor_state in successor_states: to_print += "(" + successor_state + "," + successor_states[ successor_state] + ") " print(to_print.strip()) logging.info(to_print.strip())
def test_successor_space_center_down(self): initial_node = "3215648_7" expected_node_list = { self.left: "321564_87", self.right: "32156487_", self.up: "3215_4867" } successors_dict = get_successor_states(initial_node) self.assertDictEqual(expected_node_list, successors_dict)
def test_successor_space_center_up(self): initial_node = "3_1524867" expected_node_list = { self.right: "31_524867", self.left: "_31524867", self.down: "3215_4867" } successors_dict = get_successor_states(initial_node) self.assertDictEqual(expected_node_list, successors_dict)
def test_successor_space_center_right(self): initial_node = "32154_867" expected_node_list = { self.left: "3215_4867", self.up: "32_541867", self.down: "32154786_" } successors_dict = get_successor_states(initial_node) self.assertDictEqual(expected_node_list, successors_dict)
def test_successor_space_center_left(self): initial_node = "321_54867" expected_node_list = { self.right: "3215_4867", self.up: "_21354867", self.down: "321854_67" } successors_dict = get_successor_states(initial_node) self.assertDictEqual(expected_node_list, successors_dict)
def test_successor_space_center(self): initial_state = "3215_4867" expected_state_list = { self.left: "321_54867", self.right: "32154_867", self.up: "3_1524867", self.down: "3215648_7" } successors_dict = get_successor_states(initial_state) self.assertDictEqual(expected_state_list, successors_dict)
def expand_node(node: Node) -> [Node]: successor_states = get_successor_states( node.state) # pega todos os movimentos validos para o estado do nó successor_nodes = [ ] # lista de nós que podem ser visitados partindo da entrada da função # para cada um dos movimentos validos for action in successor_states: # pega o estado que vai ser o atual se mover para aquele lado successor_state = successor_states[action] # cria um novo nó com o novo estado, e adiciona o nó original como pai successor_nodes.append( Node(action, successor_state, node.cost + parameters.step_cost, node)) node.set_successors( successor_nodes ) # adiciona ao nó da entrada os possiveis nós para cada movimento return successor_nodes # retorna a lista com todos os nós que podemos visitar partindo do nó de entrada