Freecell Solver - Evolution of a C ProgramFreecell Solver 0.2's ArchitectureThe Scan that was used

2.1. The Scan that was used


Solve-State(state, prev_states, ret)
    if (state == empty_state)
        Push(ret, state)
        return SOLVED
    for each move possible on state
        new_state <- apply(state, move)
        if (new_state in prev_states)
            ; Do nothing
            add new_state to prev_states
            if (Solve-State(new_state, prev_states, ret) == SOLVED)
                Push(ret, state)
                return SOLVED
    return UNSOLVED

    if (Solve-State(init_state, Null, ret) == SOLVED)
        print "State was solved"
        while (state <- Pop(ret))
            print state
        print "I could not solve this board";

Written by Shlomi Fish