Example #1
0
def runAStar():
    print("Initial State:")
    print(Problem.DESCRIBE_STATE(init_state))
    global COUNT, BACKLINKS
    COUNT = 0
    BACKLINKS = {}
    IterateAStar(init_state)
    print(str(COUNT)+" states examined.")
Example #2
0
def backtrace(S):
    global BACKLINKS

    path = []
    while not S == -1:
        path.append(S)
        S = BACKLINKS[Problem.HASHCODE(S)]
    path.reverse()
    print("Solution path: ")
    for s in path:
        print(Problem.DESCRIBE_STATE(s))
    return path    
Example #3
0
def runAStar():
    initial_state = puzzle.CREATE_INITIAL_STATE()
    print("Initial State:")
    print(Problem.DESCRIBE_STATE(initial_state))
    if Problem.PROBLEM_NAME == "Basic Eight Puzzle" and Problem.CHECK_INI_STATE(
            initial_state) % 2 != 0:
        print("This particular puzzle is not solvable.")
        return
    global COUNT, BACKLINKS
    COUNT = 0
    BACKLINKS = {}
    IterativeAStar(initial_state)
    print(str(COUNT) + " states examined.")