ChooChoo, a train network 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
Michiel
Transport Coordinator
Transport Coordinator
Posts: 368
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Crop Circles?

Image

A bit of a sneak preview: I'm experimenting with restricting the rail pathfinder to a circular boundary encompassing the start and end points of the search. This mainly helps on maps with obstacles like large bodies of water, where it prevents the pathfinder from endlessly exploring the coastline trying to find a path, which may not exist, or takes too long to find. The circle shape nicely defines "reasonable" paths; it's allowed to deviate in the middle but it should leave and arrive from sensible angles. This prevents paths that travel backwards or overshoot the goal and turn back, although it would only do so if that was actually the shortest (or only) option; this change will simply reject such paths. This is fine for my purposes; there's usually plenty of other opportunities on a map, so failing a path because it's ugly or takes too long to find is fine. I prefer finding efficient, clean paths quickly.

Image

Of course, the circles made of signs are just a debugging aid, they won't be visible in the release version.
Attachments
Selection_253.png
(1.18 MiB) Not downloaded yet
Selection_252.png
(1.37 MiB) Not downloaded yet
User avatar
GoldMine
Engineer
Engineer
Posts: 122
Joined: 31 Oct 2024 20:59

Re: ChooChoo, a train network AI

Post by GoldMine »

Glad to see some new inventions regarding path finder, fast and accurate path finder is the most important thing after all.

I've implemented different solution to deal with bodies of water...
large bodies of water make paths longer than what's actual manhattan distance between 2 points, and this means trains will earn less profit, because cargo income is influenced by travel time.
Therefore I drop the path finder result if path length far exceeds manhattan distance, it's simply not worth it not only for profit but also because infrastructure maintenance will be higher for such route, and also you'll need more trains for longer routes which further adds to expenses.

It's better to drop the path and try some other route instead.
This is only if path finder succeeds to find the path within the limit of ticks that it is given to find goals.

Another more expensive option is longer bridges but it's not good for startup when cash is limited.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 368
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Pathfinding is definitely one of the trickiest parts! And frustrating because to a human it's so "obvious" but to an AI it's really not.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 368
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

New version is out with the pathfinder boundary implemented!
xarick
Transport Coordinator
Transport Coordinator
Posts: 359
Joined: 26 Feb 2015 00:52

Re: ChooChoo, a train network AI

Post by xarick »

Just a random thought: Have you considered industry tree networks? Choochoo train network seems primed for it!
Formerly known as Samu
User avatar
Captain Rand
Traffic Manager
Traffic Manager
Posts: 220
Joined: 28 Jan 2012 07:35

Re: ChooChoo, a train network AI

Post by Captain Rand »

Michiel wrote: 04 Mar 2026 22:28 Ahh I see. I don't want to add too many options, but I will see if an AI can detect those game settings. If it can, it can skip the replacement.
If it can't be detected then I'll have to stay on the previous version to this latest one.
So, can you tell me what's the version number of this? I'll make sure I have the one before downloaded.
( This isn't a problem for me. I've been using an old version happily for years and years with no problems whatsoever.)

Pete.
There's nothing like a deadline to hone the concentration.

Good manners cost nothing, but earn respect.

" 'Impossible' is not in our vocabulary." Jack Chrichton, Farscape
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 368
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Version 432 has the change, so you'd have to stay on 431 or earlier. Can you explain why vehicle replacement is a problem for you?
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 368
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

xarick wrote: 07 Mar 2026 10:47 Just a random thought: Have you considered industry tree networks? Choochoo train network seems primed for it!
You'd think so, and I did consider it, but it'd be trickier to implement than you might think. Passengers can go from any town to any other, but for cargo, you need both a source and a destination. ChooChoo grows its networks "organically"/randomly, without any planning what it will connect beforehand. It just plops down a crossing and expands from there. So it could hook up industries opportunistically as it finds them, but if it connects, say, a power plant, there might not be any coal mines that end up in the network, or vice versa.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 368
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

But of course now you have me thinking about it again :P It could see if there's an industry it could hook up to a crossing (say a power plant), but if there's no matching one (coal mine) in the network yet, just leave that connection open as a "maybe connect this industry later" task. Then when a coal mine shows up, it can see that it had plans to connect a power plant, and then do both. If no coal mine appears, it can just build a town connection from that original crossing instead. Who knows, something for the future :)
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 368
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Another update! Some general cleanup to the track building, and a new feature: you can now tell ChooChoo to stop expanding if it exceeds a percentage value of the player (company #1). So if you set that to 200%, ChooChoo will stop building new track and stations when its company value is more than twice your company value. If you grow your company, ChooChoo will resume expanding. I hope this makes it more friendly for casual play, where sometimes you just want to sit back and watch your trains go :D
limit-company-value.png
limit-company-value.png (28.34 KiB) Viewed 4167 times
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 368
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

And as requested, vehicle replacement is now optional:
Captain Rand wrote: 04 Mar 2026 15:33
Michiel wrote: 03 Mar 2026 22:27 Why do you want to (be able to) turn it off? After a certain date vehicles become unavailable for purchase so they can no longer be auto renewed. If you play with breakdowns enabled, eventually those old vehicles will spend all their time broken down. They will no longer make a profit and get find, so you end up with unused ChooChoo track and stations on the map. (It's not smart enough to clean up those tracks.)
I play with "Trains never expire" and breakdowns are off.

Pete.
If your game has these settings (vehicles never expire and no breakdowns) then ChooChoo will not replace vehicles with new models (but it will still enable autorenew because old vehicles are bad for ratings). Steam trains forever, if that's what you want!
User avatar
Captain Rand
Traffic Manager
Traffic Manager
Posts: 220
Joined: 28 Jan 2012 07:35

Re: ChooChoo, a train network AI

Post by Captain Rand »

Michiel wrote: 22 Mar 2026 22:00 And as requested, vehicle replacement is now optional:
Captain Rand wrote: 04 Mar 2026 15:33
Michiel wrote: 03 Mar 2026 22:27 Why do you want to (be able to) turn it off? After a certain date vehicles become unavailable for purchase so they can no longer be auto renewed. If you play with breakdowns enabled, eventually those old vehicles will spend all their time broken down. They will no longer make a profit and get find, so you end up with unused ChooChoo track and stations on the map. (It's not smart enough to clean up those tracks.)
I play with "Trains never expire" and breakdowns are off.

Pete.
If your game has these settings (vehicles never expire and no breakdowns) then ChooChoo will not replace vehicles with new models (but it will still enable autorenew because old vehicles are bad for ratings). Steam trains forever, if that's what you want!

This is great! I won't be limited to an old version (wouldn't be a problem, but it IS nice to be able to update).
Thank you so much!
And, I owe you an apology. I had meant to reply to your earlier question but it had completely slipped my mind (I'm getting old, and probably going senile).
I do feel I owe you an answer though, so,
Michiel wrote: 09 Mar 2026 09:42 .............Can you explain why vehicle replacement is a problem for you?
I usually play on larger maps (2k*2 minimum (each game lasts years IRL)) and I divide the map into "regions"
I mix vehicle GRF's from many countries and assign the trains to different regions. Where a rail line crosses borders The assignment is based on where the the train starts i.e. the first order.
In the case of A.I.'s, I use the cheat menu to change to that player, and manually replace the trains.
So if an A.I. replaces it's trains, It could ruin my system and I wouldn't be able to use it.
I should point out that I don't allow A.I.s to build anything but railways. I also use Infrastructure Sharing to connect A.I.s to each other (and Human company 1), and make a cohesive network.
Obviously, my games aren't set on Earth but in a fictional world, and I try never to use the "R" word.

I've left out a lot of details but needed to keep this short. Hope it makes sense.

And thanks again!

Pete.
There's nothing like a deadline to hone the concentration.

Good manners cost nothing, but earn respect.

" 'Impossible' is not in our vocabulary." Jack Chrichton, Farscape
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 368
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Captain Rand wrote: 23 Mar 2026 18:14 I usually play on larger maps (2k*2 minimum (each game lasts years IRL)) and I divide the map into "regions"
I mix vehicle GRF's from many countries and assign the trains to different regions. Where a rail line crosses borders The assignment is based on where the the train starts i.e. the first order.
In the case of A.I.'s, I use the cheat menu to change to that player, and manually replace the trains.
So if an A.I. replaces it's trains, It could ruin my system and I wouldn't be able to use it.
I should point out that I don't allow A.I.s to build anything but railways. I also use Infrastructure Sharing to connect A.I.s to each other (and Human company 1), and make a cohesive network.
That's awesome, glad to have ChooChoo be able to support (or at least not sabotage) your playstyle :)
Obviously, my games aren't set on Earth but in a fictional world, and I try never to use the "R" word.
... I really don't know what the "R" word would be, but of course now I want to know :lol: "Realism"..?
User avatar
Captain Rand
Traffic Manager
Traffic Manager
Posts: 220
Joined: 28 Jan 2012 07:35

Re: ChooChoo, a train network AI

Post by Captain Rand »

Michiel wrote: 24 Mar 2026 10:16 That's awesome, glad to have ChooChoo be able to support (or at least not sabotage) your playstyle :)
It not only supports, but enhances. My current game is running no less than FIVE instances of Choo Choo. There's not much duplication, which is great, and any there is I can easily edit and rationalize (impossible without Infrastructure Sharing).
Choo Choo is very forgiving of human intervention.
Off the top of my head, I can think of only one other A.I. that doesn't compete against other instances of itself. Most others make exact duplicates of routes, which isn't very useful, and I only ever run one instance of those.
Michiel wrote: 24 Mar 2026 10:16 ... I really don't know what the "R" word would be, but of course now I want to know :lol: "Realism"..?
You guessed correctly. I couldn't bring myself to use such an awful word! :lol:

Pete.
There's nothing like a deadline to hone the concentration.

Good manners cost nothing, but earn respect.

" 'Impossible' is not in our vocabulary." Jack Chrichton, Farscape
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 0 guests