Can you get there from here?
Posted: 08 Feb 2019 01:50
Howdy,
TL;DR Is there a simple method to test if there is a working path between two non adjacent road tiles?
I have been tinkering with an AI off and on(mostly off) for years, and recently returned to it. Looking at my own code is like a foreign language! What was I thinking? I recall getting answers to my foolish questions from this forum, so here I go again...
My AI is designed to operate with little to no meta data. It chooses what to do from it's config settings and looking at the state of the game. I had working Airport, Ship, and Bus modules, but hit the wall trying to do the Trains. Each time I get back to working on it, I end up re-writing(improving?) or starting over. I'll see it do something like build a depot but it doesn't join any road and vehicles built there just drive around inside trying to get to a station they can never reach. Or build a station and cut off the road section from the path to the station. So I am back at the buses at the moment.
It first checks for existing stations.
If there are no stations,
choose some likely town,
choose some likely neighbor town
if easily connected and
if both have likely station sites
build the stations and road connection
along with a depot, then return
next iteration:
this time it finds the stations.
loop through the stations.
if the station has no vehicles,
find a likely station to form a vehicle route with.
And here is my problem... It's possible, and in fact fairly common for it to choose a different station than the one it built when connecting the towns. I really need some method to test whether the stations are actually connected via existing roads. I do make an attempt to connect the two chosen, and no longer build the vehicle in question if that fails, so no more buses driving around town unable to get to the destination.
I tried to use a path finding lib but it ran for 21 months and returned no path.
There must be a simpler or elegant method or algorithm. I can't be the first person to desire such a thing.
Can you set me on the right path?
Thanks in advance,
Kev!
TL;DR Is there a simple method to test if there is a working path between two non adjacent road tiles?
I have been tinkering with an AI off and on(mostly off) for years, and recently returned to it. Looking at my own code is like a foreign language! What was I thinking? I recall getting answers to my foolish questions from this forum, so here I go again...
My AI is designed to operate with little to no meta data. It chooses what to do from it's config settings and looking at the state of the game. I had working Airport, Ship, and Bus modules, but hit the wall trying to do the Trains. Each time I get back to working on it, I end up re-writing(improving?) or starting over. I'll see it do something like build a depot but it doesn't join any road and vehicles built there just drive around inside trying to get to a station they can never reach. Or build a station and cut off the road section from the path to the station. So I am back at the buses at the moment.
It first checks for existing stations.
If there are no stations,
choose some likely town,
choose some likely neighbor town
if easily connected and
if both have likely station sites
build the stations and road connection
along with a depot, then return
next iteration:
this time it finds the stations.
loop through the stations.
if the station has no vehicles,
find a likely station to form a vehicle route with.
And here is my problem... It's possible, and in fact fairly common for it to choose a different station than the one it built when connecting the towns. I really need some method to test whether the stations are actually connected via existing roads. I do make an attempt to connect the two chosen, and no longer build the vehicle in question if that fails, so no more buses driving around town unable to get to the destination.
I tried to use a path finding lib but it ran for 21 months and returned no path.
There must be a simpler or elegant method or algorithm. I can't be the first person to desire such a thing.
Can you set me on the right path?
Thanks in advance,
Kev!