Matlab programming question. I am creating a program to create a gravity maze th
ID: 3672863 • Letter: M
Question
Matlab programming question. I am creating a program to create a gravity maze that is populated with one player (set as a value of 2), one goal (a value of 3), and the rest randomly with spaces (values of 0) and barriers and a perimeter (value set at 1) that the player cannot pass through. The object is to have the user input "rotate, flip, or transpose" the matrix as many times as it takes the player until the player reaches the goal with the player falling down the column it is in at the time of the input until it hits the position right before the barrier. My issue is getting the player (3) to actually fall when a move is made. This is my code now that makes it so when the user inputs a move, the player moves down 1 space in its column. I believe the error i am making is in line 68 of the supplied code. I just cannot figure how to make it so the player will fall to one position short of the barrier in its column. I have also included a picture of the figure that is generated by this program
Thank you for any ideas
ourMaze ( player ) = 2; ourMaze ( goal ) = 3; imagesc ourMaze 16 function [ ourMaze ] createMaze ( numRows , numCo13 ) numRows = input ('number of rows ? :'); numCol3 = input ('number of columns? :'); ourMaze= rand (numRows , numCols) ; ourMaze = ourMaze > 0.75; 18 19 | direction = input( 'Pick a Direction to go in: ' , 's'); while player goal if((strcmp (direction, 'right ') ourMaze = rot90 (ourMaze) ; -46 1)) =: 21 22- 23 47 ourMaze ( numRows + 1 , : ) = 1; ourMaze = [ ones( 1 , numCols + 1 ) ; ourMaze ]; ourMaze = [ ones ( numRows + 2 , 1 ) ourMaze ]; connections bwconncomp ( -ourMaze , 4 ); while connections . NumObject3 N= 1 end if ( (strcmp (direction, 'left1)) ourMaze = rot90 (ourMaze, 3) ; 25 end 52 if ( (strcmp (direction,' transpose' ) -1)) numRows = randi ( 5 ) 5; numCol3 = rand! ( 5 ) + 5; ourMaze = rand ( numRows , numC013 ); ourMaze = ourMaze > 0.75; ourMaze ( : , numCols + 1 ) = 1; ourMaze ( numRows + 1 , : ) = 1; ourMaze = [ ones ( 1 , numCols + 1 ) ; ourMaze ]; ourMaze [ ones ( numRows + 2 , 1 connections = bwconncomp ( -ourMaze , 4 ); ourMaze = transpose (ourMaze) ; 28 - end if ( (strp (direction,' flipud' ) -1 ) ) 31 ourMaze flipud (ourMaze) ; end == 1 ) ) 58 59 60 if ( (strcmp (direction,' flip!r ' ) ourMaze flip1r (ourMaze) ; ows 2 1 ourMaze 1: end en open find ( ourMaze == 0 ); spaces open( randperm( length ( open ) , 2 ) ); player spaces( 1 ) ; goal = spaces( 2 ); ourMaze ( player ) 2; ourMaze ( goal ) = 3. (strp (direction,'exit') exit escapemonstrosity.m if 1) == end [ numRows , numCols ] = find (ourMaze-2); player = ourMaze ( numRows , numCols); ourMaze (numRows , numCo13) 0;Explanation / Answer
hi, please change line number 68 to this way and try it once