Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1 Write a program that implements the game of Tic-Tac-Toe where you can play against the computer. Player 1 will be the user and

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

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. Player 1 will be the user and player 2 will be the computer. Your program should go through the following steps: I. Generate an empty Tic-Tac-Toe board (3x3 array) 2. 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: a. Display the current layout of the tablie 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 i. ii. iii. iv. b. Ifi is player 1's turn (the user) i. Ask the user to enter their selection (the location on the board where the O should be placed (row, col)) Check to make sure that the row and column the user entered is valid ii. ii. 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. c. Ifit 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 ii Print out player 2's move computer selects and occupied space generate a new move) the column, each between 0 and 2 Problem 1 Write a program that implements the game of Tic-Tac-Toe where you can play against the computer. Player 1 will be the user and player 2 will be the computer. Your program should go through the following steps: I. Generate an empty Tic-Tac-Toe board (3x3 array) 2. 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: a. Display the current layout of the tablie 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 i. ii. iii. iv. b. Ifi is player 1's turn (the user) i. Ask the user to enter their selection (the location on the board where the O should be placed (row, col)) Check to make sure that the row and column the user entered is valid ii. ii. 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. c. Ifit 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 ii Print out player 2's move computer selects and occupied space generate a new move) the column, each between 0 and 2

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_2

Step: 3

blur-text-image_step3

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