/*_________________________________________________

___________________________________________________
preprocessor*/
#include <iostream>
using namespace std;

#include "brute.hpp"

/*_________________________________________________
brute force method */

brute::brute(char * mapn)
{
    _stack[0] = new map(mapn);
    _stack[1] = new U(_stack[0]);
    _stack[2] = new V(_stack[1]);
    _stack[3] = new W(_stack[2]);
    _stack[4] = new X(_stack[3]);
    _stack[5] = new Y(_stack[4]);
    _stack[6] = new Z(_stack[5]);
    _n=1;
}

brute::~brute()
{
    for (int i=0;i<7;i++)
        if (_stack[i])
            delete _stack[i];
}

void brute::force()
{
    if(_n==1)
        while(_n>0 && _n<7)
            if(_stack[_n]->valid())
            {
                _n++;
                if(_n<7)
                    _stack[_n]->reset();
            }
            else
            {
                if (_stack[_n]->end())
                    _n--;
                _stack[_n]->next();
            }
}

bool brute::done()const
{
    return _n==7;
}
bool brute::failed()const
{
    return _n==0;
}
void brute::print(ostream& out)
{
    if (done())
        for (int i=0;i<4;i++)
        {
            for (int j=0;j<4;j++)
                out << '[' << _stack[6]->getName(j,i) 
                    << _stack[6]->getAt(j,i) << ']';
            out << endl << endl;
        }
}
void brute::printMap(ostream& out)
{
    for (int i=0;i<4;i++)
    {
        for (int j=0;j<4;j++)
            out << _stack[0]->getAt(j,i);
        out << endl;
    }
    out << "____\n";
}
