Reinforcement Learning Tetris game agent using Deep Q network model and Duel Q network model based on pytorch.
Requirement package for running trained weight data: pytorch
, gym
, pygame
.
Requirement package for model training: matplotlib
, numpy
Tetris game is a game that requires the player to arrange different shapes in the right position to destroy the filled rows.
TetrisAI uses the deep Q network and deep Q network duel respectively to train the agent to play this game.
The agent will receive information about the height of the 10 columns in the play space, information about the shape of the current block, and information about the shape of the next block. There are a total of 7 block shapes. So observation data has 24 dimensions.
The reward will be calculated by the number of rows that the agent clears in the game screen minus the number of holes (the space between the blocks) created.
Follow pytorch installation guidance in Pytorch website
Gym : pip install gym
Pygame : pip install pygame
Matplotlib: pip install matplotlib
Numpy : pip install numpy
Simplely running the python file test_trained_ddqn.py
Simplely running the python file test_trained_dqn.py
Simplely running the python file ddqn_main.py
Simplely running the python file dqn_main.py
With Q leaning model, we can get average of 200
points (20 leared rows) per game after 30000 trains game
Result video:
Dqn_Tetris_AI_Agent.mov
With double Q learning model, using one Q for learning and another Q for evaluation, the average score we can achieve is about 400
points (40 cleared rows) per game. Therefore, duel deep Q network perform much better than deep Q network.
Result video: