puzzling puzzle

Blitz3D Forums/Blitz3D Programming/puzzling puzzle

ThE_oMiKrOn_CaT(Posted 2003) [#1]
hi there. im making a columns type game and there are four different colors.

i have a 10 by 10 grid that i store in an array called

dim grid(9,9)

i assign a value to each place on the grid depending on the color: 1=blue 2=yellow 3=red 4=green

now i need to check if 4 or more of the same color are adjacent then i want to assign their positions on the grid to 0.

ive tried different ways (using a recursive function) but it doesnt seem to work!

does anyone have any tips or some code to share?

thanx in advance!


Anthony Flack(Posted 2003) [#2]
You want to assign their positions to zero, or their colour values?


ThE_oMiKrOn_CaT(Posted 2003) [#3]
oh sorry yeah, the color value in the grid array to 0


GfK(Posted 2003) [#4]
Something like this might work. Typed straight into replybox (untested).
For Row = 0 to 9
  For Col = 0 to 6
    c = grid(row,col)
    If (grid(row,col+1) = c) And (grid(row,col+2) = c) And (grid(row,col+3) = c)
      DeleteRow(row,col,c)
      col = 7
    EndIf
  Next
Next

Function DeleteRow(row,col,c)
  For N = col to 9
    If grid(row,n) = c
      grid(row,n) = 0
    Else
      N = 10
    Endif
  Next
  ;If the blocks above this row will fall to fill the empty spaces, add that code here.
End Function



ThE_oMiKrOn_CaT(Posted 2003) [#5]
thank GDK but this only takes the case of the block being in a row, the block could be in the form of a square, or an L shape or a verical bar of four and so on...


xacto(Posted 2003) [#6]
Treat adjacent similarly colored cells as a path and walk it recursively, trying each direction in turn. Keep a tally as you walk and make any necessary determinations when the call chain is complete.

I'd recommend, however, using an array of Types and not just a simple integer array. This way you can track housekeeping information as you walk the grid.


ThE_oMiKrOn_CaT(Posted 2003) [#7]
ok thanx xacto, good to know i was on the right track, what do u mean though about tracking housekeeping info?