Rusty Maze

The other day I decided to tinker with Cursor and try to write a maze generator and pathfinder using Rust. I've dabbled a tiny bit with Rust, but wanted to see how easy it would be to write a small app without knowing much and instead relying mostly on vibe coding.

This post isn't going to focus on vibe coding or my opinion about whether its good or bad for the industry. Instead I'm just gonna talk about what I did and how quickly I was able to do it. This was all done in around 2 hours one afternoon. I'm confident that the generated code has some stupid and non idiomatic decisions for a Rust app, and because I vibe coded this instead of learning the APIs myself by reading the docs, I am completely unable to identify what those stupid decisions might be. But, what I was able to produce does work, and I think is actually pretty neat.

Here's the final product:

A generated maze with an animated sprite navigating it's way through the maze

You can check out the code here.

Sending Good Vibes

Now, I had done enough with Rust to already have a working environment, so the first things I did was prompt the AI to give me some GUI library recommendations for building my app. I explained that I wanted to build an app that would render a 2D grid with a generated maze.

The tool recommended a handful of Rust GUI libraries; macroquad, bevy, ggez. I responded that I wanted to try macroquad, and it quickly generated some basic code to render a blank white window. I thought this was pretty awesome actually. Until I tried to compile and was immediately running into an error. "No problem," I thought, "I'll just punch the error into the chat window and it will fix the issue."

So I added the error into the chat window and asked "please fix this error". The AI agent happily proceeded to to replace the entire graphics library! Well, that's one way to do it... I found this hilarious.

After course correcting the agent a bit and convincing it that, "No please don't rip and replace the entire library, just fix the compilation error," I was able to get a nice white window rendering on start.

The Vibes Are Off

Next I needed to actually generate a maze within my app. I asked the LLM to give me some maze generation algorithms to pick from and it easily suggested several well known ones; Prim's, Kruskal's, Recursive Backtracking, etc.

Not knowing any difference, I asked it to generate the Rust code to render a maze using Prim's algorithm. It confidently proceeded to do just that. After it finished generating code, I accepted it's changes and tried starting the app... and was greeted with yet another compilation error. This time an error with the borrow checker. I tried the same dance of entering the error into the chat window and politely asking it to take mercy on my ignorant soul and fix the issue. And again, it proceeded to confidently generate code and declare the issue "fixed!". I re-compiled only to be greeted with the same error. Welp.

After a few more attempts at this, I eventually had to manually intervene and muddle my way through understanding the problem and re-writing code to get a successful compilation. Yay, we have a binary! I fired up the program and... was met with a white window and a single black square. Lol.

Based on my keen observational skills, I determined that the maze generation algorithm was having some problems. I dug into the actual implementation of the maze generation algorithm and cross referenced it with the algorithm psuedocode and it was clear that the generated code was not quite right (which as it turns out is sort of important when implementing an algorithm).

I tried to correct the mistakes myself, but it was a bit difficult to untangle what the LLM had generated, and I was running out of time to make my program work before I had to be done for the day (I have young kids so I'm usually hacking under some sort of time constraint like the length of nap time).

I decided to ditch the LLM generated code and instead look for a library that already implemented the algorithms I wanted. I found someone's neat side project on GitHub named Knossos which fit the bill nicely. I asked the LLM to "please use this library" and it happily generated the code to integrate this into my app.

But again I ran into compilation issues when I tried to run my app. The generated code was trying to access information that was not publicly accessible from the library modules as far as I could tell and I ended up pulling the knossos repo and making modifications to expose a handful of modules as public, so I could reference their internals directly. I'm pretty confident this is the wrong thing to do, but again I know very little about Rust or its module system and this "fixed" my problem.

After messing around with this, I re-ran the program and finally it seemed to be generating a maze! Huzzah! I had a maze generator and barely understood what the heck the code was doing! Kind of amazing, in a way.

I'm Picking Up Good Vibrations

I thought what I had working already was pretty great! Next wanted to animate a sprite that would traverse the maze. This time I got amazing results from the AI and it basically one shot this request, generating an A* algorithm for solving the maze and animating a sprite that would traverse the path that was found. From there I asked it to add debug information that would display the pathfinding heuristic information on each cell of the maze, and again it did it in one try. Well isn't that snazzy?

Vibes Are Immaculate

While it wasn't the smoothest process from start to finish, and I definitely had to draw on my existing skillset to make things work, I was still pretty flabergasted that I was able to get to a working app within a couple hours of starting. Especially considering it was using a language I have no serious experience in, and using libraries that I have never touched before. This was a fun exercise and was really a cool "Wow, this stuff actually kinda works", even if it sometimes goes completely off the rails. I'm pretty excited to see how these tools improve and how much easier it will be to build full working pieces of software in a single day.

Maybe we're on to something with this AI thing after all.

← Back to home