We built a bot to play online tetris better than we ever could, and this bot won a few dollars.
The bot works with screen information and emulates key presses, thus, it can be adapted to any tetris game.
After reading the screen, it uses an algorithm to determine the best piece placement and executes it.
The algorithm has various modes, for example, focusing on getting a tetris, which is clearing 4 lines with a single piece.
Bot playing in mode 1
Bot playing in mode 2, in another game
- Take a screenshot of your Tetris game
- Go to
config.py
and define aDisplayConsts
instance - Set 'display consts' in
CONFIG
to your instance - If necessary, define a
colors
array with piece colors for recognition of the next piece - Set other config parameters
- Run
src/main.py
- Switch to the Tetris window
You can control how the bot plays while the game is going.
This is only checked when a new piece appears, so you need to hold the key.
Piece dropping speed
1 - the fastest speed, always hard drop
2 - no hard drop
3 - let the piece land on its own, the bot is always scared
Number of computing paths for the next piece:
z, x, c - 1, 4, 8
n - try to clean the field
m - disable cleaning mode (focus on getting tetrises)