I forgot about this thread. But I thought the problem was about determining a specified pattern of 4, not just that there are 4 connected blobs of the same color.
The first post states "blobs of a *specific color* in a pattern of 4", not "blobs of a color in a specific pattern of 4, and also the video example only shows a game in which any group of 4 or more blobs disappears, and there is nothing in it about pattern matching.
Of course, getting specific patterns of four leaves the question of what you do when you have groups with more than four blobs in them, e.g.:
Code:
x
xxx xxx
If that one x falls down in the gap you have a group of 7.
Either way, the basic idea for matching specific patterns is to predefine all shapes you want to check, and then check them. However you do that is up to the implementation. You could make it with some fancy function that takes a grid and a position as an input and checks from there, or you could just make one super complex function with many if conditions.
Essentially you'd define all the shapes you find in Tetris. The square (once), the long ones (horizontal and vertical), the Ts (rotate 4 times) the Ls and the Ns (for each, rotate 4 times + mirrored versions).
Then when you have a group of 4, you can easily determine the top and the leftmost blob of that group and apply all grids there until one matches.
[quote="[url=http://phpbb.mfgg.net/viewtopic.php?p=499930#p499930]TheShyGuy[/url]"]I forgot about this thread. But I thought the problem was about determining a specified pattern of 4, not just that there are 4 connected blobs of the same color.[/quote]
The first post states "blobs of a *specific color* in a pattern of 4", not "blobs of a color in a specific pattern of 4, and also the video example only shows a game in which any group of 4 or more blobs disappears, and there is nothing in it about pattern matching.
Of course, getting specific patterns of four leaves the question of what you do when you have groups with more than four blobs in them, e.g.:
[code] x
xxx xxx[/code]
If that one x falls down in the gap you have a group of 7.
Either way, the basic idea for matching specific patterns is to predefine all shapes you want to check, and then check them. However you do that is up to the implementation. You could make it with some fancy function that takes a grid and a position as an input and checks from there, or you could just make one super complex function with many if conditions.
Essentially you'd define all the shapes you find in Tetris. The square (once), the long ones (horizontal and vertical), the Ts (rotate 4 times) the Ls and the Ns (for each, rotate 4 times + mirrored versions).
Then when you have a group of 4, you can easily determine the top and the leftmost blob of that group and apply all grids there until one matches.