#include <iostream>
#include <string>
using namespace std;

int main()
{
    //Player names
    string player1;
    string player2;
    cout << "Enter Player1's name: " << endl;
    cin >> player1;
    if (player1 == "")
    {
        player1 = "Player1Defualt";
    }
    cout << "Enter Player2's name: " << endl;
    cin >> player2;
    if (player2 == "")
    {
        player2 = "Player2Default";
    }
    
    cout << "\nPlayer1 is: " << player1 << endl;
    cout << "Player2 is: " << player2 << endl;
    cout << endl;
    
    char board[10] = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
    char xando[] = { 'X', 'O'};
    
    cout << "These are the positions you can place X or O on." << endl;
    cout << 1 << " | " << 2 << "| " << 3 << endl;
    cout << "--+--+--" << endl;
    cout << 4 << " | " << 5 << "| " << 6 << endl;
    cout << "--+--+--" << endl;
    cout << 7 << " | " << 8 << "| " << 9 << endl;
    cout << "\n" << endl;
    
    int full = 0;
    while (full < 9)
    {
        //Position
        if(full == 0 || full == 2 || full == 4 || full == 6 || full == 8)
        {
            int position;
            cout << player1 <<" please enter position for X: ";
            cin >> position;
            cin.get();
            if (board[position] == 'X' || board[position] == 'O')
            {
                cout << "\nposition taken..." << endl;
                continue;
            }
            else
            {
                board[position] = xando[0];
                full ++;
            }
        }
        else if (full == 1 || full == 3 || full == 5 || full == 7)
        {
            int position;
            cout << player2 <<" please enter a position for O: ";
            cin >> position;
	        cin.get();
            if (board[position] == 'X' || board[position] == 'O')
            {
                cout << "\nPosition taken..." << endl;
                continue;
            }
            else
            {
                board[position] = xando[1];
                full ++;
            }
            
        }
        
        cout << board[1] << " | " << board[2] << "| " << board[3] << endl;
        cout << "--+--+--" << endl;
        cout << board[4] << " | " << board[5] << "| " << board[6] << endl;
        cout << "--+--+--" << endl;
        cout << board[7] << " | " << board[8] << "| " << board[9] << endl;
        cout << "\n" << endl;
        
        
        if (board[1] == 'X' && board[2] == 'X' && board[3] == 'X' )
        {
		    cout << player1 <<" wins!" << endl;
		    return 0;
	    }
	    else if (board[1] == 'O' && board[2] == 'O' && board[3] == 'O')
	    {
		    cout << player2 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[4] == 'X' && board[5] == 'X' && board[6] == 'X')
	    {
		    cout << player1 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[4] == 'O' && board[5] == 'O' && board[6] == 'O')
	    {
		    cout << player2 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[7] == 'X' && board[8] == 'X' && board[9] == 'X')
	    {
		    cout << player1 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[7] == 'O' && board[8] == 'O' && board[9] == 'O')
	    {
		    cout << player2 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[1] == 'X' && board[4] == 'X' && board[7] == 'X')
	    {
		    cout << player1 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[1] == 'O' && board[4] == 'O' && board[7] == 'O')
	    {
		    cout << player2 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[2] == 'X' && board[5] == 'X' && board[8] == 'X')
	    {
		    cout << player1 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[2] == 'O' && board[5] == 'O' && board[8] == 'O')
	    {
		    cout << player2 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[3] == 'X' && board[6] == 'X' && board[9] == 'X')
	    {
		    cout << player1 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[3] == 'O' && board[6] == 'O' && board[9] == 'O')
	    {
		    cout << player2 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[1] == 'X' && board[5] == 'X' && board[9] == 'X')
	    {
		    cout << player1 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[1] == 'O' && board[5] == 'O' && board[9] == 'O')
	    {
		    cout << player2 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[7] == 'X' && board[5] == 'X' && board[3] == 'X')
	    {
		    cout << player1 << " wins!" << endl;
		    return 0;
	    }
	    else if (board[7] == 'O' && board[5] == 'O' && board[3] == 'O')
	    {
		    cout << player2 << " wins!" << endl;
		    return 0;
	    }
         
    } 
    cout << "Cats Game" << endl;
    return 0;
}