Detecting similar shapes (as in Bejeweled or Diamond Dash)

Hi people,

I am in the process of making a match 3 or more game. I have my blocks laid out in a grid, and all the blocks are accessible by a 2 dimensional table (table[x][y]). However I can’t seem to figure out how to remove surrounding set of blocks with same type as the tapped one. If it was just a match 3 game, I could easily remove them with checking the row or column the tap event has occured, however the similar blocks can be in any shape or number, much like in diamond dash.

So I’ve come to conclusion that I need to use a simple flood fill algorithm on my grid, but all the examples I have found are way above my understanding. I would be delighted to have a little hand to ease my pain and suffering.

Thank you very much,

K. [import]uid: 99031 topic_id: 34547 reply_id: 334547[/import]

I might begin by making several types of gems, something like this:
[lua]local gemTypes={
[“RedDiamond”]={
imageFile=“images/red_diamond_gem.png”,
shape=“diamond”,
color=“red”
}
[“BlueDiamond”]={
imageFile=“images/blue_diamond_gem.png”,
shape=“diamond”,
color=“red”
}
}[/lua]
And on, and on, and then randomly create gems from that “gemTypes” table, by loading the “imageFile”. When you do your checking of gems, check to see if the shape and color are alike.

As for setting up the map to see if a match is possible, I have no earthly idea how to do that. [import]uid: 147322 topic_id: 34547 reply_id: 137409[/import]

I would consider doing something more like this:

shapes[1] = display.newImageRect("diamond.png",64,64)  
shapes[1].type = "diamond"  
  
shapes[2] = display.newImageRect("circle.png", 64, 64)  
shapes[2].type = "circle"  

Then you can compare the attributes to see if they are the same.
[import]uid: 199310 topic_id: 34547 reply_id: 137443[/import]

Thanks guys, but comparing types is not a problem. I have a table of with all the data I need in it, I know which game is where, it’s type and so on. what I’m looking for is a recursive algorithm that will look up and eliminate same type gems around the tapped one. Some sort of seek & destroy, so to speak.

I think it should work something like this:

  1. Search starts at point of tap (A)
  2. Gem at point A checks 4 sides if there are gems of that type
  3. Gem at point A marks itself as checked
  4. Next gem repeats the process at step 2.
  5. Repeat until no more gem reports any same type neighbours.

Yeah, but how? How can we define which gem should be checked next? Which direction(s) can we guide the search?

Brain melt.
[import]uid: 99031 topic_id: 34547 reply_id: 137491[/import]

I might begin by making several types of gems, something like this:
[lua]local gemTypes={
[“RedDiamond”]={
imageFile=“images/red_diamond_gem.png”,
shape=“diamond”,
color=“red”
}
[“BlueDiamond”]={
imageFile=“images/blue_diamond_gem.png”,
shape=“diamond”,
color=“red”
}
}[/lua]
And on, and on, and then randomly create gems from that “gemTypes” table, by loading the “imageFile”. When you do your checking of gems, check to see if the shape and color are alike.

As for setting up the map to see if a match is possible, I have no earthly idea how to do that. [import]uid: 147322 topic_id: 34547 reply_id: 137409[/import]

I would consider doing something more like this:

shapes[1] = display.newImageRect("diamond.png",64,64)  
shapes[1].type = "diamond"  
  
shapes[2] = display.newImageRect("circle.png", 64, 64)  
shapes[2].type = "circle"  

Then you can compare the attributes to see if they are the same.
[import]uid: 199310 topic_id: 34547 reply_id: 137443[/import]

Thanks guys, but comparing types is not a problem. I have a table of with all the data I need in it, I know which game is where, it’s type and so on. what I’m looking for is a recursive algorithm that will look up and eliminate same type gems around the tapped one. Some sort of seek & destroy, so to speak.

I think it should work something like this:

  1. Search starts at point of tap (A)
  2. Gem at point A checks 4 sides if there are gems of that type
  3. Gem at point A marks itself as checked
  4. Next gem repeats the process at step 2.
  5. Repeat until no more gem reports any same type neighbours.

Yeah, but how? How can we define which gem should be checked next? Which direction(s) can we guide the search?

Brain melt.
[import]uid: 99031 topic_id: 34547 reply_id: 137491[/import]