finding chains in a Multiarray?

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

Duckstab[o](Posted 2005) [#1]
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


WolRon(Posted 2005) [#2]
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.


Duckstab[o](Posted 2005) [#3]


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