You are browsing as a guest. Sign up (or log in) to start making projects!

Tetr.AI

  • 8 Devlogs
  • 23 Total hours

Neural Network that learns how to play the popular Russian game Tetris

Ship #1 Pending review

Tetr.AI

This is the first release of Tetr.AI, my first ever reinforcement-learning project built for the Hack Club Stardance YSWS.

Tetr.AI includes:

  • A custom built Tetris environment built with PyGame which allows you to train and run your own models as well as just play Tetris
  • A PyTorch neural network
  • Deep-Q-learning
  • Model checkpoint saving and loading
  • Saving of training statistics into a CSV file
  • A graphing script to allow you to visualize how well your model trained
  • Windows and Linux setup scripts

Model status

The training pipeline is completely functional, but due to time constraints this release won’t contain a model which can play Tetris well.

I completed two long duration training experiments during development which revealed problems with reward shaping, epsilon, and sparse rewards. Everything on this is documented in the README.

Training and experimentation will continue after stardance

  • 8 devlogs
  • 23h
Try project → See source code →
Open comments for this post

2h 59m 16s logged

DEVLOG 8: I think I may ship soon…

Ok so I’ve hit a road block. Stardance ends soon which means I don’t really have much time left. My project is a completely working reinforcement learning AI which can play Tetris but not well.

Originally I wanted to perfect a model and then ship the project but due to Stardance ending soon I may change that.

Recent additions

  • Added the ability to resume training on a model you made at your most recent checkpoint
  • Added setup automation scripts for windows and linux
  • Refined README with a getting started section and more detail in the Model History section to give the project more story

Because I’m essentially prepped for shipping and it is a completely working project I will probably ship soon. Wish me luck.

The screenshots shown are the results from training Tetr.AI-V2

0
0
16
Open comments for this post

4h 18m 13s logged

DEVLOG 7: more AI training (hint: FAILED)

This graph shows the results of my first training session of my AI showing how well the AI does over time through the reward. In total it lasted ~17 hours and its obviously not nearly enough time. The reward is supposed to go up over time, which it is. But not fast enough. Overall it only seems to increase in reward over time just by VERY little.

Moving onto the other graph which shows the rows cleared over time. As you can see it never really increases on average. This shows that:

  1. MY AI SUCKSSSSSSS
  2. My AI is dumb

Overall my AI can’t learn and I need to just keep on adjusting numbers over and over again.

0
0
31
Open comments for this post

2h 19m 9s logged

DEVLOG 6: actual learning

Wow two devlogs in pretty much a day… I need to touch grass…

But that is not the point. IT IS FINALLY LEARNING (just very inefficiently) Currently it only learns from two things:

  1. How many rows it cleared on a single run
  2. Whether or not it sold the game

Now pretty much the rest of this project will just be tweaking and experimenting with things. Before I ship I do want to train and release a demo model that you can test locally on your PC ( and I may want to test if it would work on android phones too ) that will come with the project. I also want to make it to where you can create and train your own models and potentially share them with other people. CAN’T WAIT FOR EVERYTHING TO BE DONE!!!!!!

0
0
17
Open comments for this post

1h 38m 5s logged

DEVLOG 5: Random movements

An update from my previous devlog where I started learning pytorch. I have not learned pytorch to the point to where I can explain everything down to its finest details but enough to make my “AI” do some random junk with no direction.

Pretty much I’m just initializing random weights and letting it go. I have 200 input neurons for my 20x10 board. The video I attached below shows the AI just doing some random stuff like rotating non stop and moving left and right.

0
0
26
Open comments for this post

3h 9m 11s logged

DEVLOG 4: The beginning of learning PyTorch & Working AI-Tetris-Environment

Pretty much the title sums up what I’ve been doing for the past 3h and 9m of this. I have some prior knowledge of the basics of machine learning ( from The Nature Of Code by Daniel Shiffman awesome book about coding would recommend ) by making a single layer perceptron ( basically a single neuron algorithm ) that can separate linearly separable data. I attempted to make a multi layered perceptron which actually puts the network in neural network. But I got stuck on back propagation. I don’t really know what to put as the picture for this devlog so I’ll just show a visualization of a neural network.

1
0
37
Open comments for this post

2h 6m 11s logged

DEVLOG 3: TETRIS ✅

THE TETRIS GAME IS PRETTY MUCH COMPLETE (besides some finishing touches) the game is completely playable with:

  • Moving pieces with arrow keys
  • Rotating pieces
  • Deleting rows
  • And the game restarts after there is no more valid places to go

So pretty much complete. Now it is time to dive into the deep waters that is…

NEURAL NETWORKS

Oh boy this is going to be fun (and hard). I already know that the kind of training that I have to do for this is reinforcement learning. Which basically is like giving dopamine to your artificial brain when it does something good and giving it a slap in the neck when it does something bad. Which in return it changes its weights based on its previous performance.

But for the first thing I got to do is set up all of the mumbo jumbo that will actually allow the neural network to see. And I think I have a rough understanding on how I’m going to implement that.

Stay tuned on this awesome journey of making an AI play Tetris!

0
0
47
Open comments for this post

1h 51m 24s logged

DEVLOG 2

Ok it’s been a couple days but I’ve added key presses where:

-Left Arrow = Piece moves to the left
-Right Arrow = Piece moves to the right
-Down Arrow = Piece soft drops.
-Space Bar = Piece hard drops.

Overall it wasn’t that hard to implement but I had this bug where after soft dropping it saves that position to the locked pieces array. Which in return kind of broke the whole game. Here is the broken code block:

if event.type == pygame.KEYDOWN:
    if event.key == pygame.K_LEFT:
        self.currentPiece.x -= 1
        if not validSpace(self.currentPiece, self.grid):
            self.currentPiece.x += 1

            lockPiece(self.currentPiece, self.locked_pos)

The problem was the last line where it says

lockPiece(self.currentPiece, self.locked_pos)

So all I had to do was remove that and it works perfectly. Now I need to make the game rules where if you finish a row it deletes it and then the hardest part… ROTATION.

0
0
85
Open comments for this post

4h 52m 56s logged

DEVLOG 1: Basic foundations

It took me way longer than it should have but I finally did it. I learned how to use PyGame and now I’m on my way to remaking Tetris. I set up a function that puts a random Tetris shape onto the 2D array that is essentially the one source of truth in Tetris at least that’s how I think of it. With PyGame I then update every frame what it should display based on that 2D array. The picture below shows me spinning up 3 instances of this code working. Currently the blocks don’t do much but I’ll start working on that tomorrow. Plus I really want to get the Tetris remake done quick so I can start building and training the neural network to actually play the game for me.

0
0
43

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…