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
Captain Rand
Traffic Manager
Traffic Manager
Posts: 205
Joined: 28 Jan 2012 07:35

Re: ChooChoo, a train network AI

Post by Captain Rand »

Michiel wrote: 04 Mar 2024 20:47 By popular request (hi Pete!) ChooChoo now also supports left hand traffic on double tracks!...........
This is awesome!
Thank you so much!

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: 345
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Michiel wrote: 25 May 2010 20:29 It should really have a lake detector... the pathfinder is still slow when it tries to find a route across or around a large body of water. Never mind, just thinking out loud :) It's fun giving it infinite money and watching it spew forth all over the map :)
It's taken almost 14 years, but today I added... a lake detector! :shock: :shock: :shock:

It's dead simple really, but the idea only came to me the other night. Consider the following mockup:
lake-detector-small.png
lake-detector-small.png (519.04 KiB) Viewed 9502 times
When trying to find a spot for a station, it'll look at the four edges of the rectangle defined by the start (crossing exit) and destination (station entrance). It checks the tiles along each edge and if it finds a long run of water (longer than the maximum bridge length it is allowed to use) it considers that edge "blocked by water". However, it will only consider this problematic if two parallel edges are blocked. In that case, it will declare it an unviable spot for a station, and look elsewhere.

This may lead to some missed opportunities (there might be a perfectly fine bit of land in between the edges), but that's fine - the network building algorithm tends to sprawl its tendrils across the map anyway. It's much better than ChooChoo sitting there, pathfinding for 20 years.

I still need to do some more testing and tweaking, but expect another release soon :D
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 345
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

New version with lake detector released!
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 345
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Another update! After the initial concept, I never gave ChooChoo's expansion algorithm much thought. But I've now changed it so that for each crossing it is extending, it'll keep going in the same direction as far as it can (if it can place an additional crossing between its current position and the next station). Expansion of the side branches is put at the end of its task list. That should result in deeper networks with much better use of space, with mainlines extending across the map and side branches filling the remaining space, like the veins of a leaf.
leaf.png
leaf.png (673.52 KiB) Viewed 9377 times
Of course, this structure is greatly perturbed by the randomness of the actual map.
choochoo-network-anim.gif
choochoo-network-anim.gif (92.5 KiB) Viewed 9385 times
Attachments
choochoo-network.gif
(121.33 KiB) Not downloaded yet
xarick
Transport Coordinator
Transport Coordinator
Posts: 351
Joined: 26 Feb 2015 00:52

Re: ChooChoo, a train network AI

Post by xarick »

Something's not right.
Attachments
Unnamed, 1949-12-01.png
(72.3 KiB) Not downloaded yet
Unnamed, 1949-12-07.png
(70.37 KiB) Not downloaded yet
Unnamed, 1949-12-07.sav
(17.81 MiB) Downloaded 220 times
Formerly known as Samu
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 345
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Thanks, I'll take a look!
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 345
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

xarick wrote: 15 Mar 2024 21:46 Something's not right.
Unfortunately I was unable to deduce the problem from your screenshots or savegame. For the next version, I've improved the code that captures the error, so I'll be able to get the info I need from a screenshot, but I have some testing to do for the next release.
xarick
Transport Coordinator
Transport Coordinator
Posts: 351
Joined: 26 Feb 2015 00:52

Re: ChooChoo, a train network AI

Post by xarick »

Is this more helpful? Seems to happen when creating a new network. Sometimes it happens early on, sometimes takes some years before it happens.
Attachments
Unnamed, 1965-09-15.png
(261.2 KiB) Not downloaded yet
Formerly known as Samu
RocketGoose
Engineer
Engineer
Posts: 1
Joined: 26 Apr 2025 07:07

Re: ChooChoo, a train network AI

Post by RocketGoose »

Screenshot 2025-04-26 080933.png
(197.52 KiB) Not downloaded yet
Hi I'm not sure what's going wrong here but choo choo seems to be doing its signals wrong so no trains can actually leave the station. I've tried swapping the driving side and it still has this problem.
Edit: I realised this is happening when using the latest version of JGR patch pack, but works correctly in the normal version of openttd.
Last edited by RocketGoose on 26 Apr 2025 07:28, edited 1 time in total.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 345
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

xarick wrote: 12 Apr 2024 11:32 Is this more helpful? Seems to happen when creating a new network. Sometimes it happens early on, sometimes takes some years before it happens.
Hi xarick, I'm sorry I missed your reply back then. Definitely something strange going on, with the "instance: <hex digits>" in the tasks. I'll keep an eye out, but I've never seen this happen in any test run :-/ If anyone else spots it, please do report it.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 345
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

RocketGoose wrote: 26 Apr 2025 07:12 Screenshot 2025-04-26 080933.png
Hi I'm not sure what's going wrong here but choo choo seems to be doing its signals wrong so no trains can actually leave the station. I've tried swapping the driving side and it still has this problem.
Edit: I realised this is happening when using the latest version of JGR patch pack, but works correctly in the normal version of openttd.
Thanks for narrowing it down to the patch pack! Sorry, I only support the base game...
User avatar
Redirect Left
Tycoon
Tycoon
Posts: 7440
Joined: 22 Jan 2005 19:31
Location: Wakefield, West Yorkshire

Re: ChooChoo, a train network AI

Post by Redirect Left »

RocketGoose wrote: 26 Apr 2025 07:12 Edit: I realised this is happening when using the latest version of JGR patch pack, but works correctly in the normal version of openttd.
It might be worth reporting this in the patchpack, as the goal of it is probably to not render some GRFs or AI in an unstable state unless absolutely necessary.

Patchpack thread is here if you'd like to let JGR know viewtopic.php?t=73469&start=4840
Image
Need some good tested AI? - Unofficial AI Tester, list of good stuff & thread is here.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 345
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

New version, with a new feature...

Image

A ChooChoo junction with a single track exit? What heresy is this? It's... a branch line!

When it finds no good spot for either another junction or a big terminus station when trying to extend a junction, ChooChoo can now opt to build a branch line instead. This is a single track line with a small branch station at the end. But: this branch can then be extended by exiting out the back of the station, potentially leading to a branch line visiting up to four more stations:

Image

Since these are single track, they only support a single train, which goes all the way down the branch and then up to one of the "mainline" stations. It probably won't make much money, but it looks cute, dunnit? :D

Image
Attachments
branch-line-announce.png
(488.86 KiB) Not downloaded yet
branch-line2.png
(2.22 MiB) Not downloaded yet
branch-line-long.png
(3.2 MiB) Not downloaded yet
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 345
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Also, a debugging/error reporting improvement: when "keep running on unexpected errors" option is disabled (so "abort with a stack trace" is active), it will now capture a more complete stack trace for the error, so fixing errors like "the index 'foo' does not exist" should now be much more viable.
choochoo-settings.png
choochoo-settings.png (12.05 KiB) Viewed 1289 times
BW89
Engineer
Engineer
Posts: 111
Joined: 10 May 2015 11:42

Re: ChooChoo, a train network AI

Post by BW89 »

Hi
I found some bugs while using ChooChoo
Often it builds a crossing and loops indefinetly (until "keep running on unexpected errors" is disabled). When disabled it crashes (choochoo_Crash.png)

When using the realistic train breaking model (JGRPP setting) block signals get placed the wrong way around. (choochoo_wrong-signal.png)
Since you do not want to support patch packs i would appreciate a warning like "only vanilla game supported, some settings might break the AI" in the AI/Game Script Debug window or as a popup

Also it struggles with many GRFs. For example when using PolRoad it wont build busses in town. When using the xussr Set multiple issues appear: Some trains only have one Mail carrige, even when additional carriges would fit in stations. Sometimes it attaches parts of EMU or DMU which cannot carry passengers when hauled with a conventional locomotive. Other times it builds only locomotives and lets them ride around without any cargo capacity.
Another Issue accurs when using Rail GRFs with different speeds. ChooChoo often chooses the last Track in the menu, with no consideration for cost or required speed.
Attachments
choochoo_wrong-signal.png
choochoo_wrong-signal.png (398.23 KiB) Viewed 459 times
choochoo_Crash.png
choochoo_Crash.png (630.73 KiB) Viewed 459 times
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 345
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

BW89 wrote: 21 Jun 2025 16:22 Hi
I found some bugs while using ChooChoo
Often it builds a crossing and loops indefinetly (until "keep running on unexpected errors" is disabled). When disabled it crashes (choochoo_Crash.png)

When using the realistic train breaking model (JGRPP setting) block signals get placed the wrong way around. (choochoo_wrong-signal.png)
Since you do not want to support patch packs i would appreciate a warning like "only vanilla game supported, some settings might break the AI" in the AI/Game Script Debug window or as a popup

Also it struggles with many GRFs. For example when using PolRoad it wont build busses in town. When using the xussr Set multiple issues appear: Some trains only have one Mail carrige, even when additional carriges would fit in stations. Sometimes it attaches parts of EMU or DMU which cannot carry passengers when hauled with a conventional locomotive. Other times it builds only locomotives and lets them ride around without any cargo capacity.
Another Issue accurs when using Rail GRFs with different speeds. ChooChoo often chooses the last Track in the menu, with no consideration for cost or required speed.
Thanks BW89! I will try to investigate your bug report.
in the AI/Game Script Debug window or as a popup
I don't think AIs can show popups, but I could write a message in the Script Debug panel.
block signals get placed the wrong way around
I don't know if AIs can detect which newgrfs or patches are active, or why it would change the orientation of signals. The AI interface for building signals is just "which tile do you want to build it on, and which direction should it face?"
In your screenshot, on which side would the trains (try to) drive? On the right hand side?
Also it struggles with many GRFs. For example when using PolRoad it wont build busses in town. When using the xussr Set multiple issues appear: Some trains only have one Mail carrige, even when additional carriges would fit in stations. Sometimes it attaches parts of EMU or DMU which cannot carry passengers when hauled with a conventional locomotive. Other times it builds only locomotives and lets them ride around without any cargo capacity.
Another Issue accurs when using Rail GRFs with different speeds. ChooChoo often chooses the last Track in the menu, with no consideration for cost or required speed.
Unfortunately I don't have the time to add support for newgrfs :-/
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 345
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Often it builds a crossing and loops indefinetly (until "keep running on unexpected errors" is disabled). When disabled it crashes (choochoo_Crash.png)
Do you happen to have a savegame where this happens?
BW89
Engineer
Engineer
Posts: 111
Joined: 10 May 2015 11:42

Re: ChooChoo, a train network AI

Post by BW89 »

I don't think AIs can show popups, but I could write a message in the Script Debug panel.
I thought WrightAI was able to produce PopUps, but I may be wrong.
I don't know if AIs can detect which newgrfs or patches are active, or why it would change the orientation of signals. The AI interface for building signals is just "which tile do you want to build it on, and which direction should it face?"
In your screenshot, on which side would the trains (try to) drive? On the right hand side?
The Issue lies with the block signals. With realistic breaking enabled Block signals do not have the double signal option, only one way or the other. My Guess is, that due to this AIs tend to place signals in the wrong direction, like a player clicking one time to much. Replacing block signals with Path signals would fix this issue since these are identical to vanilla (also Block signal might confuse new players since these are no longer enabled by default)
Unfortunately I don't have the time to add support for newgrfs :-/
In this case i would also appreciate a warning if GRFs are used, or an Error if ChooChoo is unable to build vehicles with the necessary Cargo
BW89
Engineer
Engineer
Posts: 111
Joined: 10 May 2015 11:42

Re: ChooChoo, a train network AI

Post by BW89 »

Michiel wrote: 23 Jun 2025 12:47 Do you happen to have a savegame where this happens?
Not at the moment, because I only saw this behavior in JGRPP, but i downloaded 15.0 beta 2 and found some more bugs including similar behavior.
1. When it cannot find a second town after the first station including some rail is built it abandons the infrastructure without deleting it (lonely station.png)
2. Sometimes it sends multiple trains on branch lines causing blockages (multiple trains on branchline.png)
3. Sometimes it builds station inaccessible, often multiple times (repeatet wrong station placement.png)
4. When adding a branchline it sometimes forgets single rail pieces at crossings, especially when no further mainline is built (missing rail piece 1.png and missing rail piece 2.png)
5. Some Towns get served both with branch lines and mainlines. Sometimes on the same network (normal and branch line.png)
6. Some routes get served by both trains and busses (bus and train on same route.png)
7. Sometimes very long detours are made between two towns(long detour.png - no savegame for this, but there was a train from Brunn am Semmering to Sankt Pölten even though this takes a very long time and there was already a bus serving this line)

1,2 and 3,4,5,6 are in the attached savegame. 3 has been fixed by the ai with the fifth rebuild and second network.
All files are in the zip file since i was not able to attach all images and the savegame!
Attachments
savegame and screenshots.zip
(9.86 MiB) Downloaded 9 times
BW89
Engineer
Engineer
Posts: 111
Joined: 10 May 2015 11:42

Re: ChooChoo, a train network AI

Post by BW89 »

I now had access to my PC where the Error occured (the last messages were made with my laptop where i barely play).
I tried it now with 15.0 Beta 2 on the same PC and I was able to reproduce the error without JGRPP, GRFs or GameScripts!
ChooChoo Error.PNG
ChooChoo Error.PNG (261.84 KiB) Viewed 170 times
After noticing this, i tried copying my settings over to my laptop and the issue appeared there as well.

EDIT: Added my config, which appears causing ChooChoo crashes in 15.0 Beta 2
Attachments
ChooChoo Error.sav
(300.93 KiB) Downloaded 6 times
openttd.cfg
(27 KiB) Downloaded 6 times
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests