   AI in puyo puyo style puzzle game.
  I''m writing a Puyo Puyo type game and am completely stuck on writing the AI for it as I''ve never even looked at AI before.The game works like this:I have an array of the game board:var h=16;var w=12;var map=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);  and variables for the falling blocksvar x1,y1,color1;var x2,y2,color2;  and an array to store keypresses (or AI actions)KEYS[LEFT]KEYS[RIGHT]KEYS[UP]KEYS[ROTATE]  So for the computer opponent I would subsitute my player input function with something likeAI(){ //reset keys KEYS[LEFT]=0; KEYS[RIGHT]=0; KEYS[UP]=0; KEYS[ROTATE]=0; //do AI things  if(AI wants to go left)KEYS[LEFT]=1; else if(AI wants to go right)KEYS[RIGHT]=1; ..etc}   I really have no idea of how to do this.  Any help or pointers would be greatly appreciated. 
  What is Puyo Puyo? I found some flash Puyo Puyo game that looks like Tetris or more like the variant where you must get 3 colors in line. Is that it?If it is, read this:http://www.colinfahey.com/2003jan_tetris/2003jan_tetris.htmand adapt it to your game. ;  http://www.elephantsneverforget.co.uk/puyo.htmlthis is puyo puyo.A=left; S=down; D=right; M=rotateYou have to link 4 of the same colour.I''m programming it for Atari Lynx and testing stuff out in this &#106avascript version..  I find it easier to learn how to do something in &#106avascript before coding it in C.  That way I don''t have to worry about memory and things whilst worrying about how the actual game is supposed to work.  If that makes sense?Thanks for the link ;  Hi, I've also started on a Puyo clone (for a standard PC though). The game is working, but there's no AI yet. Let me know what you come up with, and I'll keep you posted onmy findings as well. [edited by - janharal on February 9, 2004 9:55:55 AM];Basically, the AI has about a dozen possible choices:Option 1. Drop the piece vertically in the first column.Option 2. Drop the piece horizontally in the first column.Option 3. Drop the piece vertically in the second column.Option 4. Drop the piece horizontally in the second column.First, you should rule out those moves that the AI can''t make because it''s not "fast enough" (these simulated opponents are supposed to have simulated "reflexes", and some are faster than others).After that, you simulate each remaining move and see how it turns out. For example, let''s say you run a simulation of dropping the piece vertically in the third column, and the result is that a whole bunch of bubbles pop on the left side of the screen, but the right side of the screen is still piled high.After you figure out how the move turns out, you have to decide how well the AI "likes" the outcome.  Different characters may respond differently.  For example, maybe the turtle character likes having stuff piled up on the right side of the screen.  How would judge this a "good move."  You''ll have to write a function that scans the screen and evaluates ''good position'' or ''bad position'' on a scale from 1-10 or something like that - a different function for each character.  Using the function, you rate each simulated move.  You pick the move which leads to the highest-rated outcome.After the character picks his move, he has to execute it.  This part is pretty straightforward: if he''s supposed to drop it vertically in the third column, you move it left until it''s in the third column, then you rotate it until it''s vertical.  Maybe, if you wanna get fancy, add a small probability that the AI will "mess up" the move (do something slightly off, like drop it vertically in the fourth column).;I''ve added a basic AI to my game now, which basically follows thesame steps as Nekhmet mentioned.For each rotation of the new piece  For each possible horizontal position    EvaluateMoveEvaluateMove gives each move a score based on how many neighbours of the same colour the new piece has and how closeto the bottom of the board the pieces fall ( preferencegiven to low positions )Obviously, this isn''t perfect as it doesn''t involve the tradeoffbetween instant "popping" of 4 blocks and "saving for later" ofbig piles. Furthermore, my implementation doesn''t take the next block into account yet. Still, even this simple implementation does give reasonable results.;  Cool! ;  Google Puyo Puyo StrategiesThis was a pretty good hit:http://www.alexa.com/browse/general?catid=6808&mode=general 