Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 1.36 KB

README.md

File metadata and controls

24 lines (17 loc) · 1.36 KB

Tetris AI

A self-playing Tetris.

Usage

To play the the game interactively:

python tetris.py

To play the game automatically:

python tetris_ai.py

When playing the game interactively, use the arrow keys to control the tetromino's moving directions (<left>, <right>, <down>) and rotation (<up>), <space> to drop the tetromino straight down, <p> to pause or resume, and <q> to quit the game.

Implementations

The main idea is simply iterate through all the possible rotations and horizontal positions of a given tetromino, evaluate each result using a heuristic function and choose the one with the highest heuristic score. The heuristic function is based on Pierre Dellacherie’s Algorithm, read more details here.

We use depth first search in the implementaion, since there are at most two tetrominoes to consider when seaching for the optimal placement, whether to consider the next tetromino or not is a matter of choice and should be easily configured. To configure the depth of the DFS search, set LOOK_AHEAD to 1 or 2 in ai_config.py, if LOOK_AHEAD is set to 1, the algorithm would just consider the current tetromino, otherwise, it would take both one into account.

Copyright © 2016 Daogan Ao <[email protected]>