Question
Write the MatLab code for the following algorithm:

reate maze algorithm 1) Function create mazel maze size: whole number, monsters: whole number) returns maze: [1.NI][1.N] of Strings 2) maze = [mazesizelimaze size] array of strings, filled with 0 3) maze(random # 6etween 1 and mazesize] [random # between 1 and maze-size] 4) tempx - random whole number between 1 and maze size 5) tempy random whole number between 1 and maze size 6) while mazeltempx][tempd=P P temps.# random whole number between 1 and maze size a. b.tempy random whole number between 1 and maze size end while loop 7) 9) for i from 1 to monsters while mazeltempx] [tempy)-= P or mazeltempx][templ == E or maze[tempx)Itempy)M a. i. tempx random whole number between 1 and maze size i. temey- random whole number between 1 and maze size b. end while loop 10) mazeltempxl (tempy) M 11) end for loop 12) return maze
0 0
Add a comment Improve this question Transcribed image text
Answer #1

function maze=create_maze(maze_size,monsters)

% checking wether inputs are whole numbers

if ~isa(maze, 'uint64')

   error('Not a whole number!');

end

if ~isa(monsters, 'uint64')

   error('Not a whole number!');

end

% create a string array with zeros

maze=string(zeros(maze_size))

% generatre random integer indices

temp1=randi([1,maze_size],1,1)

temp2=randi([1,maze_size],1,1)

maze[temp1][temp2]=”P”

% generate random integer indices

tempx=randi([1,maze_size],1,1)

tempy=randi([1,maze_size],1,1)

while (maze[tempx][tempy]==”P”)

      tempx=randi([1,maze_size],1,1)

tempy=randi([1,maze_size],1,1)

end

maze[tempx][tempy]=”E”

for a= 1:monsters

while(maze[tempx][tempy]==”E” || maze[tempx][tempy]==”P” ||

maze[tempx][tempy]==”M” )

tempx=randi([1,maze_size],1,1)

tempy=randi([1,maze_size],1,1)

end

maze[tempx][tempy]=”M”

end

end

Add a comment
Know the answer?
Add Answer to:
Write the MatLab code for the following algorithm: reate maze algorithm 1) Function create mazel maze...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please write the matlab function that corresponds with this algorithm Create maze algorithm 1) Function create...

    please write the matlab function that corresponds with this algorithm Create maze algorithm 1) Function create maze( maze size: whole number, monsters: whole number) returns maze: [1..N][1.N] of trings 2) maze-maze-size][maze-size] array of strings, filled with "O" 3) mazerandom # between 1 and maze size [random # between 1 and maze-size-"P" 4) tempx random whole number between 1 and maze size 5) tempy random whole number between 1 and maze_size 6) while mazeltempx] [tempy]="P" a. tempx random whole number between...

  • 6. Consider the following algorithm, where P is an array containing random numbers. The function swap(v1,v2)...

    6. Consider the following algorithm, where P is an array containing random numbers. The function swap(v1,v2) will swap the values stored in the variables v1 and v2. Note that % is the modulus operation, and will return the integer remainder r of a/b, i.e., r-a%b Require: Array P with n > 0 values 1: i-1, j-n-l 2: while i<=j do for a=i to j by i do 4: 5: 6: 7: if Pla>Pat 11 and Pla]%2--0 then swap(Plal, Pla+1l) end...

  • PLEASE USE MATLAB. The code is basically given to you with the algorithm above. Write a...

    PLEASE USE MATLAB. The code is basically given to you with the algorithm above. Write a program for solving the system Ar-b by using Gauss-Seidel iterative method discussed in class that uses a computer memory for one iterate only. This could be summarized as follows: Input n -- the size of the system, matrix A-(a(i,j), the vectoir b (b (1), . . . , b(n)), the intitial guess x (x(1), ..., x(n)) (you can use x=b) maximum number of iterations...

  • Part I Short Answer (50 points) 1. Write a pseudocode declaration for a String array initialized...

    Part I Short Answer (50 points) 1. Write a pseudocode declaration for a String array initialized with the following strings: “Einstein”, “Newton”, “Copernicus”, and “Kepler”. 2. Assume names in an Integer array with 20 elements. Write a pseudocode algorithm a For Loop that displays each element of the array. 3. Assume the arrays numberArray1 and numberArray2 each have 100 elements. Write a pseudocode algorithm that copies the values in numberArray1 to numberArray2 . 4. Write a pseudocode algorithm for a...

  • Change the following code to give only the first 2 picks; or 3 picks (Matlab) %...

    Change the following code to give only the first 2 picks; or 3 picks (Matlab) % colors for ball colors = ["red", "blue", "green", "yellow"]; % initial probabilites % change as required p = [0.20, 0.25, 0.35, 0.20]; % cumulative sum of p c = cumsum(p); % continue drawing until all are drawn while(size(p) > 0) % generate a random number r = rand(); % draw ball according to random number ball = 0; for i = 1:size(p, 2) if(r...

  • Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the...

    Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the size of an array. Then create an integer array of that exact size. Ask the user to enter a maximum value and then write a loop to fill the array with random numbers with value in the range of 1 to the maximum value. For example, if the maximum value is 100, random numbers must have value 1 to 100 inclusive. Input size of...

  • 7eatng that function Write a C++ program that does the following: Fill an array of 123...

    7eatng that function Write a C++ program that does the following: Fill an array of 123 elements using srand) and rand) with random numbers between 150 and 667. Fill an array of 123 elements with random numbers between 150 and 667. Using a loop. Fill an array of 123 elements with random numbers between 150 and 667. Using a for loop Use a void function to fill an array of 123 elements with random numbers between 150 and 667, Possible...

  • In this part, you will complete the code to solve a maze.

    - Complete the code to solve a maze- Discuss related data structures topicsProgramming-----------In this part, you will complete the code to solve a maze.Begin with the "solveMaze.py" starter file.This file contains comment instructions that tell you where to add your code.Each maze resides in a text file (with a .txt extension).The following symbols are used in the mazes:BARRIER = '-' # barrierFINISH = 'F' # finish (goal)OPEN = 'O' # open stepSTART = 'S' # start stepVISITED = '#' #...

  • How can I write this code (posted below) using vectors instead of arrays? This is the...

    How can I write this code (posted below) using vectors instead of arrays? This is the task I have and the code below is for Task 1.3: Generate twenty random permutations of the number 0, 1, 2, ..., 9 using of the algorithms you designed for Task 1.3. Store these permutations into a vector and print them to the screen with the additional information of unchanged positions and number of calls torand(). Calculate the total numbers of unchanged positions. Compare...

  • 1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers...

    1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers of 1 through 15. Display your result back to the user with 2 decimal places (yes, 2 decimal places). You must implement your code using a for loop. The result should have the following format: The multiplication of 10*1 =10.00 The multiplication of 10*2 =20.00 The multiplication of 10'3=30.00 The multiplication of 10*15=150.00 2. (35 Points) Write MATLAB code to prompt a user for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT