// a simple Tic Tac Toe Game With no winning mechanisim...since i dont know how to do it

#include <iostream>
#include <time.h>
using namespace std;
class MainGame {
	public:
		string currentplayer;
		string X = " X ";
		string O = " O ";
		bool placetaken = false;
	
		string g1[3] = {"|1|","|2|","|3|"};
		string g2[3] = {"|4|","|5|","|6|"};
		string g3[3] = {"|7|","|8|","|9|"};
		
		/* how it'll look
		 	X |2| O
			|4||5||6|
			|7||8||9|			
		*/
	
	void printgrid()
	{
	   //1
 	  int size1 = sizeof(g1) / sizeof(g1[0]);

 	  for (int i = 0; i < size1; ++i) {
    	   cout << g1[i];
	   }
  	 //2
  	 cout << endl;
  	 int size2 = sizeof(g2) / sizeof(g2[0]);

 	  for (int i = 0; i < size2; ++i) {
     	  cout << g2[i];
  	 }
  	 //3
  	 cout << endl;
  	 int size3 = sizeof(g3) / sizeof(g3[0]);

 	  for (int i = 0; i < size2; ++i) {
     	  cout << g3[i];
  	 }
    
	}
	void selectslot(int slot,string slotvalue)
	{
		if (slotvalue == "X")
		{
			slotvalue = X;
		}
		else
		{
			slotvalue = O;
		}
		if (slot > 0 and slot < 10)
		{
			if (slot >= 1 and slot <= 3) //g1
			{
				if (slot == 1)
				{
					if (g1[0] == "|1|")
					{
						g1[0] = slotvalue;
					}
					else
					{
						cout << "place is taken" << endl;
						placetaken = true;
					}
				}
				if (slot == 2)
				{
					if (g1[1] == "|2|")
					{
						g1[1] = slotvalue;
					}
					else
					{
						cout << "place is taken" << endl;
						placetaken = true;
					}
				}
				if (slot == 3)
				{
					if (g1[2] == "|3|")
					{
						g1[2] = slotvalue;
					}
					else
					{
						cout << "place is taken" << endl;
						placetaken = true;
					}
				}
				printgrid();
				cout << endl;
				if (placetaken == false)
				{
					if (currentplayer == "X")
					{
						currentplayer = "O";
					}
					else
					{
						currentplayer = "X";
					}
				}		
			}
			if (slot >= 4 and slot <= 6) //g2
			{
				if (slot == 4)
				{
					if (g2[0] == "|4|")
					{
						g2[0] = slotvalue;
					}
					else
					{
						cout << "place is taken" << endl;
						placetaken = true;
					}
				}
				if (slot == 5)
				{
					if (g2[1] == "|5|")
					{
						g2[1] = slotvalue;
					}
					else
					{
						cout << "place is taken" << endl;
						placetaken = true;
					}
				}
				if (slot == 6)
				{
					if (g2[2] == "|6|")
					{
						g2[2] = slotvalue;
					}
					else
					{
						cout << "place is taken" << endl;
						placetaken = true;
					}
				}
				printgrid();
				cout << endl;
				if (placetaken == false)
				{
					if (currentplayer == "X")
					{
						currentplayer = "O";
					}
					else
					{
						currentplayer = "X";
					}
				}		
			}
			if (slot >= 7 and slot <= 9) //g3
			{
				if (slot == 7)
				{
					if (g3[0] == "|7|")
					{
						g3[0] = slotvalue;
					}
					else
					{
						cout << "place is taken" << endl;
						placetaken = true;
					}
				}
				if (slot == 8)
				{
					if (g3[1] == "|8|")
					{
						g3[1] = slotvalue;
					}
					else
					{
						cout << "place is taken" << endl;
						placetaken = true;
					}
				}
				if (slot == 9)
				{
					if (g3[2] == "|9|")
					{
						g3[2] = slotvalue;
					}
					else
					{
						cout << "place is taken" << endl;
						placetaken = true;
					}
				}
				printgrid();
				cout << endl;
				if (placetaken == false)
				{
					if (currentplayer == "X")
					{
						currentplayer = "O";
					}
					else
					{
						currentplayer = "X";
					}
				}		
			}
			
		}
		else
		{
			cout << "number not possible" << endl;
		}
	}
	
};
MainGame maingame;

int main()
{
	cout << "Welcome To TicTacToe" << endl;
	cout << "1.Start" << endl << "2.Exit" << endl;
	int start;
	cin >> start;
	if (start == 2)
	{
		cout << "Awwwww ):" << endl;
		return 0;
	}
		srand(time(0));
	int randomchooser = rand()%2;
	if (randomchooser == 0)
	{
		maingame.currentplayer = "X";
	}
	if (randomchooser == 1)
	{
		maingame.currentplayer = "O";
	}
	if (start == 1)
	{
		cout << endl << "Current Player Is " << maingame.currentplayer << endl << "You May Start Now!" << endl;
		maingame.printgrid();
		cout << endl;
	}
	int select;
	while (start == 1)
	{
		//gameplay is done but its missing a winning mechanisim and umm...i dont know how to do that
		//main loop
		cin >> select;
		maingame.placetaken = false;
			maingame.selectslot(select,maingame.currentplayer);
	}
	
}