Using functional decomposition, write a program that plays a tic-tac-toe game. A
ID: 3554027 • Letter: U
Question
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 players 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.. Dont 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, like so: |O| ----- X|0| ----- | |X 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. Submit your zipped program file to Moodle. 20 points extra credit: in a separate file, modify your program to give the user the choice of playing against the computer or another player. Set up the moves accordingly.
Explanation / Answer
#include using namespace std; char square[10] = {'o','1','2','3','4','5','6','7','8','9'}; int checkwin(); void board(); int main() { int player = 1,i,choice; char mark; do { board(); player=(player%2)?1:2; coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.