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

dasy2k1
Transport Coordinator
Transport Coordinator
Posts: 344
Joined: 20 Sep 2006 23:43
Location: UK
Contact:

Re: ChooChoo, a train network AI

Post by dasy2k1 »

I know that it wont flood an area with bus stops if you disallow building on town owned roads, but I want to still be able to do that!

please can you give an option in the AI config settings to turn this off?
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

You mean an option to not build those bus stops, even if the game settings allow it? Yes, that's a good idea (maybe I'll just let it build one little bus stop, so it's not too badly gimping itself). Unfortunately, now that I just got both Civ 5 AND Minecraft... this may take a while :oops:

Oh, and I gotta release the tram fix... mmmmmaybe this weekend :)
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: ChooChoo, a train network AI

Post by Kogut »

crash immediately after start
Attachments
Przechwytywanie.PNG
Przechwytywanie.PNG (104.34 KiB) Viewed 2445 times
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Thanks, I'll check it out!
local trainCost = AIEngine.GetPrice(engine) + AIEngine.GetPrice(wagon) * (trainLength-1) * 2;
That's weird - it checks (earlier) whether it found an engine, or at least it should. Ah - looks like it didn't find a suitable wagon. Any kinky game settings or GRFs you're using?
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: ChooChoo, a train network AI

Post by Kogut »

Michiel wrote:Thanks, I'll check it out!
local trainCost = AIEngine.GetPrice(engine) + AIEngine.GetPrice(wagon) * (trainLength-1) * 2;
That's weird - it checks (earlier) whether it found an engine, or at least it should. Ah - looks like it didn't find a suitable wagon. Any kinky game settings or GRFs you're using?
A lot of newgrfs (so I reported only crash not all weird behaviours)

riversw.grf =
egrvts.1.0\egrvts.grf =
av8_aviators_aircraft_set-1.7\pb_av8w.grf =
usstatsw.grf =
ukwaypointsw.grf =
TranspEngShowRunw.GRF =
total_bridges.grf =
swedish_houses-1.1\swehouses.grf =
ae_subuw.GRF =
stolen_trees-1\stolentreesw_162.grf =
smoothsnoww.grf =
shipdepotw.grf =
tramtrkw.grf =
transmitter.grf =
newwaterw.grf =
newshipsw.grf =
nhdepw.grf =
germanrvw.grf = 1
"BRBV v0.4w.GRF" =
dutchcatw.grf =
fish_ship_set-0.6.1\fish.grf =
buffers.grf =
foundw.grf =
heliport.grf =
indstatrw.grf =
modernsuburbanw.GRF =
mauvetoblackw.grf =
testw.grf =
harbourw_456.grf =
climate_dependant_airports-0.1.0\airportsplus.grf =
heqs_heavy_equipment_set-0.7.1\heqs.grf =
shanghaimaglev3.grf =
shanghaitransrapid.grf =
lrvs-testw.GRF =
VAST.grf =
uk_railway_set_tracks-1\pb_trax.grf =
firs-nightly-r1494\firs-nightly\firs.grf =
ukrs2__the_uk_railway_set-0.6\proj1000.grf = 0 4 0 0 0
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: ChooChoo, a train network AI

Post by Kogut »

It is game with vanilia settngs and it is visible thac CC is not upgrading its engines what results in disappearing vehicles - probably because autorenew sold old vehicle and is unable to build new.
In first attached savegame CC have 3 cargo trains, later only 1.
Attachments
autosave14.sav
(451.84 KiB) Downloaded 129 times
autosave15.sav
(414.23 KiB) Downloaded 130 times
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Kogut wrote:A lot of newgrfs (so I reported only crash not all weird behaviours)
Ah, thanks. I'll add a check so it at least doesn't crash.
Kogut wrote:It is game with vanilia settngs and it is visible thac CC is not upgrading its engines what results in disappearing vehicles - probably because autorenew sold old vehicle and is unable to build new.
That, or they became unprofitable due to breakdowns. It only does autorenew currently, it doesn't replace engines with newer types. I'm currently improving the startup code, making it a bit more aggressive and less random in selecting good starting cargo routes. Maybe after that, I'll look at long term issues, like vehicle management.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: ChooChoo, a train network AI

Post by planetmaker »

ChooChoo was having trouble in the later years of my Tournament game:

Code: Select all

dbg: [ai] [3] [S] 
dbg: [ai] [3] [S] *FUNCTION [FindPath()] ChooChoo-361.tar/choochoo-361/builder_track.nut line [107]
dbg: [ai] [3] [S] *FUNCTION [Run()] ChooChoo-361.tar/choochoo-361/builder_track.nut line [53]
dbg: [ai] [3] [S] *FUNCTION [RunSubtasks()] ChooChoo-361.tar/choochoo-361/task.nut line [115]
dbg: [ai] [3] [S] *FUNCTION [Run()] ChooChoo-361.tar/choochoo-361/builder_network.nut line [233]
dbg: [ai] [3] [S] *FUNCTION [RunSubtasks()] ChooChoo-361.tar/choochoo-361/task.nut line [115]
dbg: [ai] [3] [S] *FUNCTION [Run()] ChooChoo-361.tar/choochoo-361/builder_network.nut line [636]
dbg: [ai] [3] [S] *FUNCTION [Start()] ChooChoo-361.tar/choochoo-361/main.nut line [70]
dbg: [ai] [3] [S] 
dbg: [ai] [3] [S] [maxBridgeCost] 15389
dbg: [ai] [3] [S] [u] 100
dbg: [ai] [3] [S] [bridgeLength] 20
dbg: [ai] [3] [S] [pathfinder] INSTANCE
dbg: [ai] [3] [S] [this] INSTANCE
dbg: [ai] [3] [S] [this] INSTANCE
dbg: [ai] [3] [S] [this] INSTANCE
dbg: [ai] [3] [S] [crossing] INSTANCE
dbg: [ai] [3] [S] [this] INSTANCE
dbg: [ai] [3] [S] [this] INSTANCE
dbg: [ai] [3] [S] [exit] ARRAY
dbg: [ai] [3] [S] [this] INSTANCE
dbg: [ai] [3] [S] [task] INSTANCE
dbg: [ai] [3] [S] [minMoney] 0
dbg: [ai] [3] [S] [this] INSTANCE
dbg: [misc] TILE: 0x2c568 (360,354)
dbg: [misc] type_height  = 0x11
dbg: [misc] m1           = 0x8
dbg: [misc] m2           = 0
dbg: [misc] m3           = 0
dbg: [misc] m4           = 0x7
dbg: [misc] m5           = 0x2
dbg: [misc] m6           = 0
dbg: [misc] m7           = 0
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Update!

I've improved the startup to make it a bit more competitive. It now tries to select the most profitable cargo routes and builds more of those than before (at the same difficulty setting).

The pathfinder can now optionally follow another track, penalizing a route if it is not adjacent to the first. This results in slightly better double track layout. Usually...

Also, I've widened the area in which crossings may be placed, so hopefully it'll grow some bigger networks on rougher maps now. The new tar is in the first post, and will be on Banananananas in a minute.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

platnetmaker: thanks for the bug report, I'll look into it!

Edit: interesting... was inflation on in that game? It might be that the cost of bridges has become so high that it never starts to pathfind because it can't get the money to build the longest possible bridge.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: ChooChoo, a train network AI

Post by planetmaker »

Michiel wrote:platnetmaker: thanks for the bug report, I'll look into it!

Edit: interesting... was inflation on in that game? It might be that the cost of bridges has become so high that it never starts to pathfind because it can't get the money to build the longest possible bridge.
I didn't play with inflation. You can get the whole game with all its settings (start and final savegame ) in this thread.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Quick fix: while testing planetmaker's savegame, I kept getting ERR_PRECONDITION_FAILED trying to build newgrf cargo stations, so I've changed it to fall back to normal stations in that case.
X_stream
Engineer
Engineer
Posts: 18
Joined: 04 Nov 2004 13:29
Location: Bussum => Netherlands
Contact:

Re: ChooChoo, a train network AI

Post by X_stream »

I like your AI a lot!
I played around with it for a bit and I have some suggestions for future updates.
Maybe they have been suggested before, but I thought I would post any way.

First is that I noticed that the busses don’t transfer passengers to the stations but just service the station and some bus stations in the towns. This way they actually compete with the trains for passengers at the stations.
I think the AI would do better if you would give the busses a ‘transfer and leave empty’ order for the train stations, this way they transfer additional passengers to the stations for your trains to transport.

Second is that your AI seems to build its train routes somewhat at random. It for instance build a track to the map edge with no towns around in my last game.
I think it would be really cool if you could implement something like the mapping routine PathZilla uses (or used) for its busses.

Maybe you can do something with this.

Any way, thanks a lot for programming an AI for us to play around with!
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: ChooChoo, a train network AI

Post by Lord Aro »

Michiel wrote:Quick fix: while testing planetmaker's savegame, I kept getting ERR_PRECONDITION_FAILED trying to build newgrf cargo stations, so I've changed it to fall back to normal stations in that case.
That error usually means that one of the parameters is the wrong type, like an engine id instead of a station id or something
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

X_stream wrote:I like your AI a lot!
I played around with it for a bit and I have some suggestions for future updates.
Maybe they have been suggested before, but I thought I would post any way.
Thank you :)
X_stream wrote: First is that I noticed that the busses don’t transfer passengers to the stations but just service the station and some bus stations in the towns. This way they actually compete with the trains for passengers at the stations.
I think the AI would do better if you would give the busses a ‘transfer and leave empty’ order for the train stations, this way they transfer additional passengers to the stations for your trains to transport.
I did get that question before - so I'm gonna copy/paste the answer :p

I've actually considered both, since there's a tradeoff: if I have the bus pick up passengers at the train station, that really increases the cargo rating, so the train station gets/keeps more cargo (passengers) from the town. However, as long as a town is small, most passengers are taken away by the bus instead of the trains. On the other hand, if I set the bus to transfer and leave empty, it brings people in from town, but it doesn't help the ratings at all. Another option is to use transfer orders on both sides: then, the bus will pick (the same people) up at each end, so you get the ratings bonus without "losing" passengers, but you run the bus service at a loss.
X_stream wrote: Second is that your AI seems to build its train routes somewhat at random. It for instance build a track to the map edge with no towns around in my last game.
I think it would be really cool if you could implement something like the mapping routine PathZilla uses (or used) for its busses.
It's more than "somewhat" :) It picks a random spot for a crossing, estimates if it's likely to connect at least 3 towns, and then starts building. Sometimes, it'll connect a huge network, while sometimes, it only manages to connect a single town, making the whole exercise useless... I quite like the randomness, it's not so focussed on the large towns like most AIs. However, it could use a bit of optimization.
X_stream wrote: Maybe you can do something with this.

Any way, thanks a lot for programming an AI for us to play around with!
You're welcome, I'm only doing it for fun :)
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Big bug fixed! Now with much nicer double track, because I told the pathfinder to follow another track and then didn't give it one, so it was going all over with all the wrong costs.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: ChooChoo, a train network AI

Post by planetmaker »

With the updated version on Bananas, I noticed that ChooChoo is competing heavily with itself: one mine with three stations which connect to a different power plant each. Vice versa would make sense, but this way round - I guess it should not do that ;-)
Attachments
Gamla Österboda Transport, 2020-11-13.png
Gamla Österboda Transport, 2020-11-13.png (288.86 KiB) Viewed 2445 times
Gamla Österboda Transport, 2020-10-30.png
Gamla Österboda Transport, 2020-10-30.png (152.89 KiB) Viewed 2445 times
Another game
Another game
Unnamed, 2021-02-25.png (44.08 KiB) Viewed 6543 times
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Thanks! I think I removed the check on whether an industry is already being served. I'll put that (back) in!
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: ChooChoo, a train network AI

Post by Michiel »

Fixed! And I've increased performance a bit by using shorter trains.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: ChooChoo, a train network AI

Post by planetmaker »

Also the current bananas version still creates continuously errors (though not fatal, it's annoying as it spams the console, which is nothing I like when doing casual testing, of also other stuff concurrently):

Code: Select all

dbg: [ai] [3] [S] 
dbg: [ai] [3] [S] *FUNCTION [Run()] ChooChoo-394.tar/choochoo-394/builder_cargo.nut line [51]
dbg: [ai] [3] [S] *FUNCTION [Start()] ChooChoo-394.tar/choochoo-394/main.nut line [75]
dbg: [ai] [3] [S] 
dbg: [ai] [3] [S] [railType] 0
dbg: [ai] [3] [S] [maxDistance] 75
dbg: [ai] [3] [S] [b] 4
dbg: [ai] [3] [S] [a] 5
dbg: [ai] [3] [S] [cargo] 3
dbg: [ai] [3] [S] [route] INSTANCE
dbg: [ai] [3] [S] [this] INSTANCE
dbg: [ai] [3] [S] [task] INSTANCE
dbg: [ai] [3] [S] [minMoney] 0
dbg: [ai] [3] [S] [this] INSTANCE
dbg: [ai] [3] [S] Your script made an error: unknown error
dbg: [ai] [3] [S] 
dbg: [ai] [3] [S] *FUNCTION [Run()] ChooChoo-394.tar/choochoo-394/builder_cargo.nut line [51]
dbg: [ai] [3] [S] *FUNCTION [Start()] ChooChoo-394.tar/choochoo-394/main.nut line [75]
dbg: [ai] [3] [S] 
dbg: [ai] [3] [S] [railType] 0
dbg: [ai] [3] [S] [maxDistance] 75
dbg: [ai] [3] [S] [b] 4
dbg: [ai] [3] [S] [a] 296
dbg: [ai] [3] [S] [cargo] 3
dbg: [ai] [3] [S] [route] INSTANCE
dbg: [ai] [3] [S] [this] INSTANCE
dbg: [ai] [3] [S] [task] INSTANCE
dbg: [ai] [3] [S] [minMoney] 0
dbg: [ai] [3] [S] [this] INSTANCE
dbg: [ai] [3] [S] Your script made an error: unknown error
dbg: [ai] [3] [S] 
dbg: [ai] [3] [S] *FUNCTION [Run()] ChooChoo-394.tar/choochoo-394/builder_cargo.nut line [51]
dbg: [ai] [3] [S] *FUNCTION [Start()] ChooChoo-394.tar/choochoo-394/main.nut line [75]
dbg: [ai] [3] [S] 
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Semrush [Bot] and 15 guests