- Home /
[Puzzle Game]Finding Combination of squares in a 2D Grid
I am making a game like Lumines Remastered (https://www.youtube.com/watch?v=8aJqNGjLtaY&t=358s) and I was pretty much successful in it. But, I got stuck in one place in clearing the pieces.
I have a 2d Array grid of 16x10 and each individual pieces are stored in it.
I was successful in finding all the matching pieces using the flood fill algorithm and storing every same color matching pieces in a separate list. Now, the condition is I only want to delete the pieces that are in combination of squares with others and not the individual ones.
For example:-
Like this. 1 is in square combination and I only want to delete them.
But,
2 in this image is also a valid square (so, 1 & 2 combined should get deleted). I quite can't seem to figure out how to check for square combination. Any suggestions and ideas would be great.
Answer by Bunny83 · Apr 03, 2020 at 01:54 PM
So you want to find 2x2 squares which are made of the same color and allow overlaps? Since you want allow overlaps you just have to do a scan and mark procedure. Just iterate through all of your tiles. For each tile you compare it to the tile x+1 , also the tile y+1 and finally x+1 and y+1. If they are all the same just mark those 4 tiles for removal. If you do that for every tile you get all tiles marked which are part of a 2x2 square. Watch out to stay in bound when doing "+1" in any direction. The last column doesn't need to be checked since the tiles in the second last column would check them implicitly.
Your answer
![](https://koobas.hobune.stream/wayback/20220612230415im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Tracking ojects grid positon 1 Answer
Puzzle open door ? 1 Answer
Question about puzzle game checking for other objects 1 Answer
Jigsaw Puzzle Drag & Drop issues. 0 Answers
Troubleshooting the spawn mechanic in a puzzle game 1 Answer