C++

CheckTile( x-1, y ); // to the left CheckTile( x, y-1 ); // the one above CheckTile( x+1, y ); // to the right CheckTile( x, y+1 ); // the one belowRemember to make certain the position passed into CheckTile is valid - negative coordinates are not valid for example. If you need to check the adjacent tiles at 45-degree angles also then those would be at positions (x+1,y+1), (x+1, y-1), (x-1,y-1), and (x-1,y+1).

This is just a basic algorithm. You will likely need to pass more parameters and return something useful from the function.

To do what you described then order the search in a way that makes sense and return when the first one is found. For example, you could check in a clock-wise direction beginning with the one above. The key is to write very basic functions that you can easily arrange to make the logic work the way it needs to.