Skip to content

A genetic algorithm that learns to play Tetris effectively

Notifications You must be signed in to change notification settings

IlanIwumbwe/Tetris-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 

Repository files navigation

Tetris

This code is for my NEA project, A level computer science.


Optimisation using a genetic algorithm to make an AI that plays good Tetris

  • train_agent_scratch.py uses a genetic algorithm written from scratch, without next piece knowledge (hasn't been optimised yet)
  • With next piece knowledge, the agent does very well. Results are shown here: https://www.youtube.com/watch?v=F8TkvoR6etk&t=656s

The population and nueral net are coded in neuralnet.py

Update log


  • train_agent_scratch.py now has capability to plot graphs after running all epochs, as well as saving a population every 2 epochs
  • tetris.py -> human playable version now has complex moves implemented such as T-spins
  • Ablation tests are now possible in tetris_agent_scatch.py

References:


How to train:


  • Run tetris_ai_scratch.py to train the agent. It gives prompt for whether you want to load a population. If you want to, type "Y", it then asks from which epoch, type 2, 4, 6 ,8 or 10.
  • If you don't want to load a population, just enter.

Results


  • Over 1 million highscore after 10 epochs of training

Graphing: If graphs don't work automatically, program will print out all the data with text so you know what is what, you'll have to manually pass it into the visualization class. Make an object in that file and pass data in there, then run the visualisation file.

av_fitness av_score

About

A genetic algorithm that learns to play Tetris effectively

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages