Skip to content

runeharlyk/Tetris-AI

Repository files navigation

Tetris-AI using DQN

Tetris.png

About the project

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.

Features

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.

Heuristics

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)

Getting started

Prerequisites

The project uses Python 3.11.x which can be down from the official website.

Installation

  1. Clone the repo

    git clone https://github.com/runeharlyk/Tetris-AI.git
    cd Tetris-AI
  2. Setup virtual environment (Optional)

    python -m venv TetrisEnv
  3. Install the dependencies

    pip install -r requirements.txt

Usage

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

Roadmap

  • 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

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Authors

  • Clara
  • Lucas
  • Rune

About

The battle of the Tetris AIs - DQN vs Genetic

Resources

License

Stars

Watchers

Forks

Languages