Get the surrounding coordinate

For example I have this map
1
2
3
4
5
6
7
                 
                 
        #        
      ####       
       ##        
                 
                 

# is wall
<space> is open space

I need a function that can get all of the coordinate surrounding it..
Sorry, I don't really know how to word it

I will give example
1
2
vector< coordinate_t > getSurround( int x, int y );
getSurround( 8, 5 );


1
2
3
4
5
6
7
                 
                 
        #        
      ####       
       ##        
                 
                 



I should get

1
2
3
4
5
6
7
                 
        X        
      XX#X      
     X####X      
      X##X       
       XX        
                 


the coordinates of all the Xs

if there is no barrier surrounding it
it should return only the inputed coordinates

and also another testcase
1
2
3
4
5
6
7
8
9
10
    X#X   
   X# #X  
  X#   #X 
 X#  X  #X
X#  X#X  #
X# X#S#X#X
X#  X#X#X 
X#   X#X  
 X#  #X   
 X###X     


This problem occur in my path finding program
if the target is blocked just path find to any point where it's the area surrounding the target...

I think flood fill is the solution but I can't think of how do it.
so can anyone give me a hint ?

Thanks in advance
Last edited on
You'd use the same principle in a flood fill, but you wouldn't quite do the same thing.

For small areas you can use recursion.
I cannot grasped your answer
What is the condition for a coordinate to be a point at surrounded area ?

I know flood fill iterative form .
Topic archived. No new replies allowed.