#ifndef _SUDOKUFIELD_H
#define _SUDOKUFIELD_H

/*


*/
#include <QString>
#include <QMap>
#include <vector>
#include "backtracker.h"

//using namespace Backtrack;
namespace Backtrack
{
	class SudokuField
	{
	public:
		SudokuField() {Value=-1; X=0; Y=0; Block=0;}
		SudokuField(int v, unsigned int b, unsigned int x, unsigned int y) : Value(v), Block(b), X(x), Y(y) {qDebug("constructed %d,%d block: %d value: %d", X, Y, Block, Value);}
		//SudokuField(const SudokuField& o) {*this=o;}

		int value(void) const {return Value;}
		unsigned int x(void) const {return X;}
		unsigned int y(void) const {return Y;}
		unsigned int block(void) const {return Block;}
		int setValue(int v) {return (Value=v);}
	private:
		int Value;
		unsigned int Block;
		unsigned int X;
		unsigned int Y;
	};

	class Sudoku : public Backtrack::Generic<Sudoku>
	{

	public:
		Sudoku(QString init=QString(), unsigned int sx=3, unsigned int sy=3);
		bool fromString(QString s);
		bool solve() const;
		bool solveV2() const;
		QStringList toStringList(void) const;
		SudokuField field(int x,int y) const;

		QString toString(int mode) const;

		typedef QMap <int,int> ValueMapT;
		ValueMapT possibleValues(unsigned int i) const;
		//Trackable* clone(void) const {return new Sudoku(*this);}
	protected:
		bool solved(void) const;
		QList<Sudoku> variants(void) const;
		QString toString(void) const {return toString(1);}
	private:

		typedef std::vector <SudokuField> FieldT;
		FieldT Fields;
		unsigned int Height;
		unsigned int Width;
	};
}

#endif
