R1BBIT · PROJECT

ESP32 Project 9: AI Tetris (Autoplay)

A self-playing Tetris for the Waveshare ESP32-P4 Smart 86 Box with a 720×720 display. You don’t touch anything: the built-in AI plays the game by itself.

How it works
For every new piece the AI checks every rotation and every column and scores where the piece would land. A good spot keeps the stack low, leaves no holes and keeps the surface flat. Cleared lines add to the score. The AI then rotates the piece, moves it into place and drops it.

Features

  • AI autoplay with a heuristic board evaluation (height, holes, bumpiness, cleared lines)
  • Classic scoring: 100, 300, 500 or 800 points × level for 1–4 lines
  • The game speeds up every 10 lines
  • Side panel with score, lines, level, next piece, games played and best score
  • Smooth, flicker-free movement: only the cells that changed are redrawn
  • Background screen repair redraws the field row by row from the game state, so leftover pixels never stay on screen
  • After GAME OVER a new game starts automatically in 3 seconds

Hardware: Waveshare ESP32-P4 Smart 86 Box, ST7703 720×720 MIPI-DSI display

Settings: fall speed, minimum fall speed and AI move delay can be changed at the top of the code.