sunjay / turtle

Create Animated Drawings in Rust
http://turtle.rs
Mozilla Public License 2.0
562 stars 53 forks source link

Example Idea: Maze Generation/Solving (Advanced) #9

Closed sunjay closed 7 years ago

sunjay commented 7 years ago

Generate a maze. Use the turtle to draw the maze on the screen. Draw the turtle solving the maze. Change the pen color to red to show where the turtle made mistakes and had to backtrack.

Easy (and cool) way to draw the maze: go up and down the columns of maze walls. Lift the pen when there is no wall, put it down when there is a wall. Repeat for the rows of maze walls. This is extremely efficient in terms of time and complexity. Draw everything in just a single pass vertically and a single pass horizontally.

Implementing this would be an excellent project to go through in detail in the guide.

The maze generation algorithm (simple, pseudocode): do a breadth first traversal of a graph representing the cells of the maze grid. Insert the nodes in a random order. When visiting a node, create an edge break down the wall between that node and the previous one.

For the section of the guide on parallelism and concurrency (advanced): generate the maze faster for larger grids by generating multiple paths simultaneously. Instead of just following one path until it goes into a dead end, have several going at once. You can implement this with a work queue and multiple workers (one per CPU).

sunjay commented 7 years ago

Finished implementing the example. See maze example.