finding chains in a Multiarray?

Blitz3D Forums/Blitz3D Programming/finding chains in a Multiarray?

God Im stuck total mental block

I have an array

Dim Grid(10,10)

this contains values between 1 and 9

I am desperate need of a function to find the largest horizonal and vertical chains of identical values
and have it output the Number of chains and each ones size
for animation and scores
when a chain have been found I want to set all value involved to 10

any ideas would be welcome

start with something like this and work with it:
this shows checking rows...
Dim chainlength(100)
numchains = 0
For y = 1 to 10
	For compare = 1 To 10
		thisspot = Grid(compare, y)
		count = 1
		If thisspot < 10
			For iter = 1 To 9
				If thisspot = Grid((compare + iter) - 10 * ((compare + iter) > 10), y)
					count = count + 1
					Grid(compare, y) = 10
					Grid((compare + iter) - 10 * ((compare + iter) > 10), y) = 10
				Else
					Exit
				EndIf
			Next
		EndIf
		If count > 1
			numchains = numchains + 1
			chainlength(numchains) = count
		EndIf
	Next
Next
Of course this code corrupts the grid (for checking columns later). To work around that, you can modify the code or create a copy of the grid first.

Function Check_StartGrid()
Dim Ngrid(10,10)
Dim Ngridr(10,10)
Dim Ngridc(10,10)
  For x=1 To 10
    For y=1 To 10
     Ngridr(x,y)=Grid(x,y)
     Ngridc(x,y)=Ngridr(x,y)
     NGrid(x,y)=Ngridr(x,y)
    Next
  Next

numchains = 0
For y = 1 To 10
	For compare = 1 To 10
		thisspot = NGrid(compare, y)
		count = 1
		If thisspot < 10
			For iter = 1 To 9
				If thisspot = NGrid((compare + iter) - 10 * ((compare + iter) > 10), y)
					count = count + 1
					NGrid(compare, y) = 10
					NGrid((compare + iter) - 10 * ((compare + iter) > 10), y) = 10
				Else
					Exit
				EndIf
			Next
		EndIf
		If count > 2
			numchains = numchains + 1
			chainlength(numchains) = count
		EndIf
	Next
Next

For x=1 To 10
For y=1 To 10
Ngridr(x,y)=Ngrid(x,y)
Ngrid(x,y)=Ngridc(x,y)
Next
Next

For x = 1 To 10
	For compare = 1 To 10
		thisspot = NGrid(x,compare)
		count = 1
		If thisspot < 10
			For iter = 1 To 9
				If thisspot = NGrid(x,(iter + compare) - 10 * ((iter + compare) > 10))
					count = count + 1
					NGrid(x,compare) = 10
					NGrid(x,(iter + compare) - 10 * ((iter + compare) > 10)) = 10
				Else
					Exit
				EndIf
			Next
		EndIf
		If count > 2
			numchains = numchains + 1
			chainlength(numchains) = count
		EndIf
	Next
Next

For x=1 To 10
	For y=1 To 10
		Ngridc(x,y)=Ngrid(x,y)
		If Ngridc(x,y)=10 Then 
		Grid(x,y)=Ngridc(x,y)
		ElseIf Ngridr(x,y)=10 Then
		Grid(x,y)=Ngridr(x,y)
		EndIf
	Next
Next
End Function


does this seem allright to you my good friend Wolron thanks for the post :)