View Single Post
Old 01-28-2005, 07:36 PM   #7 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
well since he's not posting his code, here's mine...
Code:
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;
int losecount(0), tiecount(0), valid(0), lastmove(0);
string name;
char toe[9];                //// name of char array which places X's and O's
void resetboard();          //// resets the board
void human();               //// function which makes toe[?] = X
void drawboard();           //// Draws the Board
int firstmove();            //// First computer move
int secondmove();           //// Second computer move
int thirdmove();            //// third computer move
void fourthmove();          //// fourth computer move
void automove();            //// autofills the last space with X
int valcheck(int valid);    //// checks to make sure that the number enterd by the human is valid
int wincheck();             //// checks all possible combinations for a win
////////////////////////////////////////////////////////////////////////////MAIN//////////////////////////////////////////////////////////////////
int main()
{
	int lose(0);           //// this int is used to end the game (inner loop) if a loss occurs
	char yesno('y');       //// this ends the program (outer loop) if they pic 'n'
	cout << "TIC-TAC-TOE" << endl << endl << "You are 'O'. Use the number pad to place your O's." << endl << "Don't forget to make sure that num-lock is on." << endl << "Please enter your name: ";
	cin >> name;
	cout << "When you see - " << name << ": - that means it is your turn to move." << endl << "Good Luck!" << endl << endl;
	while (yesno == 'y' || yesno == 'Y')    // outer loop
	{
		lose = 0;
		while (lose == 0)                   // inner loop
		{
			resetboard();
			int i(1);                       // this variable is used for human moves
			drawboard();
			human();
			drawboard();
			lastmove = firstmove();
			drawboard();
			while (i == 1)
			{
				human();
				if (valid == 1)
				{
					i++;
					drawboard();
				}
				else if (valid == 0)
				{
					cout << "You can't play there." << endl;    
				}    
			}   
			lastmove = secondmove();               // lastmove is used to help keep things efficient by making the computer only check certain situations instead of each possible situation
			drawboard();
			while (i == 2)
			{
				human();
				if (valid == 1)
				{
					i++;
					drawboard();
				}
				else if (valid == 0)
				{
					cout << "You can't play there." << endl;    
				}    
			}
			lastmove = thirdmove();               // lastmove is used to help keep things efficient by making the computer only check certain situations instead of each possible situation
			drawboard();
			lose = wincheck();                    // if lose = 1 it skips the rest of the inner loop and asks if they want to play again
			if (lose == 1)
			{
				break;
			}
			while (i == 3)
			{
				human();
				if (valid == 1)
				{
					i++;
					drawboard();
				}
				else if (valid == 0)
				{
					cout << "You can't play there." << endl;    
				}    
			}
			fourthmove();
			drawboard();
			lose = wincheck();
			if (lose == 1)
			{
				break;
			}
			automove();
			drawboard();
			if (lose == 0)
			{
				cout << "You tied" << endl;
				tiecount++;
				break;
			}
		}
		cout << "Would you like to play again? (y or n) \t";
		cin >> yesno;
		if (yesno == 'y' || yesno == 'Y')
		{
		    system("CLS");
		}    
	}
	cout << endl << endl << endl << "You lost " << losecount << " times." << endl << "You tied " << tiecount << " times." << endl << "You won 0 times." << endl;
    system("PAUSE");	
    return 0;
}
////////////////////////////////////////////////////////////////////////////Board Reset//////////////////////////////////////////////////////////////////
void resetboard()   /// this makes every spot on the board = to a space
{
	toe[1] = ' ';
	toe[2] = ' ';
	toe[3] = ' ';
	toe[4] = ' ';
	toe[5] = ' ';
	toe[6] = ' ';
	toe[7] = ' ';
	toe[8] = ' ';
	toe[9] = ' ';
}
////////////////////////////////////////////////////////////////////////////HUMAN INPUT//////////////////////////////////////////////////////////////////
void human()
{
    int num;
    cout << name << ": ";
    cin >> num;
    valid = num;
    valid = valcheck(valid);
    if (num == 1 && valid == 1)         //  <<<<< the valid result in integrated in the if statements
    {
        toe[1]= 'X';
    }    
    if (num == 2 && valid == 1)
    {
        toe[2]= 'X';
    }
    if (num == 3 && valid == 1)
    {
        toe[3]= 'X';
    }    
    if (num == 4 && valid == 1)
    {
        toe[4]= 'X';
    }
    if (num == 5 && valid ==1)
    {
        toe[5]= 'X';
    }    
    if (num == 6 && valid == 1)
    {
        toe[6]= 'X';
    }
    if (num == 7 && valid ==1)
    {
        toe[7]= 'X';
    }    
    if (num == 8 && valid == 1)
    {
        toe[8]= 'X';
    }
    if (num == 9 && valid == 1)
    {
        toe[9] = 'X';
    }    
}    
////////////////////////////////////////////////////////////////////////////DRAW BOARD//////////////////////////////////////////////////////////////////
void drawboard()
{
    cout << endl << "\t\t\t " << toe[7] << " | " << toe[8] << " | " << toe[9] << endl << "\t\t\t---|---|---" << endl << "\t\t\t " << toe[4] << " | " << toe[5] << " | " << toe[6] << endl << "\t\t\t---|---|---" << endl << "\t\t\t " << toe[1] << " | " << toe[2] << " | " << toe[3] << endl << endl << endl << endl;
}
////////////////////////////////////////////////////////////////////////////VALIDATOR//////////////////////////////////////////////////////////////////
int valcheck(int valid)
{
    if (valid == 1)
    {
        if (toe[1] == ' ')      /// because all possible moves were set to spaces, this enables me to use an if statement say "if toe[?] == to a blank spot...." instead of "if toe[?] != to X or O
        {
        return 1;
        }
    }
    if (valid == 2)
    {
        if (toe[2] == ' ')
        {
        return 1;
        }
    }     
    if (valid == 3)
    {
        if (toe[3] == ' ')
        {
        return 1;
        }
    }
    if (valid == 4)
    {
        if (toe[4] == ' ')
        {
        return 1;
        }
    }
    if (valid == 5)
    {
        if (toe[5] == ' ')
        {
        return 1;
        }
    }
    if (valid == 6)
    {
        if (toe[6] == ' ')
        {
        return 1;
        }
    }
    if (valid == 7)
    {
        if (toe[7] == ' ')
        {
        return 1;
        }
    }
    if (valid == 8)
    {
        if (toe[8] == ' ')
        {
        return 1;
        }
    }
    if (valid == 9)
    {
        if (toe[9] == ' ')
        {
        return 1;
        }
    }    
    return 0;
}    
////////////////////////////////////////////////////////////////////////////FIRST MOVE//////////////////////////////////////////////////////////////////
int firstmove()
{
    if (toe[1] == 'X' || toe[3] == 'X' || toe[7] == 'X' || toe[9] == 'X')
    {
        toe[5] = 'O'; cout << "Computer: 5" << endl;
        return 1;                        // this number is what "lastmove" becomes = to. this keeps the next computer move from checking situations which do not apply to this move.
    }
    if (toe[8] == 'X' || toe[4] == 'X' || toe[6] == 'X' || toe[2] == 'X')
    {
        toe[5] = 'O'; cout << "Computer: 5" << endl;
        return 2;
    }    
    if (toe[5] == 'X')
    {
        toe[3] = 'O'; cout << "Computer: 3" << endl;
        return 3;
    }
}

////////////////////////////////////////////////////////////////////////////SECOND MOVE//////////////////////////////////////////////////////////////////
int secondmove()
{
    if (lastmove == 1)          /// this is the if statement which goes along with the one above this. since one was returned, it only checks this if statements instead of every possible situation.
    {
		if (toe[7] == 'X' && toe[4] == 'X' || toe[3] == 'X' && toe[2] == 'X')
        {
            toe[1] = 'O'; cout << "Computer: 1" << endl;
			return 1;
        }
		if (toe[1] == 'X' && toe[3] == 'X' || toe[1] == 'X' && toe[6] == 'X' || toe[1] == 'X' && toe[9] == 'X' || toe[3] == 'X' && toe[7] == 'X' || toe[3] == 'X' && toe[4] == 'X')
        {
            toe[2] = 'O'; cout << "Computer: 2" << endl;
			return 2;
        }
        if (toe[1] == 'X' && toe[2] == 'X' || toe[9] == 'X' && toe[6] == 'X')
        {
            toe[3] = 'O'; cout << "Computer: 3" << endl;
			return 3;
        }
        if (toe[1] == 'X' && toe[7] == 'X' || toe[1] == 'X' && toe[8] == 'X' || toe[7] == 'X' && toe[2] == 'X')
        {
            toe[4] = 'O'; cout << "Computer: 4" << endl;
			return 4;
        }
		if (toe[3] == 'X' && toe[9] == 'X' || toe[3] == 'X' && toe[8] == 'X' || toe[9] == 'X' && toe[2] == 'X')
        {
            toe[6] = 'O'; cout << "Computer: 6" << endl;
			return 5;
        }
        if (toe[1] == 'X' && toe [4] == 'X' || toe[9] == 'X' && toe[8] == 'X')
        {
            toe[7] = 'O'; cout << "Computer: 7" << endl;
			return 6;
        }
		if (toe[9] == 'X' && toe[7] == 'X' || toe[9] == 'X' && toe[4] == 'X' || toe[7] == 'X' && toe[6] == 'X')
        {
            toe[8] = 'O'; cout << "Computer: 8" << endl;
			return 7;
        }
        if (toe[3] == 'X' && toe[6] == 'X' || toe[7] == 'X' && toe[8] == 'X')
        {
            toe[9] = 'O'; cout << "Computer: 9" << endl;
			return 8;
        }  
    }
    if (lastmove == 2)
    {
        if (toe[2] == 'X' && toe[3] == 'X' || toe[2] == 'X' && toe[4] == 'X' || toe[4] == 'X' && toe[7] == 'X')
        {
            toe[1] = 'O'; cout << "Computer: 1" << endl;
			return 9;
        }
		if (toe[4] == 'X' && toe[3] == 'X' || toe[6] == 'X' && toe[1] == 'X')
        {
            toe[2] = 'O'; cout << "Computer: 2" << endl;
			return 10;
        }
        if (toe[2] == 'X' && toe[6] == 'X' || toe[6] == 'X' && toe[9] == 'X' || toe[2] == 'X' && toe[1] == 'X')
        {
            toe[3] = 'O'; cout << "Computer: 3" << endl;
			return 11;
        }
        if (toe[2] == 'X' && toe[7] == 'X' || toe[8] == 'X' && toe[1] == 'X')
        {
            toe[4] = 'O'; cout << "Computer: 4" << endl;
			return 12;
        }
        if (toe[2] == 'X' && toe[9] == 'X' || toe[8] == 'X' && toe[3] == 'X' || toe[2] == 'X' && toe[8] == 'X')
        {
            toe[6] = 'O'; cout << "Computer: 6" << endl;
			return 13;
        }
        if (toe[4] == 'X' && toe[8] == 'X' || toe[8] == 'X' && toe[9] == 'X' || toe[4] == 'X' && toe[1] == 'X')
        {
            toe[7] = 'O'; cout << "Computer: 7" << endl;
			return 14;
        }
        if (toe[4] == 'X' && toe[9] == 'X' || toe[6] == 'X' && toe[7] == 'X' || toe[4] == 'X' && toe[6] == 'X')
        {
            toe[8] = 'O'; cout << "Computer: 8" << endl;
			return 15;
        }
        if (toe[6] == 'X' && toe[8] == 'X' || toe[8] == 'X' && toe[7] == 'X' || toe[6] == 'X' && toe[3] == 'X')
        {
            toe[9] = 'O'; cout << "Computer: 9" << endl;
			return 16;
        }                                
    }
    if (lastmove == 3)
    {
		if (toe[5] == 'X' && toe[7] == 'X' || toe[5] == 'X' && toe[9] == 'X')
        {
            toe[1] = 'O'; cout << "Computer: 1" << endl;
			return 17;
        }
		if (toe[5] == 'X' && toe[8] == 'X')
        {
            toe[2] = 'O'; cout << "Computer: 2" << endl;
			return 18;
        }
		if (toe[5] == 'X' && toe[6] == 'X')
		{
			toe[4] = 'O'; cout << "Computer: 5" << endl;
			return 19;
		}
		if (toe[5] == 'X' && toe[4] == 'X')
        {
            toe[6] = 'O'; cout << "Computer: 6" << endl;
			return 20;
        }
        if (toe[5] == 'X' && toe[2] == 'X')
        {
            toe[8] = 'O'; cout << "Computer: 8" << endl;
			return 21;
        }
        if (toe[5] == 'X' && toe[1] == 'X')
        {
            toe[9] = 'O'; cout << "Computer: 9" << endl;
			return 22;
        }
    }                            
}     
////////////////////////////////////////////////////////////////////////////THIRD MOVE//////////////////////////////////////////////////////////////////
int thirdmove()
{
	if (lastmove == 1)
	{
		if (toe[7] == 'X' && toe[9] == 'X')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
			return 1;
		}
		if (toe[9] == 'X' && toe[3] == 'X')
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
			return 2;
		}
		if (toe[3] == 'X' && toe[6] == 'X')
		{
		    toe[9] = 'O'; cout << "Computer: 9" << endl;
		}    
	}
	if (lastmove == 2)
	{
		if (toe[8] == 'X' && toe[9] == 'X')
		{
			toe[7] = 'O'; cout << "Computer: 7" << endl;
			return 3;
		}
		if (toe[2] == 'O' && toe[5] == 'O' && toe[8] == ' ')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
			return 4;
		}
		if (toe[8] == 'X' && toe[3] == 'X' || toe[8] == 'X' && toe[6] == 'X')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
			return 5;
		}
	}
	if (lastmove == 3)
	{
	    if (toe[7] == ' ')
	    {
	        toe[7] = 'O'; cout << "Computer: 7" << endl;
	        return 6;
	    }    
		if (toe[7] == 'X' && toe[9] == 'X')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
			return 7;
		}
		if (toe[7] == 'X' && toe[1] == 'X')
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
			return 8;
		}
	}
	if (lastmove == 4)
	{
		if (toe[6] == ' ')
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
			return 9;
		}
		if (toe[6] == 'X' && toe[1] == 'X')
		{
			toe[3] = 'O'; cout << "Computer: 3" << endl;
			return 10;
		}
		if (toe[2] == 'X' && toe[6] == 'X')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
			return 11;
		}
	}
	if (lastmove == 5)
 	{
		if (toe[4] == ' ')
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
			return 12;
		}
		else
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
			return 13;
		}	
	}
	if (lastmove == 6)
	{
		if (toe[3] == ' ')
		{
			toe[3] = 'O'; cout << "Computer: 3" << endl;
			return 14;
		}
		if (toe[3] == 'X' && toe[1] == 'X')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
			return 15;
		}
		if (toe[3] == 'X' && toe[9] == 'X')
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
			return 16;
		}
	}
	if (lastmove == 7)
	{
		if (toe[2] == ' ')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
			return 17;
		}
		else
		{
			toe[3] = 'O'; cout << "Computer: 3" << endl;
			return 18;
		}
	}
	if (lastmove == 8)
	{
		if (toe[1] == ' ')
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
			return 19;
		}
		if (toe[1] == 'X' && toe[3] == 'X')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
			return 20;
		}
		if (toe[1] == 'X' && toe[7] == 'X')
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
			return 21;
		}
	}
	if (lastmove == 9)
	{
		if (toe[9] == 'X' && toe[3] == 'X' || toe[9] == 'X' && toe[2] == 'X')
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
			return 22;
		}
		if (toe[9] == ' ')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
			return 23;
		}
		if (toe[7] == 'X' && toe[9] == 'X')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
			return 24;
		}
	}
	if (lastmove == 10)
	{
		if (toe[8] == ' ')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
			return 25;
		}
		else
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
			return 26;
		}
	}
	if (lastmove == 11)
	{
		if (toe[7] == 'X' && toe[6] == 'X')
		{
			if (toe[7] == 'X' && toe[9] == 'X')
			{
				toe[8] = 'O'; cout << "Computer: 8" << endl;
				return 27;
			}
			else
			{
				toe[1] = 'O'; cout << "Computer: 1" << endl;
				return 27;
			}
		}
		if (toe[1] == 'X' && toe[7] == 'X')
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
			return 27;
		}
		if (toe[7] == ' ')
		{
			toe[7] = 'O'; cout << "Computer: 7" << endl;
			return 28;
		}
	}											///// I removed 29 and 30 because they were already done in 27
	if (lastmove == 12)
	{
		if (toe[6] == ' ')
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
			return 30;
		}
		if (toe[6] == 'X' && toe[7] == 'X')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
			return 31;
		}
		if ( toe[8] == 'X' && toe[6] == 'X')
		{
			toe[3] = 'O'; cout << "Computer: 3" << endl;
			return 32;
		}
	}
	if (lastmove == 13)
	{
		if (toe[4] == ' ')
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
			return 33;
		}
		if (toe[2] == 'X' && toe[4] == 'X')
		{
			toe[7] = 'O'; cout << "Computer: 7" << endl;
			return 34;
		}															///// I removed 35 because it was the same as 34
	}
	if (lastmove == 14)
	{
		if (toe[3] == ' ')
		{
			toe[3] = 'O'; cout << "Computer: 3" << endl;
			return 36;
		}
		if (toe[3] == 'X' && toe[4] == 'X')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
			return 37;
		}
		if (toe[3] == 'X' && toe[9] == 'X')
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
			return 38;
		}
		if (toe[1] == 'X' && toe[3] == 'X')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
			return 39;
		}
	}
	if (lastmove == 15)
	{
		if (toe[2] == ' ')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
			return 40;
		}
		if (toe[2] == 'X' && toe[9] == 'X')
		{
			toe[3] = 'O'; cout << "Computer: 3" << endl;
			return 41;
		}
		if (toe[2] == 'X' && toe[6] == 'X')
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
			return 42;
		}
	}
	if (lastmove == 16)
	{
		if (toe[1] == ' ')
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
			return 43;
		}
		if (toe[1] == 'X' && toe[3] == 'X')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
			return 44;
		}
		if (toe[1] == 'X' && toe[7] == 'X')
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
            return 45;
		}
	}
	if (lastmove == 17)
	{
		if (toe[2] == ' ')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
			return 46;
		}
		if (toe[2] == 'X')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
			return 47;
		}
	}
	if (lastmove == 18)
	{
		if (toe[1] == ' ')
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
			return 48;
		}
		if (toe[1] == 'X')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
			return 49;
		}
	}
	if (lastmove == 19)
	{
		if (toe[2] == 'X')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
			return 50;
		}
		if (toe[1] == 'X')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
			return 51;
		}
		if (toe[7] == 'X' || toe[9] == 'X')
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
			return 52;
		}
		if (toe[8] == 'X')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
			return 53;
		} 
	}
	if (lastmove == 20)
	{
		if (toe[9] == ' ')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
			return 54;
		}
		if (toe[9] == 'X')
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
			return 55;
		}
	}
	if (lastmove == 21)
	{
		if (toe[9] == 'X')
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
			return 56;
		}
		if (toe[6] == 'X')
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
			return 57;
		}
		if (toe[4] == 'X')
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
			return 58;
		}
		if (toe[7] == 'X' || toe[1] == 'X')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
			return 59;
		}
	}
	if (lastmove == 22)
	{
		if (toe[6] == ' ')
		{
			toe[6] = 'O';
			cout << "Computer: 6" << endl;
            return 60;
		}
		else
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
			return 61;
		}
	}
}
////////////////////////////////////////////////////////////////////////////FOURTH MOVE//////////////////////////////////////////////////////////////////
void fourthmove()
{
    if (lastmove == 1)
    {
        if (toe[2] == ' ')
        {
            toe[2] = 'O'; cout << "Computer: 2" << endl;
        }
        else
        {
            toe[3] = 'O'; cout << "Computer: 3" << endl;
        }
    }
    if (lastmove == 2)
    {
        if (toe[4] == ' ')
        {
            toe[4] = 'O'; cout << "Computer: 4" << endl;
        }
        else
        {
            toe[7] = 'O'; cout << "Computer: 7" << endl;
        }
    }
    if (lastmove == 3)
    {
        if (toe[3] == ' ')
        {
            toe[3] = 'O'; cout << "Computer: 3" << endl;
        }    
        else
        {
            toe[6] = 'O'; cout << "Computer: 3" << endl;
        }
    }
    if (lastmove == 4)
    {
        cout << "You Lose" << endl;
    }
    if (lastmove == 5)
    {
		if (toe[9] == 'O' && toe[5] == 'O' && toe[1] == ' ')
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}
		if (toe[6]  == ' ' && toe[4] == ' ' || toe[1] == 'X' && toe[7] == 'X' || toe[4] == ' ' && toe[7] == ' ')
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
		}
		if (toe[4] == 'X' && toe[1] == 'X')
		{
			toe[7] = 'O'; cout << "Computer: 7" << endl;
		}
	}                   /// If (lastmove == 6) is missing because there is nothing to do after O wins
	if (lastmove == 7)
	{
		if (toe[2] == ' ')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
		}
		else
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}
	}
	if (lastmove == 8)
	{
		if (toe[6] == ' ')
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
		}
		else
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
		}
	}           /// If (lastmove == 9) is missing because there is nothing to do after O wins
	if (lastmove == 10)
	{
		if (toe[9] == 'X')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
		}
		if (toe[8] == 'X' || toe[2] == 'X')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
		}
		if (toe[8] == 'X' && toe[9] == 'X')
		{
			toe[7] = 'O'; cout << "Computer: 7" << endl;
		}
		if (toe[1] == 'X' && toe[2] == 'X')
		{
			toe[3] = 'O'; cout << "Computer: 3" << endl;
		}
	}
	if (lastmove == 11)
	{
		if (toe[2] == 'X' && toe[3] == 'X')
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}
		if (toe[1] == 'X' && toe[2] == 'X')
		{
			toe[3] == 'O'; cout << "Computer: 3" << endl;
		}
		if (toe[8] == 'X')
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}
	}        /// If (lastmove == 12) is missing because there is nothing to do after O wins
	if (lastmove == 13)
	{
		if (toe[7] == 'X' && toe[9] == 'X')
		{
			toe[8] = 'O'; cout << "Computer: " << endl;
		}
		if (toe[8] == 'X' && toe[9] == 'X')
		{
			toe[7] = 'O'; cout << "Computer: " << endl;
		}
		if (toe[7] == 'X' && toe[8] == 'X')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
		}
	}              /// If (lastmove == 14) is missing because there is nothing to do after O wins
	if (lastmove == 15)
	{
		if (toe[8] == ' ')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
		}
		else
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
		}
	}
	if (lastmove == 16)
	{
		if (toe[4] == ' ')
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
		}
		else
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}
	}                    /// If (lastmove == 17) is missing because there is nothing to do after O wins
	if (lastmove == 18)
	{
		if (toe[4] == ' ')
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
		}
		else
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}

	}                       /// If (lastmove == 19) is missing because there is nothing to do after O wins
	if (lastmove == 20)
	{
		if (toe[8] == ' ')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
		}
		else
		{
			toe[7] = 'O'; cout << "Computer: 7" << endl;
		}
	}
	if (lastmove == 21)
	{
		if (toe[6] == ' ')
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
		}
		else
		{
			toe[3] = 'O'; cout << "Computer: 3" << endl;
		}
	}
	if (lastmove == 22)
	{
		if (toe[4] == ' ')
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
		}
		else					////// I wasn't sure if "else if(....)" would do the same, so I put the if inside the else
		{
			if (toe[7] == ' ')
			{
				toe[7] = 'O'; cout << "Computer: 7" << endl;
			}
			else
			{
				toe[8] = 'O'; cout << "Computer: 8" << endl;
			}
		}
	}                  /// If (lastmove == 23) is missing because there is nothing to do after O wins
	if (lastmove == 24)
	{
		if (toe[2] == ' ')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
		}
		else
		{
			toe[3] = 'O'; cout << "Computer: 3" << endl;
		}
	}                          /// If (lastmove == 25) is missing because there is nothing to do after O wins
	if (lastmove == 26)
	{
		if (toe[7] == ' ')
		{
			toe[7] = 'O'; cout << "Computer: 7" << endl;
		}
		else
		{
			if (toe[4] == ' ')
			{
				toe[4] = 'O'; cout << "Computer: 4" << endl;
			}
			else
			{
				toe[1] = 'O'; cout << "Computer: 1" << endl;
			}
		}
	}
	if (lastmove == 27)
	{
		if (toe[9] == ' ')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
		}
		if (toe[2] == ' ')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
		}
		else
		{
			if (toe[1] == ' ')
			{
				toe[1] = 'O'; cout << "Computer: 1" << endl;
			}
		}
		if (toe[8] == ' ' && toe[9] == 'X')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
		}
	}                 /// If (lastmove == 28) is missing because there is nothing to do after O wins
	if (lastmove == 31)
	{
		if (toe[1] == ' ')
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}
		else
		{
			toe[3] = 'O'; cout << "Computer: 3" << endl;
		}
	}
	if (lastmove == 32)
	{
		if (toe[7] == ' ')
		{
			toe[7] = 'O'; cout << "Computer: 7" << endl;
		}
		else
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
		}
	}                    /// If (lastmove == 33) is missing because there is nothing to do after O wins
	if (lastmove == 34)
	{
		if (toe[3] == ' ')
		{
			toe[3] = 'O'; cout << "Computer: 3" << endl;
		}
		else
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}
	}                    /// If (lastmove == 36) is missing because there is nothing to do after O wins
	if (lastmove == 37)
	{
		if (toe[9] == ' ')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
		}
		else
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
		}
	}
	if (lastmove == 38)
	{
		if (toe[4] == ' ')
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
		}
		else
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}
	}
	if (lastmove == 39)
	{
		if (toe[8] == ' ')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
		}
		else
		{
			toe[9] = 'O';
		}
	}                       /// If (lastmove == 40) is missing because there is nothing to do after O wins
	if (lastmove == 41)
	{
		if (toe[7] == ' ')
		{
			toe[7] = 'O'; cout << "Computer: 7" << endl;
		}
		else
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}
	}
	if (lastmove == 42)
	{
		if (toe[9] == ' ')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
		}
		else
		{
			toe[3] = 'O'; cout << "Computer: 3" << endl;
		}
	}                       /// If (lastmove == 43) is missing because there is nothing to do after O wins
	if (lastmove == 44)
	{
		if (toe[8] == ' ')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
		}
		else
		{
			toe[7] = 'O'; cout << "Computer: 7" << endl;
		}
	}
	if (lastmove == 45)
	{
		if (toe[6] == ' ')
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
		}
		else
		{
			toe[3] = 'O'; cout << "Computer: 3" << endl;
		}
	}                       /// If (lastmove == 46) is missing because there is nothing to do after O wins
	if (lastmove == 47)
	{
		if (toe[6] == ' ')
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
		}
		else
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
		}
	}                    /// If (lastmove == 48) is missing because there is nothing to do after O wins
	if (lastmove == 49)
	{
		if (toe[6] == ' ')
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
		}
		else
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
		}
	}
	if (lastmove == 50)
	{
		if (toe[9] == ' ')
		{
			toe[9] = 'O'; cout << "Computer: 89" << endl;
		}
		else
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}
	}
	if (lastmove == 51)
	{
		if (toe[8] == ' ')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
		}
		else
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
		}
	}
	if (lastmove == 52)
	{
		if (toe[2] == ' ')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
		}
		else
		{
			toe[7] = 'O'; cout << "Computer: 7" << endl;
		}
	}
	if (lastmove == 53)
	{
		if (toe[1] == ' ')
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}
		else
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
		}
	}              /// If (lastmove == 54) is missing because there is nothing to do after O wins
	if (lastmove == 55)
	{
		if (toe[2] == ' ')
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
		}
		else
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
		}
	}
	if (lastmove == 56)
	{
		if (toe[4] == ' ')
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
		}
		else
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
		}
	}
	if (lastmove == 57)
	{
		if (toe[1] == ' ')
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}
		else
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
		}
	}
	if (lastmove == 58)
	{
		if (toe[9] == ' ')
		{
			toe[9] = 'O'; cout << "Computer: 9" << endl;
		}
		else
		{
			toe[1] = 'O'; cout << "Computer: 1" << endl;
		}
	}
	if (lastmove == 59)
	{
		if (toe[7] == ' ')
		{
			toe[7] = 'O'; cout << "Computer: 7" << endl;
		}
		else if (toe[6] == ' ')
		{
			toe[6] = 'O'; cout << "Computer: 6" << endl;
		}
		else
		{
			toe[4] = 'O'; cout << "Computer: 4" << endl;
		}
	}                    /// If (lastmove == 60) is missing because there is nothing to do after O wins
	if (lastmove == 61)
	{
		if (toe[8] == ' ')
		{
			toe[8] = 'O'; cout << "Computer: 8" << endl;
		}
		else
		{
			toe[2] = 'O'; cout << "Computer: 2" << endl;
		}
	}
}
////////////////////////////////////////////////////////////////////////////AUTO-MOVE//////////////////////////////////////////////////////////////////
void automove()             // this checks for all blank spots and fills them in with X's
{
	if (toe[1] == ' ')
	{
		toe[1] = 'X'; cout << "Auto-Fill: 1" << endl;
	}
	if (toe[2] == ' ')
	{
		toe[2] = 'X'; cout << "Auto-Fill: 2" << endl;
	}
	if (toe[3] == ' ')
	{
		toe[3] = 'X'; cout << "Auto-Fill: 3" << endl;
	}
	if (toe[4] == ' ')
	{
		toe[4] = 'X'; cout << "Auto-Fill: 4" << endl;
	}
	if (toe[5] == ' ')
	{
		toe[5] = 'X'; cout << "Auto-Fill: 5" << endl;
	}
	if (toe[6] == ' ')
	{
		toe[6] = 'X'; cout << "Auto-Fill: 6" << endl;
	}
	if (toe[7] == ' ')
	{
		toe[7] = 'X'; cout << "Auto-Fill: 7" << endl;
	}
	if (toe[8] == ' ')
	{
		toe[8] = 'X'; cout << "Auto-Fill: 8" << endl;
	}
	if (toe[9] == ' ')
	{
		toe[9] = 'X'; cout << "Auto-Fill: 9" << endl;
	}
}
////////////////////////////////////////////////////////////////////////////WIN CHECK//////////////////////////////////////////////////////////////////
int wincheck()
{
	if (toe[7] == 'O' && toe[8] == 'O' && toe[9] == 'O' || toe[4] == 'O' && toe[5] == 'O' && toe[6] == 'O' || toe[1] == 'O' && toe[2] == 'O' && toe[3] == 'O' || toe[7] == 'O' && toe[4] == 'O' && toe[1] == 'O' ||
	toe[8] == 'O' && toe[5] == 'O' && toe[2] == 'O' || toe[9] == 'O' && toe[6] == 'O' && toe[3] == 'O' || toe[7] == 'O' && toe[5] == 'O' && toe[3] == 'O' || toe[9] == 'O' && toe[5] == 'O' && toe[1] == 'O')
	{
		losecount++; cout << "You Lose!" << endl;
		return 1;
	}
	return 0;
}
Androto is offline   Reply With Quote