| |
tasche Account closed
Registered: Apr 2004 Posts: 12 |
how to analyze this playfield...
just take a look at the following gfx:
as u see its a matrix of some squares. u see a bunch of yellow squares surrounded by a red line.
if i pick ONE of these squares in the bunch, the complete bunch shall be selected automaticly.
now my problem: how to calc this?
anybody out there, who got the right hint? |
|
| |
Codey
Registered: Oct 2005 Posts: 79 |
you can examine the cells adjacent of the one that was clicked. if they're the same color select them also and repeat the process for the new cells. recursively this should work although it's not very time efficient. |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
exactly. but you can skip the recursion. simply attach an attribute to each cell.
fex:
0: dont bother
1: was selected as a neighbour & same color in the prev run
2: neighbours already marked, belongs to selection.
then you do this:
0: do nothing
1: mark "0" neighbours as "1", change own attribute to 2
2: do nothing
if you run out of 1's then you're finished.
|
| |
Radiant
Registered: Sep 2004 Posts: 639 |
http://en.wikipedia.org/wiki/Flood_fill
The scanline algorithm mentioned there is AFAIK the fastest method of solving this problem, at least for larger areas. For small areas the "normal" stack based solution may be faster. |