Lab 3: Tic-Tac-Toe
In this week's lab you must write a C program to display a Tic-Tac-Toe board and allow making moves. You will need to know and use simple input/output in C (using printf and scanf), declaring variables, if statements, arithmetic operations and a loop of some kind.
The execution of the finished program should look like what is shown below. (User input is shown in bold, though in your program it will not be bold.)
Welcome to Tic-Tac-Toe.
--------------
Board is:
. . . 1 2 3
. . . 4 5 6
. . . 7 8 9
Please enter the destination and character to be placed: 5X
--------------
Board is:
. . . 1 2 3
. X . 4 5 6
. . . 7 8 9
Please enter the destination and character to be placed: 5X
Stage 1 (1 point):
Declare 9 char variables to represent the board (char c1, c2, ... all the way to c9). Initialize these all to '.' Write the code using printf statements to display the contents of these variables on the screen, as shown above.
Stage 2 (1 point):
Write an input statement using scanf to read in the destination and the character to be placed. After reading it in, update the correct variable. Put a loop around your code so that it repeats, as shown above. You may assume "trusted" users that appropriately take turns, giving perfect input.
Stage 3 (Extra Credit) (1 point):
After each move, check if there are 3 same user inputted characters in a row/column/diagonal. If so, give a message (e.g. "X wins!") and exit the program. Also the program checks whether the board is full (i.e. no '.'), if the board is full, exit the program too.
Notes:
Keep in mind that this is a team effort so you should agree with your partner on what you are going to do before you start typing. The partner who is typing is the "driver" and the partner watching is the "navigator." Be sure to switch roles every 10 to 15 minutes, to foster a deep understanding of the code for both partners. The navigator should be watching for syntax errors and verifying the correctness of the code you're writing.
It will speed things up for you if you keep a window open for editing and have a separate window open for compiling and running your program. Remember that windows are resizeable!
Submission:
You should work with a partner for a grade. Only one submission per group is necessary, but be sure to include your name if you work alone, or both people's names if you worked with a partner.
You should submit the lab to the Blackboard at the end of the lab session, by 50 minutes after the hour.