   Checking for a chain. LOGIC
  Hi. Im currently working on a puzzle project with curiosity labs called Archos. I am trying to work out how i can find out if there is a chain of blocks(5 or more) of the same colour. Heres a screen shot:So from that screen shot I would want the blocks with a red line to be removed. The playfield is represented by an array. so heres what i would do if i want to remove all green blocks on the playfield i would do this.for(int y=0; y<MAPHEIGHT; y++)    for(int x=0; x<MAPWIDTH; x++)   if(Map[x][y] == TILEGREEN) DeleteBlock(Map[x][y]);Thank you for taking your time to read this and i hope you can help me.   
  I'm not sure I understand the problem, but here goes anyway. One approach might be to set up a structure of blocks to be removed - call it a deleteMe structure. Perhaps you could have one for each color, and as you iterate through the play field, add contiguous blocks of like color to it's corresponding deleteMe structure? Hmm. As I read over what I just wrote, it seems a little messy. But if I understand your screenshot, the shapes could be any combination of colors and under some predetermined condition, they are removed? Interesting. Hope that helped.   ;  Google floodfill algorithm, I think you might apply it to your problem.;Quote:Original post by vinbI'm not sure I understand the problem, but here goes anyway. One approach might be to set up a structure of blocks to be removed - call it a deleteMe structure. Perhaps you could have one for each color, and as you iterate through the play field, add contiguous blocks of like color to it's corresponding deleteMe structure? Hmm. As I read over what I just wrote, it seems a little messy. But if I understand your screenshot, the shapes could be any combination of colors and under some predetermined condition, they are removed? Interesting. Hope that helped.Thanks for the reply but I think what Fred304 suggested will help me out and is what im looking for as the game im developing is similar to puyo puyo which uses the same algorithm. Thanks again to both of you.   ;  Note that you only need to floodfill starting from the components of the most recently dropped block. Although you might find it easier to do a full scan every time anyway, considering the sorts of things that can happen with chain reactions :)One option is to assign a "group ID" member to each block, and somewhere else maintain a mapping of group ID to group size. Then when a block falls down, all you do is see if the block touches any groups of the same colour, and if so, add to the current group (possibly merging groups if you touched more than one of the same colour at once). When a group gets too big, remove all the constituent blocks.   