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

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

Post by Dustin »

Brumi wrote:The same game is still running, and I encountered this:
The trains can't get back to the producer station because of the one-way signals.
Anyway, both companies are doing nicely, and it seems that with the default train set a lower fiscal restraint is much better.
EDIT: about the random names, I didn't mean the random generation of them, I really like the concept with the historical railway lines, I intended to say that only the ORDER of them should be randomized. I'm saying this because then it's quite improbable that the 'Colorado Kansas & Oklahoma' will appear in the game. Sorry for any misunderstanding.
Thanks for the reports. Did you see, even though I forgot to fix the typo, I added your name to the credits?

I think there may be a bug where it didn't find any routes to 28 consumers without even firing up the pathfinder. Good report.

As for the disjointed passing rail, I though I had those bugs all fixed! Another good catch. I need to design a scenario where that happens on the first route so I can experiment with it. On the plus side, the AI will figure out the route is no good in a couple of years and remove it.

I knew exactly what you meant for random names. It was a good idea and I will add it for V1.
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

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

Post by Brumi »

Dustin wrote:Did you see, even though I forgot to fix the typo, I added your name to the credits?
Yes, I saw that, thanks :)
Dustin wrote:On the plus side, the AI will figure out the route is no good in a couple of years and remove it.
As I saw it worked correctly, the AI deleted the route nicely after a few years. There was no trace of that disjointed passing lane afterwards...
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 »

RC17 posted
  • Fixed "grande" typo.
  • Added an option for random names.
  • Added steps and labels to options.
  • Add code to fix some of the disjointed passing lanes.
  • Added a little terraforming to bridge to allow it more chances to create bridges.
  • Add messages to indicate why routes to consumers have failed.
  • Fixed some bugs in the station leveling system.
  • Level should be a little less agressive now, but could probably use more work.
  • Fixed a bug preventing trees from ever being planted.
  • Fixed bug causing farm stations to build too many of one train type and none of another.
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

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

Post by Brumi »

Hi Dustin,
Nice! :) It's good to see a new version again. Is that a new feature that the AI runs both livestock and grain trains on a farm's line? Or just I didn't notice it? I think it's very good that it does so. :)
I noticed something for the first time:
The AI built a line trying to transport steel from a steel mill which wasn't supplied at all. Here' the picture:
steel problem.png
steel problem.png (215.03 KiB) Viewed 1710 times
At least it was a good test for removing an unprofitable line :)
If that's a clue, that particular company was transporting iron ore somewhere else (but not too far away), to a steel mill which was marked 'station won't fit.' But probably it has no connection to the case.
And... may I ask you to implement building the HQ? I know there's no point in that, I just miss 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 »

Brumi wrote:Hi Dustin,
Nice! :) It's good to see a new version again. Is that a new feature that the AI runs both livestock and grain trains on a farm's line? Or just I didn't notice it? I think it's very good that it does so. :)
Really more of a bug fix. It's been a problem for a long while. At some point I need to add code to estimate how many trains a particular production needs so grain trains won't block livestock trains if the grain production drops while the livestock production explodes (or vice versa).


I noticed something for the first time:
The AI built a line trying to transport steel from a steel mill which wasn't supplied at all. Here' the picture:
steel problem.png
At least it was a good test for removing an unprofitable line :)
If that's a clue, that particular company was transporting iron ore somewhere else (but not too far away), to a steel mill which was marked 'station won't fit.' But probably it has no connection to the case.
Good catch. The AI stack ranks the industries be production * value of goods produced. Then it picks one of top ones and marks it off the list. The AI should ignore industries that produced 0 last month. I wish there was a way to see production last year (without having to stop and gather it every month) so the AI could be smarter about secondaries.

And... may I ask you to implement building the HQ? I know there's no point in that, I just miss it...
Just for you I will try to release a version with HQ today.
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 »

RC 18 posted
  • Coming very close to V1.0 shipping now.
  • Added callback to pathfinder to allow the management routines to run during pathfinding.
  • Cleaned up the log a little.
  • Added a headquarters manager to place company HQ at game start now. (just for Brumi)
  • Made paydown of loan happen in one step instead of a loop.
  • Fixed bug where AI would take a loan when it had plenty of money.
  • Now scores industries with multiple cargos as one instead of N.
  • No longer consider building routes to producers with 0 production last month.
  • Fixed a bug where trains were repeatedly sent to the depot.
  • Trains now get named.
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

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

Post by Brumi »

Hi Dustin,
I've been testing RC18 and I didn't find bugs so far, good work! :) The only problematic thing I found was that the AI failed to build a passing lane for a line, which was quite short. (sorry, I have no screenshot for that) Anyway it's working nicely, so I think v0.1 should be really close 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 »

Brumi wrote:Hi Dustin,
I've been testing RC18 and I didn't find bugs so far, good work! :) The only problematic thing I found was that the AI failed to build a passing lane for a line, which was quite short. (sorry, I have no screenshot for that) Anyway it's working nicely, so I think v0.1 should be really close now.
Passing lanes are hit or miss, especially on short lines. There needs to be some flat spots to hook them up with the main track. If cash is low the AI will skip them on purpose, but it never goes back for them later.

Thanks for testing and reporting.
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 »

Hello,

I found a bug in V18 {000}. It failed to build (or removed afterwards, can't really tell) the connection rail. I've included a screenshot and the savegame.
D&RG missing rail
D&RG missing rail
DandRG-railbug_1962.png (48.37 KiB) Viewed 4600 times
Attachments
DandRG-railbug_1962.sav
(412.67 KiB) Downloaded 143 times
Last edited by 1009 on 23 Aug 2009 21:41, 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 »

Eliandor wrote:Hello,

I found a bug in V18. It failed to build (or removed afterwards, can't really tell) the connection rail. I've included a screenshot and the savegame.
DandRG-railbug_1962.png
Very interesting. Thanks for the report. The whole station should be flat. Bridge might have raised those tiles. Is stuff like this happening a lot? Those tiles around the station should have been flattened. It's strange that they are raised.

EDIT: It may also be because the bridge ends 1 tile before the station. Still those tiles should be flat!
User avatar
lawton27
Tycoon
Tycoon
Posts: 1418
Joined: 03 Aug 2009 14:29
Location: Manchester

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

Post by lawton27 »

I've spotted a small bug, the ai has built a station which is poorly laid out and for some reason the trains can't figure out how to exit, mabe solve this with waypoints.

P.s will you be adding support for UKRS?
Attachments
Dustin bug.sav
(1.43 MiB) Downloaded 147 times
bug, 14th Nov 1997.png
bug, 14th Nov 1997.png (157.15 KiB) Viewed 1684 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 »

lawton27 wrote:I've spotted a small bug, the ai has built a station which is poorly laid out and for some reason the trains can't figure out how to exit, mabe solve this with waypoints.

P.s will you be adding support for UKRS?
This isn't a waypoint problem. Check the tracks for a break someplace down the line. If you use YAPF, the trains won't even get close in that situation. Passing lanes sometimes still fail. This route is just doomed and the AI will clean it up in a couple of years.

Have you tried UKRS? It might work. If it doesn't let me know what goes wrong.
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: Very interesting. Thanks for the report. The whole station should be flat. Bridge might have raised those tiles. Is stuff like this happening a lot? Those tiles around the station should have been flattened. It's strange that they are raised.

EDIT: It may also be because the bridge ends 1 tile before the station. Still those tiles should be flat!
It's doing weird stuff with Terraforming a lot. Sometimes, near a D&RG station, a hole appears. I'll take a screenie instead of fixing it for him next time.
I'm quite positive it's D&RG, but it may be another AI (I always play with 2 or 3 more.)
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 »

New release "D" added to main page. It may not be as stable as previous releases. Please report any crashes.
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 »

lawton27 wrote:I've spotted a small bug, the ai has built a station which is poorly laid out and for some reason the trains can't figure out how to exit, mabe solve this with waypoints.

P.s will you be adding support for UKRS?
Actually you have forbid thet 90 degree turns and the AI builds them from time to time
Image
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 »

New behaviour, "consumer station already exists"? Haven't encountered it in your previous versions yet, but haven't played it one on one before either.
One consumer two producers.
One consumer two producers.
DandRG_Wund_one_consumer.png (40.86 KiB) Viewed 4490 times
I decided to give this release a headstart, put it on play and got some breakfast. I'll make sure not to do that again:
EDT 3: in 1984 without buying anything extra I overtook the AI again.
D&RG Graphs (Blue me, Red D&RG)
D&RG Graphs (Blue me, Red D&RG)
DandRG_Wund_graphs.png (10.35 KiB) Viewed 4491 times
I've noticed a flaw in pathfinding (and terraforming, see next post) though:
Pathfinding flaw
Pathfinding flaw
DandRG_Wund_pathfinding.png (198.81 KiB) Viewed 1683 times
You may want to consider running Ant after Bridge to see if it can get any better results. Only let Ant run for a short while, then. It should've discovered the non-bridge route. It's really great, though, that it always decides not to build bridges in passing lanes, only on straight / easy tracks.

Suggestions:
= you've made a "consumer station already exists". What about a "producer station nearby with same (type of) consumer"? That way it can easily connect two farms to the same factory and make a small network.
= EDT: oh, and about the log: if you include the tile ID before pathfinding (starting crow / bridge / ant: source tile 0xnn destination tile 0xnn) it's much easier to find out where the terraforms are happening. It might be a good idea if you also include a date with each pathfinding attempt? It only says "Still alive" every now and then, but I thihnk that can be improved.
= EDT 2: if the passing lane can be extended to the station, maybe you should let your AI consider doing so. That way there's not one tile of only one-track railway.
= EDT 4: I'm not fluent or anything in Squirrel, but when you find a consumer station that already exists within the vicinity of your producer, it always takes that one

Code: Select all

foreach(index, consumer in consumerStations)
  {
    if(consumer.industryIndex == this.industryIndex)
    {
      AILog.Warning("Station Already Exists at this consumer!");
      return consumer;
    }
  }
When it fails to find a path it doesn't seem to consider other stations. Is that so or have I overlooked something?
Last edited by 1009 on 22 Aug 2009 10:08, edited 4 times in total.
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 »

Terraforming oddities. {001}

I haven't encountered the "holes" I talked about in a previous post, but I'll be looking out for them (game is still running so I might spot it soon)

While pathfinding, it raised the land a few times. The pathfinding failed afterwards so I couldn't see whether the land it had raised was actually usefull for the path.
Terraform oddity #1
Terraform oddity #1
DandRG_Wund_terraform_1.png (42.67 KiB) Viewed 4485 times
Terraform oddity #3
Terraform oddity #3
DandRG_Wund_terraform_3.png (69.7 KiB) Viewed 4484 times
When considering a station, it flattened the land first then choose another spot. I don't know if you can work around that, but it seems like a waste of rating / money to me.
Terraform oddity #2
Terraform oddity #2
DandRG_Wund_terraform_2.png (145.17 KiB) Viewed 1674 times
Last edited by 1009 on 23 Aug 2009 21:41, edited 1 time in total.
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 »

Bug: failed to construct rail to depot (or removed it later on) {002}
D&RG trains unable to get to depot.
D&RG trains unable to get to depot.
DandRG_depot_fail.png (67 KiB) Viewed 4473 times
EDT: sorry for the bunch of reports. x__x here's something else again:

continued from the depot flaw:
Station flaw (continued from depot flaw)
Station flaw (continued from depot flaw)
DandRG_station_flaw_2.png (32.21 KiB) Viewed 4466 times
And the route it attached to it had a wrong passing lane piece: {003}
EDT 2: when it was clear the route was a net loss and the lanes where removed, you could see that it also demolished the tile southwest from the crossing. So, I think it has tried to build a corner there while it wasn't possible.
Passing lane flaw
Passing lane flaw
DandRG_passing_lane_flaw.png (50.64 KiB) Viewed 4469 times
Last edited by 1009 on 23 Aug 2009 21:42, edited 1 time in total.
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 »

Mm, too much screenshots (did I appologize for checking so much already?)

When it removed the unprofitable route (the one it actually managed to remove, where the trains could be send to the depot), it also removed an essential part of the other route. I guess it would've removed the top left crossing as well, if there wasn't any train there. {004}
Station flaw OneConsumer TwoProducers
Station flaw OneConsumer TwoProducers
DandRG_station_flaw_oneCons.png (26.9 KiB) Viewed 4461 times
EDT: build a Iron Ore - Steel line but Consumer wasn't close enough to Steel Mill. {005}
Consumer not close enough.
Consumer not close enough.
DandRG__Wund_no_coverage_flaw.png (75.32 KiB) Viewed 1672 times
EDT 2: finally! The holes I was talking about.
D&RG building a hole.
D&RG building a hole.
DandRG_hole.png (86.14 KiB) Viewed 1673 times
EDT 3: can't really screenshot this. When having nothing to do, D&RG takes a full loan / repays all / takes a full loan / repays all. It doesn't really get in the way of building, but it looks... weird. It also says "Waiting for money" while it can easily take more loan. (540k out of 1m)
Last edited by 1009 on 23 Aug 2009 21:45, 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 »

Eliandor wrote:New behaviour, "consumer station already exists"? Haven't encountered it in your previous versions yet, but haven't played it one on one before either.
DandRG_Wund_one_consumer.png
I decided to give this release a headstart, put it on play and got some breakfast. I'll make sure not to do that again:
EDT 3: in 1984 without buying anything extra I overtook the AI again.
DandRG_Wund_graphs.png
I've noticed a flaw in pathfinding (and terraforming, see next post) though:
DandRG_Wund_pathfinding.png
You may want to consider running Ant after Bridge to see if it can get any better results. Only let Ant run for a short while, then. It should've discovered the non-bridge route. It's really great, though, that it always decides not to build bridges in passing lanes, only on straight / easy tracks.

Suggestions:
= you've made a "consumer station already exists". What about a "producer station nearby with same (type of) consumer"? That way it can easily connect two farms to the same factory and make a small network.
= EDT: oh, and about the log: if you include the tile ID before pathfinding (starting crow / bridge / ant: source tile 0xnn destination tile 0xnn) it's much easier to find out where the terraforms are happening. It might be a good idea if you also include a date with each pathfinding attempt? It only says "Still alive" every now and then, but I thihnk that can be improved.
= EDT 2: if the passing lane can be extended to the station, maybe you should let your AI consider doing so. That way there's not one tile of only one-track railway.
= EDT 4: I'm not fluent or anything in Squirrel, but when you find a consumer station that already exists within the vicinity of your producer, it always takes that one

Code: Select all

foreach(index, consumer in consumerStations)
  {
    if(consumer.industryIndex == this.industryIndex)
    {
      AILog.Warning("Station Already Exists at this consumer!");
      return consumer;
    }
  }
When it fails to find a path it doesn't seem to consider other stations. Is that so or have I overlooked something?
Wow, good work spotting the new feature. I will take all these suggestions into consideration. In theory is should keep on looking if it can get to an existing station. You are looking at the loop that figures out if the already selected consumer already has a station. The code to loop through them in is Main.nut.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 3 guests