Pytris – A Python Script for Testing Tetris Algorithms

In another post, I explained a probably non exhaustive list of the different types of Choosing Blocks Algorithms that might exist for Tetris.  Here I explain Pytris, a script that has the logging abilities for research into the algorithms.  This is part of my ongoing Master’s Thesis Project.  If you’re interested in the source code, just contact me!  I’m happy to provide it with additional explanation.

Pytris has been implemented in Python under heavy use of the pygame library. This made it possible to account for the desired goal of having test participants create a realistic game environment on their own computer. With pyg.exe even Windows users were enabled to play the game on their operating system.

Game Mechanics

Pytris offers all game mechanics, that can generally be found in any implementation of Tetris. Players are able to translate and rotate pieces coming down. Additionally, they can listen to the original Tetris score while playing, if they desire to do so.

Upon starting the script, Pytris captures the screen in a full-screen mode so that players are not visually distracted on the screens of their computers. Graphically there are also no further distractions from the game itself. It does not show a score or a number of lines made indicating performance directly.

The initial speed of the game is set to 400 ms, which means the tetromino is moved every 400 ms. Speed increases of 5 ms happen whenever a line is removed. If more than one line is removed at the same time, the speed increase is multiplied by the number of lines removed. The minimum speed is set to 75 ms. These parameters can be changed, if needed.

tetris2

For each game the algorithm for choosing pieces is chosen at random without replacement from a bag holding all five basic algorithms described above, each of them twice. This means, each player plays ten games of Tetris, two per algorithm in a random order.

A game ends after five minutes or if a player looses – whichever event comes first. The script pauses upon that point in order to give players time to fill in a questionnaire or have a self paced break between games. However, during these breaks the screen is still captured preventing players to do any other computer based activity, at least at the machine they are playing Pytris on. Due to the time restrictions for each individual game, players play a maximum of 50 minutes during one session.

Data Recording

Pytris has been designed in order to record a lot of data in general, not only for the data analysis required for this research. For each game within a session, a log file is created. After a test session has been concluded, these files can be retrieved in a folder named by the participant ID.

Every entry in a log file has a timestamp. A log file consists foremost of a header for general test data such as the participant ID defined in the player setup, the number of the game (ranging from 1 to 10), which algorithm has been used in this game, whether the player had the original Tetris score activated and finally, when the game started. The initial speed and every speed change are recorded as well.

For each new block, a situational analysis is performed. This consists of a count of lines made so far into the game, the current pile height, the current bumpiness measure, the current number of closed holes and for which type of tetromino there are possible placements on the current contour. Finally, the chosen block and the current grid are recorded as well as every keyboard interaction of the player.

Leave a comment

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

13 − three =

This site uses Akismet to reduce spam. Learn how your comment data is processed.