CIS071
Lab07 - Tic Tac
Toe DUE: (Friday, Mar 17, NOON)
Tic Tac
Toe
About Tic Tac Toe
The object of Tic Tac
Toe is to get three in a row. You play on a three by three game board. The
first player is known as X and the second is O. Players alternate placing Xs
and Os on the game board until either opponent has three in a row or all nine
squares are filled. X always goes first, and in the event that no one has three
in a row, the stalemate is called a cat game.
Write a program that
1) Prompts a
user to enter the current state of a board.
2) Print out
the board
3) Determines
if there is a winner, and, if there is, who it is.
Important: in this assignment, it is not required of you to use functions.
Instead, you can write the complete code in the main function.
Instructions.
1) Prompt a user to enter the current
state of a board.
User is
expected to enter letter ‘x’ for player 1, ‘o’ for player 2, or ‘.’ if the position is empty. You should create a two-dimensional array tictactoe[3][3] of type char to store the board state.
The prompt
should read like this:
>Enter the
content of position (1,1) (‘x’, ‘o’, or ‘.’ if the position is empty): x
>Enter the
content of position (1,2) (‘x’, ‘o’, or ‘.’ if the position is empty): o
…
>Enter the
content of position (3,3) (‘x’, ‘o’, or ‘.’ if the position is empty): x
Hint: this
can be done by using a nested for loop
2) Print out the board.
Let us assume a
user entered the following sequence of letters: x,o,x,o,.,o,x,.,x
The board
should be printed out as:
x|o|x
-----
o|.|o
-----
x|.|x
3) Determines if there is a winner, and,
if there is, who it is.
Note that
there are 8 ways player 1 can win (have 3 x’s in a
horizontal line, 3 x’s in a vertical line, or 3 x’s in one of the two diagonals). The same holds for player
2. In the simplest solution, you should separately check each of the 8 winning
positions for both players. By using for loops it should be possible to save
some typing. Also note that it can be possible to construct a board where both players
have won (e.g. consider the case x,x,x,o,o,o,x,x,x). In such case your program should state that both players have won.
Deliverables:Submit your program; show a few sample runs of the program.