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

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 » 16 Mar 2010 16:58

Morloth wrote:Hi Dustin,

I was running a game with Denver & Rio Grande in it and I came across the following construction:
Unnamed, 13th Mar 1951.png
Hope you'll be able to fix it! :)
Thanks for the report Morloth. Saddly I don't see me being able to spend much time on the AI in the foreseable future. I spent a large part of a long vacation on it last time. (Saved vacation for years!). Now it's back to the grindstone for 5 more years or so before my next long vacation. I may get some slack time to take a look.

The problem you see actaully happens sometimes. The AI has a little trouble with certian elevations around a station. The route won't work and it will destroy it eventually.

-D

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 » 16 Mar 2010 17:21

One more problem - without industries AI crashes. But it isn't real problem because without industries it is unable to work.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2365
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

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

Post by Lord Aro » 14 Jul 2010 08:28

massive bump to report a bug:
Attachments
denver crash.png
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
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 » 14 Jul 2010 17:48

Lord Aro wrote:massive bump to report a bug:
Can you give me some details? What version of TTD, What GRFs, What settings? Those little round buttons on the AI menu don't look familiar...

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

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

Post by Zuu » 14 Jul 2010 22:01

The round buttons at the top of the window is the buttons for different AIs. They are probably square-shaped with the original TTD graphics. He uses OpenGFX (you can get it via in-game content downloader and then switch graphics set in game options).

The extra debug controls at the bottom are docummented at the wiki: http://wiki.openttd.org/AI:Need_To_Know ... og_message
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2365
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

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

Post by Lord Aro » 15 Jul 2010 18:13

r20131
denver crash newgrfs.png
if the ai isn't supposed to support ECS yet then don't worry about it (except perhaps stop it from crashing ;) )
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
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 » 16 Jul 2010 16:52

Lord Aro wrote:r20131
denver crash newgrfs.png
if the ai isn't supposed to support ECS yet then don't worry about it (except perhaps stop it from crashing ;) )
Yeah, it doesn't support ECS. I don't plan on revving the AI anytime soon. It's working about as well as I hoped and I am on to other projects. I may come back and do more in the future. So, sorry, it's just gonna crash on ECS. :oops:

-D

User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2365
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

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

Post by Lord Aro » 02 Oct 2010 12:10

another massive bump (again by me :P )

D&RG still can't handle bridges that well:
denver bridge problem.png
denver bridge problem.png (32.09 KiB) Viewed 3708 times
in this case it was it's first route and so bankrupted the AI
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
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 » 04 Oct 2010 17:13

Lord Aro wrote:another massive bump (again by me :P )

D&RG still can't handle bridges that well:
denver bridge problem.png
in this case it was it's first route and so bankrupted the AI
Yeah, I never did figure that one out. It's a stumper. The good news is the next railroad should do better since the bankrupt one leveled some ground for it!

User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2365
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

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

Post by Lord Aro » 04 Oct 2010 17:28

Heh.
When i get to the point where i can't figure out a bug, i just end up re-writing the code
But i guess re-writing a pathfinder takes time...
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

aleatorylamp
Engineer
Engineer
Posts: 5
Joined: 01 Apr 2011 18:36

Some Denver & Rio Grande trains can´t find way out

Post by aleatorylamp » 01 Apr 2011 19:15

I´ve been trying out the different AI´s and I am impressed with their different behaviours. Good work, and thank you very much!
When I use Denver & Rio Grande AI, (Open TTD 1.0.5, this AI by itself, 256x256 territory, any climate, no extra GFX) these trains often seem to get lost in consumer stations, endlessly moving back and forth without finding their way back to the main track. The AI then builds more trains at the provider whhich then queue up at the consumer. Eventually the depot fills up and the AI sells the trains after years without having got more than one haul out of each. However, in some games, they work perfectly! It does not seem to depend on the angle of the main track relative to the station, nor on the climate or on the engine type - steam or Turner, no matter... The debug console offers no information either. However, maybe it´s my fault and I´m doing something wrong without knowing...
I just thought that the developer might be interested to know.
Anyway, thank you very much to the developing team for this interesting, absorbing and well developed game, and their efforts to making it better all the time!
With kind regards,
Aleatorylamp

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

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

Post by Yexo » 01 Apr 2011 19:59

I've merged your post in the correct AI topic. If it happens consistently in some games and not at all in other games posting a few savegames (1 or 2 in which is always happens, 1 or 2 in which it never happens) might help Dustin find out why it doesn't work in some cases.

aleatorylamp
Engineer
Engineer
Posts: 5
Joined: 01 Apr 2011 18:36

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

Post by aleatorylamp » 01 Apr 2011 22:06

Hello again, and thanks for re-routing my post to the correct thread - I do beg your pardon...

I believe I have found the possible origin for this strange behaviour - i.e. trains oscillating back and borth in stations etc..: If the train has to follow, or decides it wants to follow, a route involving a 90 degree turn, e.g. into or out of a depot, even though it there´s a second track without a 90 degree turn, it will get stuck and revert to going back and forth UNLESS the rather non-realistic 90 degree turns are enabled! (see images 2 and 3 with 90 degree turns disabled).

Also, because of the way the track route connectivity is thought out in this AI, (albeit rather practical and ingenious for many reasons), when a twin track route hanges to single track for a spell due to geological reasons, or the presence of another company´s track (see image 1 with 90 degree turns enabled), depending on the orientation of the twin track route, the twin-to-single track changeover may include one or even two obligatory 90 degree turns for a train coming down one of the tracks - but not so in the opposite direction!

Well anyway, this has had me foxed for four whole days now, but I think that´s what´s going on.
Anyway, this will probably help Dustin. Might it be a good idea to include a comment as to the necessity of enabling 90 degree turns in the AI´s descriptive text? That would be easier than to teach the AI to avoid laying tracks with 90 degree turns...

With kind regards,
Aleatorylamp
Attachments
Image2.jpg
Image2.jpg (114.6 KiB) Viewed 3442 times
Image3.jpg
(123.4 KiB) Downloaded 1 time
Image1.jpg
Image1.jpg (34.52 KiB) Viewed 3442 times

User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2365
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

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

Post by Lord Aro » 02 Apr 2011 10:23

Yes, this is a known bug with the AI, and is basically unfixable, due to the way Dustin's pathfinder works.

I think the best solution would be to add a check that the 'disallow 90° turns' setting is off that stops the AI if not
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

Dwachs
Engineer
Engineer
Posts: 46
Joined: 02 Jun 2005 07:28

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

Post by Dwachs » 02 Apr 2011 14:37

What about adding more track bits to the second tile of the single tracks?

aleatorylamp
Engineer
Engineer
Posts: 5
Joined: 01 Apr 2011 18:36

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

Post by aleatorylamp » 02 Apr 2011 20:41

That would definitely help. Also, perhaps also if the single track came out one tile to the left.

I know I´m ignorant in writing AI and I greatly respect those who do it, so my suggestions are probably of limited value, but I will venture to explain what I can see:

With the ingenious and practical way D&RG connects tracks, the intention is obviously to have "universal joints" to connect tracks and stations and when changing from double to single or vice-versa. Often, this works without the need of 90 degree turns, but as we are saying, not always.

Also, placing depots adjacent and parallel to stations will force 90 degree turns. However, placing them opposite one of the platforms, in line with it and just after the signal, they wouldn´t need 90 degree turns. Of course, this would occuppy one more tile, so if there´s an obstacle, the station would have to be placed one tile further away.

Here´s a screenshot of some connections that work without 90 degree turns and some that don´t - obviously it also depends on signals being inside or outside a double double track - although it is sometimes irrelevant, depending on the angles.

The problem arises, however, when the single track comes out of the "universal joint" on the OPPOSITE side of the side the single track is turning to. If the AI could only just handle the correct side for these turns, it would work.

In the screenshots I have marked the alternative routes in red, as well as the position of the depot. Now, what I don´t know, is whether the AI can be made to decide to connect the single track to the "universal joint" on the end of the track closer to where the single track is going.

Perhaps my humble suggestion will help...

Cheers,
Aleatorylamp
Attachments
juntion connectivity.jpg
(224.55 KiB) Downloaded 1 time

aleatorylamp
Engineer
Engineer
Posts: 5
Joined: 01 Apr 2011 18:36

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

Post by aleatorylamp » 02 Apr 2011 20:59

Sorry, sorry...in the left picture in the second row, the red line still makes a 90 degree turn... the double track would have to move left one tile to make room to get around the copper ore mine without a 90 degree turn... More for the AI to figure out, but perhaps not impossible...
Cheers,
Aleatorylamp

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 » 02 Apr 2011 22:10

aleatorylamp wrote:Sorry, sorry...in the left picture in the second row, the red line still makes a 90 degree turn... the double track would have to move left one tile to make room to get around the copper ore mine without a 90 degree turn... More for the AI to figure out, but perhaps not impossible...
Cheers,
Aleatorylamp
Thanks for taking an interest in my AI. It's been a long time since I worked on it. Thanks for the thoughtful and detailed feedback! Saddly I just don't have the time to work on this project anymore. I am really proud of what I released. It met the goals I set out to achieve. Primary among them was to explore an "ant swarm" pathfinding solution and compare it computationally to to a generic algorithm like A* and to genetic algorithms. It that sense I was very successful and I learned a lot. It was also interesting programming in such a limited environment where algorithm choice really makes a difference.

The next "feature" of the AI that I was planning was a track analyzer that could spot and fix up problems in the track. Maybe by using an A* algorithm to double check connections and fix up problem areas.

If you check the first post I think burried in there someplace is the fact that "90 degree turns" must be allowed. You have discovered that support for that feature is probably do-able, I never really thought much about it. One of the interesting things about computer AI are things that are so easy for humans to see and so hard for computers to understand. 90 degree turns are in that catergory. It takes a lot of code to smooth out those turns.

I won't be working on this program in the foreseable future (unless you know how to get me a grant to work on computer AI!). I do encourage you to crack open the code and experiment with it. You may be able to adjust the station creation section to be a little smarter about hooking up tracks. That part of the code is basically a lookup table that plops down a pattern for the station. The "universal connectors" were just lazyness on my part. But it allows one generic station footprint to have tracks go off in about any direction.

Thanks agian for the interest and feedback. I am really sorry I don't have time to take up your suggestions.

-Dustin

aleatorylamp
Engineer
Engineer
Posts: 5
Joined: 01 Apr 2011 18:36

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

Post by aleatorylamp » 04 Apr 2011 09:28

Thank you for your detailed an interesting reply. Indeed things seem easier to decypher seen from a human eye than from a computer´s, and I had already thought that there wasn´t an easy solution.
Anyway, the D&RG AI definitely works andis enjoyable to use, so the fact that 90 degree turns must be enabled is only a minor issue - even if it did take me 4 days to figure that out! All in all, it is not so important, and as you say, it does what it is supposed to do! Thanks again for you reply.
Cheers,
Aleatorylamp

oxyk
Engineer
Engineer
Posts: 29
Joined: 04 May 2012 06:51
Location: ukraine

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

Post by oxyk » 07 May 2012 03:39

i discovered one funny glitch. when playing small map (128x128 or 64), AI tries to build HQ and spend years ingame to find right spot. it just writes debug lines and keep trying. i left it for 10 ingame years and it never found that spot to build. not to mention it outputs debug text as crazy, and eats CPU for nothing. would it be possible to create array of possible coordinates and save it in table? then run 100 queries, remove bad coordinates from table, save and try in a month or year again. or do the opposite - save bad coordinates. i don't mind it spam in debug window, but also it does nothing in game, so become useless.

you said you're discontinuing support for the AI? anyone can crack the code or someone already working on it?

thank you,
oxyk

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 4 guests