Skip to content

A Tetris game powered by an AI made in python using pygame

Notifications You must be signed in to change notification settings

Larmix0/Tetris-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What the project is about

This is a tetris game powered by an AI made in python using the pygame library. It's also dynamic in height and width (though the math isn't the most dynamic currently, so offsets do break if you change rows and cols too much in constants.py).

This bot was made slowly over the months with small changes every now and then, and it's one of my first "real" projects so don't' set your expectations too high.

I'm still pretty proud about this project since the AI runs at relatively decent speed (~0.15 seconds per move) while calculating 1 move into the future.

Playing the game

After running the game you use left arrow and right arrow to move the piece. Up arrow rotates, down arrow moves down, control hard-drops the piece, and "z" holds the piece. Press "t" during the game to toggle the AI on and off.

Running the project

  1. Clone the project with git clone https://github.com/Larmix0/Tetris-AI.git

  2. Change to project directory with cd Tetris-AI

  3. Create and activate a virtual environment if you don't want to install packages directly on your global pip (look for a tutorial if you don't know how).

  4. Install the required packages for the project with pip install -r requirements.txt

  5. Run the run.py file as a script or type python run.py

Running tests

To run all tests:

python -m unittest discover tests

To run a specific test (replace * with any valid test file's name):

python -m unittest tests.test_*

Note about the AI

It's worth mentioning that the AI reading into the future only computes: current -> next and held piece -> next. So it doesn't compute current -> held or held -> next (granted they're similar anyways). So there's no need to mention that missing about the AI. The reason that's the case is because it would take too much time and would barely help the AI at all especially since current -> held usually leads to the same positions as held -> current anyways.

About

A Tetris game powered by an AI made in python using pygame

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages