Turtle Maze

In CSAI class we were assigned to make our turtle go through random maze. The code for the random maze was given so that the maze is different every time.

When I was first given the problem, I was definitely confused as to how to find the most effective solution. I found a method that worked but unfortunately made the turtle go to great lengths to solve the maze.

I finally came up with a solution that did work and was effective as well. Essentially, the turtle must first go forward the length of the first barrier.

The lengths of the black lines are put into two lists, r and t. The turtle first has to go forward the length of r and then 1/2 of the distance of the gap, t. Therefore the turtle has to go forward the length of r1 (the first length in the list randomR) and 1/2 of the first length in the list t. Then you simply have to turn right, go forward 40 (since that is the length of the vertical distance between each black line. Then the turtle must turn again and then go twice the distance of the first length in the list r plus the first length in the list t and then subtract 800 from this since 800 is the length of the maze. This will take you halfway to the next gap.

Essentially you will continue to repeat this process and make some mathematical changes here and there to ensure that it works properly. Then I just saved the value of the y coordinate in a variable, y. To get to the middle of the final gap in the maze, I just calculated the x coordinate using the starting x coordinate. I used go to commands to make that work and then turned right and went forward to exit the maze.

I really enjoyed this assignment because even though the solution is simple and effective, it can be quite challenging to solve and requires some mathematical trial and error. In my first iteration, I found a solution that somewhat worked but could have been more effective. I finally found a solution and I am happy with how it worked out.

Click here to get to the maze!

The final product!(above)

Leave a Reply

Your email address will not be published. Required fields are marked *