Story
At the start of 2024, I was fascinated with AI. More specifically, genetic algorithms. I watched countless videos on YouTube that explains, showcases and makes genetic algorithms. I decided to make my own to play an old game: Panel de pon / Tetris Attack (the name depends on the version of the game).
Development
I also wanted to upgrade my skills in C++, so I decided to remake the game in C++, using the library SFML for the graphics.
Cursor
In the first video, I showcased what I did so far. I programmed the cursor, I allowed the player to swap two blocks and to connect multiple. The cursor is a pretty standard cursor. You increase the position on either axis and you clamp it so that it can't go outside the bounds.
Blocks
The neat part about this is that I, by myself, made a compact system. By that, I mean that the grid takes as little space as possible. Each block stored 3 values:
- Type (Block, Air)
- State (Swapping right, left, falling, being destroyed)
- Color (red, blue, green, yellow, ...)
Each value is an enum. However, enums are int and I don't need 4 bytes of data for each value. Yes, if I wanted to add more, it would be easy. However, I just wanted to replicate the original game. So each value just needs 1/2 bytes. By that logic, I just combined all the values into a single unsigned short.
This allows each block to only 2 bytes large. This taught me how to think like old developers and to find ways to optimize a problem. After a bit of searching, I found in an old conversation the code of this class.
Sadly, this exposes that the blocks aren't actually 2 bytes large. Their data is, but there were other fields that I needed to store, making the struct bigger.
Combo system
After that, I developed the combo system. In the original game, the more match you make from one move, the more points you gain. Here, I made that the player can make combos from falling blocks.
Not much to say other that it was a pain to manage timers and states. Each block has a timer linked to it basically two 2D arrays and all the timers are updated at once. I remember struggling with it, because blocks would match while falling or fall through matched blocks.
Rising
After that, I implemented the rising mechanic. In the game, the board automatically rises or the player can manually rise it in order to reveal new blocks.
This was more fun than the last one, because it was only offsetting stuff around and moving up a hidden layer.
Conclusion
Sadly, this is where the project ends. I never actually implemented the genetic algorithm in this project probably a combination of lack of motivation and school work. Moreover, I lost all the code in an attempt to censor my name from the system path don't try to change the name of your user folder AND MAKE BACKUPS. I'm still very lucky that I was able to show code.