Denver & Rio Grande train AI (A freight train AI)

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

wozzar
Transport Coordinator
Transport Coordinator
Posts: 328
Joined: 27 Dec 2002 09:25

Re: Denver & Rio Grande train AI (A freight train AI)

Post by wozzar »

Lord Aro wrote:works fine for me :mrgreen:
I see he updated the file this one works.
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Brumi »

{028}
Another occurence of the terraforming problem, this time the AI drove itself into bankruptcy, that 1 train didn't have a consumer station...
hill bankruptcy.png
hill bankruptcy.png (190.25 KiB) Viewed 913 times
{030}
This one is quite a common problem when multiple instances of your AI are started. The red company's one train had a similar problem, the consumer station did not exist.
company clash.png
company clash.png (120.07 KiB) Viewed 5234 times
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Dustin »

wozzar wrote:Does this work in 0.72 because it wasn't building anything. It kept saying path was blocked.
It only works in 0.7.2 for sure. Care to post a screenshot and some details? What map, setting, newgrfs, etc.
User avatar
1009
Engineer
Engineer
Posts: 81
Joined: 22 Mar 2009 07:24
Location: Haarlem, The Netherlands
Contact:

Re: Denver & Rio Grande train AI (A freight train AI)

Post by 1009 »

I've been digging into the Unkinker-code a bit, trying to see how I could recreate the weird ant crawling path that doesn't get unkinked.
It unkinks once for every route, right? And doesn't only do Ant, but the whole path, as far as I understand. It quits when FixPath() has failed more than 10 times (broke infite loop in fixpath) -- FixPath ONLY fails if TilesAreSameLevelAndFlat( tile, path2.Begin() ) returns true. That sounds a little weird to me, shouldn't it fail if they are NOT the same level and flat?
Anyway, to recreate, we should let that function return true 10 times. I'm trying to get it to do that now x__x;;'

EDT *screams* I was right XD gosh, this has puzzled me for some time. OK, I have a scenario where it displays this behaviour three times (:P, sorry) at the first route. Takes some time to PF though, so take a cup-a-coffee meanwhile.
DandRG_lovely_route.png
(66.17 KiB) Downloaded 69 times
DandRG_UnKinkV2.scn
(8.51 KiB) Downloaded 198 times
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Kogut »

{015} Let AI pathfind when there isn't enough money
- Good idea. Probably work on it later. However, the map changes over time, so the routes would have a higher failure rate.
You can check path before building.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Vemarkis
Engineer
Engineer
Posts: 83
Joined: 06 Jan 2009 18:27
Location: Helsinki, Finland

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Vemarkis »

I like this AI, but it has some problems. Even when the minimum route lenght is set to short, it still prefers 200 to 400 tile long routes. Usually it won't have money to completely doubletrack the route, so it ends up with a huge stretch of single track. In that situation, its wasting money on a 3rd train when it will end up just being unprofitable, or very near to unprofitable which it ends up selling anyways. Is it possible for the AI to check the average time that a train waits at a signal? It could always complete the doubletracking after it has more money. This seems to be my experience in tropical climate, with NARS, and Pikka's Basic Industries & a grf that increases all the building costs with a max loan of £500,000. Many times, a DRG ai won't get off the ground cause it decides it wants this 500 tile route, which it cannot afford, and it has no trains. So it keeps waiting for more money that won't appear according to the debug log. Also, the AI does not seem to recognize a situation where 90 degree turns are forbidden which is a major downer.

Good thing I noticed is that it has a very keen eye for profitable routes, and when it does succeed in building one its train profits are usually 2 or 3 times as much as its competitors(AdmiralAI).
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Lord Aro »

its not supposed to build it completely double tracked
they're called passing tracks - the old ai did it
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Vemarkis
Engineer
Engineer
Posts: 83
Joined: 06 Jan 2009 18:27
Location: Helsinki, Finland

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Vemarkis »

Lord Aro wrote:its not supposed to build it completely double tracked
they're called passing tracks - the old ai did it
Passing loops actually. And anyways, my point was it usually has at least over 50 to 100 squares of single track at places just cause it couldn't build the passing loops the first time. I just tested by giving the AI tens of millions of pounds, and it preferred not to have that much single track.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Lord Aro »

meh :| :rolleyes:
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Michiel »

Eliandor wrote: EDT *screams* I was right XD gosh, this has puzzled me for some time. OK, I have a scenario where it displays this behaviour three times (:P, sorry) at the first route. Takes some time to PF though, so take a cup-a-coffee meanwhile.
DandRG_lovely_route.png
DandRG_UnKinkV2.scn
Dude, you are one hell of a software tester :bow:
User avatar
1009
Engineer
Engineer
Posts: 81
Joined: 22 Mar 2009 07:24
Location: Haarlem, The Netherlands
Contact:

Re: Denver & Rio Grande train AI (A freight train AI)

Post by 1009 »

Michiel wrote:Dude, you are one hell of a software tester :bow:
XD thanks. If you add in an options that a. shows PF with signals and B. enables/disables the first three lines I can also extensively bug test yours. If you want me to :).
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Michiel »

Cool :D I'm just using the library pathfinder though, but it can use some debugging aids in the form of signs showing what it's doing, that's for sure.

Dustin, sorry for hijacking your thread ;)
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Dustin »

Eliandor wrote:I've been digging into the Unkinker-code a bit, trying to see how I could recreate the weird ant crawling path that doesn't get unkinked.
It unkinks once for every route, right? And doesn't only do Ant, but the whole path, as far as I understand. It quits when FixPath() has failed more than 10 times (broke infite loop in fixpath) -- FixPath ONLY fails if TilesAreSameLevelAndFlat( tile, path2.Begin() ) returns true. That sounds a little weird to me, shouldn't it fail if they are NOT the same level and flat?
Anyway, to recreate, we should let that function return true 10 times. I'm trying to get it to do that now x__x;;'

EDT *screams* I was right XD gosh, this has puzzled me for some time. OK, I have a scenario where it displays this behaviour three times (:P, sorry) at the first route. Takes some time to PF though, so take a cup-a-coffee meanwhile.
DandRG_lovely_route.png
DandRG_UnKinkV2.scn
I love that obstacle course! I can't wait to get time to try it out. So it sounds like you had a code fix for the unkinker. Did you test it?
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Dustin »

Vemarkis wrote:I like this AI, but it has some problems. Even when the minimum route lenght is set to short, it still prefers 200 to 400 tile long routes. Usually it won't have money to completely doubletrack the route, so it ends up with a huge stretch of single track. In that situation, its wasting money on a 3rd train when it will end up just being unprofitable, or very near to unprofitable which it ends up selling anyways. Is it possible for the AI to check the average time that a train waits at a signal? It could always complete the doubletracking after it has more money. This seems to be my experience in tropical climate, with NARS, and Pikka's Basic Industries & a grf that increases all the building costs with a max loan of £500,000. Many times, a DRG ai won't get off the ground cause it decides it wants this 500 tile route, which it cannot afford, and it has no trains. So it keeps waiting for more money that won't appear according to the debug log. Also, the AI does not seem to recognize a situation where 90 degree turns are forbidden which is a major downer.

Good thing I noticed is that it has a very keen eye for profitable routes, and when it does succeed in building one its train profits are usually 2 or 3 times as much as its competitors(AdmiralAI).
NARS is supported.
Pikka's Basic Industries is not currently supported. Sounds like it works OK though.
a grf that increases all the building costs with a max loan of £500,000 is not supported and not likely to be. Be sure to turn up "fiscal restraint" all the way that might help a little.
"No 90 degree turns" is not supported, and probably never will be.


Yeah, the minimum is just that. Here is how it works in some detail.

Code: Select all

* PRODUCER LOOP
   * Pick an unused producer from the top 5.
   * Check if a station will fit without terraforming, otherise go back to start.
         * CONSUMER LOOP
           * Find the (next) closest consumer that is at least min-distance away. (If out of consumers, go to start)
           * Check if a station will fit. Otherwise go back to the top of CONSUMER LOOP.
           * Try to find a path. If that fails, go back to the top of CONSUMER LOOP.
           * Estimate the cost of the path, if to high, go back to the top of CONSUMER LOOP.
           * Build the path and the trains.
[edit]So there is Bias for shorter routes, but practically speaking middle distance routes will happen first due to the sort order. Changing the sort order based on route length would be pretty major. It might help your (edge) case where you are using a very harsh newgrf. It would have the side effect of filling the map with shorter routes that don't make as much money. The fact that the choosen routes tend to be winners is a side effect of how they are chosen.



Is it possible for the AI to check the average time that a train waits at a signal?
Not without having to check a lot.

It could always complete the doubletracking after it has more money.
In theory yes, but once trains are rolling, it's hard. It would have to recall all the trains. Wait for them to depot. Lay the passing lane. Start the trains back up. All the while it would either have to put pathfinding for new routes on hold, or have a more complex state machine to juggle more things at once. If the first route is profitable, then the second route can have passing lanes. The first route is really just to get off the ground.


Many times, a DRG ai won't get off the ground cause it decides it wants this 500 tile route, which it cannot afford, and it has no trains.
That's a bug. It shouldn't try to build a route it doesn't have enough money for. The route estimation function might need to be tweaked upwards. It should be possible for it to not find any worthwile routes, then terraform itself into bankruptcy. But if you don't see a message about lifting restrictions, it shouldn't go bankrupt.

The only thing in here I am likely to fix soon is to make fiscal restraint have more effect on routes being considered.

[edit] Maybe I should add a mission statement to the main post so it's clear what the AI is likely to support in the future.
Last edited by Dustin on 03 Sep 2009 00:57, edited 1 time in total.
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Dustin »

Kogut wrote:
{015} Let AI pathfind when there isn't enough money
- Good idea. Probably work on it later. However, the map changes over time, so the routes would have a higher failure rate.
You can check path before building.
True, but what do you do when they fail? I am just saying caching routes isn't super helpful. And the AI currently doesn't have the ability to pathfind the end of a half done, but errored route. Maybe in a later version.
User avatar
1009
Engineer
Engineer
Posts: 81
Joined: 22 Mar 2009 07:24
Location: Haarlem, The Netherlands
Contact:

Re: Denver & Rio Grande train AI (A freight train AI)

Post by 1009 »

Dustin wrote:I love that obstacle course! I can't wait to get time to try it out. So it sounds like you had a code fix for the unkinker. Did you test it?
Didn't test it yet, will soon. The code /looked/ to me as if it unkinks a maximum of 10 tiles -- I'll try it in an hour.

Edit: tested, no fix. :( must be something else.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Kogut »

Dustin wrote:
Kogut wrote:
{015} Let AI pathfind when there isn't enough money
- Good idea. Probably work on it later. However, the map changes over time, so the routes would have a higher failure rate.
You can check path before building.
True, but what do you do when they fail? I am just saying caching routes isn't super helpful. And the AI currently doesn't have the ability to pathfind the end of a half done, but errored route. Maybe in a later version.
fail - nothing wrong, you can start a new one (as so far)
OK - very good, you find route (so far: you start pathfinder)
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Vemarkis
Engineer
Engineer
Posts: 83
Joined: 06 Jan 2009 18:27
Location: Helsinki, Finland

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Vemarkis »

One bug I noticed today while running multiple DRG Ai's, sometimes one DRG AI will try to connect their line to the network of an another DRG AI. Usually this happens when it decides it has found a consumer at the same place as another DRG Ai. It will complete the tracks all the way to the another AI's station, it even finds a proper place at the junction to connect at, and then sell the route when it finds out it cannot buy trains for that route(sadly, stupid me I forgot to take a screenshot of the debug log, but thats what it said at the moment). However, this bug seems to be a rather rare instance, and quite usually they just place their stations next to each other.

[edit]here is a save where it has happened, see Blue player's station "Consumer 17". Included a list of grf's with the screenshot of the place. This time, the ai trying to connect to the other AI's station even built trains..
Attachments
InterDest Transport, 21-12-1925.sav
(1.04 MiB) Downloaded 177 times
InterDest Transport, 22-12-1925.png
(289.61 KiB) Downloaded 27 times
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI (A freight train AI)

Post by Dustin »

Vemarkis wrote:One bug I noticed today while running multiple DRG Ai's, sometimes one DRG AI will try to connect their line to the network of an another DRG AI. Usually this happens when it decides it has found a consumer at the same place as another DRG Ai. It will complete the tracks all the way to the another AI's station, it even finds a proper place at the junction to connect at, and then sell the route when it finds out it cannot buy trains for that route(sadly, stupid me I forgot to take a screenshot of the debug log, but thats what it said at the moment). However, this bug seems to be a rather rare instance, and quite usually they just place their stations next to each other.

[edit]here is a save where it has happened, see Blue player's station "Consumer 17". Included a list of grf's with the screenshot of the place. This time, the ai trying to connect to the other AI's station even built trains..
Good bug. DR&G will consider a consumer station to "exist" if it could have built one there at the start of pathfinding. So there is a race condition here. Whichever player gets to the flat spot first wins. The loser needs to figure out that it lost and do something about it.

Your screenshot also shows 17 consumer didn't hook up it's depot with track. That happens from time to time and I have no idea what causes it.
User avatar
1009
Engineer
Engineer
Posts: 81
Joined: 22 Mar 2009 07:24
Location: Haarlem, The Netherlands
Contact:

Re: Denver & Rio Grande train AI (A freight train AI)

Post by 1009 »

Dustin wrote:Your screenshot also shows 17 consumer didn't hook up it's depot with track. That happens from time to time and I have no idea what causes it.
It looks like {22}, when removing a producer route, it removes one tile too many near the consumer station.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 28 guests