Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Matlab Programming. please complete the code as per the instruction. Thank You!! Create a MATLAB app that is a maze solving game. Your app should

Matlab Programming.
please complete the code as per the instruction.
Thank You!!
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Create a MATLAB app that is a maze solving game. Your app should have a radio button group to select which maze to solve (out of the three provided mazes) and buttons for moving through the maze (up, left, right, down). As you solve the maze, you will need to collect the cherries (red dots) throughout the maze. You can only win the game by collecting all the cherries and by completing the maze. You can think of this app as a rudimentary pacman game Maze Files The maze files can be loaded from this .mat file: MAZE files.mat - There are 6 variables stored in the mat file M1 and C1 are the maze and cherry locations, respectively, for Maze 1 M2 and C2 are the maze and cherry locations, respectively, for Maze 2 - M3 and C3 are the maze and cherry locations, respectively, for Maze 3 - The mazes are organized as a grid - The walls of the maze are marked as 1 - The parts of the maze where you can navigate are marked as 0 - Your location in the maze (and where you have been in the maze) is marked by 3 - Each maze starts at the index [1,2]1 have already put a 3 in this location of the maze - The cherry data is stored in two columns where the first column is x-location of the cherry and the second column is the y-location of the cherry - Open one the mat file in the browser before starting your app to look at the different variables - this will help you better understand what is given to you - You can load.mat files using the load function I highly recommend first getting your maze working without using the cherries THEN adding in the cherry collection Callbacks My app had 5 callbacks - Generate Maze: GenerateMazeButtonPushed - DOWN button: DOWNButtonPushed - UP botton: UPButtonPushed - RIGHT button: RIGHTButtonPushed - LEFT button: LEFTButtonPushed I recommend first coding the Generate Maze callback and checking that you can correctly generate all the mazes. Then, I recommend moving on to the DOWN button callback and checking that you can press the down button to move all the way down until you run into the wall. Once you have done that, 1 recommend then moving on to the UP button and seeing if you can move down to the wall, then back up Getting started with the logic In the video below I walk through the logic of how to move through the maze and how to eat the cherries. I highly recommend watching this video AND the video below this one before starting your code - Location defines your current [X,Y] location in the game should be defined within the Generate Maze callback should be updated in each direction button callback IMPORTANT: X corresponds to the column index and Y corresponds to the row index, so when you press the down button, the location will be updated by adding +1 to the Y value (if there is not a wall in the way) - Cherries locations of cherries will be defined within the Generate Maze callback (C1, C2, or C3) should be updated within the direction button callbacks if you pass over a cherry - Cherry_Count count of the number of cherries will be defined within the Generate Maze callback - 6 for Maze 1 - 10 for Maze 2 - 14 for Maze 3 - should be updated within the direction button callbacks if you pass over a cherry Eating the cherries - As mentioned above, get your maze working without the cherries first, then add in the cherries - To eat the cherries, in each direction callback I did the following - I created an emotv variable cherrv to eat I then used a for loop to go through each cherry and check if the X-cherry-location matches the X location AND the Y-cherry-location matches the Y-location - if the X - and Y-locations matched, then I set cherry_to eat to the looping index - Note: a while loop could also work here instead of a for loop - Then after the for loop I had an if statement - if isempty(cherry_to_eat) =0 Xmeans cherry to eat is NOT empty and we need to renove a cherry - inside the if statement, 1 removed the cherry in the cherry_to_eat row - I have designed it so that every maze will be finished by pressing the DOWN button - Within the DOWN button callback, I recommend starting your if statement by checking if the next move will complete the maze think: will pressing the DOWN button mean that I have reached the last row? If yes, and the number of remaining cherries is 0 , then the game has been won Hints - I had a single for loop in each of my direction callbacks to check for the cherries - I did not use any other for or while loops - I did use a lot of if/elseif statements in my code - to get the updating title - I put something that looked like this within each section of each if statement - T= 'Down 1 '; then when I nletted at the hottnm nf the rallhark I uend T far the title - To play sounds or music in your app, you can use the lines of code - music - load ('train,mat'); Wother options for sounds are gong. mat and handel, mat P= oudioplayer(muste, y, music, Fs); playblocking(P) Create a MATLAB app that is a maze solving game. Your app should have a radio button group to select which maze to solve (out of the three provided mazes) and buttons for moving through the maze (up, left, right, down). As you solve the maze, you will need to collect the cherries (red dots) throughout the maze. You can only win the game by collecting all the cherries and by completing the maze. You can think of this app as a rudimentary pacman game Maze Files The maze files can be loaded from this .mat file: MAZE files.mat - There are 6 variables stored in the mat file M1 and C1 are the maze and cherry locations, respectively, for Maze 1 M2 and C2 are the maze and cherry locations, respectively, for Maze 2 - M3 and C3 are the maze and cherry locations, respectively, for Maze 3 - The mazes are organized as a grid - The walls of the maze are marked as 1 - The parts of the maze where you can navigate are marked as 0 - Your location in the maze (and where you have been in the maze) is marked by 3 - Each maze starts at the index [1,2]1 have already put a 3 in this location of the maze - The cherry data is stored in two columns where the first column is x-location of the cherry and the second column is the y-location of the cherry - Open one the mat file in the browser before starting your app to look at the different variables - this will help you better understand what is given to you - You can load.mat files using the load function I highly recommend first getting your maze working without using the cherries THEN adding in the cherry collection Callbacks My app had 5 callbacks - Generate Maze: GenerateMazeButtonPushed - DOWN button: DOWNButtonPushed - UP botton: UPButtonPushed - RIGHT button: RIGHTButtonPushed - LEFT button: LEFTButtonPushed I recommend first coding the Generate Maze callback and checking that you can correctly generate all the mazes. Then, I recommend moving on to the DOWN button callback and checking that you can press the down button to move all the way down until you run into the wall. Once you have done that, 1 recommend then moving on to the UP button and seeing if you can move down to the wall, then back up Getting started with the logic In the video below I walk through the logic of how to move through the maze and how to eat the cherries. I highly recommend watching this video AND the video below this one before starting your code - Location defines your current [X,Y] location in the game should be defined within the Generate Maze callback should be updated in each direction button callback IMPORTANT: X corresponds to the column index and Y corresponds to the row index, so when you press the down button, the location will be updated by adding +1 to the Y value (if there is not a wall in the way) - Cherries locations of cherries will be defined within the Generate Maze callback (C1, C2, or C3) should be updated within the direction button callbacks if you pass over a cherry - Cherry_Count count of the number of cherries will be defined within the Generate Maze callback - 6 for Maze 1 - 10 for Maze 2 - 14 for Maze 3 - should be updated within the direction button callbacks if you pass over a cherry Eating the cherries - As mentioned above, get your maze working without the cherries first, then add in the cherries - To eat the cherries, in each direction callback I did the following - I created an emotv variable cherrv to eat I then used a for loop to go through each cherry and check if the X-cherry-location matches the X location AND the Y-cherry-location matches the Y-location - if the X - and Y-locations matched, then I set cherry_to eat to the looping index - Note: a while loop could also work here instead of a for loop - Then after the for loop I had an if statement - if isempty(cherry_to_eat) =0 Xmeans cherry to eat is NOT empty and we need to renove a cherry - inside the if statement, 1 removed the cherry in the cherry_to_eat row - I have designed it so that every maze will be finished by pressing the DOWN button - Within the DOWN button callback, I recommend starting your if statement by checking if the next move will complete the maze think: will pressing the DOWN button mean that I have reached the last row? If yes, and the number of remaining cherries is 0 , then the game has been won Hints - I had a single for loop in each of my direction callbacks to check for the cherries - I did not use any other for or while loops - I did use a lot of if/elseif statements in my code - to get the updating title - I put something that looked like this within each section of each if statement - T= 'Down 1 '; then when I nletted at the hottnm nf the rallhark I uend T far the title - To play sounds or music in your app, you can use the lines of code - music - load ('train,mat'); Wother options for sounds are gong. mat and handel, mat P= oudioplayer(muste, y, music, Fs); playblocking(P)

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: 3

blur-text-image

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

Handbook Of Energy Audits

Authors: Albert Thumann, Terry Niehus, William J. Younger

9th Edition

1466561629, 978-1466561625

More Books

Students also viewed these Accounting questions

Question

Perform the indicated operation, if possible. BA

Answered: 1 week ago