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.
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.
-
Clone the project with
git clone https://github.com/Larmix0/Tetris-AI.git
-
Change to project directory with
cd Tetris-AI
-
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).
-
Install the required packages for the project with
pip install -r requirements.txt
-
Run the run.py file as a script or type
python run.py
python -m unittest discover tests
python -m unittest tests.test_*
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.