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

Hello, I need a help with making a Tic Tac Toe game in C++ Here are detailed ins

ID: 3576261 • Letter: H

Question

Hello,

I need a help with making a Tic Tac Toe game in C++

Here are detailed instructions that NEED to be followed:

You need to develop a program in which a human plays against the computer.
1. Validate user input at every opportunity.
a. Do not allow number entries less than 0
b. Do not allow number entries greater than 8
c. Do not allow non-numeric entries
2. Do not use global variables in the development of the program
3. You may use global constants in the development of the program
4. Use one-dimensional arrays to keep track of the game:
a. Computer moves
b. Human moves
5. Use functions to pass arrays and implement other program requirements.
6. The program must be developed using functions so that the main() function consists mostly of function calls
7. Computer must be aggressive and take every opportunity to win the game if and when the human makes errors (for computer best move use "if" statements)
8. The main() function must use a loop to keep the user in the program until he/she wants to quit.
9. You may not use infinite loops: for(;;) or while(true)
10. You may not use the break statement to exit loops

Below is a list of functions to use in the development of this project:


splashScreen()//displays game and developer’s information
askForUserNames()//requests for username


validateUserName()//validate username
switchPlayer()//switch from one player to another


resetGame()//reset the game when one concludes; this includes filling the array with vales 0-8
displayGrid()//display the grid after each player makes a move


playerMakeMove()//prompts player to make a move, invokes validatePlayersMove, checkPositionAvailability
validatePlayersMove()//validates that user entry X is such that 0<=X<=8


checkPositionAvailability()//check that the position selected by the user is available
checkWin()//check for a winning player


checkTie()//check for a tie

makeBestMove()//select best option


computerMakeMove()//used to make the move, in other words populate the array

Program Flow


1. At the start of the game, an initial “Splash” screen must be displayed which includes:
a. The game’s title
b. Your name

2. Be sure to validate user entries; no white space, no numbers X, such that 0<=X<=8, no alpha characters.

3. The computer will choose a spot immediately after the human.

4. Don’t allow the human to select a square which is already in use (the human chose a position already in use)

5. A winner is detected when one occurs and a request to play again is made. Don’t forget to validate!

A tie is detected when one occurs.

6. Program ends when players don’t want to play anymore

PLEASE NOTE: THIS IS A FINAL WORK. FOLLOWING ALL INSTRUCTIONS AND PROGRAM FLOW ABOVE IS VERY IMPORTANT

Thank you!

C:UserslfloreslalDesktop Project1Debug Project1.exe TIC TAC TOE By Prof E Flores Press any key to continue

Explanation / Answer

   #include<iostream>

#include <conio.h>

#include <windows.h>

char square[10]={'0','1','2','3','4','5','6','7','8','9'};

void Board();

int checkWinner();

int scoreA=0;

int scoreB=0;

int z;

bool win(int, int, int);

int main() // main function

{

    int i;

    int j;

    int choice;

    for(j=48; j < 58; j++) // creates values for the tic-tac-toe board

        {

                square[j-48]=j;

        }

    bool shutoff = false; // if the game will continue or not

std::cout<<"do you want best out of 3 or 5?:";

std::cin>>z;

int mark;

int player;

    while(shutoff == false) // pretty much until player decides that s/he wants to quit

    {

        for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

        player=1,i,choice;

        system ("cls");

    }

    if(z==3) // if player's choice was best out of 3

    {

        do

        {   Board();

            player=(player%2)? 1:2;             /* the loop will allow this game to switch between player one and two */

            std::cout<<"Player"<<player<<", make your choice: ";

            std::cin>>choice;

            mark=(player==1)? 'X':'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

            {

                std::cout<<"Dude, invalid move!!!";

                player--;

                getch();

            }

            player++;

             i=checkWinner();

        }

       

        //game condition

       

        while(i==0);

        {

          Board();

        }

        if(i==1)

        {

            std::cout<<"Winner is, Player:1";

            scoreA++;

            getch();

            system("cls");

            for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

        Board();

      }

        else if (i==2)

        {

            std::cout<<"Winner is, Player:2";

            scoreB++;

            getch();

            system("cls");

            for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

            Board();

        }

        else

        {

        std::cout<<"It's a draw!";

        getch();

        system("cls");

        for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

        Board();

        }

        shutoff = win(scoreA, scoreB, z);

    }

   

   

    //same as the if (z==3), but only best out of 5

    else if(z==5)

    {

        do

        {   Board();

            player=(player%2)? 1:2;

            std::cout<<"Player"<<player<<", make your choice: ";

            std::cin>>choice;

            mark=(player==1)? 'X':'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

            {

                std::cout<<"Dude, invalid move!!!";

                player--;

                getch();

            }

            player++;

             i=checkWinner();

        }

        while(i==0);

        {

          Board();

        }

        if(i==1)

        {

            std::cout<<"Winner is, Player:1";

            scoreA++;

            getch();

            system("cls");

            for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

            Board();

        }

        else if (i==2)

        {

            std::cout<<"Winner is, Player:2";

            scoreB++;

            getch();

            system("cls");

            for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

            Board();

        }

        else

        {

        std::cout<<"It's a draw!";

        getch();

        system("cls");

        for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

        Board();

        }

        shutoff = win(scoreA, scoreB, z);

    }

   

    // if player decides to enter a different number

    //There will be a bug if you enter a letter

    else if(z!=3,5)

    {

    std::cout<<"Enter a 3 or a 5"<<std::endl;

    std::cout<<"Press any key to go back";

    getch();

    system("cls");

    main();

    }

    }

return 0;

}

bool win(int scoreA, int scoreB, int z)

{

    if(z==3)

    {

        if (scoreB==2)

        {

            std::cout<<"overall winner is player2";

            getch();

            system ("cls");

            std::cout<<"Thanks For Playing!!!!";

            getch();

            return true;

        }

        else if (scoreA==2)

        {

            std::cout<<"overall winner is player1";

            getch();

            system ("cls");

            std::cout<<"Thanks For Playing!!!!";

            getch();

            return true;

        }

        return false;

    }

  

    if(z==5)

    {

        if (scoreB==3)

        {

            std::cout<<"overall winner is player2";

            getch();

            system("cls");

            std::cout<<"Thanks for Playing!!!!";

            getch();

            return true;

        }

        else if (scoreA==3)

        {

            std::cout<<"overall winner is player1";

            getch();

            system("cls");

            std::cout<<"Thanks for Playing!!!!";

            getch();

            return true;

        }

        return false;

    }

}

int checkWinner()

{

    if(square[1] == square[2] && square[2] == square[3] && square[1]=='X')

   {

        return 1;

    }

    else if(square[4] == square [5] && square [5] == square [6] && square[4]=='X')

    {

        return 1;

    }

    else if (square [7] == square [8] && square [8] == square[9] && square[7]=='X')

    {

        return 1;

    }

    else if(square [1] == square [4] && square [4] == square [7] && square [1]=='X')

    {

        return 1;

    }

    else if(square [2]== square[5] && square [5] == square [8] && square[2]=='X')

    {

        return 1;

    }

    else if(square [3] == square [6] && square [6] == square [9] && square[3]=='X')

    {

        return 1;

    }

    else if(square [1] == square [5] && square [5] == square [9] && square[1]=='X')

    {

        return 1;

    }

    else if(square[3] == square [5] && square [5] == square [7] && square[3]=='X')

    {

        return 1;

    }

     else if(square[1] == square[2] && square[2] == square[3] && square[1]=='O')

    {

        return 2;

    }

    else if(square[4] == square [5] && square [5] == square [6] && square[4]=='O')

    {

        return 2;

    }

    else if (square [7] == square [8] && square [8] == square[9] && square[7]=='O')

    {

        return 2;

    }

    else if(square [1] == square [4] && square [4] == square [7] && square[1]=='O')

    {

        return 2;

    }

    else if(square [2]== square[5] && square [5] == square [8] && square[2]=='O')

    {

        return 2;

    }

    else if(square [3] == square [6] && square [6] == square [9] && square[3]=='O')

    {

        return 2;

    }

    else if(square [1] == square [5] && square [5] == square [9] && square[1]=='O')

    {

        return 2;

    }

    else if(square[3] == square [5] && square [5] == square [7] && square[3]=='O')

    {

        return 2;

    }

    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 9000;

    }

    else

    {

        return 0;

    }

}

//This function draws the Board

void Board()

{   system("cls");

    std::cout<<"Tic Tac Toe, Best out of "<< z <<std::endl;

    std::cout<<"Programmed by Shaka Kanenobu"<<std::endl;

    std::cout<<"Player 1-X: Player 2-O"<<std::endl;

    std::cout<<std::endl;

    std::cout<<"score:"<<scoreA<<" : "<<scoreB<<std::endl;

    std::cout<<"    |    |    "<<std::endl;

    std::cout<<" "<<square[1]<<"   "<<square[2]<<"    "<<square[3]<<" "<<std::endl;

    std::cout<<"____|____|____"<<std::endl;

    std::cout<<"    |    |    "<<std::endl;

  std::cout<<" "<<square[4]<<"   "<<square[5]<<"    "<<square[6]<<" "<<std::endl;

    std::cout<<"____|____|____"<<std::endl;

    std::cout<<"    |    |    "<<std::endl;

    std::cout<<" "<<square[7]<<"   "<<square[8]<<"    "<<square[9]<<" "<<std::endl;

    std::cout<<"    |    |    "<<std::endl;

}

   #include<iostream>

#include <conio.h>

#include <windows.h>

char square[10]={'0','1','2','3','4','5','6','7','8','9'};

void Board();

int checkWinner();

int scoreA=0;

int scoreB=0;

int z;

bool win(int, int, int);

int main() // main function

{

    int i;

    int j;

    int choice;

    for(j=48; j < 58; j++) // creates values for the tic-tac-toe board

        {

                square[j-48]=j;

        }

    bool shutoff = false; // if the game will continue or not

std::cout<<"do you want best out of 3 or 5?:";

std::cin>>z;

int mark;

int player;

    while(shutoff == false) // pretty much until player decides that s/he wants to quit

    {

        for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

        player=1,i,choice;

        system ("cls");

    }

    if(z==3) // if player's choice was best out of 3

    {

        do

        {   Board();

            player=(player%2)? 1:2;             /* the loop will allow this game to switch between player one and two */

            std::cout<<"Player"<<player<<", make your choice: ";

            std::cin>>choice;

            mark=(player==1)? 'X':'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

            {

                std::cout<<"Dude, invalid move!!!";

                player--;

                getch();

            }

            player++;

             i=checkWinner();

        }

       

        //game condition

       

        while(i==0);

        {

          Board();

        }

        if(i==1)

        {

            std::cout<<"Winner is, Player:1";

            scoreA++;

            getch();

            system("cls");

            for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

        Board();

      }

        else if (i==2)

        {

            std::cout<<"Winner is, Player:2";

            scoreB++;

            getch();

            system("cls");

            for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

            Board();

        }

        else

        {

        std::cout<<"It's a draw!";

        getch();

        system("cls");

        for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

        Board();

        }

        shutoff = win(scoreA, scoreB, z);

    }

   

   

    //same as the if (z==3), but only best out of 5

    else if(z==5)

    {

        do

        {   Board();

            player=(player%2)? 1:2;

            std::cout<<"Player"<<player<<", make your choice: ";

            std::cin>>choice;

            mark=(player==1)? 'X':'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

            {

                std::cout<<"Dude, invalid move!!!";

                player--;

                getch();

            }

            player++;

             i=checkWinner();

        }

        while(i==0);

        {

          Board();

        }

        if(i==1)

        {

            std::cout<<"Winner is, Player:1";

            scoreA++;

            getch();

            system("cls");

            for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

            Board();

        }

        else if (i==2)

        {

            std::cout<<"Winner is, Player:2";

            scoreB++;

            getch();

            system("cls");

            for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

            Board();

        }

        else

        {

        std::cout<<"It's a draw!";

        getch();

        system("cls");

        for(j=48; j < 58; j++)

        {

                square[j-48]=j;

        }

        Board();

        }

        shutoff = win(scoreA, scoreB, z);

    }

   

    // if player decides to enter a different number

    //There will be a bug if you enter a letter

    else if(z!=3,5)

    {

    std::cout<<"Enter a 3 or a 5"<<std::endl;

    std::cout<<"Press any key to go back";

    getch();

    system("cls");

    main();

    }

    }

return 0;

}

bool win(int scoreA, int scoreB, int z)

{

    if(z==3)

    {

        if (scoreB==2)

        {

            std::cout<<"overall winner is player2";

            getch();

            system ("cls");

            std::cout<<"Thanks For Playing!!!!";

            getch();

            return true;

        }

        else if (scoreA==2)

        {

            std::cout<<"overall winner is player1";

            getch();

            system ("cls");

            std::cout<<"Thanks For Playing!!!!";

            getch();

            return true;

        }

        return false;

    }

  

    if(z==5)

    {

        if (scoreB==3)

        {

            std::cout<<"overall winner is player2";

            getch();

            system("cls");

            std::cout<<"Thanks for Playing!!!!";

            getch();

            return true;

        }

        else if (scoreA==3)

        {

            std::cout<<"overall winner is player1";

            getch();

            system("cls");

            std::cout<<"Thanks for Playing!!!!";

            getch();

            return true;

        }

        return false;

    }

}

int checkWinner()

{

    if(square[1] == square[2] && square[2] == square[3] && square[1]=='X')

   {

        return 1;

    }

    else if(square[4] == square [5] && square [5] == square [6] && square[4]=='X')

    {

        return 1;

    }

    else if (square [7] == square [8] && square [8] == square[9] && square[7]=='X')

    {

        return 1;

    }

    else if(square [1] == square [4] && square [4] == square [7] && square [1]=='X')

    {

        return 1;

    }

    else if(square [2]== square[5] && square [5] == square [8] && square[2]=='X')

    {

        return 1;

    }

    else if(square [3] == square [6] && square [6] == square [9] && square[3]=='X')

    {

        return 1;

    }

    else if(square [1] == square [5] && square [5] == square [9] && square[1]=='X')

    {

        return 1;

    }

    else if(square[3] == square [5] && square [5] == square [7] && square[3]=='X')

    {

        return 1;

    }

     else if(square[1] == square[2] && square[2] == square[3] && square[1]=='O')

    {

        return 2;

    }

    else if(square[4] == square [5] && square [5] == square [6] && square[4]=='O')

    {

        return 2;

    }

    else if (square [7] == square [8] && square [8] == square[9] && square[7]=='O')

    {

        return 2;

    }

    else if(square [1] == square [4] && square [4] == square [7] && square[1]=='O')

    {

        return 2;

    }

    else if(square [2]== square[5] && square [5] == square [8] && square[2]=='O')

    {

        return 2;

    }

    else if(square [3] == square [6] && square [6] == square [9] && square[3]=='O')

    {

        return 2;

    }

    else if(square [1] == square [5] && square [5] == square [9] && square[1]=='O')

    {

        return 2;

    }

    else if(square[3] == square [5] && square [5] == square [7] && square[3]=='O')

    {

        return 2;

    }

    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 9000;

    }

    else

    {

        return 0;

    }

}

//This function draws the Board

void Board()

{   system("cls");

    std::cout<<"Tic Tac Toe, Best out of "<< z <<std::endl;

    std::cout<<"Programmed by Shaka Kanenobu"<<std::endl;

    std::cout<<"Player 1-X: Player 2-O"<<std::endl;

    std::cout<<std::endl;

    std::cout<<"score:"<<scoreA<<" : "<<scoreB<<std::endl;

    std::cout<<"    |    |    "<<std::endl;

    std::cout<<" "<<square[1]<<"   "<<square[2]<<"    "<<square[3]<<" "<<std::endl;

    std::cout<<"____|____|____"<<std::endl;

    std::cout<<"    |    |    "<<std::endl;

  std::cout<<" "<<square[4]<<"   "<<square[5]<<"    "<<square[6]<<" "<<std::endl;

    std::cout<<"____|____|____"<<std::endl;

    std::cout<<"    |    |    "<<std::endl;

    std::cout<<" "<<square[7]<<"   "<<square[8]<<"    "<<square[9]<<" "<<std::endl;

    std::cout<<"    |    |    "<<std::endl;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote