Skip to content

A bot that reads the screen and emulates key presses to play online Tetris on a superhuman level

License

Notifications You must be signed in to change notification settings

mikhail-vlasenko/Tetris-AI

Repository files navigation

Tetris-AI

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.

Gameplay demonstration

Bot playing in mode 1

demo mode 1

Bot playing in mode 2, in another game

demo mode 2

Usage guide

How to run

  1. Take a screenshot of your Tetris game
  2. Go to config.py and define a DisplayConsts instance
  3. Set 'display consts' in CONFIG to your instance
  4. If necessary, define a colors array with piece colors for recognition of the next piece
  5. Set other config parameters
  6. Run src/main.py
  7. Switch to the Tetris window

Runtime tuning

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)

About

A bot that reads the screen and emulates key presses to play online Tetris on a superhuman level

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages