Debugging Marupeke: Rust from Scratch

In my previous post I managed set up a simple landing page for my Marupeke puzzle project hosted on AWS S3.

In the weeks after having uploaded the page I have been working on a puzzle generation algorithm in Rust after hours. I don’t know anything about Rust but am motivated to learn. Some weeks have been more productive than others and with the help of Github Copilot and now Cursor, which made me drop Visual Studio Code all-together, the hour I code in the evening feels pretty productive.

Meanwhile, I got side-tracked by training for the half marathon in Vitória, ES. I was training three days per week and was able to finish the half marathon in 1h58m which was nice since my goal was to go sub 2 hours.

Vitória, Espírito Santo, Brazil

I’m back in São Paulo and the temperature here dropped to a chilly 12 degrees celsius. As there normally isn’t any central heating in the apartments here I am sitting at my desk with a blanket covering me while writing this 🥶

Spring is less than a month away and can’t come soon enough — I loathe the cold. I even moved my peyote cacti, jagube and chambá plants indoors and am planning some psychoactive plants experiments in the future when the temperature gets more amenable but that’s a story for a future post.

Back to Marupeke.

Since I don’t know anything about Rust and don’t want to waste weeks reading tutorials and documentation I am all in on the AI code assistants so I get the basic skeleton up and running through a combination of ChatGPT-4o, Copilot and now Cursor and I must’ve been out of the loop for a long time because these things get you off and running at an incredible speed and I got the basic constraints working after some hours.

But there’s a problem. The generated puzzles are wrong.

I added a string representation of the board where an X represents a Cross, an O represents a Circle and a B represents a Block. We start with an empty grid and the algorithm randomly tries to place elements at empty positions in the grid while checking that the constraints of the puzzle are not violated. I also added some debug functions to print each step of the generation.

The constraints of Marupeke are as follows.

Fill in each empty cell of the board with either an X or an O so that no more than two consecutive cells, either horizontally, vertically or diagonally, contain the same symbol.

Now if we look at the output we see a partially generated puzzle. The next empty grid position that needs a symbol is located at position (2, 4) which is row number 2 and column number 4. We have a candidate move that we try which is to place a cross at that position, we check the puzzle constraints and the move is considered valid. But since we already have crosses at (0, 2) and (1, 3) we have now violated the constraints of no more than 2 consecutive cells with the same symbol in the diagonal direction. Clearly some of the logic is off and we can add a test case to reproduce this bug.

My hour is up. I’ll think about how to fix this some time later this week.

Subscribe to popado

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe