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:
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.