If you have your tiles saved in an array, you could work with that, identify adjacent tiles, add them to another array and check those adjacent tiles for objects.
the other array could look like this:
each x -> one tile
y=0: x coordinate in tile-array
y=1: y coordinate in tile-array
y=2: status (0 = searched for object, 1 = searched for adjacent tiles)
okay let's say you are at a junction at 5,5. You run your function.
The function will return
(4,5), (6,5), (5,4), (5,6). It didn't find an object, so it will look further. For each x in the array where at(curx,2) = 0 -> run the function again.
The function should only add coordinates if they are not already in your array (to prevent from going back, searching fields twice). After every adjacent tile was checked for (4,5), its y2 is set to 1.
The search/loops are stopped once an object was found or no new adjacent tile was added to the array. After that the array is cleaned up (set size to 1,1,1 I guess).
This makes sense. I'm using a recursive function to do this, but I think I've created an endless loop, because the preview tends to crash.
<img src="http://i.imgur.com/z31L2q1.png" border="0" />
The values in the BoardSpaces array contain the UID of the grid tiles. It's -1 if it doesn't exist.
<img src="http://i.imgur.com/rjuv2OV.png" border="0" />
My goal is to have the function recursively loop through the squares until it finds a player object, in which case ComputerTarget is set to that UID and the function should stop running. However, in my testing I get an endless loop and the program crashes.