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

xarick
Transport Coordinator
Transport Coordinator
Posts: 335
Joined: 26 Feb 2015 00:52

Re: ChooChoo, a train network AI

Post by xarick »

the index 'find' does not exist
Attachments
Unnamed, 1955-07-31.png
Unnamed, 1955-07-31.png (43.45 KiB) Viewed 4731 times
R25-G21 - ChooChoo vs PathZilla - 7,463 days.sav
(3.43 MiB) Downloaded 252 times
Formerly known as Samu
User avatar
Redirect Left
Tycoon
Tycoon
Posts: 7234
Joined: 22 Jan 2005 19:31
Location: Wakefield, West Yorkshire

Re: ChooChoo, a train network AI

Post by Redirect Left »

I've also had this just now with find error, on a map with lots of AIs and me spectating them.
2019-12-12 13_26_16-OpenTTD jgrpp-0.32.2.png
2019-12-12 13_26_16-OpenTTD jgrpp-0.32.2.png (45.05 KiB) Viewed 8490 times
Unfortunately the author has gone AFK for over 2 years at this point, so we might be on our own. Unless someone heree knows how to fix it, i've tried numerous times but i can't get the AI programming language down, it's very confusing and non-sensical to me, otherwise i'd have a good go at fixing numerous issues with lots of old AIs.
Image
Need some good tested AI? - Unofficial AI Tester, list of good stuff & thread is here.
mando
Engineer
Engineer
Posts: 2
Joined: 11 Jan 2020 13:11

Re: ChooChoo, a train network AI

Post by mando »

I was trying out some AIs, including ChooChoo and noticed it wasn't working. I fixed two breaking bugs:
  1. Updated road pathfinding library version from 3 to 4
  2. Checked that a returned vehicle name is not null before doing name.find("X")
    I have attached a patch, and a new updated tarball.
    Attachments
    choochoo-412-findbug-libupgrade.patch
    (867 Bytes) Downloaded 272 times
    ChooChoo412-a.tar
    (180 KiB) Downloaded 260 times
    User avatar
    Donald Duck
    Engineer
    Engineer
    Posts: 18
    Joined: 24 Apr 2020 07:05

    Re: ChooChoo, a train network AI

    Post by Donald Duck »

    I tried using this AI and got some errors:

    Image
    HGus
    Engineer
    Engineer
    Posts: 120
    Joined: 12 May 2013 22:28
    Location: Argentina

    Re: ChooChoo, a train network AI

    Post by HGus »

    That is not an error from AI, but your installation. Use the update function from ingame or install manually Pathfinder library version 3
    User avatar
    Michiel
    Transport Coordinator
    Transport Coordinator
    Posts: 338
    Joined: 13 Jul 2008 00:57
    Contact:

    Re: ChooChoo, a train network AI

    Post by Michiel »

    Hello! Not dead, just busy elsewhere. Looks like it doesn't download that library automatically (anymore). I'll see if I can package a copy with my AI, so it just works out of the box.
    User avatar
    Michiel
    Transport Coordinator
    Transport Coordinator
    Posts: 338
    Joined: 13 Jul 2008 00:57
    Contact:

    Re: ChooChoo, a train network AI

    Post by Michiel »

    It's working again! You may have to update or reload the AI from the "check online content" screen.
    User avatar
    andrejHUN
    Engineer
    Engineer
    Posts: 4
    Joined: 02 Aug 2017 18:38
    Contact:

    Re: ChooChoo, a train network AI

    Post by andrejHUN »

    Hello,

    Now I completely understand what it says there, that it's not an actual error, but to be safe and sound, is it not? Should I reload the AI or leave it at that?

    Here's the screenshot from today:
    ArskelissTrans, 2009-08-02.png
    Screenshot
    (88.4 KiB) Not downloaded yet
    User avatar
    Michiel
    Transport Coordinator
    Transport Coordinator
    Posts: 338
    Joined: 13 Jul 2008 00:57
    Contact:

    Re: ChooChoo, a train network AI

    Post by Michiel »

    No, that's a real error. The "the following red text is not an actual error" message is out of date; older versions of the game would print (in red text) all errors, even ones handled by the program. That appears not to be the case anymore. However, the red text you see now *is* a real error and you'll have to reload the AI.

    I'm not sure what happened though - did you rename some of the AI's vehicles? It stores information in the name, so that'll confuse it.

    Or maybe it tried to delete the same vehicle twice - once on its yearly "cleanup" loop, and once more because it received a "vehicle unprofitable" event. The second can then fail because the vehicle is already gone. That looks like it's very unlikely to happen, but possible :-/
    xarick
    Transport Coordinator
    Transport Coordinator
    Posts: 335
    Joined: 26 Feb 2015 00:52

    Re: ChooChoo, a train network AI

    Post by xarick »

    choo choo always crashing with the index find does not exist error
    what I think it happened: A vehicle was unprofitable event happened. Before choochoo got to it, the vehicle crashes and poofed
    when it tried to handle the event, it got the vehicle id of it, but the vehicle is no longer valid
    tried to get the name of the vehicle, but since it wasn't a valid vehicle it returned null
    name.find("X") crashes the script, because can't use find on null
    Attachments
    screenshot#6.png
    (259.98 KiB) Not downloaded yet
    Formerly known as Samu
    User avatar
    Redirect Left
    Tycoon
    Tycoon
    Posts: 7234
    Joined: 22 Jan 2005 19:31
    Location: Wakefield, West Yorkshire

    Re: ChooChoo, a train network AI

    Post by Redirect Left »

    xarick wrote: 03 Jun 2022 11:15 choo choo always crashing with the index find does not exist error
    what I think it happened: A vehicle was unprofitable event happened. Before choochoo got to it, the vehicle crashes and poofed
    when it tried to handle the event, it got the vehicle id of it, but the vehicle is no longer valid
    tried to get the name of the vehicle, but since it wasn't a valid vehicle it returned null
    name.find("X") crashes the script, because can't use find on null
    During my mass AI testing for this thread, I have also run into this, and it was during the process of it wiping non-profitable vehicles, so i think you're right.
    It listed all the vehicles it was wiping, and then it came across one that isn't defined (I presume this is what would return null) and it crashed.
    Sadly the author hasn't been about since mid 2022, so it might be bad news for any official fix.
    It's a really nice AI though, so it'd be nice to try fixing it outside of that if they're unavailable.
    Attachments
    2023-03-15 19_17_43-OpenTTD 13.0.png
    2023-03-15 19_17_43-OpenTTD 13.0.png (12.41 KiB) Viewed 4010 times
    Image
    Need some good tested AI? - Unofficial AI Tester, list of good stuff & thread is here.
    User avatar
    Michiel
    Transport Coordinator
    Transport Coordinator
    Posts: 338
    Joined: 13 Jul 2008 00:57
    Contact:

    Re: ChooChoo, a train network AI

    Post by Michiel »

    some of the AI I've tested are genuinely really good at what they do, even if they are a bit flawed (looking at you ChooChoo, with your magnificent networks)
    Turns out, flattery will get you everywhere :-p

    I've just uploaded version 413 that fixes the bug, and adds an option (which is on by default) to not crash on unexpected errors, but just keep going. It's still possible a bug will leave the AI dead in the water, but it might also be that the error is survivable and the AI can at least keep playing.

    Unfortunately, I was unable to find a way to print a stack trace without letting the error "escape" and kill the AI, so if you want to report a bug in the future, please turn off this option and send me a screenshot with a stack trace in it:
    keep-running.png
    keep-running.png (9.18 KiB) Viewed 3986 times
    User avatar
    Redirect Left
    Tycoon
    Tycoon
    Posts: 7234
    Joined: 22 Jan 2005 19:31
    Location: Wakefield, West Yorkshire

    Re: ChooChoo, a train network AI

    Post by Redirect Left »

    Michiel wrote: 16 Mar 2023 14:54 Turns out, flattery will get you everywhere :-p
    Haha, I'm glad to hear it in this case, it's one of the best AI I've come across in terms of networking things together reliably.
    It's really great to see you return to try patching it up, and I hope you're able to continue doing so, as it was the one i was contemplating the most on forking and patching up myself, saves me a job!

    For the record, the example in the document for its weird track building which i cannot find any logic behind was this. Some of them are the exact shape of an industry, so i presume at one point an industry was in the way, and built around, but never corrected after the industry went under, but this one? I ain't too sure about.
    Image
    Need some good tested AI? - Unofficial AI Tester, list of good stuff & thread is here.
    User avatar
    Michiel
    Transport Coordinator
    Transport Coordinator
    Posts: 338
    Joined: 13 Jul 2008 00:57
    Contact:

    Re: ChooChoo, a train network AI

    Post by Michiel »

    You're welcome!

    I think I can explain that. The logic is that it never was "connecting Wunnbury and Sonbourne". Instead, it started from the junction (the bit in the top left, with the waypoint) and then started extending it. It managed to connect the SW exit to Wunnbury and the NE exit to Sonbourne, and then didn't find valid/reachable towns for the NW and SE exits, so those got deconstructed and you end up with this weird looking loop.

    I do find it surprising that it considered Sonbourne for the NE exit, since it's actually to the south of that exit, but I don't remember how the selection exactly works.

    It never does any "corrections" to track after its built, by the way. That would be an awesome feature to add, to remove unused track and try to optimize tracks that are still used. But I never got around to implementing that.
    xarick
    Transport Coordinator
    Transport Coordinator
    Posts: 335
    Joined: 26 Feb 2015 00:52

    Re: ChooChoo, a train network AI

    Post by xarick »

    Hey Michiel, do you have a repository of your AI on Github. I have made a few changes to the code, which improve the flow of train traffic on junctions, and also the way buses load and transfer passengers. Not sure if you're interested.

    Btw, as I was speaking, here's a savegame of a massive train jam.
    Attachments
    autosave1.sav
    (14.88 MiB) Downloaded 53 times
    Unnamed, 1941-09-12.png
    (382.43 KiB) Not downloaded yet
    Formerly known as Samu
    xarick
    Transport Coordinator
    Transport Coordinator
    Posts: 335
    Joined: 26 Feb 2015 00:52

    Re: ChooChoo, a train network AI

    Post by xarick »

    Congratulations on 5000 trains!
    Attachments
    Unnamed, 1970-12-26.sav
    (16.31 MiB) Downloaded 55 times
    Choo Choo 5000 trains!.png
    Choo Choo 5000 trains!.png (101.14 KiB) Viewed 3872 times
    Formerly known as Samu
    User avatar
    Redirect Left
    Tycoon
    Tycoon
    Posts: 7234
    Joined: 22 Jan 2005 19:31
    Location: Wakefield, West Yorkshire

    Re: ChooChoo, a train network AI

    Post by Redirect Left »

    xarick wrote: 19 Mar 2023 22:00 Congratulations on 5000 trains!
    haha, nice. I have to limit AI to 2500 trains, 1000 RVs, 250 aircraft & 250 ships for my mass AI testing, else it runs to a crawl, even on an i9-12900 :(
    Image
    Need some good tested AI? - Unofficial AI Tester, list of good stuff & thread is here.
    User avatar
    Michiel
    Transport Coordinator
    Transport Coordinator
    Posts: 338
    Joined: 13 Jul 2008 00:57
    Contact:

    Re: ChooChoo, a train network AI

    Post by Michiel »

    xarick wrote: 18 Mar 2023 20:35 Hey Michiel, do you have a repository of your AI on Github. I have made a few changes to the code, which improve the flow of train traffic on junctions, and also the way buses load and transfer passengers. Not sure if you're interested.
    Not yet, it's currently in a private Subversion repo, but I was already thinking of moving it to GitHub, so... soon? I can't promise I'll accept pull requests, but I'll definitely look at them!
    xarick wrote: 19 Mar 2023 22:00 Congratulations on 5000 trains!
    Wow :D I'll take a look at that save later!
    xarick
    Transport Coordinator
    Transport Coordinator
    Posts: 335
    Joined: 26 Feb 2015 00:52

    Re: ChooChoo, a train network AI

    Post by xarick »

    Just sent a Draft Pull Request. Some changes you might disagree with and that's fine.

    From my testings it becomes a bit more competitive early on, but at some cost of jams in the long run, which I tried to address by sending trains to always visit depots. Might require more intervention in the way trains are duplicated, or the spacing between signals to allow a more compact number of trains, another idea I had was to come up with a way to never have trains blocking a junction while waiting for a free path, but I didn't manage to do it properly and gave up.
    Formerly known as Samu
    Post Reply

    Return to “OpenTTD AIs and Game Scripts”

    Who is online

    Users browsing this forum: No registered users and 11 guests