From 4422707ce2bb29563407dd09aeb61206c9150738 Mon Sep 17 00:00:00 2001 From: Rodolfo Ferro Date: Fri, 28 Dec 2018 17:51:37 -0600 Subject: [PATCH] Edited linear puzzle problem. :outbox_tray: --- linear_puzzle_bfs.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/linear_puzzle_bfs.py b/linear_puzzle_bfs.py index 76d3c5c..1b24f08 100644 --- a/linear_puzzle_bfs.py +++ b/linear_puzzle_bfs.py @@ -41,7 +41,7 @@ def border_operator(node): return Node(operated_data) -def search_solution_with_bfs(initial_state, solution): +def solution_with_bfs(operators, initial_state, solution): """ Function that generates new states from the initial state (using the defined operators) to solve the Linear Puzzle with four elements by @@ -52,8 +52,6 @@ def search_solution_with_bfs(initial_state, solution): visited, border = [], [] initial_node = Node(initial_state) border.append(initial_node) - opertators = [left_operator, center_operator, - right_operator, border_operator] # While we border nodes is not empty and puzzle not solved: while len(border) > 0: @@ -84,8 +82,12 @@ def search_solution_with_bfs(initial_state, solution): initial_state = [1, 4, 3, 2] solution = [1, 2, 3, 4] + # Define operatos list: + opertators = [left_operator, center_operator, + right_operator, border_operator] + # Compute solution: - solution_node = search_solution_with_bfs(initial_state, solution) + solution_node = solution_with_bfs(opertators, initial_state, solution) # Build steps (by getting the father nodes of the solution): resulting_path = []