Tetris Bot

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.

Screenshot of the Tetris gameLike 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.

Screenshot of Tetris Bot with settings for evaluation criteriaIn the following the six criteria used by the Tetris Bot will be explained in more detail:

  1. “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.
  2. “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.
  3. “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.
  4. “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.
  5. “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.
  6. “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.)

Screen capturing of playing Tetris Bot

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:

  1. 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.
  2. 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.
  3. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *