#ifndef BOGGLE_H
#define BOGGLE_H
#include <string>
#include <fstream>
#include <iostream>
#include <time.h>

using namespace std;

template <class T>
class Boggle
{

public:
	char boardPieces[3][3];
	Boggle(void);
	~Boggle(void);
	void Solve(int x, int y, const string& sofar);   
	void createBoard();
	void LoadWordList(string fileName);
	void LoadWordList();
	string getWord();

	HashTable<string> wordList;
	HashTable<string> stem;
	Tree<string> found;

};
#endif

template <class T>
Boggle<T>::Boggle(void)
{
}
template <class T>
Boggle<T>::~Boggle(void)
{
}
template <class T>
void Boggle<T>::createBoard()
{	
	srand ( time(0) );

	for(int i = 0; i < 3; ++i)
	{
		cout << endl;
		for(int j = 0; j < 3; ++j)
		{
			boardPieces[i][j] = (rand() % 26) + 'a';
			cout << " ";
			cout << boardPieces[i][j];
		}
	}

}
template <class T>
void Boggle<T>::LoadWordList(string fileName)
{
	
	static int count = 0;
	ifstream fi;
	fi.open(fileName.c_str());

	if(fi.is_open())
	{
		char line[30];
		string strline;
		while(!fi.eof())
		{
			fi.getline(line, 30);

			strline = line;
			wordList.INSERT(strline); // Hash Table's Insert
		}
		fi.close();
	}else
	{
		cout << "\nDid not FIND: " << fileName << endl;
	}

}
template <class T>
void Boggle<T>::LoadWordList()
{
	string fileName = "EnglishWL.txt";
	LoadWordList(fileName);
}
template <class T>
void Boggle<T>::Solve(int x, int y, const string& sofar)
{
		
	string word = sofar + boardPieces[x][y];1vg
	if(wordList.FIND(word))
	{
		found.Insert(word);
	}
	found.inOrderPrint();
	for( int i = -1; i <= 1; ++ i )
	{
		int countX = x + i;
		if ( countX < 0 || countX > 3) continue;
		for (int j = -1; j <= 1; ++j)
		{
			int countY = y + j;
			if ( countY < 0 || countY>3 ) continue;  
				Solve(countX, countY, word);   

		}

	}
	
}