Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Tic Tac Toe -Matlab Instructions Getting Started Download ticTacToe.m and ticTacToe.fig from the assignment link. You will not have to modify the .fig file in

Tic Tac Toe -Matlab

Instructions

Getting Started

Download ticTacToe.m and ticTacToe.fig from the assignment link. You will not have to modify the .fig file in any way for this project.

Understanding the program

Read through the entirety of ticTacToe.m. Try to come to an understanding of what the code written in the program currently does. I have written an extensive amount of comments to help you understand what is going on.

What still needs to be written

The current ticTacToe program lacks the code required for players to put pieces on the board, and the code needed to determine whether the game has ended.

Game Rules

In Tic Tac Toe, two players take turns placing their pieces (o and x) in a 3x3 grid. The o player goes first, and the x player goes second. The game is won if a player creates a line of three pieces horizontally, vertically, or diagonally. The game ends in a tie, also known as a Cats Game, if all squares get taken up without a player winning.

Step 1: Writing a buttonPress buttonPress is a function that places pieces on the ticTacToe board in the GUI.

buttonPress is a function that should be called by every pushbutton callback function in ticTacToe except for the newGame button.

- buttonPress takes the handles structure for the GUI and the hObject structure for the button that was pressed as inputs

- and returns an updated handles structure as an output. Hint: You can use hObject to determine which button was just pressed.

buttonPress should do the following:

- Check to see if the button that was clicked is a valid button to place a piece. Buttons are valid if they are empty, and invalid if they already contain a piece.

o Invalid buttons should briefly flash red if they are clicked.

- If the button is valid, the button should be updated to contain the players piece by changing the String property of the button.

- If a piece was placed, you should update any turn information data (such as handles.turnNumber)so that it is now the next players turn.

- If a piece was placed, should also change the String of the static text box whoseTurn to display the next piece to be placed (the piece of the next player).

Step 2: Writing checkWinner

checkWinner is a function that determines whether the game of ticTacToe is over, either because somebody won or because the game has ended in a tie. checkWinner is a function that should be called by every pushbutton callback function in ticTacToe except for the newGame button.

- checkWinner takes the handles structure of the GUI as an input - and returns an updated handles structure as an output. checkWinner should do the following:

- Check whether either player has won the game.

- Check whether the game has ended in a tie (because all of the buttons have pieces on them).

- If the game is over, display the result of the game, either with a pop up message like the ones created with functions like errordlg and msgbox, or in one of the static text boxes on the GUI.

Step 3: Writing the callback functions

The code for each callback function should be the same:

- A call to buttonPress

- A call to checkWinner

- guidata(hObjuect,handles)

As it says in the comments of ticTacToe, writing anything more than that, or anything different, is wrong.

Submission

When you have completed this project, and have verified that your code has run correctly, you are ready to submit. Please do the following to submit:

- Copy and paste the code for buttonPress and checkWinner into a new .m file.

- Save that .m file.

- Submit that .m file on Canvas

- Print that .m file and give it to your recitation instructor.

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database Systems On GPUs In Databases

Authors: Johns Paul ,Shengliang Lu ,Bingsheng He

1st Edition

1680838482, 978-1680838480

More Books

Students also viewed these Databases questions

Question

Why do jewelers add small amounts of copper to gold and silver?

Answered: 1 week ago

Question

=+ B-2 Describe descriptive statistics.

Answered: 1 week ago

Question

Question in Chemical Engineering Please Write Correct answer 7 3 .

Answered: 1 week ago

Question

Evaluate the importance of diversity in the workforce.

Answered: 1 week ago

Question

Identify the legal standards of the recruitment process.

Answered: 1 week ago