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 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...
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?
Implement the Tic-tac-toe game for variable board sizes, you may assume: 2 < s < 11,...
Implement the Tic-tac-toe game for variable board sizes, you may assume: 2 < s < 11, where s is the board size. Before the game starts the program will prompt for the board size. Note: the winning conditions are the same as the original Tic-tac-toe game in that you need to fill the entire row/column/diagonal to win. Here are a few sample runs. The output is a bit different so that we can handle two-digit coordinates consistently. We expect (but...
please create a tic tac toe game with python using only graphics.py library
please create a tic tac toe game with python using only graphics.py library
If you were to write a game of tic-tac-toe, you may store the representation of the...
If you were to write a game of tic-tac-toe, you may store the representation of the game board as a two dimensional list such as   [['X', '', 'X'], ['O', 'X', ''], ['', 'O', 'X']] where each sublist is a row in the board.   Empty strings ('') denote a space that does not yet have a value. Assuming this representation, write functions (contained in the same file) that do the following: a) Create a new empty tic-tac-toe board. This function should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT