Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program must be written in C Problem 1 Write a program that implements the game of Tic-Tac-Toe where you can play against the computer. Player1

Program must be written in C

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Problem 1 Write a program that implements the game of Tic-Tac-Toe where you can play against the computer. Player1 will be the user and player 2 will be the computer. Your program should go through the following steps: Generate an empty Tic-Tac-Toe board (3x3 array) Run a loop until one of the players places three in a row (a player has won) or the table is full (stalemate). This loop should: 1. 2. a. Display the current layout of the table i. ii. iii. iv. Blank spaces are displayed as an underscore O for player 1's moves (user) X for player 2's moves (computer) Put spaces between the squares b. If it is player 1's turn (the user) Ask the user to enter their selection (the location on the board where the O should be la,ca i. Check to make sure that the row and column the user entered is valid If the row or column player 1 entered was invalid (outside the bounds of the board or a space that is already occupied) the program should ask the user to enter the option again. ii. iii. c. If it is player 2's turn (the computer) i. Randomly generate a move (row, col) in the board that is not currently occupied (if the ii. To generate a random move: generate two random integers, one for the row and one for i Print out player 2's move computer selects and occupied space generate a new move) the column, each between 0 and 2 iv. Update the board with player 2's move If the above loop ends because one of the players has placed three in a row then the program should print out a winning message of that player (see below). Else, it should print out the follow: "Game over, player wins. 3. no

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions