Tic Tac Toe


We all know the game of TicTacToe. It’s easy, quick and fun. In this assignment, you will implement a computerized version of the game using a 2-dimensional array. This game will be played by two humans sharing the same keyboard. The screen will also show the snapshot or the state of the board after every player’s move. You will store the board as a single 2-dimensional array of base type char that has 3 rows and 3 columns.
Your program should:

• Keep track of whose turn it is (‘X’ or ‘O’) and inform the player about it.

• Allow a player to make a move. A player makes a move by informing your program at which location of the board he/she wants his/her respective symbol (‘X’ or ‘O’) to be placed. The options are as follows: ‘0 0’, ‘0 1’, ‘0 2’, ‘1 0’, ‘1 1’, ‘1 2’, ‘2 0’, ‘2 1’, ‘2 2’. Notice that the player informs the row number, followed by a space, followed by a column number. Your program should verify if the move is valid (for example, 3 1 is not a valid move) and, in case of an invalid move, inform the user about it and ask for a valid move again.

• Verify if there is a winner after every player’s move and also if the board is already full but we have no winners.

• Your program should also allow the player to reinitialize the game to the beginning. On the next page is what your program should look like. Take note of spacing and punctuation:

New Game: X goes first.
-----------------
|R\C| 0 | 1 | 2 |
-----------------
|0||||
-----------------
|1||||
-----------------
|2||||
-----------------
X's turn.
Where do you want your X placed?
Please enter row number and column number separated by a space.
00
You have entered row #0
and column #0
Thank you for your selection.
-----------------
|R\C| 0 | 1 | 2 |
-----------------
|0|X| | |
-----------------
|1||||
-----------------
|2||||
-----------------
O's turn.
Where do you want your O placed?
Please enter row number and column number separated by a space.
33
You have entered row #3
and column #3
Invalid entry: try again.
Row & column numbers must be either 0, 1, or 2.
O's turn.
Where do you want your O placed?
Please enter row number and column number separated by a space.
00
You have entered row #0
and column #0
That cell is already taken.
Please make another selection.
O's turn.
Where do you want your O placed?
Please enter row number and column number separated by a space.
11
You have entered row #1
and column #1
Thank you for your selection.
-----------------
|R\C| 0 | 1 | 2 |
-----------------
|0|X| | |
-----------------
|1| |O| |
-----------------
|2||||
-----------------
X's turn.
Where do you want your X placed?
Please enter row number and column number separated by a space.
10
You have entered row #1
and column #0
Thank you for your selection.
-----------------
|R\C| 0 | 1 | 2 |
-----------------
|0|X| | |
-----------------
|1|X|O| |
-----------------
|2||||
-----------------
O's turn.
Where do you want your O placed?
Please enter row number and column number separated by a space.
01
You have entered row #0
and column #1
Thank you for your selection.
-----------------
|R\C| 0 | 1 | 2 |
-----------------
|0|X|O| |
-----------------
|1|X|O| |
-----------------
|2||||
-----------------
X's turn.
Where do you want your X placed?
Please enter row number and column number separated by a space.
20
You have entered row #2
and column #0
Thank you for your selection.
X IS THE WINNER!!!
-----------------
|R\C| 0 | 1 | 2 |
-----------------
|0|X|O| |
-----------------
|1|X|O| |
-----------------
|2|X| | |
-----------------
Another game? Enter Y or y for yes.
Y
closed account (48T7M4Gy)
See Beginners forum :)
Rofl-
Topic archived. No new replies allowed.