This project utilizes deep reinforcement learning to master the game of Tetris. The game engine makes use of the NumPy library for efficient numerical computations and the AI agent is implemented using PyTorch. Our project aims to showcase how Deep Q-Networks (DQN) can be applied to classic games, demonstrating both the learning capability of neural networks and the strategic depth of Tetris.
Deep Q-Network Implementation: Utilizes a DQN for learning optimal play strategies.
Customizable Hyperparameters: Allows tweaking learning rate, discount factor, etc.
Real-time Learning Plotting: Watch the AI learn and improve over time.
To efficiently train and run the neural network the game state is reduced to a few heuristics:
- Number of full rows
- Max height of the columns
- Number of bridges (a bridge is an empty cell beneath a full cell in the column above).
- Bumpiness (sum of absolute difference between column height)
The project uses Python 3.11.x which can be down from the official website.
-
Clone the repo
git clone https://github.com/runeharlyk/Tetris-AI.git cd Tetris-AI
-
Setup virtual environment (Optional)
python -m venv TetrisEnv
-
Install the dependencies
pip install -r requirements.txt
To train a model, run their training script eg.
python train_DQLAgent.py
To test, without modifying, the models run their test script eg.
python test_model.py -model dqn
- Generate states, without duplicates
- python decorator for logging function calls
- Number of sims per second printed every second
- Rolling average
- Graph for model reward prediction
- Model weight visualization
See issues for more details
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions to the project are welcome! If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
- Clara
- Lucas
- Rune