Tetris ML

Tetris ML

This program, written in Python with pygame for the visuals, trains a bot to play Tetris.

The Tetris clone includes all the mechanics of the original game besides storing blocks. The highest score it has achieved during training passed 700 lines cleared.

How It Works

The bot works by calculating the results of its actions weighed by specific variables. The bot learns by randomly adjusting the weights from a parent bot. The most successful child bot will then compete against the parent to determine who will become the next parent bot.

This genetic algorithm approach allows the bot to evolve and improve over generations, finding optimal strategies for playing Tetris through trial and error.

Weight Variables

covered

Avoids covering unfilled tiles with another block.

height

Minimizes the height of the blocks placed.

twospace

Tries to leave space for 2-wide blocks to fit in.

edgespace

Attempts to fill in the sides to avoid reliance on lines.

Technical Details

Built with Python and pygame, this project demonstrates machine learning concepts through a practical application. The genetic algorithm approach allows the bot to discover effective strategies without explicit programming of game rules.

The bot's ability to clear over 700 lines shows that the learning algorithm successfully found strategies that balance the different weight variables to maximize performance.