Question: HW1 Algorithms Key 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,

HW1 Algorithms Key

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

i.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

i.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

i.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

i.playerx = 1

end if statement

end if statement

if randomy_dir == 1

playery = playery + 1

if playery > N

i.playery = 1

end if statement

end if statement

if randomx_dir == 2

playerx = playerx 1

if playerx < 1

i.playerx = N

end if statement

end if statement

if randomy_dir == 2

playery = playery 1

if playery < 1

i.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

i.print You win! You get to keep going!

ii.print Your new coordinates are

iii.print playerx

iv.print playery

v.maze[playerx] [playery] = P

vi.maze[original_playerx] [original_playery] = 0

else

i.print You lost. The monster kill you

ii.maze[1..N][1..N] = L

end if statement

else if maze[playerx] [playery] == E

print You win!

maze[1..N][1..N] = W

else

print Your new coordinates are

print playerx

print playery

maze[original_playerx] [original_playery] = 0

maze[playerx] [playery] = P

end if statement

return maze

^^need help wirting code for the above algorithm in Matlab?? Thank you!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!