//#include <string>
#include "BackTrack.h"
//#include <iostream>

using namespace std;

BackTrack::BackTrack (const Application& app)
{
    this -> app = app;
} // constructor


bool BackTrack::tryToSolve (Position pos)
{
    bool success = false;
    
    Application::Iterator itr (pos);
    while (!success && !itr.atEnd())
    {
        pos = itr++;
        if (app.valid (pos))
        {
            app.record (pos);
            if (app.done (pos))
                success = true;
            else
            {
                success = tryToSolve (pos);
                if (!success)
                    app.undo (pos);
            } // not done
        } // a valid position
    } // while
    return success;
} // method tryToSolve


