In this post, I will talk about the implementation for the varied reward functions in implementing the Tetris game.
Intro to Tetris Scoring
After digging into Tetris documentations, I found a lot of resources on how each move in Tetris is scored. It is A LOT more in-depth than what I knew about Tetris.
It's like, have I really been playing the same game as them? I only knew that clearing more = better scores...
Implementation
Overall, I took the same scoring system from this Tetris Wikipedia, as I want my game to behave as similarly to a real Tetris game as possible, so that my Tetris bot can extrapolate to the real game well.
I implemented the normal scores (single, double, triple and quad) as well as combo scores pretty easily -- All they required was some variables to keep track of rows cleared and combo so far.
To adhere to SWE principles, I also made sure to encapsulate the score calculation in a separate RewardManager class, and my game logic will call the API from this class to update the score.
Once that's done, it is time to move on to the boss of the section:
T-spins
T-SPINS!!
I have to say that this is the first time I had read a documentation on the formal definition of a T-spin. In essence, it is when the player is controlling a T-block, and rotates into a slot where 3 out of 4 corners in the 3x3 surrounding area are filled.
To check for this, I implemented an additional function when I land a T-block to check whether this action is eligible for a T-spin. Since I need to check the 4 corners, I hardcoded the corner values from the center, and counted how many corners were filled. I then adjusted the RewardManager to award T-spin score if a T-spin was done.
However, there is another move called T-spin Minis, and I didn't even know they existed! From what I read, they are kind of like an easier version of the T-spin, where you have to slot the T-block into a hard-to-reach, yet not incredibly hard-to-reach space. Sounds complicated, right? It did for me, at least, and I am not confident that I can successfully and reliably pull T-spin Minis off to test the functionality. Therefore, I decided to put T-spin Minis on hold for potential future addition, and only consider the regular and more difficult T-spin.
Conclusion
With that, the Tetris game clone is looking good! I am planning to pause the development here, and look into building the AI bot for this Tetris game. Stay tuned for the next post!
Top comments (0)