Question

In RobotBASIC what is the best way to solve this random maze generator? cellSize = 80...

In RobotBASIC what is the best way to solve this random maze generator?

cellSize = 80 'pixel size of maze cells

mazeWidth = 9 'number of cells horizontally
mazeHeight = 6 'number of cells vertically
DIM maze[mazeWidth,mazeHeight]

'draw a random maze on the screen
Call CreateMaze(mazeWidth,mazeHeight,cellSize)
'place robot in a random location
rLocate Random(mazeWidth)*cellSize+cellSize/2, Random(mazeHeight)*cellSize+cellSize/2, 0, 20
Delay 1000 'pause

' YOUR PROGRAM SOLUTION GOES HERE...

xyString 0,500,"Done."
End 'this must be here!

Sub CreateMaze(w,h,s)
mConstant maze,0 'zero out entire matrix
' draw a grid
LineWidth 5
For y=0 to h \ Line 0,s*y,s*w,s*y \ Next
For x=0 to w \ Line s*x,0,s*x,s*h \ Next
'draw ending "finish box"
Rectangle s*w,s*(h-1),s*w+65,s*h,GREEN,GREEN
Call Cell(0,0,w,h,s)
Return

Sub Cell(x, y, w, h, s)
maze[x,y] = maze[x,y] bOr 4 'mark cell as visited
r = Random(4) 'choose a random direction
For i = r to r+3 'visit each neighbor
If Mod(i,4)=0 then p=x \ q=y-1 'N
If Mod(i,4)=1 then p=x \ q=y+1 'S
If Mod(i,4)=2 then p=x+1 \ q=y 'E
If Mod(i,4)=3 then p=x-1 \ q=y 'W
If (p>=0) and (p<w) and (q>=0) and (q<h)
If maze[p,q] < 4 'skip already visited cells
If p>x then maze[p,q]=maze[p,q]|1 \ Rectangle s*p,s*y+3,s*p,s*(y+1)-2,WHITE
If q>y then maze[p,q]=maze[p,q]|2 \ Rectangle s*x+3,s*q,s*(x+1)-2,s*q,WHITE
If x>p then maze[x,y]=maze[x,y]|1 \ Rectangle s*x,s*y+3,s*x,s*(y+1)-2,WHITE
If y>q then maze[x,y]=maze[x,y]|2 \ Rectangle s*x+3,s*y,s*(x+1)-2,s*y,WHITE
Call Cell(p,q,w,h,s) 'recurse
EndIf
EndIf
Next
Return

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution: void remove(int) void findSol(int, int); void displaySol) class Mazet public: Maze(int); int find root(int); void uint main int argc, char argv) exit if something is missing in the command line exit if the user provides unacceptable informaprecondition: victim should, but not must, be an element in the vector that holds all cells postcondition: victim is erased f

Add a comment
Know the answer?
Add Answer to:
In RobotBASIC what is the best way to solve this random maze generator? cellSize = 80...
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
  • I NEED HELP IN MAZE PROBLEM. Re-write the following program using classes. The design is up...

    I NEED HELP IN MAZE PROBLEM. Re-write the following program using classes. The design is up to you, but at a minimum, you should have a Maze class with appropriate constructors and methods. You can add additional classes you may deem necessary. // This program fills in a maze with random positions and then runs the solver to solve it. // The moves are saved in two arrays, which store the X/Y coordinates we are moving to. // They are...

  • why do i get this syntax error? for example: i have these two classes: class Maze...

    why do i get this syntax error? for example: i have these two classes: class Maze { private: int row, col; cell **arr; public: Maze(int r = 0, int c = 0) { this->row = r; this->col = c; arr = new cell*[row]; for (int i = 0; i < row; i++) arr[i] = new cell[col]; } }; class cell { private: bool visited; bool up, down, right, left; int x, y; int px, py; char status; public: cell() {...

  • A mouse is put into a linear maze with 6 cells, with Cell 0 on the...

    A mouse is put into a linear maze with 6 cells, with Cell 0 on the left end where the mouse will receive a shock, and Cell 5 on the right end, where the mouse will find food. The four cells in between are numbered 1 to 4. Assume that from any of the cells 1 to 4, the mouse moves right or left with probability p and q = 1 ? p a) Starting from Cell 3, find the...

  • Code a program and reads a maze file and exits non-zero if the maze is not...

    Code a program and reads a maze file and exits non-zero if the maze is not valid. Or outputs the maze in a frame if it is good. The name of the file containg the maze is the only command-line parameter to this program. Read that file with the stdio functions, and close it propperly. A maze is a rectangular array of characters. It is encoded in the file in 2 parts: header line The header has 2 decimal intergers...

  • Write the MatLab code for the following algorithm: reate maze algorithm 1) Function create mazel maze...

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

  • Part II: Vectors in a Maze 1. Using only straight lines, find your way from the...

    Part II: Vectors in a Maze 1. Using only straight lines, find your way from the top of the maze to the bottom. 2. Determine the magnitude and direction of the individual vectors required to navigate the maze. 3. Determine the x and y components of each vector. Graphically add the vertical and horizontal components. 5. Draw the resultant 6. Calculate the magnitude and direction of the resultant 7. Measure the magnitude and direction of the resultant. How do they...

  • Question 1 、 Let X, Y and Z be three random variables that take values in the alphabet {0,1, M-l...

    Question 1 、 Let X, Y and Z be three random variables that take values in the alphabet {0,1, M-lj. We assume X and Z are independent and Y = X +2(mod M), The distribution of Z is given as P(Z 0)1 -p and P (Z =i)= , for i = 1, M-1. For question 1-3 we M-1 will assume that X is uniform on f0,1,..,M-1}. Find H(X) and H(Z) Find H(Y ) Find 1 (X; Y) and「X, YZ) and...

  • The Problem A robot is asked to navigate a maze. It is placed at a certain...

    The Problem A robot is asked to navigate a maze. It is placed at a certain position (the starting position) in the maze and is asked to try to reach another position (the goal position). Positions in the maze will either be open or blocked with an obstacle. Positions are identified by (x,y) coordinates. At any given moment, the robot can only move 1 step in one of 4 directions. Valid moves are: ● Go North: (x,y) -> (x,y-1) ●...

  • Solve the problem. Arat is placed at random in one of five compartments in a maze....

    Solve the problem. Arat is placed at random in one of five compartments in a maze. Compartments 1, 2, and 5 have food; so the rat will remain at any of these once reached. If the rat is placed in compartment 3, what is the expected number of times it will be in compartment 3 or 4 before it finds food? Round your answer to the nearest hundredth. 1 12345 1 0 0 0 2 0 1 0 0 3...

  • Let a random variable X be uniformly distributed between −1 and 2. Let another random variable...

    Let a random variable X be uniformly distributed between −1 and 2. Let another random variable Y be normally distributed with mean −8 and standard deviation 3. Also, let V = 22+X and W = 13+X −2Y . (a) Is X discrete or continuous? Draw and explain. (b) Is Y discrete or continuous? Draw and explain. (c) Find the following probabilities. (i) The probability that X is less than 2. (ii) P(X > 0) (iii) P(Y > −11) (iv) P...

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