This topic is now archived and is closed to further replies.

what AI for a tetris-like game?

This topic is 5531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

dont take my word as im just some random noob, but i dont think an AI is needed in tetris? just drop some random piece at some random location at the top of the window and drop them at a constant speed, then the user move the piece around?

Share this post

Link to post
Share on other sites
I think nicho_tedja is talking about a computer player.

All it really needs is for the computer to look at the piece, determine the best fit (maybe one that clears a line asap, or sets up for multiple lines). Then depending on difficulty, put some random errors in it''s "keypresses" to simulate pressing the wrong button and dropping the piece in the wrong spot.

Not too difficult, but then again, I haven''t got to making my ''tris game yet.


Share this post

Link to post
Share on other sites

I actually implemented a computer player, with succes.

It evaluates every possible position and orientation of a piece, and applies the following rules:

- give one point for every border of the piece that fits.
- add one point if it makes a line
- deduct one point if it makes an error (blank space under piece)
- deduct points if it tries to build higher than middle of tetris-field.

Pick the piece with the highest value. That''s it.

My app usually gets around 20.000 lines before dying. However it is capable of reaching 50.000 lines. An interesting fact is that, because this algorithm is so simple, it makes quite a few ''errors''. These errors aren''t bad though, because they stimulate making more than one line at the time whenever the error is cleared up!
This algorithm usually builds pieces like an ''U'' (lots of pieces at the side).

Hope this helps,


Share this post

Link to post
Share on other sites
Actually, you can''t call it ''tris'', or any variant name that includes the syllable ''tris''... copyright infringement already tested in case law a couple of years ago!

An alternative approach to your computer player would be to implement some basic pattern recognition. Or, do a brute force search using a bit representation of the game board.

If you want some idea for ''Conway'' style rules... how about:

1) Try to place the piece as low down the board as possible;
2) Try to lay the piece as flat as possible;

If needs be, add in a third rule:

3) Try to avoid making holes below the piece.

I suspect though that the first two might be enough to create a basic tetris agent.



Share this post

Link to post
Share on other sites