A pathfinding problem: how to tell water-road situation?

Hello. as you see, there is a map pathfinding problem.

The yellow tiles in the map are the Land, and blue ones are the ocean. The red font means there is a waterway, and the green font means there is a road. The correct path should be linked as road-road, waterway-waterway, road-harbor-waterway or waterway-harbor-road. Therefore,

2,6City can link to 2,4City via (2,6City)-(1,6)-(0,6)-(1,5)-(2,5)-(3,4Harbor)-(2,4City) ,

2,6City can link to 0,0City via (2,6City)-(1,6)-(0,6)-(1,5)-(2,5)-(3,4Harbor)-(2,4City)–(1,4)-
(0,3City)-(0,2)-(0,1)-(0,0City),

2,6City can link to 3,0City via (2,6City)-(1,6)-(0,6)-(1,5)-(2,5)-(3,4Harbor)-(3,3)–(3,2)-
(4,1Harbor)-(3,0City).

However, when I use GKGridGraph to create a map for Pathfinding, I don’t know how to tell the situation that waterway is not accessible to road. You can see, I DON’T want:

2,6City can link to 2,4City via (2,6City)-(2,5)-(2.4City) or

2,4City is linked to 2,2City because (2,4City)-(3,4Harbor)-(3,3)-(3,2)-(2,2City)

So, any suggestion? Thanks a lot.

截屏2021-12-18 下午1.09.07

First remove all non-navigable cells (Black), and ignore background colors
then go over grid constructing green and red networks, joining green to green and red to red(by examining nearest-neighbors).
Then join green and red where City is nearest-neighbor to a Harbor .
You can now traverse between any two points via the graph of connections.

thanks, I would try that.

This topic was automatically closed after 166 days. New replies are no longer allowed.