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

Post Reply
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

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

Post by Dustin »

Update Release V1 on Bananas

Presenting the Denver and Rio Grande train AI. It's named for the railroad my grandfather worked on. That's him as the president.

Mission The goal of D&RG is to be a train focused AI that's a reasonable replacement for the "old AI" and a showcase and testbed for completely custom pathfinding. It should be profitable, robust and interesting in the default game and with popular NewGrfs.

Bugs Post


Features
  • North America themed. Prefers the NARS train set. (But supports default and 2cc).
  • Two way tracks.
  • Train management.
  • Remove stations for closed industries.
  • BSD License
  • Completely custom pathfinder that is much faster than the default rail pathfinder.
  • Minimal terraforming.
  • Mostly Non-network style connections (sort of like the Old AI).
  • Pathfinder uses 3 sub-pathfinders.
  • Main pathfinder is "as the crow flies" CrowPathFinder that heads directly for the goal (watching slopes to ensure tracks can be built). This is the key to speed since most of the time this is all you need.
  • Bridge and Ant pathfinders are secondary. Bridge just tries to bridge gaps the crow detects. If bridge fails the ant (slow and similar to A*) wanders around trying to find a path.
  • Poor to decent code. I was more interested in making it work than making the code very good.
  • There are settings for a "verbose" mode so you can see the pathfinder in real time.
  • 2cc compatible, but don't expect it to turn a profit on rough or hilly maps with default costs. The engines in that set are really expensive. Turn up fininacial restraint to high for best results.
  • Reuse of consumer stations for mini networks.
  • Untested with non-default industry grfs.
  • Lots of user tweakable settings.

Non-features (I.E. Don't ask please, they aren't planned anytime soon.)
  • "no 90 degree turns".
  • industry newgrfs.
  • dealing with newgrfs that are financially challenging. Low loans, increased building costs, ect.
  • non-trains. (Though some limited bus capability might be forthcoming).
  • Support for versions other than the current stable release. (0.7.2 at this time)
Please check it out. If it crashes, please let me know.

Save games or custom scenarios where bugs show up early (and after issueing a "restart" command) are VERY helpful.

Thanks to the AI API developers! It's really good.
Thanks to the other AI authors for help, examples, inspiration and encouragement.
Thanks to Brumi, Eliandor and Sirkoz for lots of bug reports.
Attachments
DustinAI_PBS_Station.png
DustinAI_PBS_Station.png (20.44 KiB) Viewed 26001 times
Last edited by Dustin on 02 Oct 2009 19:18, edited 38 times in total.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Denver & Rio Grande train AI

Post by Yexo »

Got an error pretty fast: Index Depot doesn't exist (main.nut, line 150). Changing line 331 to return null instead of false fixed it. Other than that I haven't really done much testing. It doesn't seem to work without NARS, as it build an engine without any wagons.
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI

Post by Dustin »

Yexo wrote:Got an error pretty fast: Index Depot doesn't exist (main.nut, line 150). Changing line 331 to return null instead of false fixed it. Other than that I haven't really done much testing. It doesn't seem to work without NARS, as it build an engine without any wagons.
Thanks for the report. I will look into it. I don't see how you could test it much more in the 30 minutes since I uploaded it. :)

By the way: Super awesome good job on the API! It's really nice. I have worked with a lot of "real" api's and I wish they were all as nice as this one.
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Denver & Rio Grande train AI

Post by fanioz »

Dustin wrote: Thanks for the report. I will look into it. I don't see how you could test it much more in the 30 minutes since I uploaded it. :)
Thats why his name is Yexo. (he even hack my hundreds line of code into just below ten :D )
your pathfinder concept seems interesting. I'll try it at home.
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: Denver & Rio Grande train AI

Post by Dustin »

Yexo wrote:Got an error pretty fast: Index Depot doesn't exist (main.nut, line 150). Changing line 331 to return null instead of false fixed it. Other than that I haven't really done much testing. It doesn't seem to work without NARS, as it build an engine without any wagons.
Fixed and Fixed in A3. You were right about needing Null there. Good eye. Also, I wasn't filtering the wagons enough, I think I was trying to build maglev wagons on regular tracks. I also had a problem with the engine since the default wagons don't list a top speed.

The AI should work with no grfs now.
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 »

Is there a recomended way to create a .TAR (on windows) instead of the .Zip to make it easier to use?
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 »

I don't know if there is a recommended way. But I have 7Zip installed with the hooks for the right-click menu enabled. So I just right click on my AI's folder and go into the 7Zip menu and select "add to archive ..." and then in the dialog I select tar-archive if it is not what I last used.

There are certainly many other ways out there. Good to know is that 7Zip is an open source software and that it is hosted at sf.net. A quick google should get you to their homepage.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
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 »

Zuu wrote:I don't know if there is a recommended way. But I have 7Zip installed with the hooks for the right-click menu enabled. So I just right click on my AI's folder and go into the 7Zip menu and select "add to archive ..." and then in the dialog I select tar-archive if it is not what I last used.

There are certainly many other ways out there. Good to know is that 7Zip is an open source software and that it is hosted at sf.net. A quick google should get you to their homepage.
Ironically, I had used 7Zip to make the zip file. I saw another post that said some tars don't work correctly, so I wasn't sure if 7zip would work. Thanks! Upload a .tar file.
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 »

I think the most common error with tars would be that people make a tar of the contents of their AI directory without including the folder itself. OpenTTD requires that the folder is included in the tar, and not just having all the files directly in the tar.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
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 »

Zuu wrote:I think the most common error with tars would be that people make a tar of the contents of their AI directory without including the folder itself. OpenTTD requires that the folder is included in the tar, and not just having all the files directly in the tar.

Whoops. I think I fixed mine. But I am having a lot of problems uploading files to the board.
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

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

Post by Zutty »

Hey interesting AI Dustin. Its quite fun to watch it do its thing.

I noticed a couple of small issues. First the TAR doesn't have a directory in it so it makes it harder to install. Second the "display signs" setting cant be turned off. In info.nut it says....

Code: Select all

AddSetting({name = "display_thinking", description = "Display signs showing what the pathfinder is thinking", easy_value = 1, medium_value = 1, hard_value = 1, custom_value = 1, flags = 0, min_value = 1, max_value = 1});
I think it should have min_value = 0, or you could change it to a boolean so it has a toggle button.
PathZilla - A networking AI - Now with tram support.
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 »

I would also suggest that debug signs are off by default, as most users would probably want to have them turned off.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
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 »

Zutty wrote:Hey interesting AI Dustin. Its quite fun to watch it do its thing.
Thanks! Glad to see someone is trying it. I tried it with PathZilla. My bridge building needs more work before they get along as well as I would like.
Zutty wrote:
I noticed a couple of small issues. First the TAR doesn't have a directory in it so it makes it harder to install. Second the "display signs" setting cant be turned off. In info.nut it says....

Code: Select all

AddSetting({name = "display_thinking", 
description = "Display signs showing what the pathfinder is thinking", 
easy_value = 1, medium_value = 1, hard_value = 1, custom_value = 1, flags = 0, min_value = 1, max_value = 1});
I think it should have min_value = 0, or you could change it to a boolean so it has a toggle button.
Zuu wrote:I would also suggest that debug signs are off by default, as most users would probably want to have them turned off.
You are both correct. I did that to get the settings to take effect so I could see the debug signs. For some reason I can see and set the settings, but the ones I pick aren't used. Whatever is defined in the Info.nut is what is used. Any hints on how to fix my settings would be appreciated. I'll look into how to make it a bool.

A6 has these changes. It's also got two days worth of improvements. It doesn't spew quite so many signs and keeps them cleaned up now anyway.

I will upload A6 now.
User avatar
Abenhor
Engineer
Engineer
Posts: 33
Joined: 08 Jul 2009 20:06
Location: Spain

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

Post by Abenhor »

Dustin wrote:I will upload A6 now.
DustinAI v6 don't build any route :(
BuildRoute() (main.nut line 200) returns false while trying only one route.
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 »

Abenhor wrote:
Dustin wrote:I will upload A6 now.
DustinAI v6 don't build any route :(
BuildRoute() (main.nut line 200) returns false while trying only one route.

)@)&$)(@$*@n. I am having terrible troubles uploading new versions to the board. One verion of A6 is bad, but I thought I had uploaded the fix. I will try to edit the main post again. In the mean time, here is A7.
Attachments
DustinAI.A7.tar
(69.5 KiB) Downloaded 655 times
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

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

Post by SirkoZ »

Dustin wrote:I am having terrible troubles uploading new versions to the board....
Why kind of troubles exactly are you experiencing when uploading these little files to the Forum? Why do you think it comes to this? I'm really curious now that you've metioned it at least two times. :-)
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

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

Post by Zutty »

WOW! :shock: This is a huge improvement. It just barely turns a profit, but it can stay alive for 20+ years, unike the last version. It builds really fast, and I like the simple RoRo stations.

I noted though that the pathfinder is perhaps a bit to eager to build bridges, as you can see in the attached screenshot.

Still, keep up the good work :)
Attachments
Unnamed, 24th Jan 1950.png
(199.75 KiB) Downloaded 136 times
PathZilla - A networking AI - Now with tram support.
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 »

SirkoZ wrote:
Dustin wrote:I am having terrible troubles uploading new versions to the board....
Why kind of troubles exactly are you experiencing when uploading these little files to the Forum? Why do you think it comes to this? I'm really curious now that you've metioned it at least two times. :-)

Mostly I have problems when I edit the first post.

Well, when I try to upload any file to it, I often get a message from IE that the connection to the server was broken. When I do manage to upload, I don't always see the list of previous files I uploaded. At least once I thought the upload worked and older version of the file was there.

It takes me 4 or 5 tries to upload anything. If I don't turn on compatibility mode, the edit window scrolls back to the top after each character I type. Each character takes half a second to show up and the whole edit window seems to jitter as I type.

The board probably works in IE7 and Firefox. But it's not too happy with IE8 I guess. I don't want to get another browser just to post. So I am sad.
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 »

Zutty wrote:WOW! :shock: This is a huge improvement. It just barely turns a profit, but it can stay alive for 20+ years, unike the last version. It builds really fast, and I like the simple RoRo stations.

I noted though that the pathfinder is perhaps a bit to eager to build bridges, as you can see in the attached screenshot.

Still, keep up the good work :)
Thanks, glad you like it. Until A7 most of the work was in the pathfinder. It had plenty of bugs to squash there I can tell you. A7 introduced an actual station manager and the ro-ro stations. They are designed to allow hookups to any front or back tile and still work.

Barely turns a profit? :P What settings are you running under? In my tests it's steadily profitable. It's nothing compared to an Airport loving AI, but not bad for trains.

I personally really like those bridges. Why go around a town (hard and slow for my pathfinder) when you can just hop over? :) It will sometimes build a useless bridge near a station if the last 20 or so tiles are along an axis.

I have improved the town aviodance in this version a lot. I use a square around each city center that the pathfinder won't enter. Keeps it from getting hung up in an inside corner of a town. The ant can't cope well with concave obstacles, so I just tell it the towns are are squareish.

I still have a route-killing bug in the ant somewhere that's devilishly hard to reproduce. It submits disjointed routes that invoke the bridge logic incorrectly and things go downhill from there.

Once I squash a few more bugs I want to improve the routes to two way track so I can build more trains for good producers. Or at least add passing lanes like from the original games AI.

Later, if I can get user option settings working, I may add bus service. However the bus service would be designed to lose money while making sure all the small towns are being grown.
User avatar
Abenhor
Engineer
Engineer
Posts: 33
Joined: 08 Jul 2009 20:06
Location: Spain

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

Post by Abenhor »

Dustin wrote:
Zuu wrote:I would also suggest that debug signs are off by default, as most users would probably want to have them turned off.
I did that to get the settings to take effect so I could see the debug signs. For some reason I can see and set the settings, but the ones I pick aren't used. Whatever is defined in the Info.nut is what is used. Any hints on how to fix my settings would be appreciated.
Your settings are working well, where used. When turning off 'display_thinking' no more path signs '{.}' appears, but for the main signs (while searching good locations for stations) you aren't using these settings.
Maybe if you use some internal list to copy these signs (while placing it) and check this list instead of the real signs you could make the same job without showing signs.

I was playing a bit more with DustinAI (v7) and I have some questions for you.

While removing signals, problematic points aren't removed. I don't know if it's a bug or a feature. If it's a bug, you can change
change line 535 in main.nut from

Code: Select all

 if(name == "{.}" || name == "{-}" ||name == "{A}" || name == "{B}" || name == "{+}" || name == "{=}")
to

Code: Select all

 if(name == "{.}" || name == "{-}" ||name == "{A}" || name == "{B}" || name == "{+}" || name == "{=}" || name == "{*}")
When a new route fails, the cost of building the producing station could be done later, and so some more money could be available for another route (lines 414 and 464 in main.nut), if you are checking the internal list mentioned before (instead of the real signs).

A bug building a new station (in the point of view, ignore the new route pathfinding):
DustinAI_0.png
Bug building a station
(232.6 KiB) Downloaded 87 times
And finally, a curious joke: I tried 2 DustinAI, and they are both trying the same routes at the same time, resulting in mixed lines (some tiles with tracks from Dustin1 and another with tracks from Dustin2). :lol:
DustinAI_1.png
2 DustinAI Minimap
(93.96 KiB) Downloaded 104 times
DustinAI_2.png
2 DustinAI Station list
(265.79 KiB) Downloaded 106 times
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest