Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Fri Feb 22, 2019 7:23 am

All times are UTC




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Feb 08, 2019 1:50 am 
Offline
Engineer
Engineer
User avatar

Joined: Tue Jun 21, 2011 4:30 pm
Posts: 35
Location: In Da House!
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!

_________________
I DO like a nice caboose...


Top
   
PostPosted: Fri Feb 08, 2019 3:00 am 
Offline
Graphics Moderator
Graphics Moderator
User avatar

Joined: Mon Sep 13, 2004 1:21 pm
Posts: 5338
Location: The Moon
Kev! wrote:
Is there a simple method to test if there is a working path between two non adjacent road tiles?


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.

FWIW CivilAI saves almost no data, and runs itself entirely on what it can "see" on the map.

_________________
Pikkarail.com blog | Patreon
Dev reference: NML Specs - NewGRF Specs - Savegame Internals - NoAi API - NoGo API


Top
   
PostPosted: Fri Feb 08, 2019 1:39 pm 
Offline
Engineer
Engineer
User avatar

Joined: Tue Jun 21, 2011 4:30 pm
Posts: 35
Location: In Da House!
Howdy,

your quick response is much appreciated!

PikkaBird wrote:

... run the road pathfinder a sensible number of iterations having set cost.no_existing_road to cost.max_cost.


I'm certain this is meaningful to someone with an understanding of the term "set" in this context.

Is there documentation somewhere on a level for dummies? I have looked at the wiki and the examples were not helpful to me.

specifically...
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.

PikkaBird wrote:
If it returns no path, then there is no path.


Also good to know


PikkaBird wrote:
FWIW CivilAI saves almost no data, and runs itself entirely on what it can "see" on the map.


I will take a look at your code.

Thanks for taking the time to help out,
Kev!

_________________
I DO like a nice caboose...


Top
   
PostPosted: Fri Feb 08, 2019 5:27 pm 
Offline
Graphics Moderator
Graphics Moderator
User avatar

Joined: Mon Sep 13, 2004 1:21 pm
Posts: 5338
Location: The Moon
https://wiki.openttd.org/AI:RoadPathfinder is the tutorial.

_________________
Pikkarail.com blog | Patreon
Dev reference: NML Specs - NewGRF Specs - Savegame Internals - NoAi API - NoGo API


Top
   
PostPosted: Thu Feb 14, 2019 9:08 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4548
Location: /home/sweden
It may be as easy to do it yourself, but if you want medium to high level library with some opinions on how to do certain things, then SuperLib may be helpful. If not else to get you started and then swap out its station building code for your own if you want to dig into details.

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.

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2019 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2019.
Hosted by Zernebok Hosting.