Ok, I've a data structure that consists of a matrix of linked nodes, lets say 10x10. I would like to be able to choose any of these nodes arbitrarily, and - from there - process a number of the surrounding nodes following the pattern of expanding concentric squares (I used less nodes below for illustration purposes). As far as specifics go, the implementation will be in Actionscript - but feel free to answer in another language :) - and it's for a minesweeper game (specifically the feature where, if clicking on a patch of mine-less squares, they -all- get cleared regardless of irregular shape, up to the surrounding mines). It will also be event based - dispatching one for each node traversed, so the way I imagine it is that when the iterator or whatever comes across a field containing a mine, traversal would stop from going further in that direction while the rest would continue. The nodes are doubly linked to their top, right, bottom, and left neighbors, and I wouldn't be opposed to adding more links if necessary. There's probably some other way to do it, but I can think of a number of uses for this kind of solution and would like to include it in a framework I'm creating, so I'd like to walk away with something I can reuse.
first:
0 0 0 0 0
0 0 0 0 0
0 0 X 0 0
0 0 0 0 0
0 0 0 0 0
second:
0 0 0 0 0
0 X X X 0
0 X 0 X 0
0 X X X 0
0 0 0 0 0
third:
X X X X X
X 0 0 0 X
X 0 0 0 X
X 0 0 0 X
X X X X X