The solver was built as one monolithic function
(named solve_for_state
). The function
accepted a state and an integer that specified the depth
of the recursion, and returned a boolean verdict whether
the state was solvable or not. (prev_states
was implemented as a global variable)
solve_for_state
tried to do several
moves on the board in the following order:
Move a card found at the top of a column, into the foundations.
Move a card found in one of the freecells, into the foundations.
Put a freecell card on top of a parent card, which is present on top of one of the columns. (this does not involve moving a card from a freecell to an empty column)
Move a sequence of cards from the top of a column to a parent card on a different column. (again, while not moving cards to a vacant column)
Move a sequence of cards from the top of a column to an empty stack.
Put cards that occupy a freecell in an empty stack.
Move a sequence of cards that is already on top of a valid parent to a different parent.
Move a cards that is hidden under some cards, into the foundations, by moving cards above it to vacant freecells and columns.
Empty an entire stack into the freecells so other cards can inhabit it.