TicTacToe

By AlexRapso on Apr 27, 2010

TicTacToe game i made for a university project, has a pointless 10x10 square which i had to make but all the rest is good.

#include <iostream> // basic library for standard C++
#include <string>   // library so you can use strongs
#include <fstream>  // allows you to read and save files

using namespace std;
// making variables and assigning values
bool gamedone;
int choice,player,again,game,move,gamewin,aturn,players,top;
string playagain,whichplayer;
string playernameone = " ";
string playernametwo = " ";
char sep = ' ';
// making a structure for the tictactoe spaces, which is a huge array of data
struct Tictactoe 
{
    string a;
    string b;
    string c;
    string d;
    string e;
    string f;
    string g;
    string h;
    string i;
    string j;
} space[10];
//Structure for the score table
struct Table 
{
    string name;
    int play;
    int win;
    int loss;
    int draw;
}playa[20];
//making sure that the value put into this function is a number if not it converts to a 0 
int WholeNumberValidation()
{
    int choice; // making a local variable
    char sEntry[255];
    cin >> sEntry;
    choice = atoi(sEntry);
    return choice;
}
/*
    this is a function to check that the name being used isn't already in use by another person
    and if it is they will be asked if it is them if not they have to change name
*/
string namecheck(string playername)
{   
    top = 0;
    string yesno;
    ifstream datafile("table.rec"); // opening a file for read only 
    datafile >> top; // taking the first piece of data out of the file and putting it into "top"
    if (top > 0)
    {
        do 
        {
            yesno = "yes";
            for (int counter = 0; counter < top; counter++) 
            {
                datafile >> playa[counter].name;
                datafile >> playa[counter].play;
                datafile >> playa[counter].win;
                datafile >> playa[counter].loss;
                datafile >> playa[counter].draw;
                /*
                    using a for loop to check if the name entered is a match to one in the file
                */
                if (playername == playa[counter].name)
                {
                    system("cls"); // clearing the screen 
                    cout << "There is already a player called " << playername << " is this you?" << endl; 
                    cout << "Please type yes or no: ";
                    cin >> yesno; // user input 
                    if (yesno == "no" && top < 20) // if its a no then this statement happens
                    {
                        do 
                        {
                            system("cls");
                            cout << "Please enter a new name: ";
                            cin >> playername;
                        } while (playername == playa[counter].name);
                    }
                }
            }
        } while (yesno == "no");
        if (top == 20) { cout << "Sorry but you will not be able to join the league table"; } 
        // if there are 20 people in the league table already then they cant join the table
    }
    datafile.close(); // closing the file
    return playername;
}
/*
    there can be 1 or 2 players so i needed to different prts to saving a file
    this is the function to save for 1 player
*/
void saveresultstwo(string windrawlose)
{
    int check = 0;
    ifstream datafile("table.rec"); // opening a file
    datafile >> top;
    if (top <= 20) // if there are more than 20 people it will skip this part 
    {
        if (top >= 1) // if there is more than 1 or more persons this part will happen 
        {
            for (int counter = 0; counter < top; counter++)
            {
                datafile >> playa[counter].name;
                datafile >> playa[counter].play;
                datafile >> playa[counter].win;
                datafile >> playa[counter].loss;
                datafile >> playa[counter].draw;
                if (playernameone == playa[counter].name)
                {
                    if (windrawlose == "win") //if player wins this functions happens
                    {
                        playa[counter].play = playa[counter].play + 1;
                        playa[counter].win = playa[counter].win + 1;
                        check = 1;
                    }
                    if (windrawlose == "lose")//if player loses this functions happens
                    {
                        playa[counter].play = playa[counter].play + 1;
                        playa[counter].loss = playa[counter].loss + 1;
                        check = 1;
                    }
                    if (windrawlose == "draw")//if player draws this functions happens
                    {
                        playa[counter].play = playa[counter].play + 1;
                        playa[counter].draw = playa[counter].draw + 1;
                        check = 1;
                    }
                }
            }
            datafile.close(); // closing file
            if (check != 1)
            {
                if (windrawlose == "win")
                {
                    top = top + 1;
                    playa[top-1].name = playernameone;
                    playa[top-1].play = 1;
                    playa[top-1].win = 1;
                    playa[top-1].loss = 0;
                    playa[top-1].draw = 0;
                    check = 1;
                    cout << check;
                }
                if (windrawlose == "lose")
                {
                    top = top + 1;
                    playa[top-1].name = playernameone;
                    playa[top-1].play = 1;
                    playa[top-1].win = 0;
                    playa[top-1].loss = 1;
                    playa[top-1].draw = 0;
                    check = 1;
                }
                if (windrawlose == "draw")
                {
                    top = top + 1;
                    playa[top-1].name = playernameone;
                    playa[top-1].play = 1;
                    playa[top-1].win = 0;
                    playa[top-1].loss = 0;
                    playa[top-1].draw = 1;
                    check = 1;
                }
            }
        }
        else // if there are no people in the file this part happens
        {
            if (windrawlose == "win")
            {
                top = 1;
                playa[0].name = playernameone;
                playa[0].play = 1;
                playa[0].win = 1;
                playa[0].loss = 0;
                playa[0].draw = 0;
            }
            if (windrawlose == "lose")
            {
                top = 1;
                playa[0].name = playernameone;
                playa[0].play = 1;
                playa[0].win = 0;
                playa[0].loss = 1;
                playa[0].draw = 0;
            }
            if (windrawlose == "draw")
            {
                top = 1;
                playa[0].name = playernameone;
                playa[0].play = 1;
                playa[0].win = 0;
                playa[0].loss = 0;
                playa[0].draw = 1;
            }
            /*
                opening the file and then saving the date to it
            */
            ofstream datafile("table.rec");
            datafile << top << sep << playa[0].name << sep << playa[0].play << sep << playa[0].win << sep << playa[0].loss << sep << playa[0].draw << sep;
            check = 0;
        }
        if (check == 1)
        {
            /*
                opening the file and then saving multiple files at once in a for loop 
            */
            ofstream datafile("table.rec");
            datafile << top << sep; // put the first top part in first so you can read it next time
            cout <<top;
            for (int counter = 0; counter < top; counter++)
            {
                datafile << playa[counter].name << sep << playa[counter].play << sep << playa[counter].win << sep << playa[counter].loss << sep << playa[counter].draw << sep;
            }
        }
    }
    datafile.close(); // closing the file properly so no data is lost 
}
/*
    this is the second saving part for 2 players it uses the same things as before but does it for 2 different players
*/
void saveresults(string windraw)
{
    string won;
    string loss;
    int check = 0;
    ifstream datafile("table.rec");
    datafile >> top;
    if (top <= 20)
    {
        if (windraw == "win")
        {
            won = whichplayer;
            if (whichplayer != playernameone) { loss = playernameone; } // figures out which player won and lost 
            else { loss = playernametwo; }
            if (top > 0)
            {
                for (int counter = 0; counter <= top; counter++) // this is for the player that won
                {
                    datafile >> playa[counter].name;
                    datafile >> playa[counter].play;
                    datafile >> playa[counter].win;
                    datafile >> playa[counter].loss;
                    datafile >> playa[counter].draw;
                    if (won == playa[counter].name)
                    {
                        playa[counter].play = playa[counter].play + 1;
                        playa[counter].win = playa[counter].win + 1;
                        check = 1;
                    }
                }
                datafile.close();
                if (check != 1)
                {
                    top = top + 1;
                    playa[top-1].name = won;
                    playa[top-1].play = 1;
                    playa[top-1].win = 1;
                    playa[top-1].loss = 0;
                    playa[top-1].draw = 0;
                }
                check = 0;
                for (int counter = 0; counter < top; counter++) // this is for the player that lost
                {
                    datafile >> playa[counter].name;
                    datafile >> playa[counter].play;
                    datafile >> playa[counter].win;
                    datafile >> playa[counter].loss;
                    datafile >> playa[counter].draw;
                    if (loss == playa[counter].name)
                    {
                        playa[counter].play = playa[counter].play + 1;
                        playa[counter].loss = playa[counter].loss + 1;
                        check = 1;
                    }
                }
                if (check != 1)
                {
                    top = top + 1;
                    playa[top-1].name = loss;
                    playa[top-1].play = 1;
                    playa[top-1].win = 0;
                    playa[top-1].loss = 1;
                    playa[top-1].draw = 0;
                }
                check = 1;
            }
            else // if there was noone in the file already it saves both players at once
            {
                top = 2;
                playa[0].name = won;
                playa[0].play = 1;
                playa[0].win = 1;
                playa[0].loss = 0;
                playa[0].draw = 0;
                playa[1].name = loss;
                playa[1].play = 1;
                playa[1].win = 0;
                playa[1].loss = 1;
                playa[1].draw = 0;
                ofstream datafile("table.rec");
                datafile << top << sep << playa[0].name << sep << playa[0].play << sep << playa[0].win << sep << playa[0].loss << sep << playa[0].draw;
                datafile << sep << playa[1].name << sep << playa[1].play << sep << playa[1].win << sep << playa[1].loss << sep << playa[1].draw << sep;
                check = 0;
            }
            if (check == 1)
            {
                ofstream datafile("table.rec");
                datafile << top << sep;
                for (int counter = 0; counter < top; counter++)
                {
                    datafile << playa[counter].name << sep << playa[counter].play << sep << playa[counter].win << sep << playa[counter].loss << sep << playa[counter].draw << sep;
                }
            }
        }
        if (windraw == "draw") // if there was a draw this would happen 
        {
            if (top > 0)
            {
                int check = 0;
                for (int counter = 0; counter < top; counter++) // they both drew so player 1 is first this time
                {
                    datafile >> playa[counter].name;
                    datafile >> playa[counter].play;
                    datafile >> playa[counter].win;
                    datafile >> playa[counter].loss;
                    datafile >> playa[counter].draw;
                    if (playernameone == playa[counter].name)
                    {
                        playa[counter].play = playa[counter].play + 1;
                        playa[counter].draw = playa[counter].draw + 1;
                        check = 1;
                    }
                }
                if (check != 1)
                {
                    top = top + 1;
                    playa[top-1].name = playernameone;
                    playa[top-1].play = 1;
                    playa[top-1].win = 0;
                    playa[top-1].loss = 0;
                    playa[top-1].draw = 1;
                }
                check = 0;
                for (int counter = 0; counter < top; counter++) //next is player two
                {
                    datafile >> playa[counter].name;
                    datafile >> playa[counter].play;
                    datafile >> playa[counter].win;
                    datafile >> playa[counter].loss;
                    datafile >> playa[counter].draw;
                    if (playernametwo == playa[counter].name)
                    {
                        playa[counter].play = playa[counter].play + 1;
                        playa[counter].loss = playa[counter].draw + 1;
                        int check = 1;
                    }
                }
                if (check != 1)
                {
                    top = top + 1;
                    playa[top-1].name = playernametwo;
                    playa[top-1].play = 1;
                    playa[top-1].win = 0;
                    playa[top-1].loss = 0;
                    playa[top-1].draw = 1;
                }
                check = 1;
            }
            else // if there is noone in the file it saves both as a draw
            {
                top = 2;
                playa[0].name = playernameone;
                playa[0].play = 1;
                playa[0].win = 0;
                playa[0].loss = 0;
                playa[0].draw = 1;
                playa[1].name = playernametwo;
                playa[1].play = 1;
                playa[1].win = 0;
                playa[1].loss = 0;
                playa[1].draw = 1;
                ofstream datafile("table.rec");
                datafile << top << sep << playa[0].name << sep << playa[0].play << sep << playa[0].win << sep << playa[0].loss << sep << playa[0].draw;
                datafile << sep << playa[1].name << sep << playa[1].play << sep << playa[1].win << sep << playa[1].loss << sep << playa[1].draw << sep;
                check = 0;
            }
            if (check == 1)//saving the file the same way as before
            {
                ofstream datafile("table.rec");
                datafile << top << sep;
                for (int counter = 0; counter < top; counter++)
                {
                    datafile << playa[counter].name << sep << playa[counter].play << sep << playa[counter].win << sep << playa[counter].loss << sep << playa[counter].draw << sep;
                }
            }
        }
    }
    datafile.close();//closing the file properly 
}
void win(bool x)
{
    /*
        when the player wins on the expert game it brings them to here
        it shows the 10x10 square and who has won the game
    */
    system("cls");
    cout << "Tic Tac Toe" << endl << endl;
    cout << playernameone << " (X)  -  " << playernametwo << " (O)" << endl << endl;
    cout << endl;
    cout << "     1    |2    |3    |4    |5    |6    |7    |8    |9    | 10    " << endl; 
    cout << "       " << space[0].a << "  |  " << space[0].b << "  |  " << space[0].c << "  |  " << space[0].d << "  |  " << space[0].e << "  |  " << space[0].f << "  |  " << space[0].g << "  |  " << space[0].h << "  |  " << space[0].i << "  |  " << space[0].j << endl;
    cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl; 
    cout << "     11   |12   |13   |14   |15   |16   |17   |18   |19   |20   " << endl; 
    cout << "       " << space[1].a << "  |  " << space[1].b << "  |  " << space[1].c << "  |  " << space[1].d << "  |  " << space[1].e << "  |  " << space[1].f << "  |  " << space[1].g << "  |  " << space[1].h << "  |  " << space[1].i << "  |  " << space[1].j << endl;
    cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl; 
    cout << "     21   |22   |23   |24   |25   |26   |27   |28   |29   |30   " << endl; 
    cout << "       " << space[2].a << "  |  " << space[2].b << "  |  " << space[2].c << "  |  " << space[2].d << "  |  " << space[2].e << "  |  " << space[2].f << "  |  " << space[2].g << "  |  " << space[2].h << "  |  " << space[2].i << "  |  " << space[2].j << endl;
    cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl;
    cout << "     31   |32   |33   |34   |35   |36   |37   |38   |39   |40   " << endl; 
    cout << "       " << space[3].a << "  |  " << space[3].b << "  |  " << space[3].c << "  |  " << space[3].d << "  |  " << space[3].e << "  |  " << space[3].f << "  |  " << space[3].g << "  |  " << space[3].h << "  |  " << space[3].i << "  |  " << space[3].j << endl;
    cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl;
    cout << "     41   |42   |43   |44   |45   |46   |47   |48   |49   |50   " << endl; 
    cout << "       " << space[4].a << "  |  " << space[4].b << "  |  " << space[4].c << "  |  " << space[4].d << "  |  " << space[4].e << "  |  " << space[4].f << "  |  " << space[4].g << "  |  " << space[4].h << "  |  " << space[4].i << "  |  " << space[4].j << endl;
    cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl;
    cout << "     51   |52   |53   |54   |55   |56   |57   |58   |59   |60   " << endl; 
    cout << "       " << space[5].a << "  |  " << space[5].b << "  |  " << space[5].c << "  |  " << space[5].d << "  |  " << space[5].e << "  |  " << space[5].f << "  |  " << space[5].g << "  |  " << space[5].h << "  |  " << space[5].i << "  |  " << space[5].j << endl;
    cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl; 
    cout << "     61   |62   |63   |64   |65   |66   |67   |68   |69   |70   " << endl; 
    cout << "       " << space[6].a << "  |  " << space[6].b << "  |  " << space[6].c << "  |  " << space[6].d << "  |  " << space[6].e << "  |  " << space[6].f << "  |  " << space[6].g << "  |  " << space[6].h << "  |  " << space[6].i << "  |  " << space[6].j << endl;
    cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl; 
    cout << "     71   |72   |73   |74   |75   |76   |77   |78   |79   |80   " << endl; 
    cout << "       " << space[7].a << "  |  " << space[7].b << "  |  " << space[7].c << "  |  " << space[7].d << "  |  " << space[7].e << "  |  " << space[7].f << "  |  " << space[7].g << "  |  " << space[7].h << "  |  " << space[7].i << "  |  " << space[7].j << endl;
    cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl;
    cout << "     81   |82   |83   |84   |85   |86   |87   |88   |89   |90     " << endl; 
    cout << "       " << space[8].a << "  |  " << space[8].b << "  |  " << space[8].c << "  |  " << space[8].d << "  |  " << space[8].e << "  |  " << space[8].f << "  |  " << space[8].g << "  |  " << space[8].h << "  |  " << space[8].i << "  |  " << space[8].j << endl;
    cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl;
    cout << "     91   |92   |93   |94   |95   |96   |97   |98   |99   |100  " << endl; 
    cout << "       " << space[9].a << "  |  " << space[9].b << "  |  " << space[9].c << "  |  " << space[9].d << "  |  " << space[9].e << "  |  " << space[9].f << "  |  " << space[9].g << "  |  " << space[9].h << "  |  " << space[9].i << "  |  " << space[9].j << endl;
    cout << "          |     |     |     |     |     |     |     |     |     " << endl << endl;
    if (x == true) // if game is won not drawn this part happens
    {              // it is then saved to the file as a win and loss
        cout << whichplayer << " won!!!" << endl << endl;
        saveresults("win");
    }   
    else { cout << "It's a stale mate!" << endl << endl; saveresults("draw"); }
    // if not this happens because it is an else statement and the results are saved to the file as a draw
    gamedone = true; 
    system("pause");
}
/*
    this is the complicated and effort consuming part 
    using if statements to check every single win line 
    if the game has been won it will jump to the win function and end the game
*/
void checkwin()
{
    if (space[0].a != " " && space[0].a == space[0].b && space[0].b == space[0].c) win(true);
    if (space[0].b != " " && space[0].b == space[0].c && space[0].c == space[0].d) win(true);
    if (space[0].c != " " && space[0].c == space[0].d && space[0].d == space[0].e) win(true);
    if (space[0].d != " " && space[0].d == space[0].e && space[0].e == space[0].f) win(true);
    if (space[0].e != " " && space[0].e == space[0].f && space[0].f == space[0].g) win(true);
    if (space[0].f != " " && space[0].f == space[0].g && space[0].g == space[0].h) win(true);
    if (space[0].g != " " && space[0].g == space[0].h && space[0].h == space[0].i) win(true);
    if (space[0].h != " " && space[0].h == space[0].i && space[0].i == space[0].j) win(true);
    if (space[1].a != " " && space[1].a == space[1].b && space[1].b == space[1].c) win(true);
    if (space[1].b != " " && space[1].b == space[1].c && space[1].c == space[1].d) win(true);
    if (space[1].c != " " && space[1].c == space[1].d && space[1].d == space[1].e) win(true);
    if (space[1].d != " " && space[1].d == space[1].e && space[1].e == space[1].f) win(true);
    if (space[1].e != " " && space[1].e == space[1].f && space[1].f == space[1].g) win(true);
    if (space[1].f != " " && space[1].f == space[1].g && space[1].g == space[1].h) win(true);
    if (space[1].g != " " && space[1].g == space[1].h && space[1].h == space[1].i) win(true);
    if (space[1].h != " " && space[1].h == space[1].i && space[1].i == space[1].j) win(true);
    if (space[2].a != " " && space[2].a == space[2].b && space[2].b == space[2].c) win(true);
    if (space[2].b != " " && space[2].b == space[2].c && space[2].c == space[2].d) win(true);
    if (space[2].c != " " && space[2].c == space[2].d && space[2].d == space[2].e) win(true);
    if (space[2].d != " " && space[2].d == space[2].e && space[2].e == space[2].f) win(true);
    if (space[2].e != " " && space[2].e == space[2].f && space[2].f == space[2].g) win(true);
    if (space[2].f != " " && space[2].f == space[2].g && space[2].g == space[2].h) win(true);
    if (space[2].g != " " && space[2].g == space[2].h && space[2].h == space[2].i) win(true);
    if (space[2].h != " " && space[2].h == space[2].i && space[2].i == space[2].j) win(true);
    if (space[3].a != " " && space[3].a == space[3].b && space[3].b == space[3].c) win(true);
    if (space[3].b != " " && space[3].b == space[3].c && space[3].c == space[3].d) win(true);
    if (space[3].c != " " && space[3].c == space[3].d && space[3].d == space[3].e) win(true);
    if (space[3].d != " " && space[3].d == space[3].e && space[3].e == space[3].f) win(true);
    if (space[3].e != " " && space[3].e == space[3].f && space[3].f == space[3].g) win(true);
    if (space[3].f != " " && space[3].f == space[3].g && space[3].g == space[3].h) win(true);
    if (space[3].g != " " && space[3].g == space[3].h && space[3].h == space[3].i) win(true);
    if (space[3].h != " " && space[3].h == space[3].i && space[3].i == space[3].j) win(true);
    if (space[4].a != " " && space[4].a == space[4].b && space[4].b == space[4].c) win(true);
    if (space[4].b != " " && space[4].b == space[4].c && space[4].c == space[4].d) win(true);
    if (space[4].c != " " && space[4].c == space[4].d && space[4].d == space[4].e) win(true);
    if (space[4].d != " " && space[4].d == space[4].e && space[4].e == space[4].f) win(true);
    if (space[4].e != " " && space[4].e == space[4].f && space[4].f == space[4].g) win(true);
    if (space[4].f != " " && space[4].f == space[4].g && space[4].g == space[4].h) win(true);
    if (space[4].g != " " && space[4].g == space[4].h && space[4].h == space[4].i) win(true);
    if (space[4].h != " " && space[4].h == space[4].i && space[4].i == space[4].j) win(true);
    if (space[5].a != " " && space[5].a == space[5].b && space[5].b == space[5].c) win(true);
    if (space[5].b != " " && space[5].b == space[5].c && space[5].c == space[5].d) win(true);
    if (space[5].c != " " && space[5].c == space[5].d && space[5].d == space[5].e) win(true);
    if (space[5].d != " " && space[5].d == space[5].e && space[5].e == space[5].f) win(true);
    if (space[5].e != " " && space[5].e == space[5].f && space[5].f == space[5].g) win(true);
    if (space[5].f != " " && space[5].f == space[5].g && space[5].g == space[5].h) win(true);
    if (space[5].g != " " && space[5].g == space[5].h && space[5].h == space[5].i) win(true);
    if (space[5].h != " " && space[5].h == space[5].i && space[5].i == space[5].j) win(true);
    if (space[6].a != " " && space[6].a == space[6].b && space[6].b == space[6].c) win(true);
    if (space[6].b != " " && space[6].b == space[6].c && space[6].c == space[6].d) win(true);
    if (space[6].c != " " && space[6].c == space[6].d && space[6].d == space[6].e) win(true);
    if (space[6].d != " " && space[6].d == space[6].e && space[6].e == space[6].f) win(true);
    if (space[6].e != " " && space[6].e == space[6].f && space[6].f == space[6].g) win(true);
    if (space[6].f != " " && space[6].f == space[6].g && space[6].g == space[6].h) win(true);
    if (space[6].g != " " && space[6].g == space[6].h && space[6].h == space[6].i) win(true);
    if (space[6].h != " " && space[6].h == space[6].i && space[6].i == space[6].j) win(true);
    if (space[7].a != " " && space[7].a == space[7].b && space[7].b == space[7].c) win(true);
    if (space[7].b != " " && space[7].b == space[7].c && space[7].c == space[7].d) win(true);
    if (space[7].c != " " && space[7].c == space[7].d && space[7].d == space[7].e) win(true);
    if (space[7].d != " " && space[7].d == space[7].e && space[7].e == space[7].f) win(true);
    if (space[7].e != " " && space[7].e == space[7].f && space[7].f == space[7].g) win(true);
    if (space[7].f != " " && space[7].f == space[7].g && space[7].g == space[7].h) win(true);
    if (space[7].g != " " && space[7].g == space[7].h && space[7].h == space[7].i) win(true);
    if (space[7].h != " " && space[7].h == space[7].i && space[7].i == space[7].j) win(true);
    if (space[8].a != " " && space[8].a == space[8].b && space[8].b == space[8].c) win(true);
    if (space[8].b != " " && space[8].b == space[8].c && space[8].c == space[8].d) win(true);
    if (space[8].c != " " && space[8].c == space[8].d && space[8].d == space[8].e) win(true);
    if (space[8].d != " " && space[8].d == space[8].e && space[8].e == space[8].f) win(true);
    if (space[8].e != " " && space[8].e == space[8].f && space[8].f == space[8].g) win(true);
    if (space[8].f != " " && space[8].f == space[8].g && space[8].g == space[8].h) win(true);
    if (space[8].g != " " && space[8].g == space[8].h && space[8].h == space[8].i) win(true);
    if (space[8].h != " " && space[8].h == space[8].i && space[8].i == space[8].j) win(true);
    if (space[9].a != " " && space[9].a == space[9].b && space[9].b == space[9].c) win(true);
    if (space[9].b != " " && space[9].b == space[9].c && space[9].c == space[9].d) win(true);
    if (space[9].c != " " && space[9].c == space[9].d && space[9].d == space[9].e) win(true);
    if (space[9].d != " " && space[9].d == space[9].e && space[9].e == space[9].f) win(true);
    if (space[9].e != " " && space[9].e == space[9].f && space[9].f == space[9].g) win(true);
    if (space[9].f != " " && space[9].f == space[9].g && space[9].g == space[9].h) win(true);
    if (space[9].g != " " && space[9].g == space[9].h && space[9].h == space[9].i) win(true);
    if (space[9].h != " " && space[9].h == space[9].i && space[9].i == space[9].j) win(true);
    if (space[0].a != " " && space[0].a == space[1].b && space[1].b == space[2].c) win(true);
    if (space[1].b != " " && space[1].b == space[2].c && space[2].c == space[3].d) win(true);
    if (space[2].c != " " && space[2].c == space[3].d && space[3].d == space[4].e) win(true);
    if (space[3].d != " " && space[3].d == space[4].e && space[4].e == space[5].f) win(true);
    if (space[4].e != " " && space[4].e == space[5].f && space[5].f == space[6].g) win(true);
    if (space[5].f != " " && space[5].f == space[6].g && space[6].g == space[7].h) win(true);
    if (space[6].g != " " && space[6].g == space[7].h && space[7].h == space[8].i) win(true);
    if (space[7].h != " " && space[7].h == space[8].i && space[8].i == space[9].j) win(true);
    if (space[0].b != " " && space[0].b == space[1].c && space[1].c == space[2].d) win(true);
    if (space[1].c != " " && space[1].c == space[2].d && space[2].d == space[3].e) win(true);
    if (space[2].d != " " && space[2].d == space[3].e && space[3].e == space[4].f) win(true);
    if (space[3].e != " " && space[3].e == space[4].f && space[4].f == space[5].g) win(true);
    if (space[4].f != " " && space[4].f == space[5].g && space[5].g == space[6].h) win(true);
    if (space[5].g != " " && space[5].g == space[6].h && space[6].h == space[7].i) win(true);
    if (space[6].h != " " && space[6].h == space[7].i && space[7].i == space[8].j) win(true);
    if (space[0].c != " " && space[0].c == space[1].d && space[1].d == space[2].e) win(true);
    if (space[1].d != " " && space[1].d == space[2].e && space[2].e == space[3].f) win(true);
    if (space[2].e != " " && space[2].e == space[3].f && space[3].f == space[4].g) win(true);
    if (space[3].f != " " && space[3].f == space[4].g && space[4].g == space[5].h) win(true);
    if (space[4].g != " " && space[4].g == space[5].h && space[5].h == space[6].i) win(true);
    if (space[5].h != " " && space[5].h == space[6].i && space[6].i == space[7].j) win(true);
    if (space[0].d != " " && space[0].d == space[1].e && space[1].e == space[2].f) win(true);
    if (space[1].e != " " && space[1].e == space[2].f && space[2].f == space[3].g) win(true);
    if (space[2].f != " " && space[2].f == space[3].g && space[3].g == space[4].h) win(true);
    if (space[3].g != " " && space[3].g == space[4].h && space[4].h == space[5].i) win(true);
    if (space[4].h != " " && space[4].h == space[5].i && space[5].i == space[6].j) win(true);
    if (space[0].e != " " && space[0].e == space[1].f && space[1].f == space[2].g) win(true);
    if (space[1].f != " " && space[1].f == space[2].g && space[2].g == space[3].h) win(true);
    if (space[2].g != " " && space[2].g == space[3].h && space[3].h == space[4].i) win(true);
    if (space[3].h != " " && space[3].h == space[4].i && space[4].i == space[5].j) win(true);
    if (space[0].f != " " && space[0].f == space[1].g && space[1].g == space[2].h) win(true);
    if (space[1].g != " " && space[1].g == space[2].h && space[2].h == space[3].i) win(true);
    if (space[2].h != " " && space[2].h == space[3].i && space[3].i == space[4].j) win(true);
    if (space[0].g != " " && space[0].g == space[1].h && space[1].h == space[2].i) win(true);
    if (space[1].h != " " && space[1].h == space[2].i && space[2].i == space[3].j) win(true);
    if (space[0].h != " " && space[0].h == space[1].i && space[1].i == space[2].j) win(true);
    if (space[1].a != " " && space[1].a == space[2].b && space[2].b == space[3].c) win(true);
    if (space[2].b != " " && space[2].b == space[3].c && space[3].c == space[4].d) win(true);
    if (space[3].c != " " && space[3].c == space[4].d && space[4].d == space[5].e) win(true);
    if (space[4].d != " " && space[4].d == space[5].e && space[5].e == space[6].f) win(true);
    if (space[5].e != " " && space[5].e == space[6].f && space[6].f == space[7].g) win(true);
    if (space[6].f != " " && space[6].f == space[7].g && space[7].g == space[8].h) win(true);
    if (space[7].g != " " && space[7].g == space[8].h && space[8].h == space[9].i) win(true);
    if (space[2].a != " " && space[2].a == space[3].b && space[3].b == space[4].c) win(true);
    if (space[3].b != " " && space[3].b == space[4].c && space[4].c == space[5].d) win(true);
    if (space[4].c != " " && space[4].c == space[5].d && space[5].d == space[6].e) win(true);
    if (space[5].d != " " && space[5].d == space[6].e && space[6].e == space[7].f) win(true);
    if (space[6].e != " " && space[6].e == space[7].f && space[7].f == space[8].g) win(true);
    if (space[7].f != " " && space[7].f == space[8].g && space[8].g == space[9].h) win(true);
    if (space[3].a != " " && space[3].a == space[4].b && space[4].b == space[5].c) win(true);
    if (space[4].b != " " && space[4].b == space[5].c && space[5].c == space[6].d) win(true);
    if (space[5].c != " " && space[5].c == space[6].d && space[6].d == space[7].e) win(true);
    if (space[6].d != " " && space[6].d == space[7].e && space[7].e == space[8].f) win(true);
    if (space[7].e != " " && space[7].e == space[8].f && space[8].f == space[9].g) win(true);
    if (space[4].a != " " && space[4].a == space[5].b && space[5].b == space[6].c) win(true);
    if (space[5].b != " " && space[5].b == space[6].c && space[6].c == space[7].d) win(true);
    if (space[6].c != " " && space[6].c == space[7].d && space[7].d == space[8].e) win(true);
    if (space[7].d != " " && space[7].d == space[8].e && space[8].e == space[9].f) win(true);
    if (space[5].a != " " && space[5].a == space[6].b && space[6].b == space[7].c) win(true);
    if (space[6].b != " " && space[6].b == space[7].c && space[7].c == space[8].d) win(true);
    if (space[7].c != " " && space[7].c == space[8].d && space[8].d == space[9].e) win(true);
    if (space[6].a != " " && space[6].a == space[7].b && space[7].b == space[8].c) win(true);
    if (space[7].b != " " && space[7].b == space[8].c && space[8].c == space[9].d) win(true);
    if (space[7].a != " " && space[7].a == space[8].b && space[8].b == space[9].c) win(true);
    if (space[0].a != " " && space[0].a == space[1].a && space[1].a == space[2].a) win(true);
    if (space[1].a != " " && space[1].a == space[2].a && space[2].a == space[3].a) win(true);
    if (space[2].a != " " && space[2].a == space[3].a && space[3].a == space[4].a) win(true);
    if (space[3].a != " " && space[3].a == space[4].a && space[4].a == space[5].a) win(true);
    if (space[4].a != " " && space[4].a == space[5].a && space[5].a == space[6].a) win(true);
    if (space[5].a != " " && space[5].a == space[6].a && space[6].a == space[7].a) win(true);
    if (space[6].a != " " && space[6].a == space[7].a && space[7].a == space[8].a) win(true);
    if (space[7].a != " " && space[7].a == space[8].a && space[8].a == space[9].a) win(true);
    if (space[0].b != " " && space[0].b == space[1].b && space[1].b == space[2].b) win(true);
    if (space[1].b != " " && space[1].b == space[2].b && space[2].b == space[3].b) win(true);
    if (space[2].b != " " && space[2].b == space[3].b && space[3].b == space[4].b) win(true);
    if (space[3].b != " " && space[3].b == space[4].b && space[4].b == space[5].b) win(true);
    if (space[4].b != " " && space[4].b == space[5].b && space[5].b == space[6].b) win(true);
    if (space[5].b != " " && space[5].b == space[6].b && space[6].b == space[7].b) win(true);
    if (space[6].b != " " && space[6].b == space[7].b && space[7].b == space[8].b) win(true);
    if (space[7].b != " " && space[7].b == space[8].b && space[8].b == space[9].b) win(true);
    if (space[0].c != " " && space[0].c == space[1].c && space[1].c == space[2].c) win(true);
    if (space[1].c != " " && space[1].c == space[2].c && space[2].c == space[3].c) win(true);
    if (space[2].c != " " && space[2].c == space[3].c && space[3].c == space[4].c) win(true);
    if (space[3].c != " " && space[3].c == space[4].c && space[4].c == space[5].c) win(true);
    if (space[4].c != " " && space[4].c == space[5].c && space[5].c == space[6].c) win(true);
    if (space[5].c != " " && space[5].c == space[6].c && space[6].c == space[7].c) win(true);
    if (space[6].c != " " && space[6].c == space[7].c && space[7].c == space[8].c) win(true);
    if (space[7].c != " " && space[7].c == space[8].c && space[8].c == space[9].c) win(true);
    if (space[0].d != " " && space[0].d == space[1].d && space[1].d == space[2].d) win(true);
    if (space[1].d != " " && space[1].d == space[2].d && space[2].d == space[3].d) win(true);
    if (space[2].d != " " && space[2].d == space[3].d && space[3].d == space[4].d) win(true);
    if (space[3].d != " " && space[3].d == space[4].d && space[4].d == space[5].d) win(true);
    if (space[4].d != " " && space[4].d == space[5].d && space[5].d == space[6].d) win(true);
    if (space[5].d != " " && space[5].d == space[6].d && space[6].d == space[7].d) win(true);
    if (space[6].d != " " && space[6].d == space[7].d && space[7].d == space[8].d) win(true);
    if (space[7].d != " " && space[7].d == space[8].d && space[8].d == space[9].d) win(true);
    if (space[0].e != " " && space[0].e == space[1].e && space[1].e == space[2].e) win(true);
    if (space[1].e != " " && space[1].e == space[2].e && space[2].e == space[3].e) win(true);
    if (space[2].e != " " && space[2].e == space[3].e && space[3].e == space[4].e) win(true);
    if (space[3].e != " " && space[3].e == space[4].e && space[4].e == space[5].e) win(true);
    if (space[4].e != " " && space[4].e == space[5].e && space[5].e == space[6].e) win(true);
    if (space[5].e != " " && space[5].e == space[6].e && space[6].e == space[7].e) win(true);
    if (space[6].e != " " && space[6].e == space[7].e && space[7].e == space[8].e) win(true);
    if (space[7].e != " " && space[7].e == space[8].e && space[8].e == space[9].e) win(true);
    if (space[0].f != " " && space[0].f == space[1].f && space[1].f == space[2].f) win(true);
    if (space[1].f != " " && space[1].f == space[2].f && space[2].f == space[3].f) win(true);
    if (space[2].f != " " && space[2].f == space[3].f && space[3].f == space[4].f) win(true);
    if (space[3].f != " " && space[3].f == space[4].f && space[4].f == space[5].f) win(true);
    if (space[4].f != " " && space[4].f == space[5].f && space[5].f == space[6].f) win(true);
    if (space[5].f != " " && space[5].f == space[6].f && space[6].f == space[7].f) win(true);
    if (space[6].f != " " && space[6].f == space[7].f && space[7].f == space[8].f) win(true);
    if (space[7].f != " " && space[7].f == space[8].f && space[8].f == space[9].f) win(true);
    if (space[0].g != " " && space[0].g == space[1].g && space[1].g == space[2].g) win(true);
    if (space[1].g != " " && space[1].g == space[2].g && space[2].g == space[3].g) win(true);
    if (space[2].g != " " && space[2].g == space[3].g && space[3].g == space[4].g) win(true);
    if (space[3].g != " " && space[3].g == space[4].g && space[4].g == space[5].g) win(true);
    if (space[4].g != " " && space[4].g == space[5].g && space[5].g == space[6].g) win(true);
    if (space[5].g != " " && space[5].g == space[6].g && space[6].g == space[7].g) win(true);
    if (space[6].g != " " && space[6].g == space[7].g && space[7].g == space[8].g) win(true);
    if (space[7].g != " " && space[7].g == space[8].g && space[8].g == space[9].g) win(true);
    if (space[0].h != " " && space[0].h == space[1].h && space[1].h == space[2].h) win(true);
    if (space[1].h != " " && space[1].h == space[2].h && space[2].h == space[3].h) win(true);
    if (space[2].h != " " && space[2].h == space[3].h && space[3].h == space[4].h) win(true);
    if (space[3].h != " " && space[3].h == space[4].h && space[4].h == space[5].h) win(true);
    if (space[4].h != " " && space[4].h == space[5].h && space[5].h == space[6].h) win(true);
    if (space[5].h != " " && space[5].h == space[6].h && space[6].h == space[7].h) win(true);
    if (space[6].h != " " && space[6].h == space[7].h && space[7].h == space[8].h) win(true);
    if (space[7].h != " " && space[7].h == space[8].h && space[8].h == space[9].h) win(true);
    if (space[0].i != " " && space[0].i == space[1].i && space[1].i == space[2].i) win(true);
    if (space[1].i != " " && space[1].i == space[2].i && space[2].i == space[3].i) win(true);
    if (space[2].i != " " && space[2].i == space[3].i && space[3].i == space[4].i) win(true);
    if (space[3].i != " " && space[3].i == space[4].i && space[4].i == space[5].i) win(true);
    if (space[4].i != " " && space[4].i == space[5].i && space[5].i == space[6].i) win(true);
    if (space[5].i != " " && space[5].i == space[6].i && space[6].i == space[7].i) win(true);
    if (space[6].i != " " && space[6].i == space[7].i && space[7].i == space[8].i) win(true);
    if (space[7].i != " " && space[7].i == space[8].i && space[8].i == space[9].i) win(true);
    if (space[0].j != " " && space[0].j == space[1].j && space[1].j == space[2].j) win(true);
    if (space[1].j != " " && space[1].j == space[2].j && space[2].j == space[3].j) win(true);
    if (space[2].j != " " && space[2].j == space[3].j && space[3].j == space[4].j) win(true);
    if (space[3].j != " " && space[3].j == space[4].j && space[4].j == space[5].j) win(true);
    if (space[4].j != " " && space[4].j == space[5].j && space[5].j == space[6].j) win(true);
    if (space[5].j != " " && space[5].j == space[6].j && space[6].j == space[7].j) win(true);
    if (space[6].j != " " && space[6].j == space[7].j && space[7].j == space[8].j) win(true);
    if (space[7].j != " " && space[7].j == space[8].j && space[8].j == space[9].j) win(true);
    if (space[9].a != " " && space[9].a == space[8].b && space[8].b == space[7].c) win(true);
    if (space[8].b != " " && space[8].b == space[7].c && space[7].c == space[6].d) win(true);
    if (space[7].c != " " && space[7].c == space[6].d && space[6].d == space[5].e) win(true);
    if (space[6].d != " " && space[6].d == space[5].e && space[5].e == space[4].f) win(true);
    if (space[5].e != " " && space[5].e == space[4].f && space[4].f == space[3].g) win(true);
    if (space[4].f != " " && space[4].f == space[3].g && space[3].g == space[2].h) win(true);
    if (space[3].g != " " && space[3].g == space[2].h && space[2].h == space[1].i) win(true);
    if (space[2].h != " " && space[2].h == space[1].i && space[1].i == space[0].j) win(true);
    if (space[8].a != " " && space[8].a == space[7].b && space[7].b == space[6].c) win(true);
    if (space[7].b != " " && space[7].b == space[6].c && space[6].c == space[5].d) win(true);
    if (space[6].c != " " && space[6].c == space[5].d && space[5].d == space[4].e) win(true);
    if (space[5].d != " " && space[5].d == space[4].e && space[4].e == space[3].f) win(true);
    if (space[4].e != " " && space[4].e == space[3].f && space[3].f == space[2].g) win(true);
    if (space[3].f != " " && space[3].f == space[2].g && space[2].g == space[1].h) win(true);
    if (space[2].g != " " && space[2].g == space[1].h && space[1].h == space[0].i) win(true);
    if (space[7].a != " " && space[7].a == space[6].b && space[6].b == space[5].c) win(true);
    if (space[6].b != " " && space[6].b == space[5].c && space[5].c == space[4].d) win(true);
    if (space[5].c != " " && space[5].c == space[4].d && space[4].d == space[3].e) win(true);
    if (space[4].d != " " && space[4].d == space[3].e && space[3].e == space[2].f) win(true);
    if (space[3].e != " " && space[3].e == space[2].f && space[2].f == space[1].g) win(true);
    if (space[2].f != " " && space[2].f == space[1].g && space[1].g == space[0].h) win(true);
    if (space[6].a != " " && space[6].a == space[5].b && space[5].b == space[4].c) win(true);
    if (space[5].b != " " && space[5].b == space[4].c && space[4].c == space[3].d) win(true);
    if (space[4].c != " " && space[4].c == space[3].d && space[3].d == space[2].e) win(true);
    if (space[3].d != " " && space[3].d == space[2].e && space[2].e == space[1].f) win(true);
    if (space[2].e != " " && space[2].e == space[1].f && space[1].f == space[0].g) win(true);
    if (space[5].a != " " && space[5].a == space[4].b && space[4].b == space[3].c) win(true);
    if (space[4].b != " " && space[4].b == space[3].c && space[3].c == space[2].d) win(true);
    if (space[3].c != " " && space[3].c == space[2].d && space[2].d == space[1].e) win(true);
    if (space[2].d != " " && space[2].d == space[1].e && space[1].e == space[0].f) win(true);
    if (space[4].a != " " && space[4].a == space[3].b && space[3].b == space[2].c) win(true);
    if (space[3].b != " " && space[3].b == space[2].c && space[2].c == space[1].d) win(true);
    if (space[2].c != " " && space[2].c == space[1].d && space[1].d == space[0].e) win(true);
    if (space[3].a != " " && space[3].a == space[2].b && space[2].b == space[1].c) win(true);
    if (space[2].b != " " && space[2].b == space[1].c && space[1].c == space[0].d) win(true);
    if (space[2].a != " " && space[2].a == space[1].b && space[1].b == space[0].c) win(true);
    if (space[9].b != " " && space[9].b == space[8].c && space[8].c == space[7].d) win(true);
    if (space[8].c != " " && space[8].c == space[7].d && space[7].d == space[6].e) win(true);
    if (space[7].d != " " && space[7].d == space[6].e && space[6].e == space[5].f) win(true);
    if (space[6].e != " " && space[6].e == space[5].f && space[5].f == space[4].g) win(true);
    if (space[5].f != " " && space[5].f == space[4].g && space[4].g == space[3].h) win(true);
    if (space[4].g != " " && space[4].g == space[3].h && space[3].h == space[2].i) win(true);
    if (space[3].h != " " && space[3].h == space[2].i && space[2].i == space[1].j) win(true);
    if (space[9].c != " " && space[9].c == space[8].d && space[8].d == space[7].e) win(true);
    if (space[8].d != " " && space[8].d == space[7].e && space[7].e == space[6].f) win(true);
    if (space[7].e != " " && space[7].e == space[6].f && space[6].f == space[5].g) win(true);
    if (space[6].f != " " && space[6].f == space[5].g && space[5].g == space[4].h) win(true);
    if (space[5].g != " " && space[5].g == space[4].h && space[4].h == space[3].i) win(true);
    if (space[4].h != " " && space[4].h == space[3].i && space[3].i == space[2].j) win(true);
    if (space[9].d != " " && space[9].d == space[8].e && space[8].e == space[7].f) win(true);
    if (space[8].e != " " && space[8].e == space[7].f && space[7].f == space[6].g) win(true);
    if (space[7].f != " " && space[7].f == space[6].g && space[6].g == space[5].h) win(true);
    if (space[6].g != " " && space[6].g == space[5].h && space[5].h == space[4].i) win(true);
    if (space[5].h != " " && space[5].h == space[4].i && space[4].i == space[3].j) win(true);
    if (space[9].e != " " && space[9].e == space[8].f && space[8].f == space[7].g) win(true);
    if (space[8].f != " " && space[8].f == space[7].g && space[7].g == space[6].h) win(true);
    if (space[7].g != " " && space[7].g == space[6].h && space[6].h == space[5].i) win(true);
    if (space[6].h != " " && space[6].h == space[5].i && space[5].i == space[4].j) win(true);
    if (space[9].f != " " && space[9].f == space[8].g && space[8].g == space[7].h) win(true);
    if (space[8].g != " " && space[8].g == space[7].h && space[7].h == space[6].i) win(true);
    if (space[7].h != " " && space[7].h == space[6].i && space[6].i == space[5].j) win(true);
    if (space[9].g != " " && space[9].g == space[8].h && space[8].h == space[7].i) win(true);
    if (space[8].h != " " && space[8].h == space[7].i && space[7].i == space[6].j) win(true);
    if (space[9].h != " " && space[9].h == space[8].i && space[8].i == space[7].j) win(true);
}
// this is the start of the expert game
void Expert()
{
    gamedone = false;
    player = 1;
    again = 0;
    move = 1;
    //assigning all the spaces with a value of nothing which has to be done or the grid will be messed up
    space[0].a = " ";space[0].b = " ";space[0].c = " ";space[0].d = " ";space[0].e = " ";space[0].f = " ";space[0].g = " ";space[0].h = " ";space[0].i = " ";space[0].j = " ";
    space[1].a = " ";space[1].b = " ";space[1].c = " ";space[1].d = " ";space[1].e = " ";space[1].f = " ";space[1].g = " ";space[1].h = " ";space[1].i = " ";space[1].j = " ";
    space[2].a = " ";space[2].b = " ";space[2].c = " ";space[2].d = " ";space[2].e = " ";space[2].f = " ";space[2].g = " ";space[2].h = " ";space[2].i = " ";space[2].j = " ";
    space[3].a = " ";space[3].b = " ";space[3].c = " ";space[3].d = " ";space[3].e = " ";space[3].f = " ";space[3].g = " ";space[3].h = " ";space[3].i = " ";space[3].j = " ";
    space[4].a = " ";space[4].b = " ";space[4].c = " ";space[4].d = " ";space[4].e = " ";space[4].f = " ";space[4].g = " ";space[4].h = " ";space[4].i = " ";space[4].j = " ";
    space[5].a = " ";space[5].b = " ";space[5].c = " ";space[5].d = " ";space[5].e = " ";space[5].f = " ";space[5].g = " ";space[5].h = " ";space[5].i = " ";space[5].j = " ";
    space[6].a = " ";space[6].b = " ";space[6].c = " ";space[6].d = " ";space[6].e = " ";space[6].f = " ";space[6].g = " ";space[6].h = " ";space[6].i = " ";space[6].j = " ";
    space[7].a = " ";space[7].b = " ";space[7].c = " ";space[7].d = " ";space[7].e = " ";space[7].f = " ";space[7].g = " ";space[7].h = " ";space[7].i = " ";space[7].j = " ";
    space[8].a = " ";space[8].b = " ";space[8].c = " ";space[8].d = " ";space[8].e = " ";space[8].f = " ";space[8].g = " ";space[8].h = " ";space[8].i = " ";space[8].j = " ";
    space[9].a = " ";space[9].b = " ";space[9].c = " ";space[9].d = " ";space[9].e = " ";space[9].f = " ";space[9].g = " ";space[9].h = " ";space[9].i = " ";space[9].j = " ";
    /*
    you are asked to eneter the first and second players names where it will be check 
    if there is one there you will be asked if its you 
    if not you will change your name
    */
    system("cls");
    cout << "TicTacToe Expert Menu" << endl << endl;
    cout << "Type a number for what game you want to play" << endl;
    cout << "Two player: 1" << endl;
    cout << "Main menu: 2" << endl << "Enter here: ";
    // if 3 it goes back to the 
    cin >> players;
    if (players == 1)
    {
        do if (playernameone == " ")
        {
            system("cls");
            cout << "Player 1 please enter your name: ";
            cin >> playernameone;
            playernameone = namecheck(playernameone); // checks to see if the is already someone with this name
        } while (playernameone == " "); // if the name is blank it asks for another name
        // if there is no player 2 then it does this loop
        do
        {
            do if (playernametwo == " " || playernametwo == playernameone)
            {
                system("cls");
                if (playernametwo == playernameone)
                {
                    cout << "This name is already taken by player 1" << endl;
                }
                cout << "Player 2 please enter your name: "; 
                cin >> playernametwo;
                if (playernametwo != playernameone)
                {
                    playernametwo = namecheck(playernametwo); // checks to see if the is already someone with this name
                }
            } while (playernametwo == " ");// if the name is blank it asks for another name
        } while (playernametwo == playernameone);
        do if (gamedone == false)
        {
            do 
            {
                /* 
                    this is the grid i made using whitespace
                    its got the number always in the grid because the grid became distorted when 
                    the numbers where changing from a double digit number to an x or o 
                */
                system("cls");
                cout << "Tic Tac Toe" << endl << endl;
                cout << playernameone << " (X)  -  " << playernametwo << " (O)" << endl << endl;
                cout << endl;
                cout << "     1    |2    |3    |4    |5    |6    |7    |8    |9    | 10    " << endl; 
                cout << "       " << space[0].a << "  |  " << space[0].b << "  |  " << space[0].c << "  |  " << space[0].d << "  |  " << space[0].e << "  |  " << space[0].f << "  |  " << space[0].g << "  |  " << space[0].h << "  |  " << space[0].i << "  |  " << space[0].j << endl;
                cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl; 
                cout << "     11   |12   |13   |14   |15   |16   |17   |18   |19   |20   " << endl; 
                cout << "       " << space[1].a << "  |  " << space[1].b << "  |  " << space[1].c << "  |  " << space[1].d << "  |  " << space[1].e << "  |  " << space[1].f << "  |  " << space[1].g << "  |  " << space[1].h << "  |  " << space[1].i << "  |  " << space[1].j << endl;
                cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl; 
                cout << "     21   |22   |23   |24   |25   |26   |27   |28   |29   |30   " << endl; 
                cout << "       " << space[2].a << "  |  " << space[2].b << "  |  " << space[2].c << "  |  " << space[2].d << "  |  " << space[2].e << "  |  " << space[2].f << "  |  " << space[2].g << "  |  " << space[2].h << "  |  " << space[2].i << "  |  " << space[2].j << endl;
                cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl;
                cout << "     31   |32   |33   |34   |35   |36   |37   |38   |39   |40   " << endl; 
                cout << "       " << space[3].a << "  |  " << space[3].b << "  |  " << space[3].c << "  |  " << space[3].d << "  |  " << space[3].e << "  |  " << space[3].f << "  |  " << space[3].g << "  |  " << space[3].h << "  |  " << space[3].i << "  |  " << space[3].j << endl;
                cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl;
                cout << "     41   |42   |43   |44   |45   |46   |47   |48   |49   |50   " << endl; 
                cout << "       " << space[4].a << "  |  " << space[4].b << "  |  " << space[4].c << "  |  " << space[4].d << "  |  " << space[4].e << "  |  " << space[4].f << "  |  " << space[4].g << "  |  " << space[4].h << "  |  " << space[4].i << "  |  " << space[4].j << endl;
                cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl;
                cout << "     51   |52   |53   |54   |55   |56   |57   |58   |59   |60   " << endl; 
                cout << "       " << space[5].a << "  |  " << space[5].b << "  |  " << space[5].c << "  |  " << space[5].d << "  |  " << space[5].e << "  |  " << space[5].f << "  |  " << space[5].g << "  |  " << space[5].h << "  |  " << space[5].i << "  |  " << space[5].j << endl;
                cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl; 
                cout << "     61   |62   |63   |64   |65   |66   |67   |68   |69   |70   " << endl; 
                cout << "       " << space[6].a << "  |  " << space[6].b << "  |  " << space[6].c << "  |  " << space[6].d << "  |  " << space[6].e << "  |  " << space[6].f << "  |  " << space[6].g << "  |  " << space[6].h << "  |  " << space[6].i << "  |  " << space[6].j << endl;
                cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl; 
                cout << "     71   |72   |73   |74   |75   |76   |77   |78   |79   |80   " << endl; 
                cout << "       " << space[7].a << "  |  " << space[7].b << "  |  " << space[7].c << "  |  " << space[7].d << "  |  " << space[7].e << "  |  " << space[7].f << "  |  " << space[7].g << "  |  " << space[7].h << "  |  " << space[7].i << "  |  " << space[7].j << endl;
                cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl;
                cout << "     81   |82   |83   |84   |85   |86   |87   |88   |89   |90     " << endl; 
                cout << "       " << space[8].a << "  |  " << space[8].b << "  |  " << space[8].c << "  |  " << space[8].d << "  |  " << space[8].e << "  |  " << space[8].f << "  |  " << space[8].g << "  |  " << space[8].h << "  |  " << space[8].i << "  |  " << space[8].j << endl;
                cout << "     _____|_____|_____|_____|_____|_____|_____|_____|_____|_____" << endl;
                cout << "     91   |92   |93   |94   |95   |96   |97   |98   |99   |100  " << endl; 
                cout << "       " << space[9].a << "  |  " << space[9].b << "  |  " << space[9].c << "  |  " << space[9].d << "  |  " << space[9].e << "  |  " << space[9].f << "  |  " << space[9].g << "  |  " << space[9].h << "  |  " << space[9].i << "  |  " << space[9].j << endl;
                cout << "          |     |     |     |     |     |     |     |     |     " << endl << endl;
                if (again == 1)
                {
                    cout << "Please choose another number" << endl; // if you enter a number that has already been used
                }
                if (player == 1) { whichplayer = playernameone; }
                else { whichplayer = playernametwo; }
                cout << whichplayer << ", please enter a number:  ";
                choice = WholeNumberValidation();   // validating the number entered
                if (choice == 0) { again = 1; }
            } while (choice == 0);
            /*
                this checks all the spaces to see if you can enter there if not it says enter a new number
            */
            if (choice == 1 && space[0].a != " ") { again = 1; }
            if (choice == 2 && space[0].b != " ") { again = 1; }
            if (choice == 3 && space[0].c != " ") { again = 1; }
            if (choice == 4 && space[0].d != " ") { again = 1; }
            if (choice == 5 && space[0].e != " ") { again = 1; }
            if (choice == 6 && space[0].f != " ") { again = 1; }
            if (choice == 7 && space[0].g != " ") { again = 1; }
            if (choice == 8 && space[0].h != " ") { again = 1; }
            if (choice == 9 && space[0].i != " ") { again = 1; }
            if (choice == 10 && space[0].j != " ") { again = 1; }
            if (choice == 11 && space[1].a != " ") { again = 1; }
            if (choice == 12 && space[1].b != " ") { again = 1; }
            if (choice == 13 && space[1].c != " ") { again = 1; }
            if (choice == 14 && space[1].d != " ") { again = 1; }
            if (choice == 15 && space[1].e != " ") { again = 1; }
            if (choice == 16 && space[1].f != " ") { again = 1; }
            if (choice == 17 && space[1].g != " ") { again = 1; }
            if (choice == 18 && space[1].h != " ") { again = 1; }
            if (choice == 19 && space[1].i != " ") { again = 1; }
            if (choice == 20 && space[1].j != " ") { again = 1; }
            if (choice == 21 && space[2].a != " ") { again = 1; }
            if (choice == 22 && space[2].b != " ") { again = 1; }
            if (choice == 23 && space[2].c != " ") { again = 1; }
            if (choice == 24 && space[2].d != " ") { again = 1; }
            if (choice == 25 && space[2].e != " ") { again = 1; }
            if (choice == 26 && space[2].f != " ") { again = 1; }
            if (choice == 27 && space[2].g != " ") { again = 1; }
            if (choice == 28 && space[2].h != " ") { again = 1; }
            if (choice == 29 && space[2].i != " ") { again = 1; }
            if (choice == 30 && space[2].j != " ") { again = 1; }
            if (choice == 31 && space[3].a != " ") { again = 1; }
            if (choice == 32 && space[3].b != " ") { again = 1; }
            if (choice == 33 && space[3].c != " ") { again = 1; }
            if (choice == 34 && space[3].d != " ") { again = 1; }
            if (choice == 35 && space[3].e != " ") { again = 1; }
            if (choice == 36 && space[3].f != " ") { again = 1; }
            if (choice == 37 && space[3].g != " ") { again = 1; }
            if (choice == 38 && space[3].h != " ") { again = 1; }
            if (choice == 39 && space[3].i != " ") { again = 1; }
            if (choice == 40 && space[3].j != " ") { again = 1; }
            if (choice == 41 && space[4].a != " ") { again = 1; }
            if (choice == 42 && space[4].b != " ") { again = 1; }
            if (choice == 43 && space[4].c != " ") { again = 1; }
            if (choice == 44 && space[4].d != " ") { again = 1; }
            if (choice == 45 && space[4].e != " ") { again = 1; }
            if (choice == 46 && space[4].f != " ") { again = 1; }
            if (choice == 47 && space[4].g != " ") { again = 1; }
            if (choice == 48 && space[4].h != " ") { again = 1; }
            if (choice == 49 && space[4].i != " ") { again = 1; }   
            if (choice == 50 && space[4].j != " ") { again = 1; }
            if (choice == 51 && space[5].a != " ") { again = 1; }
            if (choice == 52 && space[5].b != " ") { again = 1; }
            if (choice == 53 && space[5].c != " ") { again = 1; }
            if (choice == 54 && space[5].d != " ") { again = 1; }
            if (choice == 55 && space[5].e != " ") { again = 1; }
            if (choice == 56 && space[5].f != " ") { again = 1; }
            if (choice == 57 && space[5].g != " ") { again = 1; }
            if (choice == 58 && space[5].h != " ") { again = 1; }
            if (choice == 59 && space[5].i != " ") { again = 1; }
            if (choice == 60 && space[5].j != " ") { again = 1; }
            if (choice == 61 && space[6].a != " ") { again = 1; }
            if (choice == 62 && space[6].b != " ") { again = 1; }
            if (choice == 63 && space[6].c != " ") { again = 1; }
            if (choice == 64 && space[6].d != " ") { again = 1; }
            if (choice == 65 && space[6].e != " ") { again = 1; }
            if (choice == 66 && space[6].f != " ") { again = 1; }
            if (choice == 67 && space[6].g != " ") { again = 1; }
            if (choice == 68 && space[6].h != " ") { again = 1; }
            if (choice == 69 && space[6].i != " ") { again = 1; }
            if (choice == 70 && space[6].j != " ") { again = 1; }
            if (choice == 71 && space[7].a != " ") { again = 1; }
            if (choice == 72 && space[7].b != " ") { again = 1; }
            if (choice == 73 && space[7].c != " ") { again = 1; }
            if (choice == 74 && space[7].d != " ") { again = 1; }
            if (choice == 75 && space[7].e != " ") { again = 1; }
            if (choice == 76 && space[7].f != " ") { again = 1; }
            if (choice == 77 && space[7].g != " ") { again = 1; }
            if (choice == 78 && space[7].h != " ") { again = 1; }
            if (choice == 79 && space[7].i != " ") { again = 1; }
            if (choice == 80 && space[7].j != " ") { again = 1; }
            if (choice == 81 && space[8].a != " ") { again = 1; }
            if (choice == 82 && space[8].b != " ") { again = 1; }
            if (choice == 83 && space[8].c != " ") { again = 1; }
            if (choice == 84 && space[8].d != " ") { again = 1; }
            if (choice == 85 && space[8].e != " ") { again = 1; }
            if (choice == 86 && space[8].f != " ") { again = 1; }
            if (choice == 87 && space[8].g != " ") { again = 1; }
            if (choice == 88 && space[8].h != " ") { again = 1; }
            if (choice == 89 && space[8].i != " ") { again = 1; }
            if (choice == 90 && space[8].j != " ") { again = 1; }
            if (choice == 91 && space[9].a != " ") { again = 1; }
            if (choice == 92 && space[9].b != " ") { again = 1; }
            if (choice == 93 && space[9].c != " ") { again = 1; }
            if (choice == 94 && space[9].d != " ") { again = 1; }
            if (choice == 95 && space[9].e != " ") { again = 1; }
            if (choice == 96 && space[9].f != " ") { again = 1; }
            if (choice == 97 && space[9].g != " ") { again = 1; }
            if (choice == 98 && space[9].h != " ") { again = 1; }
            if (choice == 99 && space[9].i != " ") { again = 1; }
            if (choice == 100 && space[9].j != " ") { again = 1; }
            if (choice == 1 && space[0].a == " ") { 
                space[0].a = (player == 1) ? "X" : "O"; // this is how you know if its going to be an x or o 
                // its kind of like an if else statement but written differently 
                player = (player == 1) ? 2 : 1; //same thing here for the player
                again = 0;
            }
            if (choice == 2 && space[0].b == " ") {
                space[0].b = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 3 && space[0].c == " ") { 
                space[0].c = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 4 && space[0].d == " ") { 
                space[0].d = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 5 && space[0].e == " ") {
                space[0].e = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 6 && space[0].f == " ") {
                space[0].f = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 7 && space[0].g == " ") { 
                space[0].g = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 8 && space[0].h == " ") { 
                space[0].h = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 9 && space[0].i == " ") { 
                space[0].i = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 10 && space[0].j == " ") { 
                space[0].j = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 11 && space[1].a == " ") {
                space[1].a = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 12 && space[1].b == " ") { 
                space[1].b = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 13 && space[1].c == " ") { 
                space[1].c = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 14 && space[1].d == " ") { 
                space[1].d = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 15 && space[1].e == " ") { 
                space[1].e = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 16 && space[1].f == " ") {
                space[1].f = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 17 && space[1].g == " ") {
                space[1].g = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 18 && space[1].h == " ") { 
                space[1].h = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 19 && space[1].i == " ") { 
                space[1].i = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 20 && space[1].j == " ") { 
                space[1].j = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 21 && space[2].a == " ") {
                space[2].a = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 22 && space[2].b == " ") {
                space[2].b = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 23 && space[2].c == " ") { 
                space[2].c = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 24 && space[2].d == " ") { 
                space[2].d = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 25 && space[2].e == " ") {                
                space[2].e = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;             
                again = 0;
            }
            if (choice == 26 && space[2].f == " ") { 
                space[2].f = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 27 && space[2].g == " ") { 
                space[2].g = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 28 && space[2].h == " ") { 
                space[2].h = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 29 && space[2].i == " ") { 
                space[2].i = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 30 && space[2].j == " ") { 
                space[2].j = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 31 && space[3].a == " ") { 
                space[3].a = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 32 && space[3].b == " ") { 
                space[3].b = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 33 && space[3].c == " ") { 
                space[3].c = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
                ; }
            if (choice == 34 && space[3].d == " ") { 
                space[3].d = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 35 && space[3].e == " ") { 
                space[3].e = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 36 && space[3].f == " ") {
                space[3].f = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 37 && space[3].g == " ") { 
                space[3].g = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 38 && space[3].h == " ") { 
                space[3].h = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 39 && space[3].i == " ") {
                space[3].i = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 40 && space[3].j == " ") { 
                space[3].j = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 41 && space[4].a == " ") { 
                space[4].a = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 42 && space[4].b == " ") { 
                space[4].b = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 43 && space[4].c == " ") { 
                space[4].c = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 44 && space[4].d == " ") { 
                space[4].d = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 45 && space[4].e == " ") { 
                space[4].e = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 46 && space[4].f == " ") { 
                space[4].f = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 47 && space[4].g == " ") { 
                space[4].g = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 48 && space[4].h == " ") { 
                space[4].h = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 49 && space[4].i == " ") { 
                space[4].i = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 50 && space[4].j == " ") { 
                space[4].j = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 51 && space[5].a == " ") { 
                space[5].a = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 52 && space[5].b == " ") { 
                space[5].b = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 53 && space[5].c == " ") { 
                space[5].c = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 54 && space[5].d == " ") { 
                space[5].d = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 55 && space[5].e == " ") { 
                space[5].e = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 56 && space[5].f == " ") { 
                space[5].f = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 57 && space[5].g == " ") { 
                space[5].g = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 58 && space[5].h == " ") { 
                space[5].h = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 59 && space[5].i == " ") { 
                space[5].i = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 60 && space[5].j == " ") { 
                space[5].j = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;  
            }
            if (choice == 61 && space[6].a == " ") { 
                space[6].a = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 62 && space[6].b == " ") { 
                space[6].b = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 63 && space[6].c == " ") { 
                space[6].c = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 64 && space[6].d == " ") { 
                space[6].d = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 65 && space[6].e == " ") { 
                space[6].e = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 66 && space[6].f == " ") { 
                space[6].f = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 67 && space[6].g == " ") { 
                space[6].g = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 68 && space[6].h == " ") { 
                space[6].h = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 69 && space[6].i == " ") {
                space[6].i = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 70 && space[6].j == " ") { 
                space[6].j = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 71 && space[7].a == " ") { 
                space[7].a = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 72 && space[7].b == " ") { 
                space[7].b = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 73 && space[7].c == " ") { 
                space[7].c = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 74 && space[7].d == " ") { 
                space[7].d = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 75 && space[7].e == " ") { 
                space[7].e = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 76 && space[7].f == " ") { 
                space[7].f = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 77 && space[7].g == " ") { 
                space[7].g = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 78 && space[7].h == " ") { 
                space[7].h = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 79 && space[7].i == " ") { 
                space[7].i = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 80 && space[7].j == " ") { 
                space[7].j = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 81 && space[8].a == " ") { 
                space[8].a = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 82 && space[8].b == " ") { 
                space[8].b = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 83 && space[8].c == " ") { 
                space[8].c = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;  
            }
            if (choice == 84 && space[8].d == " ") { 
                space[8].d = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 85 && space[8].e == " ") {
                space[8].e = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 86 && space[8].f == " ") { 
                space[8].f = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 87 && space[8].g == " ") { 
                space[8].g = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 88 && space[8].h == " ") { 
                space[8].h = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 89 && space[8].i == " ") { 
                space[8].i = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 90 && space[8].j == " ") { 
                space[8].j = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 91 && space[9].a == " ") { 
                space[9].a = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 92 && space[9].b == " ") { 
                space[9].b = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 93 && space[9].c == " ") { 
                space[9].c = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 94 && space[9].d == " ") { 
                space[9].d = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 95 && space[9].e == " ") { 
                space[9].e = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 96 && space[9].f == " ") { 
                space[9].f = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 97 && space[9].g == " ") { 
                space[9].g = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 98 && space[9].h == " ") { 
                space[9].h = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 99 && space[9].i == " ") { 
                space[9].i = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 100 && space[9].j == " ") { 
                space[9].j = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            // this triggers a function to check if the game has been done
            checkwin();
        } while (gamedone == false);// if the game has been won gamedone will be true and the loop will finish
    }
    if (players != 1)
    {
        gamedone = true;
        players = 3;
    }
}
// this is when you win on the begginer level 
void win2(bool x)
{
    system("cls");
    cout << "Tic Tac Toe" << endl << endl;
    if (players == 2)// if there are 2 players it shows both payer names
    {
        cout << playernameone << " (X)  -  " << playernametwo << " (O)" << endl << endl;
    }
    else // if its just 1 player it shows player ones names and then AI for Artificial intelligence
    {
        cout << playernameone << " (X)  -  AI (O)" << endl << endl;
    }// smaller grid with number in the middle 
    cout << endl;
    cout << "     |     |     " << endl; 
    cout << "  " << space[0].a << "  |  " << space[0].b << "  |  " << space[0].c << endl;
    cout << "_____|_____|_____" << endl; 
    cout << "     |     |     " << endl; 
    cout << "  " << space[1].a << "  |  " << space[1].b << "  |  " << space[1].c << endl;
    cout << "_____|_____|_____" << endl; 
    cout << "     |     |     " << endl; 
    cout << "  " << space[2].a << "  |  " << space[2].b << "  |  " << space[2].c << endl;
    cout << "     |     |     " << endl << endl;
    if (x == true) 
    {
        if (gamewin == 3) // if the computer wins 
        {
            cout << "The computer won :(" << endl << endl;
            saveresultstwo("lose"); // goes to 1 player file saving
        }
        if (players == 2)//if there are 2 players
        {
            cout << whichplayer << " won!!!" << endl << endl; // figures out which player has won
            saveresults("win");// goes to 2 player file saving
        }
        if (gamewin == 1) // if one player has won
        {
            cout << playernameone << " won!!!" << endl << endl;
            saveresultstwo("win");// goes to 1 player file saving
        }
    }   // if its 2 players and a draw it goes to 2 player saving
    else if (players == 2) { cout << "It's a stale mate!" << endl << endl; saveresults("draw"); }
    else { cout << "It's a stale mate!" << endl << endl; saveresultstwo("draw"); }
    // if not it goes to 1 player saving
    gamedone = true; // changing the bool to true so that the game can end
    system("pause");
}

void checkwin2()
{
    //checking the wins for the begginer game not so complex as the expert game
    if (space[0].a == space[0].b && space[0].b == space[0].c) win2(true);
    else if (space[1].a == space[1].b && space[1].b == space[1].c) win2(true); // if one space equals the next space 
    else if (space[2].a == space[2].b && space[2].b == space[2].c) win2(true); // and the next space equals the next space
    else if (space[0].a == space[1].a && space[1].a == space[2].a) win2(true); // then the game is over 
    else if (space[0].b == space[1].b && space[1].b == space[2].b) win2(true);
    else if (space[0].c == space[1].c && space[1].c == space[2].c) win2(true);
    else if (space[0].a == space[1].b && space[1].b == space[2].c) win2(true);
    else if (space[0].c == space[1].b && space[1].b == space[2].a) win2(true);
    else if (space[0].a != "1" && space[0].b != "2" && space[0].c != "3" && space[1].a != "4" && space[1].b != "5" && space[1].c != "6" && space[2].a != "7" && space[2].b != "8" && space[2].c != "9") win2(false);
    // if all the spaces are filled than the game is a draw
}
/*
    the artificial intelligence is just programming the computer to be able to think for its self 
    if the player has two in a row the computer will block it unless it has the chance to win itself
    just using if statements and checking which boxes are taken
*/
void aimove()
{
    //the computers first move which is a simple if then an else if 
    if (move == 1)
    {
        if (space[1].b == "5"){ space[1].b = "O";}
        else if (space[1].b != "5" && space[1].b != "O"){ space[2].c = "O"; }
    }
    // second is a bit more complicated 
    // just checking all the different combinations
    if (move == 2)
    {
        if (aturn == 0 && space[0].a == space[0].b && space[0].c == "3" && space[0].a != "O" ){ space[0].c = "O"; aturn = 1; }
        if (aturn == 0 && space[0].a == space[1].a && space[2].a == "7" && space[0].a != "O" ){ space[2].a = "O"; aturn = 1; }
        if (aturn == 0 && space[0].a == space[0].c && space[0].b == "2" && space[0].a != "O" ){ space[0].b = "O"; aturn = 1; }
        if (aturn == 0 && space[0].a == space[2].a && space[1].a == "4" && space[0].a != "O" ){ space[1].a = "O"; aturn = 1; }
        if (aturn == 0 && space[0].c == space[1].c && space[2].c == "9" && space[0].c != "O" ){ space[2].c = "O"; aturn = 1; }
        if (aturn == 0 && space[0].c == space[2].c && space[1].c == "6" && space[0].c != "O" ){ space[1].c = "O"; aturn = 1; }
        if (aturn == 0 && space[0].c == space[0].b && space[0].a == "1" && space[0].c != "O" ){ space[0].a = "O"; aturn = 1; }
        if (aturn == 0 && space[0].c == space[1].b && space[2].a == "7" && space[0].c != "O" ){ space[2].a = "O"; aturn = 1; }
        if (aturn == 0 && space[2].a == space[1].a && space[0].a == "1" && space[2].a != "O" ){ space[0].a = "O"; aturn = 1; }
        if (aturn == 0 && space[2].a == space[2].b && space[2].c == "9" && space[2].a != "O" ){ space[2].c = "O"; aturn = 1; }
        if (aturn == 0 && space[2].a == space[2].c && space[2].b == "8" && space[2].a != "O" ){ space[2].b = "O"; aturn = 1; }
        if (aturn == 0 && space[2].a == space[1].b && space[0].c == "3" && space[2].a != "O" ){ space[0].c = "O"; aturn = 1; }
        if (aturn == 0 && space[2].c == space[2].b && space[2].a == "7" && space[2].c != "O" ){ space[2].a = "O"; aturn = 1; }
        if (aturn == 0 && space[2].c == space[1].c && space[0].c == "3" && space[2].c != "O" ){ space[0].c = "O"; aturn = 1; }
        if (aturn == 0 && space[1].b == space[0].b && space[2].b == "8" && space[1].b != "O" ){ space[2].b = "O"; aturn = 1; }
        if (aturn == 0 && space[1].b == space[1].a && space[1].c == "6" && space[1].b != "O" ){ space[1].c = "O"; aturn = 1; }
        if (aturn == 0 && space[1].b == space[1].c && space[1].a == "4" && space[1].b != "O" ){ space[1].a = "O"; aturn = 1; }
        if (aturn == 0 && space[1].b == space[2].b && space[0].b == "2" && space[1].b != "O" ){ space[0].b = "O"; aturn = 1; }
        if (aturn == 0 && space[1].c == "X" && space[0].a == "X" && space[0].b == "2") { space[0].b = "O"; aturn = 1; }
        if (aturn == 0 && space[1].b == "X" && space[0].a == "X" && space[2].a == "7") { space[2].a = "O"; aturn = 1; }
        if (aturn == 0 && space[1].c == "X" && space[2].a == "X" && space[2].b == "8") { space[2].b = "O"; aturn = 1; }
        if (aturn == 0 && space[0].a == "X" && space[1].a == "4") { space[1].a = "O"; aturn = 1; }
        if (aturn == 0 && space[0].c == "X" && space[2].c == "9") { space[2].c = "O"; aturn = 1; }
        if (aturn == 0 && space[0].a == "1" && space[2].c != "X") { space[0].a = "O"; aturn = 1; }
        if (aturn == 0 && space[0].c == "3" && space[2].a != "X") { space[0].c = "O"; aturn = 1; }
    }
    if (gamedone == false) // if the the game hasn't already been won by this point
    {
        if (move == 3)
        { 
            // same as above but this time the computer has the chance to win because it has its 3rd move
            if (aturn == 0 && space[0].a == space[0].b && space[0].a == "O" && space[0].c == "3"){ space[0].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].a == space[0].c && space[0].a == "O" && space[0].b == "2"){ space[0].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].a == space[1].b && space[0].a == "O" && space[2].c == "9"){ space[2].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].a == space[2].c && space[0].a == "O" && space[1].b == "5"){ space[1].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].a == space[1].a && space[1].a == "O" && space[2].a == "7"){ space[2].a = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].a == space[2].a && space[0].a == "O" && space[1].a == "4"){ space[1].a = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].c == space[0].b && space[0].b == "O" && space[0].a == "1"){ space[0].a = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].c == space[1].b && space[1].b == "O" && space[2].a == "7"){ space[2].a = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].c == space[2].a && space[2].a == "O" && space[1].b == "5"){ space[1].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].c == space[1].c && space[1].c == "O" && space[2].c == "9"){ space[2].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].c == space[2].c && space[2].c == "O" && space[1].c == "6"){ space[1].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[2].a == space[2].b && space[2].a == "O" && space[2].c == "9"){ space[2].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[2].a == space[2].c && space[2].c == "O" && space[2].b == "8"){ space[2].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[2].a == space[1].a && space[1].a == "O" && space[0].a == "1"){ space[0].a = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[2].a == space[1].b && space[1].b == "O" && space[0].c == "3"){ space[0].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[1].a == space[1].b && space[1].a == "O" && space[1].c == "6"){ space[1].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[1].a == space[1].c && space[1].a == "O" && space[1].b == "5"){ space[1].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].b == space[1].b && space[0].b == "O" && space[2].b == "8"){ space[2].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].b == space[2].b && space[0].b == "O" && space[1].b == "5"){ space[1].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[1].b == space[2].b && space[1].b == "O" && space[0].b == "2"){ space[0].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[2].b == space[2].c && space[2].b == "O" && space[2].a == "7"){ space[2].a = "O"; gamedone = true; aturn = 1; }
            gamewin = 3;
            if (gamedone == false)
            {
                if (aturn == 0 && space[0].a == space[0].b && space[0].c == "3" && space[0].a != "O" ){ space[0].c = "O"; aturn = 1; }
                if (aturn == 0 && space[0].a == space[1].a && space[2].a == "7" && space[0].a != "O" ){ space[2].a = "O"; aturn = 1; }
                if (aturn == 0 && space[0].a == space[0].c && space[0].b == "2" && space[0].a != "O" ){ space[0].b = "O"; aturn = 1; }
                if (aturn == 0 && space[0].a == space[2].a && space[1].a == "4" && space[0].a != "O" ){ space[1].a = "O"; aturn = 1; }
                if (aturn == 0 && space[0].c == space[1].c && space[2].c == "9" && space[0].c != "O" ){ space[2].c = "O"; aturn = 1; }
                if (aturn == 0 && space[0].c == space[2].c && space[1].c == "6" && space[0].c != "O" ){ space[1].c = "O"; aturn = 1; }
                if (aturn == 0 && space[0].c == space[0].b && space[0].a == "1" && space[0].c != "O" ){ space[0].a = "O"; aturn = 1; }
                if (aturn == 0 && space[0].c == space[1].b && space[2].a == "7" && space[0].c != "O" ){ space[2].a = "O"; aturn = 1; }
                if (aturn == 0 && space[2].a == space[1].a && space[0].a == "1" && space[2].a != "O" ){ space[0].a = "O"; aturn = 1; }
                if (aturn == 0 && space[2].a == space[2].b && space[2].c == "9" && space[2].a != "O" ){ space[2].c = "O"; aturn = 1; }
                if (aturn == 0 && space[2].a == space[2].c && space[2].b == "8" && space[2].a != "O" ){ space[2].b = "O"; aturn = 1; }
                if (aturn == 0 && space[2].a == space[1].b && space[0].c == "3" && space[2].a != "O" ){ space[0].c = "O"; aturn = 1; }
                if (aturn == 0 && space[2].c == space[2].b && space[2].a == "7" && space[2].c != "O" ){ space[2].a = "O"; aturn = 1; }
                if (aturn == 0 && space[2].c == space[1].c && space[0].c == "3" && space[2].c != "O" ){ space[0].c = "O"; aturn = 1; }
                if (aturn == 0 && space[1].b == space[0].b && space[2].b == "8" && space[1].b != "O" ){ space[2].b = "O"; aturn = 1; }
                if (aturn == 0 && space[1].b == space[1].a && space[1].c == "6" && space[1].b != "O" ){ space[1].c = "O"; aturn = 1; }
                if (aturn == 0 && space[1].b == space[2].b && space[0].b == "2" && space[1].b != "O" ){ space[0].b = "O"; aturn = 1; }
                if (aturn == 0 && space[1].b == space[1].c && space[1].a == "4" && space[1].b != "O" ){ space[1].a = "O"; aturn = 1; }
                if (aturn == 0 && space[1].c == "X" && space[2].a == "X" && space[0].b == "X" && space[2].b == "O" && space[1].b == "O"){ space[0].a = "O"; aturn = 1; }
                if (aturn == 0 && space[0].a == "X" && space[0].c == "X" && space[2].b == "X" && space[1].a == "4"){ space[1].a = "O"; aturn = 1; }
                if (aturn == 0 && space[1].c == "X" && space[2].c == "9"){ space[2].c = "O"; aturn = 1; }
                if (aturn == 0 && space[2].c == "X" && space[2].b == "8"){ space[2].b = "O"; aturn = 1; }
            }
        }
        if (move == 4)
        { 
            // pretty much the same as move 3 
            if (aturn == 0 && space[0].a == space[0].b && space[0].a == "O" && space[0].c == "3"){ space[0].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].a == space[0].c && space[0].a == "O" && space[0].b == "2"){ space[0].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].a == space[1].b && space[0].a == "O" && space[2].c == "9"){ space[2].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].a == space[2].c && space[0].a == "O" && space[1].b == "5"){ space[1].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].a == space[1].a && space[1].a == "O" && space[2].a == "7"){ space[2].a = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].a == space[2].a && space[0].a == "O" && space[1].a == "4"){ space[1].a = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].c == space[0].b && space[0].b == "O" && space[0].a == "1"){ space[0].a = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].c == space[1].b && space[1].b == "O" && space[2].a == "7"){ space[2].a = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].c == space[2].a && space[2].a == "O" && space[1].b == "5"){ space[1].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].c == space[1].c && space[1].c == "O" && space[2].c == "9"){ space[2].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].c == space[2].c && space[2].c == "O" && space[1].c == "6"){ space[1].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[2].a == space[2].b && space[2].a == "O" && space[2].c == "9"){ space[2].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[2].a == space[2].c && space[2].c == "O" && space[2].b == "8"){ space[2].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[2].a == space[1].a && space[1].a == "O" && space[0].a == "1"){ space[0].a = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[2].a == space[1].b && space[1].b == "O" && space[0].c == "3"){ space[0].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[1].a == space[1].b && space[1].a == "O" && space[1].c == "6"){ space[1].c = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[1].a == space[1].c && space[1].a == "O" && space[1].b == "5"){ space[1].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].b == space[1].b && space[0].b == "O" && space[2].b == "8"){ space[2].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[0].b == space[2].b && space[0].b == "O" && space[1].b == "5"){ space[1].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[1].b == space[2].b && space[1].b == "O" && space[0].b == "2"){ space[0].b = "O"; gamedone = true; aturn = 1; }
            if (aturn == 0 && space[2].b == space[2].c && space[2].b == "O" && space[2].a == "7"){ space[2].a = "O"; gamedone = true; aturn = 1; }
            gamewin = 3;
            if (gamedone == false)
            {
                if (aturn == 0 && space[0].a == space[0].b && space[0].c == "3" && space[0].a != "O" ){ space[0].c = "O"; aturn = 1; }
                if (aturn == 0 && space[0].a == space[1].a && space[2].a == "7" && space[0].a != "O" ){ space[2].a = "O"; aturn = 1; }
                if (aturn == 0 && space[0].a == space[0].c && space[0].b == "2" && space[0].a != "O" ){ space[0].b = "O"; aturn = 1; }
                if (aturn == 0 && space[0].a == space[2].a && space[1].a == "4" && space[0].a != "O" ){ space[1].a = "O"; aturn = 1; }
                if (aturn == 0 && space[0].c == space[1].c && space[2].c == "9" && space[0].c != "O" ){ space[2].c = "O"; aturn = 1; }
                if (aturn == 0 && space[0].c == space[2].c && space[1].c == "6" && space[0].c != "O" ){ space[1].c = "O"; aturn = 1; }
                if (aturn == 0 && space[0].c == space[0].b && space[0].a == "1" && space[0].c != "O" ){ space[0].a = "O"; aturn = 1; }
                if (aturn == 0 && space[0].c == space[1].b && space[2].a == "7" && space[0].c != "O" ){ space[2].a = "O"; aturn = 1; }
                if (aturn == 0 && space[2].a == space[1].a && space[0].a == "1" && space[2].a != "O" ){ space[0].a = "O"; aturn = 1; }
                if (aturn == 0 && space[2].a == space[2].b && space[2].c == "9" && space[2].a != "O" ){ space[2].c = "O"; aturn = 1; }
                if (aturn == 0 && space[2].a == space[2].c && space[2].b == "8" && space[2].a != "O" ){ space[2].b = "O"; aturn = 1; }
                if (aturn == 0 && space[2].a == space[1].b && space[0].c == "3" && space[2].a != "O" ){ space[0].c = "O"; aturn = 1; }
                if (aturn == 0 && space[2].c == space[2].b && space[2].a == "7" && space[2].c != "O" ){ space[2].a = "O"; aturn = 1; }
                if (aturn == 0 && space[2].c == space[1].c && space[0].c == "3" && space[2].c != "O" ){ space[0].c = "O"; aturn = 1; }
                if (aturn == 0 && space[1].b == space[0].b && space[2].b == "8" && space[1].b != "O" ){ space[2].b = "O"; aturn = 1; }
                if (aturn == 0 && space[1].b == space[1].a && space[1].c == "6" && space[1].b != "O" ){ space[1].c = "O"; aturn = 1; }
                if (aturn == 0 && space[1].b == space[1].c && space[1].a == "4" && space[1].b != "O" ){ space[1].a = "O"; aturn = 1; }
                if (aturn == 0 && space[1].b == space[2].b && space[0].b == "2" && space[1].b != "O" ){ space[0].b = "O"; aturn = 1; }
                if (aturn == 0 && space[1].b == space[1].c && space[2].b == "8" && space[1].b != "O" ){ space[2].b = "O"; aturn = 1; }
                if (aturn == 0 && space[1].b == space[1].c && space[2].b == "8" && space[1].b != "O" ){ space[2].b = "O"; aturn = 1; }
                if (aturn == 0 && space[1].c == "X" && space[2].c == "9"){ space[2].c = "O"; aturn = 1; }
                if (aturn == 0 && space[2].c == "X" && space[2].b == "8"){ space[2].b = "O"; aturn = 1; }
                if (aturn == 0 && space[0].b == "2" ){ space[0].b = "O"; aturn = 1; }
            }
        }
        if (gamedone == false)
        {
            // at the end of the AI combinations the computer will have made its move and 
            // and the grid will be show again saying that the computer has made its move
            system("cls");
            cout << "Tic Tac Toe" << endl << endl;
            cout << playernameone << " (X)  -  AI (O)" << endl << endl;
            cout << endl;
            cout << "     |     |     " << endl; 
            cout << "  " << space[0].a << "  |  " << space[0].b << "  |  " << space[0].c << endl;
            cout << "_____|_____|_____" << endl; 
            cout << "     |     |     " << endl; 
            cout << "  " << space[1].a << "  |  " << space[1].b << "  |  " << space[1].c << endl;
            cout << "_____|_____|_____" << endl; 
            cout << "     |     |     " << endl; 
            cout << "  " << space[2].a << "  |  " << space[2].b << "  |  " << space[2].c << endl;
            cout << "     |     |     " << endl << endl; 
            cout << "The computer has made its move" << endl;
            cout << playernameone << ", enter a number: ";
            move++; // the integer move is incrimented for the next turns
                        system("pause");
        }
    }
}
/*
    the start of the begginers game there are two parts to this one because there is 1 and 2 players
    there is also a menu so you can choose between 1 and 2 players or going back to the main menu 
    same format as the expert grid but alot smaller 
*/
void Begginer()
{
    space[0].a = "1";
    space[0].b = "2";
    space[0].c = "3";       // assigning the spaces with their corresponding number
    space[1].a = "4";
    space[1].b = "5";
    space[1].c = "6";
    space[2].a = "7";
    space[2].b = "8";
    space[2].c = "9";
    gamedone = false;
    player = 1;
    again = 0;              // setting the other variables to their starting values
    move = 1;
    aturn = 0;
    // clearing the screen for the begginers menu 
    system("cls");
    cout << "TicTacToe Begginer Menu" << endl << endl;
    cout << "Type a number for what game you want to play" << endl;
    cout << "One player: 1" << endl;
    cout << "Two player: 2" << endl;
    cout << "Main menu: 3" << endl << "Enter here: ";
    // if 3 it goes back to the 
    cin >> players;
    if (players == 2)   // for a 2 player game
    {
        system("cls");
        // if there is noone already playing it does this loop
        do if (playernameone == " ")
        {
            cout << "Player 1 please enter your name: ";
            cin >> playernameone;
            playernameone = namecheck(playernameone); // checks to see if the is already someone with this name
        } while (playernameone == " "); // if the name is blank it asks for another name
        // if there is no player 2 then it does this loop
        do
        {
            do if (playernametwo == " " || playernametwo == playernameone)
            {
                system("cls");
                if (playernametwo == playernameone)
                {
                    cout << "This name is already taken by player 1" << endl;
                }
                cout << "Player 2 please enter your name: "; 
                cin >> playernametwo;
                if (playernametwo != playernameone)
                {
                    playernametwo = namecheck(playernametwo); // checks to see if the is already someone with this name
                }
            } while (playernametwo == " ");// if the name is blank it asks for another name
        } while (playernametwo == playernameone);
        do if (gamedone == false)
        {
            do
            {
                // the begginer grid
                system("cls");
                cout << "Tic Tac Toe" << endl << endl;
                cout << playernameone << " (X)  -  " << playernametwo << " (O)" << endl << endl;
                cout << endl;
                cout << "     |     |     " << endl; 
                cout << "  " << space[0].a << "  |  " << space[0].b << "  |  " << space[0].c << endl;
                cout << "_____|_____|_____" << endl; 
                cout << "     |     |     " << endl; 
                cout << "  " << space[1].a << "  |  " << space[1].b << "  |  " << space[1].c << endl;
                cout << "_____|_____|_____" << endl; 
                cout << "     |     |     " << endl; 
                cout << "  " << space[2].a << "  |  " << space[2].b << "  |  " << space[2].c << endl;
                cout << "     |     |     " << endl << endl; 
                if (again == 1)
                {
                    cout << "Please choose another number" << endl; // if they entered a number that is already taken 
                }                                                   // or if they entered a letter
                if (player == 1) { whichplayer = playernameone; }
                else { whichplayer = playernametwo; } // figuring out which player name
                cout << whichplayer << ", please enter a number:  ";
                choice = WholeNumberValidation(); // checking to see if the user entered a number 
                if (choice == 0) { again = 1; }
            } while (choice == 0); 
            /*
                checking all the boxes to see if the choice is a valid one
                if it is the player will swap over and the x or o will be inserted
            */
            if (choice == 1 && space[0].a != "1") { again = 1; }
            if (choice == 2 && space[0].b != "2") { again = 1; }
            if (choice == 3 && space[0].c != "3") { again = 1; }
            if (choice == 4 && space[1].a != "4") { again = 1; }
            if (choice == 5 && space[1].b != "5") { again = 1; }
            if (choice == 6 && space[1].c != "6") { again = 1; }
            if (choice == 7 && space[2].a != "7") { again = 1; }
            if (choice == 8 && space[2].b != "8") { again = 1; }
            if (choice == 9 && space[2].c != "9") { again = 1; }
            if (choice == 1 && space[0].a == "1") { 
                space[0].a = (player == 1) ? "X" : "O"; 
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 2 && space[0].b == "2") {         
                space[0].b = (player == 1) ? "X" : "O";
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 3 && space[0].c == "3") {
                space[0].c = (player == 1) ? "X" : "O";
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 4 && space[1].a == "4") {
                space[1].a = (player == 1) ? "X" : "O";
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 5 && space[1].b == "5") {
                space[1].b = (player == 1) ? "X" : "O";
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 6 && space[1].c == "6") {
            space[1].c = (player == 1) ? "X" : "O";
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 7 && space[2].a == "7") {
                space[2].a = (player == 1) ? "X" : "O";
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 8 && space[2].b == "8") {
                space[2].b = (player == 1) ? "X" : "O";
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            if (choice == 9 && space[2].c == "9") {
                space[2].c = (player == 1) ? "X" : "O";
                player = (player == 1) ? 2 : 1;
                again = 0;
            }
            checkwin2();
        } while (gamedone == false);
    }
    if (players == 1) // 1 player game
    {
        system("cls");
        // if there is already a player one he doesnt have to enterr a name
        do if (playernameone == " ")
        {
            cout << "Player 1 please enter your name: ";
            cin >> playernameone;
            playernameone = namecheck(playernameone);
        } while (playernameone == " ");
        playernametwo = " ";
        // player 2 is set to nothing
        do if (gamedone == false)
        {
            do 
            {
                do 
                {
                    // same as for 2 player
                    system("cls");
                    cout << "Tic Tac Toe" << endl << endl;
                    cout << playernameone << " (X)  -  AI (O)" << endl << endl;
                    cout << endl;
                    cout << "     |     |     " << endl; 
                    cout << "  " << space[0].a << "  |  " << space[0].b << "  |  " << space[0].c << endl;
                    cout << "_____|_____|_____" << endl; 
                    cout << "     |     |     " << endl; 
                    cout << "  " << space[1].a << "  |  " << space[1].b << "  |  " << space[1].c << endl;
                    cout << "_____|_____|_____" << endl; 
                    cout << "     |     |     " << endl; 
                    cout << "  " << space[2].a << "  |  " << space[2].b << "  |  " << space[2].c << endl;
                    cout << "     |     |     " << endl << endl; 
                    if (again == 1)
                    {
                        cout << "Please choose another number" << endl;
                    }
                    again = 0;
                    cout << playernameone << ", please enter a number: "; 
                    choice = WholeNumberValidation();
                    if (choice == 0) { again = 1; }
                } while (choice == 0);
                if (choice == 1 && space[0].a != "1") { again = 1; }
                if (choice == 2 && space[0].b != "2") { again = 1; }
                if (choice == 3 && space[0].c != "3") { again = 1; }
                if (choice == 4 && space[1].a != "4") { again = 1; }
                if (choice == 5 && space[1].b != "5") { again = 1; }
                if (choice == 6 && space[1].c != "6") { again = 1; }
                if (choice == 7 && space[2].a != "7") { again = 1; }
                if (choice == 8 && space[2].b != "8") { again = 1; }
                if (choice == 9 && space[2].c != "9") { again = 1; }
            } while (again == 1); 
            // extra loop so that the AI doesnt make a move when its not supposed to 
            // checking all the choices again
            if (choice == 1 && space[0].a == "1") { 
                space[0].a = "X"; 
                again = 0;
            }
            if (choice == 2 && space[0].b == "2") {
                space[0].b = "X";
                again = 0;
            }
            if (choice == 3 && space[0].c == "3") {
                space[0].c = "X";
                again = 0;
            }
            if (choice == 4 && space[1].a == "4") {
                space[1].a = "X";
                again = 0;
            }
            if (choice == 5 && space[1].b == "5") {
                space[1].b = "X";
                again = 0;
            }
            if (choice == 6 && space[1].c == "6") {
                space[1].c = "X";
                again = 0;
            }
            if (choice == 7 && space[2].a == "7") {
                space[2].a = "X";
                again = 0;
            }
            if (choice == 8 && space[2].b == "8") {
                space[2].b = "X";
                again = 0;
            }
            if (choice == 9 && space[2].c == "9") {
                space[2].c = "X";
                again = 0;
            }
            gamewin = 1;
            checkwin2(); // function to check the win
            if (gamedone == false) // if there is no win AI makes its move
            {
                aimove(); // function to go to ai move
                checkwin2(); // checks to see if the computer has won
                aturn = 0;
            }
        } while (gamedone == false); // when the game is over it jumps out of the loop
    }
    else { playagain = "yes"; player = 3; }
}
/*
    the league table shows the name of the player how many times they have played
    how many wins, losses and draws they have
*/
void showtable()
{
    //opens the file up
    ifstream datafile("table.rec");
    datafile >> top; 
    // takes out the first piece of information
    cout << "     Player Name     Played    Won     Lost   Drawn" << endl << endl;
    for (int counter = 0; counter < top; counter++)
    {
        datafile >> playa[counter].name;
        datafile >> playa[counter].play;
        datafile >> playa[counter].win;         // reads out each piece of player information then sends it to the screen
        datafile >> playa[counter].loss;
        datafile >> playa[counter].draw;
        cout << "\t" << playa[counter].name << "\t\t" << playa[counter].play << "\t" << playa[counter].win << "\t" << playa[counter].loss << "\t"  << playa[counter].draw << endl;
    }
    datafile.close();// closes the file
    cout << endl << endl;
    system("pause");    
}
// this is where the program starts 
int main(void)
{
    do 
    {
        /*
            the game menu is one big loop so you can choose which game you want to play
            and you can see the league table and exit the game
        */
        system("cls");
        cout << "TicTacToe Main Menu" << endl << endl;
        cout << "Type a number for what game you want to play" << endl;
        cout << "Begginer: 1" << endl;
        cout << "Expert: 2" << endl;
        cout << "Show Scores Table: 3" << endl;
        cout << "Exit game: 4" << endl << "Enter here: ";
        cin >> game; // entering which game you want
        if (game == 1)// begginers game
        {
            Begginer();
        }
        if (game == 2)// expert game
        {
            Expert();
        }
        if (game == 3)// league table
        {
            system("cls");
            showtable();
            playagain = "yes";
        }
        if (game == 4)// exiting the game and program
        {
            playagain = "no";
        }
        else { playagain = "yes"; game = 3; }
        if (players == 3)
        {
            playagain = "yes";
        }
        do if (game != 3 && game != 4 && players != 3)// if you didnt click on the leage table or exit 
        {                                             // and you didnt click main menu in the begginers menu 
            cout << "Would you like to play again? type yes or no: ";
            cin >> playagain;
        } while (playagain != "yes" && playagain !="no");
    } while (playagain == "yes"); // if "playagain" variable equals no the game will exit 
}

Comments

Sign in to comment.
PyThOn   -  Jul 20, 2011

Lets say i want to start learning C++ What software would i need to write the code to where it gives me auto options. If not needed where would i code C== Scripts/Snippets at?

 Respond  
sunslayer   -  May 19, 2010

sunslayer, your newline suggestion probably won't work too well because everybody's window is going to have a different number of rows.true.

 Respond  
Hawkee   -  May 19, 2010

For this type of command line app I don't think a cls is even necessary. It's fine to see the series of events that led up to the current state.

sunslayer, your newline suggestion probably won't work too well because everybody's window is going to have a different number of rows.

 Respond  
sunslayer   -  May 19, 2010

system() is a Windows bound cmd, there are several alternatives to system("Pause") and system("cls"), i.e. in iostream.h you can use std::cin.get/ignore() or getline() and for cls the easiest was is probably just to make a loop of newline characters

 Respond  
AlexRapso   -  May 19, 2010

system("cls"); clears the screen but i guess it doesnt work on other operating systems :/

 Respond  
Hawkee   -  May 19, 2010

It works now but it behaves strangely. Sometimes the computer simply stops playing and I get to go 2-3 times in a row. Also, the computer always seems to make the exact same move. I think this is due to the hard-coded logic. Would be nice if you used an algorithm. The pause and cls aren't working for me, nor do I think they're very necessary. I do like the score table though.

 Respond  
AlexRapso   -  May 19, 2010

Looks good, but I can't run it on OS X. conio.h is a Windows/DOS library that generally doesn't run on Linux/Unix systems. Maybe you can find an alternative that works more universally?

took that out and replaced it with a system pause instead.

 Respond  
Sonny   -  May 12, 2010

I think it's pretty good, man. Sure, you could change some things here and there, but all in all, it's good.

 Respond  
AlexRapso   -  May 01, 2010

@raccoon

usually it does end in a tie or a loss for the user

@hawkee

i have only been using windows tbh and not programming C++ that long still learning :P

 Respond  
raccoon   -  Apr 28, 2010

Does the computer make best logical moves? Games should always end in a player loss or a tie, on expert. :)

 Respond  
Hawkee   -  Apr 27, 2010

Looks good, but I can't run it on OS X. conio.h is a Windows/DOS library that generally doesn't run on Linux/Unix systems. Maybe you can find an alternative that works more universally?

Also, isn't there a better way to do the logic rather than hard code all the possible moves?

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.