Reference no: EM13159228
Using functional decomposition, write a program that plays a tic-tac-toe game. Ask the user if they want to go first; the player (user or computer) that goes first is designated X and the other player is O. The board is represented by three one-dimensional arrays (a, b, and c) each with three members (0, 1, 2). The players take turns making moves by designating a letter and a number; e.g., a1. Each player's move must be evaluated to make sure it is valid (within the range and not already occupied). If the user makes a bad move, tell them and ask for another move. If the computer makes an invalid move, keep getting a move until one is valid
In this game, the computer is not intelligent; its moves are random.
A player wins if they occupy three positions in a row; e.g., a1, b1, and c1, or a0, a1, and a2, etc.. Don't forget diagonals.
Before the game starts and after each valid move, show the user the board. Use a combination of spaces, dashes, and vertical lines.
The game ends when a player wins or the maximum number of moves has occurred. If the maximum number of moves takes place and there is no winner, the game is a tie. Tell the user what the result is (winner or tie).
When the game is over, ask the player if they want to play again. If yes, clear the board and start again; if no, say good bye and exit.
Use functions as appropriate.