How to check:
If points (1,1) and (5,5) are connected? (Yes)
If points (7,1) and (7,6) are connected? (No)
If points (1,9) and (9,5) are connected? (Yes)
you need to iterate through all directions to see if there's a valid direction and if there is iterate again by calling the same sub again for the new position.