How can I fix this error in my code creating a maze game?

I am trying to create a maze type game in Matlab for a class project. I am following my professor's algorithm key, but I keep getting an error when I run the function. The maze_size is supposed to be a random string array, and I am also unsure if this is correct for that. Below is the error I am receiving.
Not enough input arguments.
Error in create_maze (line 3)
maze = [maze_size, maze_size];
My code is below. There will be a second function that will have the player randomly move through the "game board" and encounter monsters they will have to "fight" by guessing a correct number before moving to try and find the exit.
function maze = create_maze(maze_size, monsters)
maze = [maze_size, maze_size];
maze = (1:maze_size), (1:maze_size) == '0'
maze(randX, randY) = 'P'
tempX = maze_size(randi(numel(maze_size)))
tempY = maze_size(randi(numel(maze_size)))
if maze(tempX, tempY) == 'P'
maze(tempX, tempY) = 'E';
elseif tempX < maze_size
maze(tempX + 1, tempY) = 'E'
elseif tempY < maze_size
maze(tempX, tempY + 1) = 'E';
elseif tempX > 1
maze(tempX - 1, tempY) = 'E';
else
maze(tempX, tempY - 1) = 'E';
end
if monsters > 0
tempX = rand(1:maze_size);
tempY = rand(1:maze_size);
if maze(tempX, tempY) == 'P' && maze(tempX, tempY) == 'E'
maze(tempX, tempY) = 'M';
end
tempX = rand(1:maze_size);
tempY = rand(1:maze_size);
if maze(tempX, tempY) == 'P' && maze(tempX, tempY) == 'E'
maze(tempX, tempY) = 'M'
end
end
end

Answers (1)

generally this exception is thrown when you are trying to use an input argument which was not set when calling this function.

2 Comments

I am a beginner to Matlab, and I don't understand why it is giving me this error when I am using the inputs that are in the function. It is giving me the error on the line:
maze = [maze_size, maze_size];
This line is supposed to be setting an array to the size of maze_size.
Thank you.
You are trying to run the code by clicking on the green Run button. You need to go down to the command line and invoke the function passing in appropriate values.

Sign in to comment.

Categories

Find more on Strategy & Logic in Help Center and File Exchange

Products

Release

R2018a

Asked:

on 1 Nov 2018

Commented:

on 2 Nov 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!