Level solving algorithm