{"by":"eigenvalue","descendants":38,"id":41162505,"kids":[41162538,41166636,41163285,41162943,41163424,41166107,41172328,41163767,41165967,41164102,41169780],"score":135,"text":"I was fascinated reading through another recent HN submission about a highly efficient implementation of A* in Lisp, which got me thinking about how I could do something similar in Python. However, these kinds of pathfinding algorithms really need complex terrain&#x2F;mazes with interesting obstructions to showcase what they can do and how they work. So, I started thinking about how I could generate cool and diverse random &quot;mazes&quot; (they aren&#x27;t really mazes, but I&#x27;m not sure what the best term is). I got a bit carried away thinking of lots of different cool ways to generate these mazes, such as cellular automata, fractals, Fourier transforms, etc.<p>Then it turned out that many of the generated mazes weren&#x27;t actually solvable, so I spent some time coming up with various strategies to test and validate the generated mazes and then modify them so they would work better for this purpose. I spent a fair amount of effort trying to optimize the performance as much as possible using tools like Numba where applicable, but I also got tired of the code bringing my very powerful machine to its knees. So, I tried to make it play nice with the rest of the system while also saturating a big computer with tons of CPU cores. This was done using concurrent futures with some tweaks, like using a Semaphore and lowering the CPU priority. People might find this project interesting just for these performance-tuning features.<p>I also spent a lot of time trying to make beautiful-looking animations that show multiple randomly generated mazes side by side, where you can see A* &quot;races&quot; as it tries to solve all the mazes at the same time, showing the current progress. When a solution is found, it is traced out on the screen. It&#x27;s actually not that easy to get really slick&#x2F;beautiful looking results straight out of Matplotlib, but if you use custom fonts and tweak a lot of parameters, it starts to look pretty polished.<p>Now you can just run this on a spare Linux machine and come back in a few hours to have a bunch of cool-looking animations to check out. By changing the grid sizes, you can get very different-looking effects, although larger grids can take a lot of compute power to render. Anyway, I hope you guys like it! I&#x27;m happy to answer any questions. I&#x27;m sure there are still some bugs, but it has been running pretty well for me and generating lots of cool-looking animations. Note: I know that the pulsating title at the top in the demo video is annoying— I already slowed this way down in the code but didn&#x27;t want to wait for it to regenerate the video.","time":1722873361,"title":"Show HN: Visual A* pathfinding and maze generation in Python","type":"story","url":"https://github.com/Dicklesworthstone/visual_astar_python"}