# Dynamic Maze Programming

Before I give my students this final project. I need help with the solution. note: in vex vr threads python rather than block code. I have coded it in around 8 lines, but I can’t seem to shorten it. I have heard it is possible to do it in under 6 not including VR threads if anyone could help me out I would appreciate it.

Thank you,
Ryan Riddling

Can you post your code here, and elaborate on the project that you need help with? Make sure to format your code by enclosing it in 3 diacritics (`) for readability, like

``````this.
``````

Sure thing the project is called Dynamic Wall Maze on vex.vr.
Here is what I have so far:

``````def main():
while not down_eye.detect(RED):
if right_bumper.pressed():
drivetrain.turn_for(RIGHT, 90, DEGREES)
drivetrain.drive_for(FORWARD, 200, MM)
else:
drivetrain.drive_for(FORWARD, 200, MM)
``````

Could have sworn it was working before seems I may have broken it.
in this project the robot needs to travel through a “randomly generated maze” with both a starting and a end. the ending square contains red and should stop on the ending location.

I don’t see a way for the code as written to escape the starting hallway.

It seems to me you would need to evaluate open pathways at each square. Perhaps even an array to evaluate if you have been to a square already.

1 Like

Do you have any ideas on how I could implement that I am experienced in python but I have been only using vex python for a the past week.

My favorite maze solving algorithm is just to hug one wall.

6 Likes

Generally, the simplest algorithm is the one above. Have a sonar on the right side of the robot so it tracks the wall on the right of it, and a front bumper to detect collision with the wall.

I think something like this should work
Pseudocode:

``````While true{

If front bumper is pressed -> back up a bit, turn left 90 degrees

Else If sonar does not detect a wall -> turn right, drive forward, then turn right again

Else -> drive forward
}
``````

Hugging the wall is pretty meta in minecraft mazes, so I am betting that some students may be able to solve the maze pretty easily, assuming an ideal world where the robot drives straight

1 Like

The VEXcode VR robot only has front facing bumpers and distance so you’d need to evaluate each square independently.

2 Likes

That’s the only way I’ve found to do it. It’s super slow unfortunately, but I haven’t seen a better way. Just stopping at every square and turning to check if there is a wall, and if there isn’t going forward. And then of course stopping when you get to the end.

Was involved in micromouse competitions many many years ago.
in fact, when I was in university, this was the only robotics competition available for students.

Anyway, what @holbrook mentioned is the wall-following algorithm. It is easy to implement and widely used.

For micromouse, the end goal is not just solving the maze, but also using the shortest time.
We normally used more complicated algorithms such as Lee’s algorithms.

This video is not done by me. But it gives quite a good explanation of it - Lee's Algorithm for Maze Routing - YouTube

Now that I’m not on mobile I will link my code-golfed blocks solution to the dynamic maze: