### Thread: C# - Find Adjacent Number Groups Of 3 Or More In 2d Matrix

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
May 2012
Posts
1
Rep Power
0

#### C# - Find Adjacent Number Groups Of 3 Or More In 2d Matrix

Trying to write some code to search a 2d matrix/array.
It will look for groupings of adjacent numbers of 3 or more.

So for example

1123
1245
4321

Here there is a group of 1's adjacent in the top left.

Its for a beginners game in .NET c# XNA.

for (int x=0;x<maxx;x++)
for (int y=0;x<maxy;y++)
{
// Match found
if(matrix[x,y]==matrix[x+1,y])&&(matrix[x,y]==matrix[x+1,y]))
// then match the found item
}

That is where I got stuck I couldnt see how to continue searching once a match was found..

Appreciate any help.
2. What do you want to happen?

Be careful with copy/paste:
- In you second if, you forgot to change a x to y.
- You forgot to change the index of last matrix comparison, it should be x+2.

You should also check for "out of bound" issues: x , x+1 and x+2 should never be higher than maxx.