Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need the matlab code for the folllowing algorithm: Create maze algorithm Function create_maze( maze_size: whole number, monsters: whole number) returns maze: [1..N][1..N] of Strings

I need the matlab code for the folllowing algorithm:

Create maze algorithm

Function create_maze( maze_size: whole number, monsters: whole number) returns maze: [1..N][1..N] of Strings

maze = [maze_size][maze_size] array of strings, filled with 0

maze[random x] [random z] = P

tempx = random whole number between 1 and maze_size

tempy = random whole number between 1 and maze_size

if maze[tempx] [tempy] != P

maze[tempx] [tempy] = E

else if tempx < maze_size

maze[tempx+1] [tempy ] = E

else if tempy < maze_size

maze[tempx] [tempy+1] = E

else if tempx > 1

maze[tempx-1] [tempy] = E

else

maze[tempx] [tempy-1] = E

end if statement

if monsters > 0

tempx = random whole number between 1 and maze_size

tempy = random whole number between 1 and maze_size

if maze[tempx] [tempy] != P AND maze[tempx] [tempy] != E

maze[tempx] [tempy] = M

end if statement

tempx = random whole number between 1 and maze_size

tempy = random whole number between 1 and maze_size

if maze[tempx] [tempy] != P AND maze[tempx] [tempy] != E

maze[tempx] [tempy] = M

end if statement

tempx = random whole number between 1 and maze_size

tempy = random whole number between 1 and maze_size

if maze[tempx] [tempy] != P AND maze[tempx] [tempy] != E

maze[tempx] [tempy] = M

end if statement

end if statement

return maze

Random Move Algorithm

function random_move(maze: NxN array of strings) returns maze

original_playerx = x coordinate for string P in maze

original_playery = y coordinate for string P in maze

playerx = x coordinate for string P in maze

playery = y coordinate for string P in maze

randomx_dir = random number between 1 and 3

randomy_dir = random number between 1 and 3

if randomx_dir == 1

playerx = playerx+1

if playerx > N

playerx = 1

end if statement

end if statement

if randomy_dir == 1

playery = playery + 1

if playery > N

playery = 1

end if statement

end if statement

if randomx_dir == 2

playerx = playerx 1

if playerx < 1

playerx = N

end if statement

end if statement

if randomy_dir == 2

playery = playery 1

if playery < 1

playery = N

end if statement

end if statement

if maze[playerx, playery] == M

print You encountered a monster!

print Rolling the dice!

pick_a_number = random # between 1 and 6

your_choice = user entered #

if your_choice == pick_a_number

print You win! You get to keep going!

print Your new coordinates are

print playerx

print playery

maze[playerx] [playery] = P

maze[original_playerx] [original_playery] = 0

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

Students also viewed these Databases questions

Question

Explain the importance of Human Resource Management

Answered: 1 week ago