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

Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

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

Post by Brumi »

Hi Dustin,
I tried your AI, it's quite interesting to watch, seems it will have a good future :)
Sometimes it build weird tracks, trying to outperform the old AI in its own style... :)
DustinAI, old AI style
DustinAI, old AI style
oldaistyle.png (97.71 KiB) Viewed 3635 times
I have one suggestion, that the signal marked should be a pre-signal instead of an exit-signal if the main line is coming from the direction like that in the picture, ortherwise the exit-signal is OK.
And could you tell me the meanings of the symbols used in the signs by the pathfinder?
Brumi
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

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

Post by Brumi »

The AI achieved a deadlock while I was writing my previous post.
deadlock.png
deadlock.png (65.98 KiB) Viewed 3638 times
EDIT: While I was writing, it was somehow solved, I don't know if it was solved by the AI or the automatic train reversing. Anyway, the trains took a long time sitting there...
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 »

Brumi wrote:Hi Dustin,
I tried your AI, it's quite interesting to watch, seems it will have a good future :)
Sometimes it build weird tracks, trying to outperform the old AI in its own style... :)
oldaistyle.png
I have one suggestion, that the signal marked should be a pre-signal instead of an exit-signal if the main line is coming from the direction like that in the picture, ortherwise the exit-signal is OK.
And could you tell me the meanings of the symbols used in the signs by the pathfinder?
Brumi

Classic! I might keep that "bug" in there just cause it reminds me of the old AI. :) Also, all my efforts to fix it have ended baddly. It's a result of the semi-random pathfinder I use. I had written a post-processor to unkink the line, but I didn't get it working correctly. I need more time to think the algorithm through.

As for the deadlock and the signals, I am experimenting with that. Auto Reverse will eventually put a train in the depot and fix things. Sometimes trains get stuck in the depot a long time. I wish the depot was alwasy FIFO. The problem with the station design is it's meant to allow a track from any of the corners to work. In fact, in the future I might want to hook up multiple corners. I think adding 4 more plain signal in front of the one you circled will at least fix the deadlock.

As I have mentioned before, I don't like how I make the passing lanes at all. It's way too slow when the map starts to fill up. I am working on a faster system. Saddly, my vacation is over so my AI time is now very limited.

Pathfinder Symbols:

Crow:
{.} Track here will work.
{-} track here is invalid, looking for a place along the line where it will.
{+} Last good tile along strait path
{*} (I think, since I can see the code right now) This is where the path picks up again.
{B} Bridge pathfinder start
{A} Ant Pathfinder choosen path.

So crow goes until it hits +, remembers it, goes on to * and askes if a bridge from + to * will work. If not it give + and * to Ant and runs several trials to see if there is a good way round. Crow always hands things over to ant for the last 15 tiles. Crow can make a mess in close due to the simplified method it uses to make sure the path can cross slopes. In fact it will build switchbacks sometimes that could be avioded.

Ant is the one that makes the crazy tracks. Ants make a list of all the tiles they could move into, stack rank them by distance, slope and a couple other factors, then pick one randomly favoring the best one. The first ant is set to wander a lot and is likely to at least find a route. Subsequent ants are less and less likely to wander. One with lowest cost to build wins. In the picture you sent, probably Ant 1 found a route and the rest trapped themselves in a dead end of thier own making. They never recurse back when they hit a dead end. They just give up and start a new ant.

One day I will replace ant with some simpler pathfinders. Bee (which never quite worked right due to my terrible implementation) tries to just make a box around obstacles. I have a better version partially made. I also want to create a Seagull to follow shorelines when I hit water. Ant I will save for the last resort in complex scenarios. Imagine two cities that almost overlap with an industry in the gap. Ant can sometimes handle that. However most obstacles are just standing in the middle of a clear area and a much simpler plan will get around them.

Ant is also quite slow and is the reason my passing lanes take too long right now. That and I have a minor bug where I add failed station footprints to the "no fly zone".

Thanks so much for the feedback. It's really appreciated!
Wold
Transport Coordinator
Transport Coordinator
Posts: 318
Joined: 03 Aug 2006 19:32
Skype: woldy_bg
Location: Bulgaria

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

Post by Wold »

Done this lane twice ( after reloading the AI ) and it hasn't build a train yet ( 2 years )
Attachments
Gefingbourne Bridge Transport, 13th Mar 1970.png
Gefingbourne Bridge Transport, 13th Mar 1970.png (91.4 KiB) Viewed 752 times
Image
Dezmond_snz
Engineer
Engineer
Posts: 58
Joined: 19 Apr 2009 11:50

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

Post by Dezmond_snz »

Sometimes i think that i attract AI bugs to my games like magnet! :D

Here is one.
missed track segment
missed track segment
Sindingstone Transport, 1951-12-14.png (58.41 KiB) Viewed 3482 times
Dustin, can you check errors from building each tile of track or may be this is pathfinder bug?
(using RC8 from first post)

btw, nice AI. It's interesting to observe its gameplay. :)
Russia
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 »

Dezmond_snz wrote:Sometimes i think that i attract AI bugs to my games like magnet! :D

Here is one.
Dustin, can you check errors from building each tile of track or may be this is pathfinder bug?
(using RC8 from first post)

btw, nice AI. It's interesting to observe its gameplay. :)
Thanks for that report. I too see about one of those per game. Debugging it is super hard, whenever I instrument the routes, I don't see it because building signs is really slow and perturbs the random number generator. It's almost certianly a bug in the way the ant considers slopes. It also may have to do where ant leaves off and crow takes back over. I see about 1 bad link in every 5 stations due this bug and one that causes the route to run into a depot.

I can check the route and if it fails take it back up and try again, but I have been trying to fix the actuall pathfinder issue rather than work around the problem. I actually need to do both, since towns sometimes change the landscape right as the tracks are going down and cause a route to fail.

Thanks for the complements as well!


wold wrote: Done this lane twice ( after reloading the AI ) and it hasn't build a train yet ( 2 years )
This is another known issue. Building Passing Lane is sometimes really, really slow. It can take 6-10 years or even more in the later game. I have been working on a faster replacement and am making some good progress. I tried to build trains before the passing lane, but detecting them and building around them was harder than just fixing the slowness issue. Thanks for the screenshot and the report.
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

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

Post by Brumi »

{.} Track here will work.
{-} track here is invalid, looking for a place along the line where it will.
{+} Last good tile along strait path
{*} (I think, since I can see the code right now) This is where the path picks up again.
{B} Bridge pathfinder start
{A} Ant Pathfinder choosen path.
Thank you, that makes things clear. One more thing... What is {<}?
Anyway, I like your sub-pathfinder naming concept :D
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

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

Post by Brumi »

I know you're trying to improve the currect passing lane building method, but you might be interested:
Here the passing lane is too short to be functional, causing jams.
passinglane.png
passinglane.png (113.5 KiB) Viewed 3370 times
P.S: How can I make the PNG attachments appear as only links? This might be an isssue if post larger screentshots.
Wold
Transport Coordinator
Transport Coordinator
Posts: 318
Joined: 03 Aug 2006 19:32
Skype: woldy_bg
Location: Bulgaria

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

Post by Wold »

Brumi wrote:I know you're trying to improve the currect passing lane building method, but you might be interested:
Here the passing lane is too short to be functional, causing jams.
The attachment passinglane.png is no longer available
P.S: How can I make the PNG attachments appear as only links? This might be an isssue if post larger screentshots.
When they are large enough they appear as links :)

This might sort the problem with the stations
Attachments
Fonnton Transport, 9th Dec 1970.png
Fonnton Transport, 9th Dec 1970.png (117.88 KiB) Viewed 761 times
Image
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 »

Brumi wrote:
{.} Track here will work.
{-} track here is invalid, looking for a place along the line where it will.
{+} Last good tile along strait path
{*} (I think, since I can see the code right now) This is where the path picks up again.
{B} Bridge pathfinder start
{A} Ant Pathfinder choosen path.
Thank you, that makes things clear. One more thing... What is {<}?
Anyway, I like your sub-pathfinder naming concept :D
{<} This is where crow tells Ant to go to. Same as {*}, redundant.
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 »

Brumi wrote:I know you're trying to improve the currect passing lane building method, but you might be interested:
Here the passing lane is too short to be functional, causing jams.
passinglane.png
P.S: How can I make the PNG attachments appear as only links? This might be an isssue if post larger screentshots.

Thanks for that. I thought I had a limit to the size that would prevent jams, but I now see the error of the method I used. I am indeed redoing how I make those. I will keep this report in mind as I do so.
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 »

Wold wrote:
Brumi wrote: This might sort the problem with the stations
Nice!

The pathfinder needs to be able to come out the front OR back. Otherwise I have to do a lot of work to "aim" the stations or get the tracks to go around them. Also, hanging the depot out like I do, it gets in the way. Consumer stations only have a depot to allow deadlocks to resolve. A bit of a nasty hack, that.


I was thinking of changing to this:
PBS Based Stations
PBS Based Stations
DustinAI.PBS.Station.png (20.44 KiB) Viewed 3264 times
Wold
Transport Coordinator
Transport Coordinator
Posts: 318
Joined: 03 Aug 2006 19:32
Skype: woldy_bg
Location: Bulgaria

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

Post by Wold »

Actually I mean this:
Attachments
Fonnton Transport, 22nd Nov 1979.png
Fonnton Transport, 22nd Nov 1979.png (121.85 KiB) Viewed 773 times
Image
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 »

Wold wrote:Actually I mean this:
Meant it for what though? My particular pathfinder need 4 "corners" to try. So the station with the depot in the back breaks my pathfinder. The depot in the way. It's a nice station in the picture and I see how it fixes a lot of my problems. Saddly, it creates a much more complex situation for my pathfinder.
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 »

RC9 is up. It addresses a lot of the recent issues and should work better with 2cc now.
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

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

Post by Brumi »

I'm glad to see the new version!
I made short test, and I see that the passing lane construction was improved a lot. Nice job! :)
However, I ran into some strange behaviour: (I haven't seen this in RC8)
useless rail.png
useless rail.png (112.23 KiB) Viewed 754 times
Here I saw that this railway segment was built, there were still pathfinder signs over it, but the AI seemed to do nothing. In the AI debug window it constantly said 'Waiting for money...', so I cheated and gave the AI money to see what happens. Then after some thinking, it removed the signs and the station at the end, but did not remove the rail. Maybe you know what this is.
Anyway, congratulations again for the new version!
Brumi
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 »

Brumi wrote:I'm glad to see the new version!
I made short test, and I see that the passing lane construction was improved a lot. Nice job! :)
However, I ran into some strange behaviour: (I haven't seen this in RC8)
useless rail.png
Here I saw that this railway segment was built, there were still pathfinder signs over it, but the AI seemed to do nothing. In the AI debug window it constantly said 'Waiting for money...', so I cheated and gave the AI money to see what happens. Then after some thinking, it removed the signs and the station at the end, but did not remove the rail. Maybe you know what this is.
Anyway, congratulations again for the new version!
Brumi
Thanks for the report as always. If you have a save of this game, it would really help me out.

I think what happend is the AI overeached itself for the first link. Then it ran low on money during construction. On flat maps I think this is a fairly likely outcome. In that case the company is doomed. The AI doesn't check to see if the links are too long. It relies on the fact that the pathfinder tries closer links first (but nothing closer than 50 tiles). So I haven't seen it overeach. With a low initial loan amount and a large flat map it might have problems.
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 »

RC11 posted in first post.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

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

Post by planetmaker »

could you tune your AI such that it works with 90° curves off?
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 »

planetmaker wrote:could you tune your AI such that it works with 90° curves off?
That would mean a major overhaul to the pathfinder. In order to detect you made a 90 degree turn you need to know the last 4 tiles in the path and test that you haven't doubled back. The way the ant pathfinder works makes this tricky to say the least. The unkinker should help some.

I would probably also need to overhaul my stations since I think there is a 90° turn to get the second train out.

I will consider it a feature to add once I stabilize the realease and get it uploaded to bananas.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 5 guests