Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 4: Needs to be written in C code not C++!!! Tic-Tac-Toe Game The Task Its time to play a game. You are asked to

Assignment 4: Needs to be written in C code not C++!!!

Tic-Tac-Toe Game The Task Its time to play a game. You are asked to develop a Tic Tac Toe game program. Here are some guidelines. 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[][])).

Notes: 1. The function checkWinner display messages Game is a draw instead of Player X has won when a draw is detected.

2. Note that the coordinates are entered on the same line.

3. You will be using many if statements in your program. Most of the statements will have an empty else section. The else portion of the if-statement need not be present. In the interest of cleaner code, you may omit the else section of the if statement, but indicate this using a comment as follows if (condition) } // } // no else do nothing

4. Do not be intimidated by the number of functions to create. Most of these functions are very short and similar. For example there is not much difference between checking for winning columns and winning rows.

5. The testRows, testCols, and testDiag, return one of -, X or O characters. If a hyphen is returned then no winner was found, otherwise the character corresponding to the winner will be returned.

6. Make any further assumptions if not defined in the problem statement as needed. Annex sample output Start a game (Y or N): y

0 1 2

0 - - -

1 - - -

2 - - -

Player X, please enter row and col between 0 and 2: 1 1

0 1 2

0 - - -

1 - X -

2 - - -

Player O, please enter row and col between 0 and 2: 0 0

0 1 2 0

O - -

1 - X -

2 - - -

Player X, please enter row and col between 0 and 2: 1 3

Player X, please enter row and col between 0 and 2: 2 2

0 1 2

0 O - -

1 - X -

2 - - X

Player O, please enter row and col between 0 and 2: 0 0

Space at 0 0 is occupied Player O, please enter row and col between 0 and 2: 0 2

0 1 2

0O - O

1 - X -

2 - - X

Player X, please enter row and col between 0 and 2: 1 0

0 1 2

0 O - O

1 X X -

2 - - X

Player O, please enter row and col between 0 and 2: 0 1

Player O has won 0 1 2 0 O O O 1 X X - 2 - - X Start a game (Y or N)

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

Step: 3

blur-text-image

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 Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

Question What are the advantages of a written bonus plan?

Answered: 1 week ago