Question: Write a program that allows two players to play a game of tic-tac-toe. Use a twodimensional char array with three rows and three columns as
Write a program that allows two players to play a game of tic-tac-toe. Use a twodimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that Displays the contents of the board array Allows player 1 to select a location on the board for an X. The program should ask the user to enter the row and column number.
Allows player 2 to select a location on the board for an O. The program should ask the user to enter the row and column number. Determines whether a player has won, or a tie has occurred. If a player has won, the program should declare that player the winner and end. If a tie has occurred, the program should say so and end. Player 1 wins when there are three Xs in a row on the game board. The Xs can appear in a row, in a column, or diagonally across the board. A tie occurs when all of the locations on the board are full, but there is no winner.
Constraints:
DO NOT USE GLOBAL VARIABLES (GLOBAL CONSTANTS ARE OK)
Program must use functions and CANNOT be written as one main program.
Use a function to display a set of instructions describing how the user must enter a "move" (this has to called only once at the beginning of the program)
Use a function to display the contents of the board.
The program must clear the display screen after the user enters a new move, then display the contents of the board with the new move shown (see sample output below).
Use a function for the player's turn.
Validate each users move (i.e. if the user enters a location that already contains an X or an O or the numbers entered are not a valid position on the board an error will be displayed). The program must then ask the user to re-input their move.
Use a function to determine whether the player has won. The function should receive as arguments, the board and the player ( 'X' or 'O'). You also check for a Tie or End of Game in this function or create a separate function to do this.
The program should ask the player to enter the row and column number.
The board and the elements contained within the board must line up correctly.
The program MUST use a 2D Array.
Determine whether a player has won or there is a tie. If there is a winner, the program should display that a player has won the game and which player has won. If there is a tie the program should display that a tie has occurred an exit.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
