Introduction
Tic-Tac-Toe is a simple game which, if played optimally by both players, will always result in
a tie. And the game can be made significantly more complex by increasing the size of the
board [1]. A completed game of Tic-Tac-Toe is shown is Figure 1 [1].
Figure 1. A completed game of Tic-Tac-Toe [2].
Rules of Playing the Tic-Tac-Toe game in our project
On a 3x3 Board
o Player1 with a drawing symbol of “O” always goes first. Player2 is with a drawing
symbol of “X”.
o Players alternate placing “O”s and “X”s on the board until either (a) one player
has three in a row, horizontally, vertically or diagonally; or (b) all nine squares
are filled.
o If a player is able to draw three “O”s or three “X”s in a row, that player wins.
o If all nine squares are filled and neither player has three in a row, the game is a
tie.
H61CAE-porject TURN OVER
On a 4x4 Board
o Player1 with a drawing symbol of “O” always goes first. Player2 is with a drawing
symbol of “X”.
o Players alternate placing “O”s and “X”s on the board until either (a) one player
has four in a row, horizontally, vertically or diagonally; or (b) all sixteen squares
are filled.
o If a player is able to draw four “O”s or four “X”s in a row, that player wins.
o If all sixteen squares are filled and neither player has four in a row, the game is
a tie.
On a 6x6 Board
o Player1 with a drawing symbol of “O” always goes first. Player2 is with a drawing
symbol of “X”.
o Players alternate placing “O”s and “X”s on the board until either (a) one player
has four in a row, horizontally, vertically or diagonally; or (b) all thirty-six
squares are filled.
o If a player is able to draw four “O”s or four “X”s in a row, that player wins.
o If all thirty-six squares are filled and neither player has four in a row, the game
is a tie.
Project practice
You need to create a simple Tic-Tac-Toe game based on the user selection. For the game
design, you need to design a user-friendly menu for the players strictly following the
requirements. The Tic Tac toe game in this project is designed for two players only. Four
board options are provided for the players to select from 3×3, 4×4, 5×5, and 6×6 boards.
Design steps and requirements
1. Display the exact welcome message "Welcome to play the game!” at the
beginning of the game.
2. In a new line, prompt the player to select the board options with the exact
message "Please choose the board size from 3 to 6: ". Get the board size
information from the user. If the number entered by user is smaller than 3 or
bigger than 6, keep prompting the player to enter the board size information
until a valid board size is entered.
3. Once a valid board size is entered, clear the screen and create the initial board
for the game to start. The display needs to follow the given example for the 3×3
board exactly (board_3x3.c). The box number is from 0 to 8 for the 3×3 board.
For other size of boards, the board size and the box number need to grow, and
the board title needs to be modified correspondingly.
4. After the initial board is created, prompt the player 1 to make a move by
printing the exact message “Player 1, enter a number: ” on the screen.
5. Player 1 enters a movement destination by the box number. If the number
entered is beyond the maximum box index or if the box is already taken, keep
prompting the player 1 to enter a new number until a valid box number is
entered with the exact message “Invalid move! Player 1, enter a number: ”.
Once a valid box number is entered, the board is refreshed accordingly with the
box number on the board replaced by an “O” symbol.
6. Check if a winning or a tie situation can be determined. If a winning condition or
a tie condition can be determined, starting from a new line display the exact
message “Player 1 wins!” or “A tied game!”. And in a new line display the exact
message "Play again? ” to ask if the user wants to play again. If the user enters
H61CAE-porject TURN OVER
“Y” or “y”, go back to step 3 and start a new game. If the user enters any other
character, in a new line, display the exact message “The final score is A - B” with
“A” and “B” replaced by the actual scores of player 1 and player 2. And in a new
line, display the exact message “Thanks for playing this game!” and terminate
the program.
7. If a winning or a tie condition cannot be determined, prompt the player 2 to
make a move by printing the exact message “Player 2, enter a number: ” on the
screen. If the number entered is beyond the maximum box index or if the box is
already taken, keep prompting the player 2 to enter a new number until a valid
box number is entered with the exact message “Invalid move! Player 2, enter a
number: ”. Once a valid box number is entered, the board is refreshed
accordingly with the box number on the board replaced by an “X” symbol.
8. Check if a winning situation or a tie situation can be determined. If a winning
condition or a tie condition can be determined, starting from a new line display
the exact message “Player 2 wins!” or “A tied game!”. And in a new line display
the exact message "Play again? ” to ask if the user wants to play again? If the
user enters “Y” or “y”, go back to step 3 and start a new game. If the user
enters any other character, in a new line, display the exact message “The final
score is A - B” with “A” and “B” replaced by the actual scores of player 1 and
player 2. And in a new line, display the exact message “Thanks for playing this
game!” and terminate the program.
9. If the wining or a tie condition cannot be determined, repeat from the step 5 to
prompt the player 1 to make a move.
Note
o An example program for the initial creation of the 3×3 board (board_3x3.c) is
given to you to demonstrate the board display format. However, it is only for the
3×3 board. You have to make sure other board options are correctly
implemented and the board information can be correctly updated for each
movement. The output of the initial 3x3 board is shown in Figure 2.
o An application file (tic_tac_toe_3x3.exe) is given to you to demonstrate the
entire game procedure, but it is only for the 3×3 board. You have to make sure
the game is correctly implemented for other board options. The output of a
finished game with the 3x3 board is shown in Figure 3.
o It is extremely important that you keep all the display format and procedures
exact the same as the example code (board_3x3.c) and the application file
(tic_tac_toe_3x3.exe). Failing to do so will result in up to 50% deduction of your
final mark. To display the exact messages, you should only use and directly copy
the following commands provided and properly placed them in your program.
printf("Welcome to play the game!\n");
printf("Please choose the board size from 3 to 6: ");
printf("Player %d, enter a number: ", PLID);
//PLID is the player ID and has a value of 1 or 2
printf("Invalid move! Player %d, enter a number: ", PLID);
//PLID is the player ID and has a value of 1 or 2
printf("\nA tied game!");
printf("\nPlay again? ");
printf("\nThe final score is %d - %d", A, B);
//A and B are the final scores for player1 and player2
printf("\nThanks for playing this game!");
H61CAE-porject TURN OVER
Figure 2. The output of the initial 3x3 board.
Figure 3. The output of a finished game with the 3x3 board.
Coding style. requirements
o A function external to main() must be created for the game board drawing
and update with the function name called BoardDawing. If no external
BoardDawing function can be found from your program, there will be a 20%
deduction of your final mark.
o A function external to main() must be created for the results evaluation after
each movement with the function name called ResultChecking. If no external
ResultChecking function can be found from your program, there will be a 20%
deduction of your final mark.
o Indentation must be used in your program and make sure you have enough
comments in your program. Failing to do so will result in up to 10% deduction
of your final mark.
Submission requirements
o Just submit one single C program file with the name called zyxxxxx.c on
moodle by 4pm Dec. 23rd. You need to replace the “x”s in the file name with
the last five digits of your student ID. If multiple files submitted or with the
wrong name, there will be a 30% deduction of your final mark.
o Please make sure the main() function and all the external functions are
included in this single file.
o Your program should be warning free, which means that no warning
messages should be shown in the Codeblocks build messages window. If
there are warning messages, there will be up to 20% deduction of your final
mark.
o Please make sure the single C program you submit can be compiled. Zero
functionality mark will be given if your file cannot be compiled.
H61CAE-porject END