Tetris AI?

Started by
9 comments, last by Wachar 21 years, 8 months ago
How would I make a good Tetris AI? Have the AI make certain moves for certain moves the player makes or just random moves? Wachar''s Eternity <-<-<-<-<- Me own site!
Wachar's Eternity <-<-<-<-<- Me own site!
Advertisement
Random moves in Tetris? Well, the AI should do their best to build as many full lines as possible. I don''t think you have to take special care for the player''s moves...


Yesterday we still stood at the verge of the abyss,
today we''re a step onward!
Yesterday we still stood at the verge of the abyss,today we're a step onward! Don't klick me!!!
The way I''d do it is for the current piece, try to fit it in
the best way possible, using every orientation of the piece.
How to define best ? That''s up to you. It can be
completing the most lines or leaving the fewest holes .

*** 500 Internal Server Error ***


Kami no Itte ga ore ni zettai naru!
神はサイコロを振らない!
OOps, I meant to say Tic Tac To3!!!!!



Wachar''s Eternity <-<-<-<-<- Me own site!
Wachar's Eternity <-<-<-<-<- Me own site!
quote:Original post by Wachar
OOps, I meant to say Tic Tac To3!!!!!


Wow, how could you get Tic Tac Toe confused with Tetris?


Kami no Itte ga ore ni zettai naru!
神はサイコロを振らない!

If you read Radagars source there is a great AI.

Download the Game HERE

Download the Source HERE

And read the reception the game got <a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=107914>HERE (the downloads can also be found there).

>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Ilthigore-
<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>>>>>>>>>>>>>>Ilthigore<<<<<<<<<<<<<<<<<
OMG, you''re dumb!!
Wachar,

If you don't want to download and dig through my source, here's how I did that AI....

First, I checked to see if the Computer could win in one move. If he could, Move there.

If not, I checked to see if the Player could win in one move. If he could, Block him.

If not, I checked to see if there was any spot on the board where the computer could make 2 in a row, and be one from winning.

If not, I tried moving to the middle square.

If that didn't work, I moved to a random open position.

This does amount to a TON of code, and there may be a better way, but it works. Here's an example.
----------
The way I checked the board was writing 8 blocks of code for the 8 different rows that you could win on and checked to see what was there. I did this for each of the scenarios above.

For example....


  // This code will check the top Row to see if the computer can win in one move.// XX_// ???// ???if (pBoard[1] == CPU_MOVE && pBoard[2] == CPU_MOVE && pBoard[3] == BLANK){    movespot = 3;}else if (pBoard[1] == CPU_MOVE && pBoard[2] == BLANK && pBoard[3] = CPU_MOVE)// X_X// ???// ???{    movespot = 2;else if (pBoard[1] == BLANK && pBoard[2] == CPU_MOVE && pBoard[3] = CPU_MOVE)// _XX// ???// ???{    movespot = 1;}pBoard[movespot] = CPU_MOVE;  


Hope this helps!


~~~~~~~~~~~
Chris Vogel
~~~~~~~~~~~

edit - Fixed the code

[edited by - Radagar on August 12, 2002 12:09:25 PM]
WyrmSlayer RPG - In Early Development
Thankee Grand master!


Wachar''s Eternity (To be changed)<-<-Me own site!
-----------------------------
Thrander<--Formerly know as Wachar
Wachar's Eternity (To be changed)<-<-Me own site!-----------------------------Thrander<--Formerly know as Wachar
quote:Original post by Thrander
Thankee Grand master!


Wachar''s Eternity (To be changed)<-<-Me own site!
-----------------------------
Thrander<--Formerly know as Wachar


Grand Master? I''m hardly an apprentice =)

I''m still learning this myself. that Tic-Tac-Toe program took about all I knew. I''m not sure I can do Tetris yet, but I''m trying.

Glad I could be of help.



~~~~~~~~~~~
Chris Vogel
~~~~~~~~~~~
WyrmSlayer RPG - In Early Development

This topic is closed to new replies.

Advertisement