Tetris AI
Hi!
I want to create a very simple Tetris AI. But I can't figure out a good enough algorithm.
I've tried to search for known algorithms for this, but all documents I find seems to lead to one person (Colin Fahey), and his work can't even be found.. :(
Does anyone have an algorithm, source or anything that can help me create a simple Tetris AI? Prefarable an algorithm that are simple to understand.
I don't really understand, because in Tetris there really isn't any AI. You simply need to randomly create a piece with a random color and have that piece displayed on the screen. I have a Tetris clone on my webpage you can look at to see how I did it.
www.adamwlarson.com
www.adamwlarson.com
Adamhttp://www.allgamedevelopment.com
August 21, 2006 12:57 PM
Quote: Original post by adam23
I don't really understand, because in Tetris there really isn't any AI. You simply need to randomly create a piece with a random color and have that piece displayed on the screen. I have a Tetris clone on my webpage you can look at to see how I did it.
www.adamwlarson.com
...
......I think he meant he wants an AI that Plays Tetris, not that the AI is part of the game itself...
Anyhow, I dont know how to approach a Tetris AI, but I will put out this thought:
the reason I as a human lose Tetris, is because eventually the pieces move so fast that I cant react and end up with a big pile in the middle that blocks off opportunities to move anything
a 'dumb' AI that merely attepts to fill up the lowest holes first, and does it without the human reaction time disadvantage, might be good enough; it's speed might offset it's lack of intelligent strategy with trying to get combo rows and stuff...
To create a simple (but fairly effective) tetris player just test the places where the brick would fit and put it in the lowest place. If it doesn't fit anywhere rotate the brick once and try again.
To create a very good tetris player you could use the minimax algorithm.
This works by creating a tree of all possible moves and selecting the path that would result in the destruction of the most bricks. ~Assuming you can see one brick ahead the tree would only be two layers deep.
Sorry, I misunderstood the question :(
Adamhttp://www.allgamedevelopment.com
Yes, I meant an AI player for Tetris. I forgot to mention that :P
Thanks for the help. I was thinking about that solution, to search for every possible move until I can make it fit somewhere. But it seem too far-fetched.
I think I'll try with the minimax algorithm you suggested. So I need to store each possible move into the tree. Do I have to store the amount of blocks in a row that particular move affect, and then pick the move where the most blocks in a row is? Or something like that?
Thanks for the help. I was thinking about that solution, to search for every possible move until I can make it fit somewhere. But it seem too far-fetched.
I think I'll try with the minimax algorithm you suggested. So I need to store each possible move into the tree. Do I have to store the amount of blocks in a row that particular move affect, and then pick the move where the most blocks in a row is? Or something like that?
August 21, 2006 07:30 PM
I believe Colin's website is back up now, (http://www.colinfahey.com) but i'm not sure if it has the tetris ai on it again.
I think he used a neural network to play the game, but i'm not 100% sure.
I think he used a neural network to play the game, but i'm not 100% sure.
Hi,
I already made some replies in a similar topic on Tetris AI: view
Tetris AI Topic
You might want to read this first...If you have any questions afterwards, I'll be happy to reply..
Edo
I already made some replies in a similar topic on Tetris AI: view
Tetris AI Topic
You might want to read this first...If you have any questions afterwards, I'll be happy to reply..
Edo
Edo
Thanks alot edotorpedo, I'll try to implement your method.
But I don't know if I understand your method correctly. My AI for the moment, weights the number of holes it makes and the lowest position possible. But that tends to make alot of I holes that only the I-block can save.
Could you make a very simple example on one block that is dropped, so I can see how the numbers are retrieved and calculated?
But I don't know if I understand your method correctly. My AI for the moment, weights the number of holes it makes and the lowest position possible. But that tends to make alot of I holes that only the I-block can save.
Could you make a very simple example on one block that is dropped, so I can see how the numbers are retrieved and calculated?
Quote: Original post by delbogun
Thanks alot edotorpedo, I'll try to implement your method.
But I don't know if I understand your method correctly. My AI for the moment, weights the number of holes it makes and the lowest position possible. But that tends to make alot of I holes that only the I-block can save.
Could you make a very simple example on one block that is dropped, so I can see how the numbers are retrieved and calculated?
Try placing the the block in each position, and then evaluate the board afterwards, rather than the position. What I mean is say you have a blank board, and the first piece is a square, then just put it in the very left and check the board. Things you could check are total pile height, holes, wells, 'flatness/bumpiness', etc (my implementation was based initially on Colin Fahey's work). So for this example height would be 2, holes would be 0, and bumpiness (depending on how you felt like checking this, I just walk along and sum all the height differences) would be 2, wells would be 0, etc.
Now just add up the score with weights for each feature. Say you don't want pile height, so the weight could be -10 or something, everything else is 1 (for this example), so total score would be -18.
Now check the next position and do the same, and keep track of the highest score. Notice there's no reward for lines, this is implicit in the pile height. Basically this method finds the 'least-worst place' for a piece, then just have the AI try to put it there.
The only hard part is finding the weights, as I mentioned in my post in edotorpedo's link a friend and I used a GA to find the weights, but that's not necessary. You can get pretty decent results this way, certainly good enough if you wanted an AI playing along side a player or something.
Does that help?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement