예제 #1
0
from bfs import BFS
from dfs import DFS

SEARCH_TYPE = sys.argv[1]
INITIAL_STATE = map(int, sys.argv[2].split(','))

game = State(INITIAL_STATE);

search = None

if SEARCH_TYPE == 'bfs':
    search = BFS(game)
if SEARCH_TYPE == 'dfs':
    search = DFS(game)

result = search.perform_search()
goal_pos = result.position

res = resource.getrusage(resource.RUSAGE_SELF)

def trace_path(goal_pos):
    pos = goal_pos
    path = []

    while pos != None:
        if (pos.node.action != None):
            path.append(pos.node.action)
        pos = pos.prev

    return path[::-1]