// Include the iostream library
#include <iostream>
#include <string>
#include <ctime>
// Using the standard namespace
using namespace std;
// declare global variables
char Board [9];
// Declare Functions
void showBoard ( );
bool moveIsValid (int m );
int whoWon(); // Returns 0 if no one has won,1 if player 1 has won, 2 if player 2 has won
void main ( )
{
// Seed the random number
srand (time (NULL) );
// Declare Global Variables
string Player_1_name;
string Player_2_name;
int Whose_Turn = 1; // 1 means players turn and 2 means player 2 turns
int Move; // Store where the players wants to move
int Total_Moves = 0;
int num_players = 0;
// Give Choise to play 2 player or against computer
cout << "Welcome to Tic Tac Toe.\n Enter 1 for 1 player or 2 for 2 player" << endl;
if (num_players == 1)
{
//Get PLayer Names
cout << " Player 1: Please enter your name " << endl;
cin >> Player_1_name;
while (whoWon ( ) ==0 && Total_Moves < 9)
{
do
{
// Show the board
showBoard ();
// Tell which player to move
if (Whose_Turn ==1)
{
cout << Player_1_name << ": It's your turn" << endl;
cout << " Enter the number of the spot where you'd like to move." << endl;
cin >> move
}
else
{
cout << "The Computer's move is:" << endl;
Move = rand() % 9;
}
// Get move
cout << "Enter the number of spot you'd like to move" << endl;
cin >> Move;
} while (moveIsValid (Move) != true);
// ADd 1 to Total_Moves
Total_Moves++;
// Change whose turn it is
switch (Whose_Turn)
{
case (1):
{
Board[Move] = 'x';
Whose_Turn = 2;
break;
}
case (2):
{
Board[Move] = 'o';
Whose_Turn = 1;
}
}
}
// sow the board
showBoard ();
if (whoWon () == 1)
{
// show the board
showBoard();
cout << Player_1_name << " has won the game!" << endl;
}
else if (whoWon () == 2)
{
// Show the board
showBoard();
cout << " The computer has won the game! " << endl;
}
else
{
// Show the board
showBoard();
cout << "It;s a tie game!" << endl;
}
{
if (num_players ==2)
}