## CS 2401 Assignment #2

Due Date: Tuesday, September 13 or Wednesday, September 14 depending on the day of your lab.

Objective: The goal of this assignment is to practice using 2-dimensional arrays.

Background: The game of Tic-Tac-Toe is a popular 2-player game, particularly among children. It is played using a 3 by 3 grid, as shown below. The players alternate turns, with the first player placing an "X" in any open space, the second player placing an "O" in any open space, and so on. The goal for each player is to get three of their own symbol in a straight line, whether it be a row, column, or diagonal. The game ends when either player wins by getting three "X" or "O" marks in a line, or when all 9 spaces are filled, in which case the game is declared a draw.

```
|  |

--|--|--

|  |

--|--|--

|  |

```
Assignment:

Part I Your assignment is to write a program that will allow two players to play a game of Tic-Tac-Toe. Your program should:

• Print the current game board (using ASCII, similar to what is shown above)
• Prompt the correct player (1 or 2) on the console to make a move by entering the row and column to place a mark in
• Check whether the player has won the game and if so, print a message congratulating the winning player
• Check whether the game is a draw, and if so, print a message declaring the draw
• Print out the updated game board

Be sure that your program checks for invalid inputs from the user!

Part II (Extra Credit) The game of Tic-Tac-Toe is fairly simple, let us make it more interesting. Modify your program so that it can be played in three dimensions, as shown below. Now there are three game boards, with each board conceptually stacked on top of the others to form a cube. The left board is the bottom, the second board is the middle, and the rightmost board is the top. In this game placing an "X" in the top-left corner of each of the three boards counts as a line in the vertical dimension.

```
|  |        |  |          |  |

--|--|--    --|--|--      --|--|--

|  |        |  |          |  |

--|--|--    --|--|--      --|--|--

|  |        |  |          |  |

```
Your program should still print the current game board, prompt the user for a move, and check for win/draw conditions as in the 2-dimensional version of the game. In this case, the user's move will have three components: the row, the column, and the board. Be careful to check for all possible ways that a player could get three symbols in a straight light, including diagonal lines that go across all three boards!

Deliverables: Your TA will instruct you.