Question

In: Mechanical Engineering

Assume that the human player makes the first move against the computer in a game of Tic-Tac-Toe,

Assume that the human player makes the first move against the computer in a game of Tic-Tac-Toe, which has a 3 x 3 grid. Write a MATLAB function that lets the computer respond to that move. The function’s input argument should be the cell location of the human player’s move. The function’s output should be the cell location of the computer’s rst move. Label the cells as 1, 2, 3 across the top row; 4, 5, 6 across the middle row; and 7, 8, 9 across the bottom row.

Solutions

Expert Solution

Program plan:

• To check the given code to find the values of the variable each time the while statement is executed.

 

Program:

%**********************************************************

%The given matlab code is checked for the values of the

%variables for each time execution of the while statement.

%**********************************************************

%Program codes

%Initialization of value

k = 1;

%Initialization of value

b = -2;

%Initialization of value

x = -1;

%Initialization of value

y = -2;

while k <= 3 %Start of loop

%Displays string

disp([num2str(k), \' \',num2str(b),\' \', num2str(x),\' \', num2str(y)]);

%Computes value

y = x^2 - 3;

if y < b %Conditional statement

%Assign the value

b = y;

end %End of conditional statement

%Increment of value

x = x + 1;

%Increment of loop variable

k = k + 1;

end %End of loop

 

Output:


Related Solutions

explain a pseudocode for tic tac toe in c++ between a computer and a player in...
explain a pseudocode for tic tac toe in c++ between a computer and a player in words
Write a program that plays tic-tac-toe. The tic-tac-toe game is played on a 3 × 3...
Write a program that plays tic-tac-toe. The tic-tac-toe game is played on a 3 × 3 grid as shown below: The game is played by two players, who take turns. The first player marks moves with a circle, the second with a cross. The player who has formed a horizontal, vertical, or diagonal sequence of three marks wins. Your program should draw the game board, ask the user for the coordinates of the next mark (their move), change the players...
Game of Tic Tac Toe with the following conditions A point system where a  move that leads...
Game of Tic Tac Toe with the following conditions A point system where a  move that leads to a winning game is given 1 point, a move that leads to a tie is given 0 point, and a  lead to a losing game will get -1 point. Grid size of 5x5 A timer that can be set for how long a game can be played 5 symbols in a row to get a point Connected lines cannot be crossed (No diagonal lines)...
PYTHON (Game: Tic-tac-toe): Write a program that plays the tic-tac-toe game. Two players take turns clicking...
PYTHON (Game: Tic-tac-toe): Write a program that plays the tic-tac-toe game. Two players take turns clicking an available cell in a 3 x 3 grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A draw (no winner) occurs when all the cells in the grid have been filled with tokens and neither player has...
Python Code Needed Two-Player, Two-Dimensional Tic-Tac-Toe Write a script to play two-dimensional Tic-Tac-Toe between two human...
Python Code Needed Two-Player, Two-Dimensional Tic-Tac-Toe Write a script to play two-dimensional Tic-Tac-Toe between two human players who alternate entering their moves on the same computer. Create a 3-by-3 two-dimensional array. Each player indicates their moves by entering a pair of numbers representing the row and column indices of the square in which they want to place their mark, either an 'X' or an 'O'. When the first player moves, place an 'X' in the specified square. When the second...
How to make tic tac toe game in javascript with vue.js
How to make tic tac toe game in javascript with vue.js
The objective of this assignment is to implement the tic-tac-toe game with a C program. The...
The objective of this assignment is to implement the tic-tac-toe game with a C program. The game is played by two players on a board defined as a 5x5 grid (array). Each board position can contain one of two possible markers, either ‘X’ or ‘O’. The first player plays with ‘X’ while the second player plays with ‘O’. Players place their markers in an empty position of the board in turns. The objective is to place 5 consecutive markers of...
How to make a 2D array Tic Tac Toe game in C?
How to make a 2D array Tic Tac Toe game in C?
In a game of tic tac toe. How do you check if all the positions in...
In a game of tic tac toe. How do you check if all the positions in a double array are taken, the double arrays are used to store the x's and o's?
Here is an interaction in a tic-tac-toe game, with user input in bold: >> gm =...
Here is an interaction in a tic-tac-toe game, with user input in bold: >> gm = Game.new('andy', 'mike') => #<Game:0x2e91d78 @players=[Andy, Mike]> >> gm.play_game('mike') Mike, enter your next O O-- --- --- Andy, enter your next X O-X --- --- Mike, enter your next O O-X -O- --- Andy, enter your next X move Bad move dude! You go again. O-X -O- --- Andy, enter your next X move O-X -OX --- Mike, enter your next O move O-X -OX...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT