Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a program that plays a game of tic-tac-toe between a human and the computer in c++ Use a variable board[3][3] to store the board.

Create a program that plays a game of tic-tac-toe between a human and the computer in c++ Use a variable board[3][3] to store the board. Since the board is needed by all parts of the program, it can be a global variable. You will want to create the following functions: int score(int cell1,int cell2,int cell3) Using +1 for an X, 1 for an O and 0 for an empty cell, add the values for the three specified cells and return the sum. bool playerWins(char player) Returns true if the given player has won, false if they have not currently won (note: this doesnt necessarily mean that the player has lost.) bool canWin(char player,int &square) This function should look at the board and return true if the given player (X or O) can win on this move and return false if the player cannot win on this move. Fill in the appropriate square if the player can win on this move. Hint: Whats the difference between canWin(X,sq) and canBlock(O,sq)? void printBoard(void) Displays the current board (see above.) int getComputerMove(char player) Gets the computers move as either X or O according to the algorithm described above. int getHumanMove(char player) Gets the humans move as either X or O. Also validates the move to make sure its legal.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago