Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am seeking a solution for c++ tic tac toe program. I can\'t figure why the com

ID: 3578987 • Letter: I

Question

I am seeking a solution for c++ tic tac toe program. I can't figure why the computer plays twice. The two sequences I've found this with are:

1) X1

2) X2

here is the messy code:

#include "TicTacToe.h";

#include <iostream>
#include <ctime>
#include <string>
#include <ctime>
#include <cctype>

char square[10] = { '~','1','2','3','4','5','6','7','8','9' }; /* ARRAY */
int toss;
char mark;
int choice;
int checkwin();
void printBoard();
void getComputerMove();
void getPlayerMove();
//void coinToss(int player);
int winner;
int player;
int computer;
char again;
char call;
int flip;
int a = 0;
int t; // turn
//int whosOnFirst;

using namespace std;

//MAIN PROGRAM
int main()
{
   //coinToss(player); // void COINTOSS

   char status;
   bool again = true;
       status = -1;
       do {
               printBoard();
               getPlayerMove();
               status = checkwin(); winner = 1; //check & ID, player, winner
               if (status != -1) // we have a winner - player
                   break; // leave do while

               printBoard();
               getComputerMove();
               status = checkwin(); winner = 2; // check & ID, computer, winner
               if (status != -1) // we have a winner - computer
                   break; // leave do while
       } while (status == -1);

       if (status == 0)
           cout << " All right, we'll call it a draw. ";
       else
           if (winner == 1)
           {
               printBoard();
               cout << " ******************";
               cout << " Congradulations, ";
               cout << " Player, you win!";
               cout << " ****************** ";
           }
           else
           {
               printBoard();
               cout << " ******************";
               cout << " Computer wins. ";
               cout << " ****************** ";
           }
}

// FUNCTION TO RETURN GAME STATUS************************************************
// 1 = Game over with result
// -1 = Game in progress
// O = Game over no result
int checkwin()
{
   if (square[1] == square[2] && square[2] == square[3])
       return 1;

   else if (square[4] == square[5] && square[5] == square[6])
       return 1;

   else if (square[7] == square[8] && square[8] == square[9])
       return 1;

   else if (square[1] == square[4] && square[4] == square[7])
       return 1;

   else if (square[2] == square[5] && square[5] == square[8])
       return 1;

   else if (square[3] == square[6] && square[6] == square[9])
       return 1;

   else if (square[1] == square[5] && square[5] == square[9])
       return 1;

   else if (square[3] == square[5] && square[5] == square[7])
       return 1;

   else if (square[1] != '1' && square[2] != '2' && square[3] != '3'
       && square[4] != '4' && square[5] != '5' && square[6] != '6'
       && square[7] != '7' && square[8] != '8' && square[9] != '9')
       return 0;

   else
       return -1;
}

// DRAW TIC TAC TOE BOARD --------------------------------------------------------------------
void printBoard()
{

   cout << " Tic Tac Toe ";

       cout << " Player: X | Computer: O ";

   cout << endl;

   cout << " | | " << endl;
   cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl;

   cout << " _____|_____|_____" << endl;
   cout << " | | " << endl;

   cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl;

   cout << " _____|_____|_____" << endl;
   cout << " | | " << endl;

   cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl;

   cout << " | | " << endl << endl;
}

//GET PLAYER MOVE *****************************************************************
void getPlayerMove()
{
       mark = 'X';

   cout << "Player 1, please enter your move: ";
   cin >> choice;

   if (choice == 1 && square[1] == '1')
       square[1] = mark;

   else if (choice == 2 && square[2] == '2')
       square[2] = mark;

   else if (choice == 3 && square[3] == '3')
       square[3] = mark;

   else if (choice == 4 && square[4] == '4')
       square[4] = mark;

   else if (choice == 5 && square[5] == '5')
       square[5] = mark;

   else if (choice == 6 && square[6] == '6')
       square[6] = mark;

   else if (choice == 7 && square[7] == '7')
       square[7] = mark;

   else if (choice == 8 && square[8] == '8')
       square[8] = mark;

   else if (choice == 9 && square[9] == '9')
       square[9] = mark;

   else
   {
       cout << "Invalid move ";
       cin.ignore();
       cin.get();
   }
}

//GET COMPUTER MOVE ****************************************************************
void getComputerMove()
{
   mark = 'O';
   int c = 0;

       do
       {
           //FTW
           // FTW row 1
           if (square[1] == 'O' &&
               square[2] == 'O' &&
               square[3] == '3')
           {
               square[3] = mark;
               c = 1;
           };
           if (square[1] == 'O' &&
               square[3] == 'O' &&
               square[2] == '2')
           {
               square[2] = mark;
               c = 1;
           };
           if (square[2] == 'O' &&
               square[3] == 'O' &&
               square[1] == '1')
           {
               square[1] = mark;
               c = 1;
           };
           // FTW row 2
           if (square[4] == 'O' &&
               square[5] == 'O '&&
               square[6] == '6')
           {
               square[6] = mark;
               c = 1;
           };
           if (square[4] == 'O' &&
               square[6] == 'O' &&
               square[5] == '5')
           {
               square[5] = mark;
               c = 1;
           };
           if (square[5] == 'O' &&
               square[6] == 'O' &&
               square[4] == '4')
           {
               square[4] = mark;
               c = 1;
           };
           // FTW row 3
           if (square[7] == 'O' &&
               square[8] == 'O' &&
               square[9] == '9')
           {
               square[9] = mark;
               c = 1;
           };
           if (square[7] == 'O' &&
               square[9] == 'O' &&
               square[8] == '8')
           {
               square[8] = mark;
               c = 1;
           };
           if (square[8] == 'O' &&
               square[9] == 'O' &&
               square[7] == '7')
           {
               square[7] = mark;
               c = 1;
           };

           // FTW column 1
           if (square[1] == 'O' &&
               square[4] == 'O' &&
               square[7] == '7')
           {
               square[7] = mark;
               c = 1;
           };
           if (square[1] == 'O' &&
               square[7] == 'O' &&
               square[4] == '4')
           {
               square[4] = mark;
               c = 1;
           };
           if (square[4] == 'O' &&
               square[7] == 'O' &&
               square[1] == '1')
           {
               square[1] = mark;
               c = 1;
           };

           // FTW column 2
           if (square[2] == 'O' &&
               square[5] == 'O' &&
               square[8] == '8')
           {
               square[8] = mark;
               c = 1;
           };
           if (square[2] == 'O' &&
               square[8] == 'O' &&
               square[5] == '5')
           {
               square[5] = mark;
               c = 1;
           };
           if (square[5] == 'O' &&
               square[8] == 'O' &&
               square[2] == '2')
           {
               square[2] = mark;
               c = 1;
           };

           // FTW column 3
           if (square[3] == 'O' &&
               square[6] == 'O' &&
               square[9] == '9')
           {
               square[9] = mark;
               c = 1;
           };
           if (square[3] == 'O' &&
               square[9] == 'O' &&
               square[6] == '6')
           {
               square[6] = mark;
               c = 1;
           };
           if (square[6] == 'O' &&
               square[9] == 'O' &&
               square[3] == '3')
           {
               square[3] = mark;
               c = 1;
           };

           // FTW m=+
           if (square[7] == 'O' &&
               square[5] == 'O' &&
               square[3] == '3')
           {
               square[3] = mark;
               c = 1;
           };
           if (square[5] == 'O' &&
               square[3] == 'O' &&
               square[7] == '7')
           {
               square[7] = mark;
               c = 1;
           };
           if (square[3] == 'O' &&
               square[7] == 'O' &&
               square[5] == '5')
           {
               square[5] = mark;
               c = 1;
           };

           // FTW m=-
           if (square[1] == 'O' &&
               square[5] == 'O' &&
               square[9] == '9')
           {
               square[9] = mark;
               c = 1;
           };
           if (square[1] == 'O' &&
               square[9] == 'O' &&
               square[5] == '5')
           {
               square[5] = mark;
               c = 1;
           };
           if (square[5] == 'O' &&
               square[9] == 'O' &&
               square[1] == '1')
           {
               square[1] = mark;
               c = 1;
           };
          
           // BLOCK
           // block row 1
           if (square[1] == 'X' &&
               square[2] == 'X' &&
               square[3] == '3')
           {
               square[3] = mark;
               c = 1;
           };
           if (square[1] == 'X' &&
               square[3] == 'X' &&
               square[2] == '2')
           {
               square[2] = mark;
               c = 1;
           };
           if (square[2] == 'X' &&
               square[3] == 'X' &&
               square[1] == '1')
           {
               square[1] = mark;
               c = 1;
           };
           // block row 2
           if (square[4] == 'X' &&
               square[5] == 'X' &&
               square[6] == '6')
           {
               square[6] = mark;
               c = 1;
           };
           if (square[5] == 'X' &&
               square[6] == 'X' &&
               square[4] == '4')
           {
               square[4] = mark;
               c = 1;
           };
           if (square[6] == 'X' &&
               square[4] == 'X' &&
               square[5] == '5')
           {
               square[5] = mark;
               c = 1;
           };
           // block row 3
           if (square[8] == 'X' &&
               square[9] == 'X' &&
               square[7] == '7')
           {
               square[7] = mark;
               c = 1;
           };
           if (square[7] == 'X' &&
               square[9] == 'X' &&
               square[8] == '8')
           {
               square[8] = mark;
               c = 1;
           };
           if (square[7] == 'X' &&
               square[8] == 'X' &&
               square[9] == '9')
           {
               square[9] = mark;
               c = 1;
           };
           // BLOCK COLUMNS
           // block COLUMN 1
           if (square[4] == 'X' &&
               square[7] == 'X' &&
               square[1] == '1')
           {
               square[1] = mark;
               c = 1;
           };
           if (square[1] == 'X' &&
               square[7] == 'X' &&
               square[4] == '4')
           {
               square[4] = mark;
               c = 1;
           };
           if (square[1] == 'X' &&
               square[4] == 'X' &&
               square[7] == '7')
           {
               square[7] = mark;
               c = 1;
           };
           // block COLUMN 2
           if (square[5] == 'X' &&
               square[8] == 'X' &&
               square[2] == '2')
           {
               square[2] = mark;
               c = 1;
           };
           if (square[2] == 'X' &&
               square[8] == 'X' &&
               square[5] == '5')
           {
               square[5] = mark;
               c = 1;
           };
           if (square[2] == 'X' &&
               square[5] == 'X' &&
               square[8] == '8')
           {
               square[8] = mark;
               c = 1;
           };
           // block COLUMN 3
           if (square[6] == 'X' &&
               square[9] == 'X' &&
               square[3] == '3')
           {
               square[3] = mark;
               c = 1;
           };
           if (square[3] == 'X' &&
               square[9] == 'X' &&
               square[6] == '6')
           {
               square[6] = mark;
               c = 1;
           };
           if (square[3] == 'X' &&
               square[6] == 'X' &&
               square[9] == '9')
           {
               square[9] = mark;
               c = 1;
           };
           // BLOCK m=+
           if (square[5] == 'X' &&
               square[3] == 'X' &&
               square[7] == '7')
           {
               square[7] = mark;
               c = 1;
           };
           if (square[7] == 'X' &&
               square[3] == 'X' &&
               square[5] == '5')
           {
               square[5] = mark;
               c = 1;
           };
           if (square[7] == 'X' &&
               square[5] == 'X' &&
               square[3] == '3')
           {
               square[3] = mark;
               c = 1;
           };
           // block m=-
           if (square[5] == 'X' &&
               square[8] == 'X' &&
               square[1] == '1')
           {
               square[1] = mark;
               c = 1;
           };
           if (square[1] == 'X' &&
               square[8] == 'X' &&
               square[5] == '5')
           {
               square[5] = mark;
               c = 1;
           };
           if (square[1] == 'X' &&
               square[5] == 'X' &&
               square[8] == '8')
           {
               square[8] = mark;
               c = 1;
           };
           // PLAY
           // play middle
           if (square[5] == '5')
           {
               square[5] = mark;
               c = 1;
           };

           // play CORNERS
           if (square[1] == 'X' &&
               (square[7] == '7' || square[7] == 'O') &&
               (square[9] == '9' || square[9] == 'O') &&
               square[3] == '3')
           {
               square[3] = mark;
               c = 1;
           };

           if (square[3] == 'X' &&
               (square[1] == '1' || square[1] == 'O') &&
               (square[7] == '7' || square[7] == 'O') &&
               square[7] == '9')
           {
               square[9] = mark;
               c = 1;
           };
           if (square[9] == 'X' &&
               (square[1] == '1' || square[1] == 'O') &&
               (square[3] == '3' || square[3] == 'O') &&
               square[7] == '7')
           {
               square[7] = mark;
               c = 1;
           };
           if (square[7] == 'X' &&
               (square[3] == '3' || square[3] == 'O') &&
               (square[9] == '9' || square[9] == 'O') &&
               square[1] == '1')
           {
               square[1] = mark;
               c = 1;
           };
           // play sides
           if (square[2] == 'X' &&
               (square[4] == '4' || square[4] == 'O') &&
               (square[8] == '8' || square[8] == 'O') &&
               square[6] == '6')
           {
               square[6] = mark;
               c = 1;
           };
           if (square[6] == 'X' &&
               (square[2] == '2' || square[2] == 'O') &&
               (square[4] == '4' || square[4] == 'O') &&
               square[8] == '8')
           {
               square[8] = mark;
               c = 1;
           };
           if (square[8] == 'X' &&
               (square[2] == '2' || square[2] == 'O') &&
               (square[6] == '6' || square[6] == 'O') &&
               square[4] == '4')
           {
               square[4] = mark;
               c = 1;
           };
           if (square[4] == 'X' &&
               (square[6] == '6' || square[6] == 'O') &&
               (square[8] == '8' || square[8] == 'O') &&
               square[2] == '2')
           {
               square[2] = mark;
               c = 1;
           };
       } while (c = 0);

   //cout << "Computer, please enter your move: ";
   //cin >> choice;

   //   mark = 'O';

   //if (choice == 1 && square[1] == '1')
   //   square[1] = mark;

   //else if (choice == 2 && square[2] == '2')
   //   square[2] = mark;

   //else if (choice == 3 && square[3] == '3')
   //   square[3] = mark;

   //else if (choice == 4 && square[4] == '4')
   //   square[4] = mark;

   //else if (choice == 5 && square[5] == '5')
   //   square[5] = mark;

   //else if (choice == 6 && square[6] == '6')
   //   square[6] = mark;

   //else if (choice == 7 && square[7] == '7')
   //   square[7] = mark;

   //else if (choice == 8 && square[8] == '8')
   //   square[8] = mark;

   //else if (choice == 9 && square[9] == '9')
   //   square[9] = mark;
   //else
   //{
   //   cout << "Invalid move ";
   //   cin.ignore();
   //   cin.get();
   //}
}

// VOID COIN TOSS ****************************************************************
//void coinToss(int player)
//{
//   srand(time(0));
//
//   do
//   {
//       flip = rand() % 2;// assign random numbers
//       a = a++;
//
//
//
//       cout << " Please choose heads or tails (h/t): ";
//       cin >> call;
//
//       if (flip = 0) // if TOSS HEADS
//       {
//           if (call == 'H' || call == 'h') // & CALL HEADS
//           {
//               cout << flip << ": Head's, player goes first.";
//               player = 0;
//           }
//           else // & CALL NOT HEADS (TAILS)
//           {
//               cout << flip << ": Head's, computer goes first.";
//               player = 1;
//           }
//       }
//       else // & TOSS NOT HEADS (TAILS)
//       {
//           if (call == 'T' || call == 't') // & CALL TAILS
//           {
//               cout << flip << ": Tails, player goes first.";
//               player = 0;
//           }
//           else // & NOT CALL TAILS
//           {
//               cout << flip << ": Tails, computer goes first.";
//               player = 1;
//           }
//       }
//   } while (a < 1);
//} // end void cointoss

Explanation / Answer

In getComputerMove() you are using only if statements instead of if else if statements as a result multiple conditions were satisfying and the procssing was not stopped after each move but continuing till end of function and all ofs were executing. Use if else as below

#include "TicTacToe.h";
#include <iostream>
#include <ctime>
#include <string>
#include <ctime>
#include <cctype>
char square[10] = { '~','1','2','3','4','5','6','7','8','9' }; /* ARRAY */
int toss;
char mark;
int choice;
int checkwin();
void printBoard();
void getComputerMove();
void getPlayerMove();
//void coinToss(int player);
int winner;
int player;
int computer;
char again;
char call;
int flip;
int a = 0;
int t; // turn
//int whosOnFirst;
using namespace std;
//MAIN PROGRAM
int main()
{
//coinToss(player); // void COINTOSS
char status;
bool again = true;
status = -1;
do {
      
printBoard();
getPlayerMove();
status = checkwin(); winner = 1; //check & ID, player, winner
if (status != -1) // we have a winner - player
break; // leave do while
printBoard();
getComputerMove();
status = checkwin(); winner = 2; // check & ID, computer, winner
if (status != -1) // we have a winner - computer
break; // leave do while
} while (status == -1);
if (status == 0)
cout << " All right, we'll call it a draw. ";
else
if (winner == 1)
{
printBoard();
cout << " ******************";
cout << " Congradulations, ";
cout << " Player, you win!";
cout << " ****************** ";
}
else
{
printBoard();
cout << " ******************";
cout << " Computer wins. ";
cout << " ****************** ";
}
}
// FUNCTION TO RETURN GAME STATUS************************************************
// 1 = Game over with result
// -1 = Game in progress
// O = Game over no result
int checkwin()
{
if (square[1] == square[2] && square[2] == square[3])
return 1;
else if (square[4] == square[5] && square[5] == square[6])
return 1;
else if (square[7] == square[8] && square[8] == square[9])
return 1;
else if (square[1] == square[4] && square[4] == square[7])
return 1;
else if (square[2] == square[5] && square[5] == square[8])
return 1;
else if (square[3] == square[6] && square[6] == square[9])
return 1;
else if (square[1] == square[5] && square[5] == square[9])
return 1;
else if (square[3] == square[5] && square[5] == square[7])
return 1;
else if (square[1] != '1' && square[2] != '2' && square[3] != '3'
&& square[4] != '4' && square[5] != '5' && square[6] != '6'
&& square[7] != '7' && square[8] != '8' && square[9] != '9')
return 0;
else
return -1;
}
// DRAW TIC TAC TOE BOARD --------------------------------------------------------------------
void printBoard()
{
cout << " Tic Tac Toe ";
cout << " Player: X | Computer: O ";
cout << endl;
cout << " | | " << endl;
cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl;
cout << " _____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl;
cout << " _____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl;
cout << " | | " << endl << endl;
}
//GET PLAYER MOVE *****************************************************************
void getPlayerMove()
{
mark = 'X';
cout << "Player 1, please enter your move: ";
cin >> choice;
if (choice == 1 && square[1] == '1')
square[1] = mark;
else if (choice == 2 && square[2] == '2')
square[2] = mark;
else if (choice == 3 && square[3] == '3')
square[3] = mark;
else if (choice == 4 && square[4] == '4')
square[4] = mark;
else if (choice == 5 && square[5] == '5')
square[5] = mark;
else if (choice == 6 && square[6] == '6')
square[6] = mark;
else if (choice == 7 && square[7] == '7')
square[7] = mark;
else if (choice == 8 && square[8] == '8')
square[8] = mark;
else if (choice == 9 && square[9] == '9')
square[9] = mark;
else
{
cout << "Invalid move ";
cin.ignore();
cin.get();
}
}
//GET COMPUTER MOVE ****************************************************************
void getComputerMove()
{
mark = 'O';
int c = 0;
do
{
  
//FTW
// FTW row 1
if (square[1] == 'O' &&
square[2] == 'O' &&
square[3] == '3')
{
square[3] = mark;
c = 1;
}
else if (square[1] == 'O' &&
square[3] == 'O' &&
square[2] == '2')
{
square[2] = mark;
c = 1;
}
else if (square[2] == 'O' &&
square[3] == 'O' &&
square[1] == '1')
{
square[1] = mark;
c = 1;
}
// FTW row 2
else if (square[4] == 'O' &&
square[5] == 'O '&&
square[6] == '6')
{
square[6] = mark;
c = 1;
}
else if (square[4] == 'O' &&
square[6] == 'O' &&
square[5] == '5')
{
square[5] = mark;
c = 1;
}
else if (square[5] == 'O' &&
square[6] == 'O' &&
square[4] == '4')
{
square[4] = mark;
c = 1;
}
// FTW row 3
else if (square[7] == 'O' &&
square[8] == 'O' &&
square[9] == '9')
{
square[9] = mark;
c = 1;
}
else if (square[7] == 'O' &&
square[9] == 'O' &&
square[8] == '8')
{
square[8] = mark;
c = 1;
}
else if (square[8] == 'O' &&
square[9] == 'O' &&
square[7] == '7')
{
square[7] = mark;
c = 1;
}
// FTW column 1
else if (square[1] == 'O' &&
square[4] == 'O' &&
square[7] == '7')
{
square[7] = mark;
c = 1;
}
else if (square[1] == 'O' &&
square[7] == 'O' &&
square[4] == '4')
{
square[4] = mark;
c = 1;
}
else if (square[4] == 'O' &&
square[7] == 'O' &&
square[1] == '1')
{
square[1] = mark;
c = 1;
}
// FTW column 2
else if (square[2] == 'O' &&
square[5] == 'O' &&
square[8] == '8')
{
square[8] = mark;
c = 1;
}
else if (square[2] == 'O' &&
square[8] == 'O' &&
square[5] == '5')
{
square[5] = mark;
c = 1;
}
else if (square[5] == 'O' &&
square[8] == 'O' &&
square[2] == '2')
{
square[2] = mark;
c = 1;
}
// FTW column 3
else if (square[3] == 'O' &&
square[6] == 'O' &&
square[9] == '9')
{
square[9] = mark;
c = 1;
}
else if (square[3] == 'O' &&
square[9] == 'O' &&
square[6] == '6')
{
square[6] = mark;
c = 1;
}
else if (square[6] == 'O' &&
square[9] == 'O' &&
square[3] == '3')
{
square[3] = mark;
c = 1;
}
// FTW m=+
else if (square[7] == 'O' &&
square[5] == 'O' &&
square[3] == '3')
{
square[3] = mark;
c = 1;
}
else if (square[5] == 'O' &&
square[3] == 'O' &&
square[7] == '7')
{
square[7] = mark;
c = 1;
};
if (square[3] == 'O' &&
square[7] == 'O' &&
square[5] == '5')
{
square[5] = mark;
c = 1;
}
// FTW m=-
else if (square[1] == 'O' &&
square[5] == 'O' &&
square[9] == '9')
{
square[9] = mark;
c = 1;
}
else if (square[1] == 'O' &&
square[9] == 'O' &&
square[5] == '5')
{
square[5] = mark;
c = 1;
}
else if (square[5] == 'O' &&
square[9] == 'O' &&
square[1] == '1')
{
square[1] = mark;
c = 1;
}
  
// BLOCK
// block row 1
else if (square[1] == 'X' &&
square[2] == 'X' &&
square[3] == '3')
{
square[3] = mark;
c = 1;
}
else if (square[1] == 'X' &&
square[3] == 'X' &&
square[2] == '2')
{
square[2] = mark;
c = 1;
}
else if (square[2] == 'X' &&
square[3] == 'X' &&
square[1] == '1')
{
square[1] = mark;
c = 1;
}
// block row 2
else if (square[4] == 'X' &&
square[5] == 'X' &&
square[6] == '6')
{
square[6] = mark;
c = 1;
}
else if (square[5] == 'X' &&
square[6] == 'X' &&
square[4] == '4')
{
square[4] = mark;
c = 1;
}
else if (square[6] == 'X' &&
square[4] == 'X' &&
square[5] == '5')
{
square[5] = mark;
c = 1;
}
// block row 3
else if (square[8] == 'X' &&
square[9] == 'X' &&
square[7] == '7')
{
square[7] = mark;
c = 1;
}
else if (square[7] == 'X' &&
square[9] == 'X' &&
square[8] == '8')
{
square[8] = mark;
c = 1;
}
else if (square[7] == 'X' &&
square[8] == 'X' &&
square[9] == '9')
{
square[9] = mark;
c = 1;
}
// BLOCK COLUMNS
// block COLUMN 1
else if (square[4] == 'X' &&
square[7] == 'X' &&
square[1] == '1')
{
square[1] = mark;
c = 1;
}
else if (square[1] == 'X' &&
square[7] == 'X' &&
square[4] == '4')
{
square[4] = mark;
c = 1;
}
else if (square[1] == 'X' &&
square[4] == 'X' &&
square[7] == '7')
{
square[7] = mark;
c = 1;
}
// block COLUMN 2
else if (square[5] == 'X' &&
square[8] == 'X' &&
square[2] == '2')
{
square[2] = mark;
c = 1;
}
else if (square[2] == 'X' &&
square[8] == 'X' &&
square[5] == '5')
{
square[5] = mark;
c = 1;
}
else if (square[2] == 'X' &&
square[5] == 'X' &&
square[8] == '8')
{
square[8] = mark;
c = 1;
}
// block COLUMN 3
else if (square[6] == 'X' &&
square[9] == 'X' &&
square[3] == '3')
{
square[3] = mark;
c = 1;
}
else if (square[3] == 'X' &&
square[9] == 'X' &&
square[6] == '6')
{
square[6] = mark;
c = 1;
}
else if (square[3] == 'X' &&
square[6] == 'X' &&
square[9] == '9')
{
square[9] = mark;
c = 1;
}
// BLOCK m=+
else if (square[5] == 'X' &&
square[3] == 'X' &&
square[7] == '7')
{
square[7] = mark;
c = 1;
}
else if (square[7] == 'X' &&
square[3] == 'X' &&
square[5] == '5')
{
square[5] = mark;
c = 1;
}
else if (square[7] == 'X' &&
square[5] == 'X' &&
square[3] == '3')
{
square[3] = mark;
c = 1;
}
// block m=-
else if (square[5] == 'X' &&
square[8] == 'X' &&
square[1] == '1')
{
square[1] = mark;
c = 1;
}
else if (square[1] == 'X' &&
square[8] == 'X' &&
square[5] == '5')
{
square[5] = mark;
c = 1;
}
else if (square[1] == 'X' &&
square[5] == 'X' &&
square[8] == '8')
{
square[8] = mark;
c = 1;
}
// PLAY
// play middle
else if (square[5] == '5')
{
square[5] = mark;
c = 1;
}
// play CORNERS
else if (square[1] == 'X' &&
(square[7] == '7' || square[7] == 'O') &&
(square[9] == '9' || square[9] == 'O') &&
square[3] == '3')
{
square[3] = mark;
c = 1;
}
else if (square[3] == 'X' &&
(square[1] == '1' || square[1] == 'O') &&
(square[7] == '7' || square[7] == 'O') &&
square[7] == '9')
{
square[9] = mark;
c = 1;
}
else if (square[9] == 'X' &&
(square[1] == '1' || square[1] == 'O') &&
(square[3] == '3' || square[3] == 'O') &&
square[7] == '7')
{
square[7] = mark;
c = 1;
  
}
else if (square[7] == 'X' &&
(square[3] == '3' || square[3] == 'O') &&
(square[9] == '9' || square[9] == 'O') &&
square[1] == '1')
{
square[1] = mark;
c = 1;
}
// play sides
else if (square[2] == 'X' &&
(square[4] == '4' || square[4] == 'O') &&
(square[8] == '8' || square[8] == 'O') &&
square[6] == '6')
{
square[6] = mark;
c = 1;
}
else if (square[6] == 'X' &&
(square[2] == '2' || square[2] == 'O') &&
(square[4] == '4' || square[4] == 'O') &&
square[8] == '8')
{
square[8] = mark;
c = 1;
}
else if (square[8] == 'X' &&
(square[2] == '2' || square[2] == 'O') &&
(square[6] == '6' || square[6] == 'O') &&
square[4] == '4')
{
square[4] = mark;
c = 1;
}
else if (square[4] == 'X' &&
(square[6] == '6' || square[6] == 'O') &&
(square[8] == '8' || square[8] == 'O') &&
square[2] == '2')
{
square[2] = mark;
c = 1;
};
} while (c = 0);
//cout << "Computer, please enter your move: ";
//cin >> choice;
// mark = 'O';
//if (choice == 1 && square[1] == '1')
// square[1] = mark;
//else if (choice == 2 && square[2] == '2')
// square[2] = mark;
//else if (choice == 3 && square[3] == '3')
// square[3] = mark;
//else if (choice == 4 && square[4] == '4')
// square[4] = mark;
//else if (choice == 5 && square[5] == '5')
// square[5] = mark;
//else if (choice == 6 && square[6] == '6')
// square[6] = mark;
//else if (choice == 7 && square[7] == '7')
// square[7] = mark;
//else if (choice == 8 && square[8] == '8')
// square[8] = mark;
//else if (choice == 9 && square[9] == '9')
// square[9] = mark;
//else
//{
// cout << "Invalid move ";
// cin.ignore();
// cin.get();
//}
}
// VOID COIN TOSS ****************************************************************
//void coinToss(int player)
//{
// srand(time(0));
//
// do
// {
// flip = rand() % 2;// assign random numbers
// a = a++;
//
//
//
// cout << " Please choose heads or tails (h/t): ";
// cin >> call;
//
// if (flip = 0) // if TOSS HEADS
// {
// if (call == 'H' || call == 'h') // & CALL HEADS
// {
// cout << flip << ": Head's, player goes first.";
// player = 0;
// }
// else // & CALL NOT HEADS (TAILS)
// {
// cout << flip << ": Head's, computer goes first.";
// player = 1;
// }
// }
// else // & TOSS NOT HEADS (TAILS)
// {
// if (call == 'T' || call == 't') // & CALL TAILS
// {
// cout << flip << ": Tails, player goes first.";
// player = 0;
// }
// else // & NOT CALL TAILS
// {
// cout << flip << ": Tails, computer goes first.";
// player = 1;
// }
// }
// } while (a < 1);
//} // end void cointoss

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote