Lecture:: 01-14-2013

posted Jan 14, 2013, 6:01 AM by Samuel Konstantinovich   [ updated Jan 14, 2013, 6:01 AM ]
A maz(ing) solver

1 Decide on what the start/end points of your path should be.

2 Decide which patches you cannot travel on. e.g. walls or pits are certain colors.

3 Set your starting point to a 'distance variable' of 0. We will use plabel for this to make it easier to see what is happening. All other plabels will default to "" (the empty string)

4 You need to make a function to calculate the total distance from start to end, and every patch in between.

   4a calculate by spreading: Every patch with a numerical distance variable should spread the distance to its neighbors (or neighbors 4) When you spread, you should increment the number so that each step is 1 unit farther. 

   4b You should make spread recursive, when should you not spread? The stopping condition matters!

5 You want to trace the path from the end back to the start, by painting the patches a specific color. You can use another variable instead of pcolor (so you don't mess up the world) but we will use pcolor so we can see what is going on. 

   5a The "solve" command should ask the ending patch to trace a path
   5b The trace command would then find the smallest neighboring distance and change that to blue, and call the trace command on that path.
   5c When should you stop calling trace?

By making the calculation and the tracing recursive, you can run this in the span of one go. This means you can re-calculate a path every go command if you want to.