#include "GridNavigatorManual.h"
#include "GridNavigatorAutomatic.h"
#include "CounterStats.h"

int main(int argc, char** argv)
{
	
	int choice = 0;
	GridNavigator* gn = nullptr;

	do
	{
		cout << "Enter choice:" << endl;
		cout << "1: Manual mode (for learning the environment)." << endl;
		cout << "2: Automatic mode, single run (for testing of your code." << endl;
		cout << "3: Benchmarking mode, 10,000 runs of automatic mode." << endl;

		cin >> choice;

		switch (choice)
		{
		case 1:
			gn = new GridNavigatorManual();
			break;
		case 2:
			gn = new GridNavigatorAutomatic();
			break;
		case 3:
			break;
		default:
			cout << "Unknown choice." << endl;
		}
	} while (choice < 1 || choice > 3);

	if (choice == 1 || choice == 2)
	{
		gn->SetupGrid();
		gn->Navigate();

		if (!gn->CheckComplete())
		{
			cout << "Error: navigation has finished, but the maze is not solved! Check code and try again. Exiting." << endl;
			exit(-1);
		}

		gn->GetCounter()->PrintCounters();

		delete gn;
	}
	else if (choice == 3) //Deliberately an else if, in case we want to add more choices later.
	{
		CounterStats* cs = new CounterStats();

		for (int i = 0; i < 10000; i++)
		{
			gn = new GridNavigatorAutomatic();

			gn->SetupGrid();
			gn->Navigate();

			if (!gn->CheckComplete())
			{
				cout << "Error: test iteration " << i << " finished, but the maze is not solved! Check code and try again. Exiting." << endl;
				exit(-1);
			}

			cs->AddCounter(gn->GetCounter());

			delete gn;
		}

		cs->PrintStats();
		delete cs;
	}

	
}