
#include "stdio.h"

#include "ui/onerror.hpp"
#include "mod/habitat.hpp"
#include "mod/robot.hpp"
#include "mod/data.hpp"


int main(int argc, char **argv)
{	
	CError MainError;
	CHabitat Habitat;
	CRobot Robot ( Habitat.GetDataAddr(), Habitat.GetSocketAddr() );
	char *host = argv[1];
	char *gamer_name = argv[2];
	int portno = 4774;
	int to_wait = 1;
		if ( argc < 3 ) MainError.OnError(ERROR_MAIN_WITHOUT_PARAMETERS);
		if ( strlen(argv[2] ) > STRING_SIZE ) MainError.OnError(ERROR_MAIN_LONG_GAMER_NAME);
		if ( argc>3 ) if ( (to_wait = atoi(argv[3])) < 1) MainError.OnError(ERROR_MAIN_WAIT_NUMBER);
		//-------------------------
		Habitat.Init(host, portno, gamer_name, to_wait);

			//------------------------- 
			do  {
				Habitat.Analyze();
					printf("\n");
						Robot.Pass();
					printf("\n");
				Habitat.WaitingTurn();
			} while ( Robot.IsWin() == 0 );
			//=========================

		Habitat.Destroy();
}

