It’s time to play a game. You are asked to develop a Tic Tac Toe game program. H
ID: 3624274 • Letter: I
Question
It’s time to play a game. You are asked to develop a Tic Tac Toe game program. Here are someguidelines.
The software is broken down into the following sub-programs:
1. The board is stored in a 3-by-3 two dimensional array (named board[3][3]).
2. Overall control (main() function) consists of the following steps.
a. Asking the user to start a game, if response is not (y or Y), then terminate the program.
The game is played as follows:
i. Clear the board (implemented as function void clearBoard(char
board[][])).
ii. Print the board (implemented as function void printBoard(char
board[][])).
iii. Do a play (implemented as function void play(char board [][], char
player) – this includes prompting the user for position on board to play).
iv. Check for win or draw (implemented as function boolean checkWinner(char
board[][])).
v. If game not completed, do another play (go to step iii).
vi. Note that the board matrix to represent the game board is created in the main()
function and it is passed to other functions.
b. After each game, ask to start another game (i.e. go back to ‘a’).
3. Checking for a win or draw is divided into the following sub-tasks (that is, the function
checkWinner calls the functions identified below).
a. Check rows for win (implemented as function char testRows(char board[][])).
b. Check cols for win (implemented as function char testCols(char board[][])).
c. Check diagonals for win (implemented as function char testDiag(char
board[][])).
d. Check for draw (implemented as function bool testDraw(char board[][])).
See the annex for sample output.
You will need to develop the following functions:
Clear the board (void clearBoard(char board[][])).
Check for win or draw (bool checkWinner(char board[][])).
Check rows for win (char testRows(char board[][])).
Check cols for win (char testCols(char board[][])).
Check diagonals for win (char testDiag(char board[][])).
Check for draw (bool testDraw(char board[][])).
Explanation / Answer
C: The Complete Reference, 4th Ed. (Paperback) by Herbert Schildt ISBN: 0072121246 Publisher: McGraw-Hill Osborne Media; 4 edition (April 26, 2000) */ #include #include char matrix[3][3]; /* the tic tac toe matrix */ char check(void); void init_matrix(void); void get_player_move(void); void get_computer_move(void); void disp_matrix(void); int main(void) { char done; printf("This is the game of Tic Tac Toe. "); printf("You will be playing against the computer. "); done = ' '; init_matrix(); do { disp_matrix(); get_player_move(); done = check(); /* see if winner */ if(done!= ' ') break; /* winner!*/ get_computer_move(); done = check(); /* see if winner */ } while(done== ' '); if(done=='X') printf("You won! "); else printf("I won!!!! "); disp_matrix(); /* show final positions */ return 0; } /* Initialize the matrix. */ void init_matrix(void) { int i, j; for(i=0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.