The Tetris Bot is a Tetris playing AI that I developed in 2008. Possible decisions are evaluated according to six simple criteria. The algorithm executes the move with the highest score. The bot can be tuned by calibratable weighting factors of the criteria.
The Tetris game with UI for human players
In order to make the development of the bot easier, the first step of this project was to develop a simple Tetris game playable by a human player. The following screenshot shows the simple UI.
Like all Tetris implementations, the game shows the player the pieces already dropped on the ground, the currently dropping piece and the piece coming next. For ease and speed of implementation, the pieces consist of single-colored black blocks. The UI also displays the players current score, the lines that have already been removed as well as the player’s current level.
Tetris Bot
The Tetris Bot is a simple AI strictly evaluating every possible position of a new piece by a set of criteria. Depending on the configurable emphasis put on each criteria a score is calculated and the position scoring best is played. However, the bot has never more information than a human player would have. So the AI doesn’t “cheat”.
Evaluation process and criteria
As already mentioned, the bot evaluates every possible position of a new piece based on a set of six criteria. In order to do so, the AI knows the playing field and the new piece it has to place. The following figure shows the game with the additional criteria configuration panel on the right hand side.
In the following the six criteria used by the Tetris Bot will be explained in more detail:
- “Embedded penalty”: Whenever a potential move causes an empty encapsulated position to be created, the position’s score gets this penalty. This penalty is relatively high, because embedded holes are hard to remove and prevent that line from being deleted. Therefore they are a great risk to loose the game.
- “Distance penalty”: This penalty is multiplied with the height of the potential position. Therefore it ensures that the bot prefers positions that near to the ground of the playing ground. This is important to prevent the bot from stacking all blocks up to the top. However, this penalty may not be to big, as this would cause the bot to prefer embedding holes.
- “Line reward”: The line reward defines a positive value added to the score for every line that can be removed by placing the block at the evaluated position. Therefore this reward encourages the bot to delete lines. Again this reward may not be to big, as it is no help to delete one line but create three unremovable lines in the same step.
- “Column reward”: This reward is given whenever a move would cause unfilled columns of just one block in width to be deleted. This is important, as this columns may only be filled with the I-piece. As before, a reward that’s to high, can cause to many embedded empty blocks.
- “Column penalty”: The column penalty is the corresponding penalty that is given whenever an evaluated potential position increases the number unfilled columns of the width of one block.
- “Double column penalty”: As the name already describes, this penalty is given for newly created columns of width two.
Tetris Bot in action
The following animated gif gives a first impression of the resulting behavior. (The score is not manipulated or something like that! The bot really played that game to more than 2200 removed lines without any interaction from my side.)
Limitations and outlook
The Tetris Bot is currently only guided by six simple criteria but already reaches very high scores. Further improvements could be achieved by applying the following ideas:
- The bot does currently not use the previewed piece. To include the next piece in the score calculation, the algorithm could search for the best position of the next piece assuming the current piece is placed on the currently evaluated position.
- The used criteria are only manually configured by watching the bot’s behavior and adjusting the values. Further tuning this parameters could increase the performance even more.
- By adding some more criteria, the bot’s behavior could also be improved. An example would be a reward for deleting 4 lines in one step, as this includes bonus points. However just adding more criteria can also reduce the performance, as it becomes harder to calibrate the settings. Unimportant criteria could also cause the bot to ignore more important ones.