[AI] RailwAI

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
RailwAI
Engineer
Engineer
Posts: 34
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: [AI] RailwAI

Post by RailwAI » 31 Oct 2019 20:02

The NoAI framework doesn't support to let an AI know much about available road types such as rattroads. Currently RailwAI assumes there can be 2 types of road (as per default): roads and tramways. I can try to let it work with rattroads, but it will always be a guess: The characteristics of other road types than the defaults can not be determined by an AI, while I want to treat roads and tramways differently.
Edit: my statement might be incorrect starting from openttd 1.10.0, let's wait if it will improve :-)

User avatar
3iff
Tycoon
Tycoon
Posts: 998
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: [AI] RailwAI

Post by 3iff » 05 Nov 2019 10:36

Quite impressed by this. A couple of issues discovered that I'd like to mention. Running version 20 on JGR 29

The AI linked an iron ore mine to a steel mill via roads then proceeded to build 3 truck services within a few months. That's hardly an efficient way to do it as only 2 stations will be getting resources. However, all three services are still active after 10 years - and it does tend to block other companies from setting up a service!

The double tracked rail lines set their signals so trains drive on the right. I always set my trains to drive on the left. I had a quick look at the code and basically didn't understand most of it. I'm guessing it's not an easy thing to change this but if you think it's possible if you could perhaps give me a few pointers so I might change it... I'm NOT asking you to make any changes (I really wouldn't expect you to do so). I'm pretty sure that players who have trains driving on the left are few in number, but I'd like to change it for myself if I possibly can. It only becomes relevant when I take over such a company and I can live with it how it is at the moment.

I do like the fact that there are shared vehicles which makes it so much easier after takeovers. Bigger rail stations are also appreciated.

---------

Actually, on further inspection, the signalling is way more complex than I first thought. There's a strange combination of single, path and one-way stuff. It mostly works except for one instance where a train went the wrong way (on a line that connected another service and the AI ended with 4 trains stuck).

It's also slightly annoying that if a rail service closes that the associated track is left in place - but I can understand the situation when services share some common track.

User avatar
RailwAI
Engineer
Engineer
Posts: 34
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: [AI] RailwAI

Post by RailwAI » 14 Nov 2019 19:28

Thank you for your reaction! Blocking other companies should not be involved in RailwAI, so that should be a problem of the other companies. Sometimes the strategy might be inefficient, but that's part of having random behaviour, everything could be an option. Or do you mean that it tried to start one service for which no cargo is produced, so nothing is being transported?

Changing trains to drive on the left track will be quite complex for sure. The rail construction contains a lot of code that is written to have trains running the right hand track. You could try to change the orientation (and types) of signals being placed on new railway lines, but it might cause deadlocks on two-track sections on single track lines.
The best way would be to change the RailTrackPlan (yes it is a huge bunch of code) in rail.nut and some more other changes. Required changes (as far as I think would be needed):
  • Make sure you understand how the VectorCoordinates work (world.nut).
  • path1 should not go from the right track to the left track, but from the left track to the right track. This can be changed in the pathfinder.InitializePath command (line 686 of rail.nut). Not that all the avoidArea and avoidTiles must be changed too: these are tiles that must be avoided by the pathfinder, basically already reserving some space for the other track.
  • GetTilesLeftFrom must be changed to a function GetTilesRightFrom. This function now returns a tile/direction array left of a given path. Note that it behaves different from corners to the left and corners to the right, because the other track crosses a different number of tiles.
  • BuildPassingSectionsLeftFromTiles must be changed to a function BuildPassingSectionsRightFromTiles
  • If there is more that refers to left or right (variable names or comments), try and check if it must be changed.
  • Disallow for train stations with more than two platforms (numPlatforms in station.nut). Current station exits will cause deadlocks with trains running on the left track, and it is all hardcoded (I still have the idea to refactor it one day). You could also try to change it, but it won't be easy.
Signal usage might look difficult, but some basic guidelines are involved:
  • On double track lines, use simple signals
  • Before switches, place path signals. Use a one-way path signal on the right track to prevent trains running on the left track.
  • Also use path signals (preferably one-way signals) on two-track sections of one track railway lines (note that more than 50% can be double track)
  • If something is changed to an existing railway line (a new bridge connected, a railroad crossing removed/placed, a new switch was placed) replace simple signals there with path signals
When a rail service closes it eventually tries after a while to remove railway track. It is still an open issue on my list that tracks towards a depot are not removed. Currently I'm quite busy in my real-world life, so I hope to be able to update RailwAI again in 2020. :)

User avatar
3iff
Tycoon
Tycoon
Posts: 998
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: [AI] RailwAI

Post by 3iff » 19 Nov 2019 10:36

Thanks for the reply.

I'm not going to attempt any changes to train driveside or signals...way too complex.

As for the 3 stations at one mine, having 2 stations should be a max limit (which might effectively block opposition - that's fine) but having a third pickup station is self defeating - so perhaps being able to detect and prevent that happening would be helpful for that company.

Removing unused track would be helpful as otherwise a smallish map can easily get clogged with redundant track and a takeover or bankruptcy is the only effective way to clear it.

Ikta
Engineer
Engineer
Posts: 1
Joined: 22 Nov 2019 17:59

Re: [AI] RailwAI

Post by Ikta » 22 Nov 2019 18:00

Ran into a error trying to load a game today that I was playing last night
Image

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Redirect Left and 2 guests