It's been a while since I've pulled out Mazes for Programmers (it looks like it was March). I picked it up again tonight to do a bit of programming. This time, I added the code to create a heat map of a maze.
You can get the current code here: GitHub - jeremybytes/mazes-for-programmers.
Here's a sample of the output:
This uses the center square as the "start". The colors get darker as the path to each square is further away.
The code in its current state produces 2 outputs. The example above is a .png file that is saved to the file system (and automatically shown by the console application).
The console application also generates a text output:
If you compare this to the graphic output, you can see that these are the same maze. The numbers here are a bit different. Instead of creating a heat map of distances, this shows the shortest path from the start (the center of the grid) to the finish (the lower left corner). By following the path, this shows that 34 steps are required to get from the center to the finish.
The code isn't great at this point. The reason is that I'm doing a straight-across port from the Ruby code that is presented in the book. And I'm also not a big fan of the way the objects are put together in the book code. But I'm still working on the underlying concepts of mazes, and then I can work on making the code a bit better.
As stated previously, I'd like to get some F# code in here, and I've gotten some great contributions from the community including this sample from Steve Gilham: Steve's F# Implementation. I haven't had a chance to dig through Steve's sample. From my initial look, I can tell that I need to think about breaking down problems in a different way than I'm used to.
I'm looking forward to diving into that more.
Happy Coding!
No comments:
Post a Comment