Jump to content
  • Advertisement
Sign in to follow this  
HexDump

I have no friends. I want my computer to play TETRIS with me.

This topic is 4964 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

Hello, First of all, sorry for the dumb topic :).´ I´m making a Tetris, and I want to play player vs computer plays. I hava no idea where to start, is there any doc on the subject or something?. Can you gimme ideas?. Thanks in advance, HexDump.

Share this post


Link to post
Share on other sites
Advertisement
How good are you in the old programming department. What language do u use. What 3D lib do u use. What OS do u use.

Loads of questions

Share this post


Link to post
Share on other sites
Don't think he is. I believe the questions were asked so that we would be more able to direct you to more relevant tutorials and other similiar resources. If you haven't programmed much, or any, then we'd probably point you towards tutorials that focus on just learning to program.

If you're a reasonably competent programmer, then it would be useful to know what programming language you use, as well as graphics API and OS, in order to direct you to resources that use the same or similar language, API and OS.

If you are quite new, though, might I suggest checking out the For Beginners page (not the forum) here on GameDev.

Share this post


Link to post
Share on other sites
Okay, I just glanced at your profile, so apparently you know about programming well enough. (Correct me if my glancing was wrong.) So are you more curious about programming a Tetris game in general, or do you have questions on how to write the AI?

Share this post


Link to post
Share on other sites
Well, I think I´m not new. I´m programming for about 10 years. I´m using C++ (C fro the GP32). Api? what Api? Gp32 has a dumb sdk, everything is written by me. The problem is that I don´t have much AI experience. So, it is a bit difficult to me to build the AI for playing a tetris game, so, I need someone to instruct me the basis.

Note: Damn, I forgot to tell I was interested in the AI part. Really sorry.

Thanks in advance,
HexDump.

Share this post


Link to post
Share on other sites
Well, grab a piece of paper and write down an algorithm which'll evaluate which place at the top of your brick wall that the currently falling piece will slot into best.

You may wish to simulate actually putting it into the slot in each possible position and then evaluating which will give you the least number of holes in your wall, etc.

Share this post


Link to post
Share on other sites
Quote:
Original post by HexDump
Are you joking or something?.


No,
I was asking speciffically how u wanted to make it. I cant giv u any help by using "generic" terms

Share this post


Link to post
Share on other sites
maybe thinking the board as a matrix of values, can help you.

The higher the row is, the higher the value of each "brick" of that row is. So before droping the piece you (the computer) can brute-force-test all the possible positions of the falling piece, emulate all those "turns", sum the values of the resulting bricks, and pick the lower one. The move that makes the already fallen bricks go down or that produce the minimum increase should be the best move.

Share this post


Link to post
Share on other sites
Lol, why does it matter what graphics API he's using? It's AI, not graphics.

Anyway, here's how I would do it. Disclaimer: I don't know anything about AI.

I'd probably try a semi-brute-force approach where for the current "falling" piece, you try to place it in evey column of your field, as well as trying to move it left or right for the last move (you know, to put it "under" a piece if possible). Now this isn't horribly complex, there are about 30 possibilities for a ten-column playing field.

What I'd also need is a measure of how "good" the field is after having dropped the piece. That means: overall height scores negatively, "lumpiness" scores negatively, holes score negatively, a tall 1-wide hole down the sides or perhaps the middle scores positively. This is a more complex part and it defines the "strategy" that the AI is going to take (does it favor safe play or building up for Tetrises), so the weights for these criteria need to be adjusted.

If the AI knows about the "next piece" then it should apply the same algorithm for that, using the best scoring outcome or the top few best scoring outcomes from the first piece trials. After that, you may want to recursively precalculate possible scored outcomes for N additional pieces... This is where branching becomes important, if we choose, say, the 5 best possibilities, and have 7 types of Tetris blocks, then for N tries you will have (5*7)^N = 35^N calculations, this gets pretty damn large as N becomes larger of course. So you also need a good balance between branching and search depth.

The good thing is that this only needs to be evaluated once for every new piece (and if you give it a time limit, it can keep calculating while the piece is falling), and if you're tricky then you can "save" some of the computations along the path you take. This is getting pretty damn complex though.

(I think I remember reading that it has been proven that an optimal Tetris game is an NP-complete problem, lol)

Also, maybe I'm completely wrong and there's a much simpler way to do this.

EDIT: I realized that I completely forgot about pieces being rotatable. This will increase the number of trials per column for a piece by a factor of 1 (no rotations for the square), 2 (line, Z shape) or 4 (L shape, T shape).

[Edited by - UfoZ on October 23, 2004 1:03:37 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!