#include <windows.h>

#include <iostream.h>
#include <string.h>

#include "02Board.h"
#include "02SolutionWindow.h"

int main(int argc, char **argv)
{
	/////// Step 1:
		 // Parse options
	bool show = false;
	bool solve = false;
	char startName[1024];
	char finalName[1024];
	bool gotStartName = false;
	bool gotFinalName = false;

	for(int i=1;i<argc;i++)
	{
		if(!strcmp(argv[i],"-solve"))
		{
			if(solve)
			{
				cerr << "Although you specified the -solve option twice,\n";
				cerr << "I will only solve it once.\n";
			}
			solve = true;
		}
		else if(!strcmp(argv[i],"-show"))
		{
			if(show)
			{
				cerr << "Although you specified the -show option twice,\n";
				cerr << "I will only show it once.\n";
			}
			show = true;
		}
		else if(!gotStartName)
		{
			strcpy(startName,argv[i]);
			gotStartName = true;
		}
		else if(!gotFinalName)
		{
			strcpy(finalName,argv[i]);
			gotFinalName = true;
		}
		else
		{
			cerr << "Unexpected argument: " << argv[i] << endl;
			return 1;
		}
	}

	if(!gotStartName)
	{
		cerr << "No starting position specified.\n";
		return 1;
	}

	Board *start = new Board(startName);
	Board *final;
	if(gotFinalName)
		final = new Board(finalName);
	else
		final = new Board();

	if(start->IsSolvable(final))
		cout << "The game is SOLVABLE!!!\n";
	else
	{
		cout << "I bet that no one will ever be able to solve this game.\n";
		return 0;
	}
	if(show)
	{
		start->ShowSolutionWindow();
		MSG msg;
		while(GetMessage(&msg,NULL,0,0))
			DispatchMessage(&msg);
	}
	return 0;
}


