Moderator: OpenTTD Developers
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
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,
Yes. You run the road pathfinder a sensible number of iterations having set cost.no_existing_road to cost.max_cost. If it returns no path, then there is no path.Kev! wrote:Is there a simple method to test if there is a working path between two non adjacent road tiles?
FWIW CivilAI saves almost no data, and runs itself entirely on what it can "see" on the map.
your quick response is much appreciated!
I'm certain this is meaningful to someone with an understanding of the term "set" in this context.PikkaBird wrote:
... run the road pathfinder a sensible number of iterations having set cost.no_existing_road to cost.max_cost.
Is there documentation somewhere on a level for dummies? I have looked at the wiki and the examples were not helpful to me.
how to limit the portion of the map the pathfinder considers.
how to "set" cost.whatever
You see, I am not knowledgeable in this area, but I am teachable.
perhaps there is a library that already has a function for this purpose? find if there is an existing road path from a to z?
I really can't believe this doesn't exist.
Also good to knowPikkaBird wrote:If it returns no path, then there is no path.
I will take a look at your code.PikkaBird wrote:FWIW CivilAI saves almost no data, and runs itself entirely on what it can "see" on the map.
Thanks for taking the time to help out,
SuperLib is a collection of different helper routines which I created back in the time when I maintained two AIs and wanted to put common code in a library. It has since then evolved into a quite large library which can be useful or overwhelming depending on how much control you want over details vs medium/high level functionality. My most maintained AI is CluelessPlus which obviously do make heavily use of SuperLib.
SuperLib.RoadBuilder is for example providing an opinionated road path finder with additions over the basic road pathfinder library and do have a repair parameter which I use to check connections for broken roads but try to avoid building new parallel roads that are only slightly better than the old one.
Users browsing this forum: No registered users and 3 guests