Question

# What is the code to recognize diagonal wins in Tic Tac Toe in Matlab?

What is the code to recognize diagonal wins in Tic Tac Toe in Matlab?

% Horizontal

if (tttXArray(1,1) == tttXArray(1,2) && tttXArray(1,1) == tttXArray(1,3))

won = 1;

elseif (tttXArray(2,1) == tttXArray(2,2) && tttXArray(2,1) == tttXArray(2,3))

won = 1;

elseif (tttXArray(3,1) == tttXArray(3,2) && tttXArray(3,1) == tttXArray(3,3))

won = 1;

% Vertical

elseif (tttXArray(1,1) == tttXArray(2,1) && tttXArray(1,1) == tttXArray(3,1))

won = 1;

elseif (tttXArray(1,2) == tttXArray(2,2) && tttXArray(1,2) == tttXArray(3,2))

won = 1;

elseif (tttXArray(1,3) == tttXArray(2,3) && tttXArray(1,3) == tttXArray(3,3))

won = 1;

% Diagonal

elseif (tttXArray(1,1) == tttXArray(2,2) && tttXArray(1,1) == tttXArray(3,3))

won = 1;

elseif (tttXArray(1,3) == tttXArray(2,2) && tttXArray(1,3) == tttXArray(3,1))

won = 1;

end

#### Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
• ### How to write a (c++ program) tic tac toe code where its the computer against a...

How to write a (c++ program) tic tac toe code where its the computer against a human. and the computer always wins. a basic c++ code program using gaming theory arrays <stdio.h> computer plays tic tac toe against a user. computer always when or the game is a draw.

• ### use python to do it implement the tic-tac-toe game. What to submit: 1. Your source code...

use python to do it implement the tic-tac-toe game. What to submit: 1. Your source code 2. Two runs, one user wins and one user loses.

• ### Tic-Tac-Toe (arrays and multidimensional arrays) C++ Write an interactive program that plays tic-tac-toe. Represent the board...

Tic-Tac-Toe (arrays and multidimensional arrays) C++ Write an interactive program that plays tic-tac-toe. Represent the board as a 3 X 3 character array. Initialize the array to blanks and ask each player in turn to input a position. The first player's position is marked on the board with a O and the second player's position is marked with an X. Continue the process until a player wins or the game is a draw. To win, a player must have 3...

• ### (Game: play a tic-tac-toe game) In a game of tic-tac-toe, two players take turns marking an...

(Game: play a tic-tac-toe game) In a game of tic-tac-toe, two players take turns marking an available cell in a 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 achieved a win. Create...

• ### what’s the code of game Tic-tac-toe by using the Alpha Beta Turing algorithm ? The code...

what’s the code of game Tic-tac-toe by using the Alpha Beta Turing algorithm ? The code in language JavaScript?

• ### (Tic-Tac-Toe) Create a class Tic-Tac-Toe that will enable you to write a program to play Tic-Tac-Toe....

(Tic-Tac-Toe) Create a class Tic-Tac-Toe that will enable you to write a program to play Tic-Tac-Toe. The class contains a private 3-by-3 two-dimensional array. Use an enumeration to represent the value in each cell of the array. The enumeration’s constants should be named X, O and EMPTY (for a position that does not contain an X or an O). The constructor should initialize the board elements to EMPTY. Allow two human players. Wherever the first player moves, place an X...

• ### Create a batch file tic tac toe game written in C code. This code should be...

Create a batch file tic tac toe game written in C code. This code should be able to run through an emulator.

• ### PYTHON Exercise 2. Tic-Tac-Toe In this exercise we are going to create a Tic-Tac-Toe game. 1....

PYTHON Exercise 2. Tic-Tac-Toe In this exercise we are going to create a Tic-Tac-Toe game. 1. Create the data structure – Nine slots that can each contain an X, an O, or a blank. – To represent the board with a dictionary, you can assign each slot a string-value key. – String values in the key-value pair to represent what’s in each slot on the board: ■ 'X' ■ 'O' ■ ‘ ‘ 2. Create a function to print the...

• ### Create a very basic tic tac toe game written in C code. This C code should...

Create a very basic tic tac toe game written in C code. This C code should be able to create a GBA file from using devkit to run in visual boy advance.

• ### Write a GUI based tic-tac-toe game for two players. Use code for the GUI and to...

Write a GUI based tic-tac-toe game for two players. Use code for the GUI and to set up event handling; include a Model.