I’ve also been following this thread. I was hoping for more activity. I love reading about multiple solutions. It’s a complex concept.
When this was originally posted I had a few ideas and I also asked a couple of AIs. Their methods were similar.
From Gemini.
(The cropped column is Performance)
(Moderate, Extremely fast and Fast)
I like the array approach. You copy the blocks in the pieces into a 2D array as they’re added and you then you scan for empty spaces. Say either using a 2D array of 0s and 1s for empty spaces or boolean trues and falses.
This would be done inside a while event so the search could end the second a valid move was found.
Gemini suggested a nice addition. It said you could use a complex sounding variable that’s not as bad as it sounds. It would be something like an array of structures that contained an array of structures that contains the X and Y of each block in each piece. It would be an offset value like 0,0 0,1 and 0,2 for straight piece. The actual variable is tough to explain without making it.
Pieces
… Straight
… … Array
… … … Structure
… … … … X =0
… … … … Y =0
… … … Structure
… … … … X =1
… … … … Y =0
… L
… … Array
… … … Structure
… … … … X =0
… … … … Y =0
… … … Structure
… … … … X =0
… … … … Y =1
It would be much quicker to go through an array than checking for collisions. If you planned on letting the player rotate the pieces then you could have a child for each piece and each rotation.
You would scan the array that represents the board for empty spaces and then check the other spaces using the offsets. If you aligned the first blocks in the array then 0,0 would be implied although that would mean some offsets would be negative values. Like, - 1,1 or - 2,3. But that would align the first block’s position.
I also liked the binary bit masking approach but GDevelop doesn’t have binary functions. Each block would be a bit in a 16 or 32 bit number. You would then compare the bits. You could create your own functions or use Javascript. I also didn’t know how to handle the column checking. I guess you would check say the 7th bit in an array of numbers. I haven’t played around with anything using binary in a while.
I like the idea of checking the size of each opening using aabb testing but I have no clue how to implement it. It makes sense to make sure there room for a tile first.
Remember. When brainstorming there are no bad ideas. You want to create a list of as many options as possible and then choose the most practical or efficient.