[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: 31
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: [AI] RailwAI

Post by RailwAI » 14 Nov 2018 22:01

Adding tunnels in existing railway tracks still showed some bugs in a few test runs (always fun when functions do something else than expected), as in
the following image:
Image

A changelog for version 9:
- Build signals around tunnels that were placed in an existing rail line
- Bugfix: verify if a tunnel will be built as the AI expects it to be built (expectations were sometimes wrong)
- Bugfix: A train stuck on a disconnected piece of rail will get a depot where it can be sold (might take a few years)

nihues
Engineer
Engineer
Posts: 44
Joined: 13 Jan 2015 10:26

Re: [AI] RailwAI

Post by nihues » 15 Nov 2018 14:40

Since V8, my savegame (and a new game) start with this error.
Attachments
Black & Co., Jul 2nd, 1951.png
(151.72 KiB) Not downloaded yet

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

Re: [AI] RailwAI

Post by RailwAI » 15 Nov 2018 20:52

Thanks for reporting. I'm really surprised by this error, but I could reproduce it easily when I download the AI through BaNaNaS and start RailwAI.
If I extract the .tar file that was downloaded by openTTD to the AI folder, RailwAI starts without any problem.

If I take a look at the .tar file, it seems that openTTD writes 3 bytes too much for the file shippathfinder.nut. Usually this wouldn't matter because of zero-padding in the tar-files, but in this case BaNaNaS generated no zero-padding here :bow: I have opened an issue on GitHub about this bug in OpenTTD.

Luckily I'm not dumb and with a slightly different file length, BaNaNaS does more zero padding. :)
Changelog for version 11 (a lots of updates lately):
- Bugfix: verify if a train is in the way to build a tunnel properly
- Small changes in pathfinder for ships
- Slightly fewer buoys are used
- Workaround for a bug in OpenTTD that made this AI not downloadable through OpenTTD

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

Re: [AI] RailwAI

Post by RailwAI » 20 Nov 2018 21:08

After a bit of development time in the last days (and a lot of testing time, mostly by running openttd in the background), version 12 is now available. I have implemented a small bit of strategy, with the goal of having more active train routes. Looking at the tests, it mainly goes at the cost of using less ships. :P

The changelog:
  • Strategy: use more trains. Use less ships. Try to build more cargo routes.
  • Bugfix: Use trucks more often
  • Bugfix: Buoys aren't anymore avoided when planning where canals should come
  • A truck service may not have the same loading station as destination station
  • Bugfix: rail will be always connected properly when a rail station became accidentally a terminus station.
  • Repair accidentally missing rail connections between two adjacent rail tiles
  • Miscellanous things: give vehicles a name
  • When extending a service A-B to C, do a better check if C is further than B (seen from A)
  • Bugfix: no crash from loading a game saved while building a new train route of which the route had been re-planned
  • Bugfix: continue building canals from a savegame, when it was doing that
  • Do not try to replan a rail track when the first attempt wasn't feasible because it was too expensive
  • Loan will not be higher than 0, if the company has 10 times more cash than the maximum allowed loan
  • Implement electrifying/upgrading rail (whole network at once, only if the company has more than 5 million pounds)

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

Re: [AI] RailwAI

Post by RailwAI » 13 Jan 2019 20:56

A new year, so it's time for a new update. A few bugfixes, of which one was a major issue (concerning the finances): RailwAI loved to buy new road vehicles without giving them orders. Obviously, those vehicles were not really profitable.

The changelog for version 13:
  • Share orders and copy vehicle to the group, when buying a new truck/bus/ship from a different type on a connection
  • Bugfix: no crash when canceling a plan to buy a new truck/bus/ship
  • Bugfix: do not build a station meant to be a terminus connecting to other tracks
  • Bugfix: continue building a road detour around a level crossing from a savegame
  • Bugfix: try to use bridges above the desired speed limit (instead of 0 km/h) when building a road bridge
  • Removal of 90 degree turns on the rail network added in the yearly checks
  • Do not build 90 degree turns when connecting rail on a specific tile to adjacent rail tiles

peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1646
Joined: 30 Mar 2005 09:43

Re: [AI] RailwAI

Post by peter1138 » 09 Feb 2019 15:49

Bug I found in v13, in road.nut on line 128, AIRail.GetBuildCost(roadType, AIRail.BT_TRACK) is called instead of AIRoad.GetBuildCost(roadtype, AIRoad.BT_ROAD)
He's like, some kind of OpenTTD developer.

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

Re: [AI] RailwAI

Post by RailwAI » 14 Feb 2019 20:32

Thanks for mentioning! I will fix it in the next update :)

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

Re: [AI] RailwAI

Post by xarick » 27 Feb 2019 23:58

Slice out of range
Attachments
Unnamed, 1991-05-21.png
(273.05 KiB) Not downloaded yet
Formerly known as Samu

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

Re: [AI] RailwAI

Post by RailwAI » 28 Feb 2019 19:44

Good finding again. I directly made a change to version 14 that I was uploading, so that is now version 15.

The changelog for version 15:
  • Bugfix: removing a dead end road on a sloping tile
  • Bugfix: do not use rail building costs when determining what road type to use
  • Bugfix: compatibility issues with Aro AI
  • Adapt chances to pick a certain transport modality based on the company name.
  • Allow to extend a single rail bridge to two parallel bridges
  • Ignore one-way roads in pathfinding.
  • Build a second road depot on long truck routes
  • Use ships slightly more often
  • Longer minimum length of double rail sections on single track railway lines
  • RailwAI became better in removing a level crossing with an alternative solution
  • Trains/trucks/buses: if only slow vehicles are available (e.g. below 60 km/h), speed is now more important for deciding which vehicle to use
  • Increased minimum distance between the first passenger railway stations on a route
  • Passenger routes: set orders sometimes to full load to increase station ratings
  • Minimum platform length of 5 tiles for freight trains
  • Improved efficiency on the feasibility checks of a new rail line
  • Retry building a level crossing when it fails because a vehicle is in the way
  • Prefer industries with high production more
  • Do not prefer very long truck routes, as the chances of getting income are less

Dr. B. Ching
Engineer
Engineer
Posts: 97
Joined: 14 May 2011 10:58
Location: Sausagewood

Re: [AI] RailwAI

Post by Dr. B. Ching » 01 Mar 2019 21:18

I don't know which change did the trick, but RailwAI seems to be doing better on sparsely populated maps now. Older versions would sometimes just sit there and investigate idea after idea, yet never build anything worthwhile or fail to establish a single route even. Perhaps industries and towns being placed much further apart than usual in comparison to the default map generator was something they couldn't handle very well.

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

Re: [AI] RailwAI

Post by RailwAI » 28 May 2019 20:26

The major improvement on sparse maps was probably a combination of changes in version 15, largest part probably done by the improvement in efficiency of evaluating ideas for a new railway line.

It has been a while, but again time for some improvements. The changelog for version 16:
  • Bugfix: Ship pathfinder shouldn't fail when trying to create a new dock on land
  • Bugfix: Do not sell trucks or buses that are in a depot and were succesfully autorenewed
  • Improved search to a suitable location for docks
  • Added passenger ferry services
  • Added new options in the list for company name parts
  • Upgraded NoAI API-version to 1.6 or higher (get rid of legacy code)

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

Re: [AI] RailwAI

Post by RailwAI » 22 Jun 2019 22:10

In the last weeks I spent some time to create version 17. Main goal was to increase the capitalistic performance (income and profit) of the company. The changelog:
  • Bugfix: verify if a road bridge is connected to the next tile, when building a new route
  • Bugfix: verify if a rail bridge is connected to the previous tile, when building a new route
  • Bugfix: do not lower tile too much when building a railway tunnel in northeast direction
  • Bugfix: do not place signals placed in the wrong direction, based on a path signal in the other direction
  • Do not randomly connect rails to an adjacent train station
  • When a ship or road vehicle is lost, build new roads or canals to let it reach its destination
  • Re-use existing water depots
  • RailwAI doesn't go to sleep when no vehicles are running yet, or when a lot of money is available to spend
  • Sell vehicles when the destination station doesn't accept the cargo anymore
  • Sell some vehicles if too many are waiting at the loading station
  • Added support for station coverage set to lower values than default
  • Check if the vehicle limit is reached before planning a new connection
  • Vehicles that have 0% reliability are actively sent to a depot
  • Allow more ships in one vehicle group
  • Added time usage logging
  • Several code optimizations to increase performance
Then, I have a new screenshot for you:
Image

User avatar
syl59
Engineer
Engineer
Posts: 19
Joined: 21 Jul 2017 10:27
Location: Paris, France

Re: [AI] RailwAI

Post by syl59 » 24 Jun 2019 20:45

Hey !
I met your AI run for a couple years on a 1024x1024 map, temperate climate. I like its building style :)
After 12 years it has :
- 20 trains
- 45 RV
- 9 ships

I have noticed 2 things in its behavior :
- It tends to scan the entire map quite frequently. I think it's limiting the expansion of the company.
=> Maybe you can reduce the frequency of the scan, to make the AI a bit more competitive ?
- Its engine choice is sometimes wierd : On a wood line, it runs 2 trains : 1 with a steam engine and some wood wagon, and another train with DMU only.
=> Maybe it should calculate, on a given train line, what configuration has the more cargo ?

These are only suggestions :)

Cheers !
kiss
keep it simple, stupid

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

Re: [AI] RailwAI

Post by RailwAI » 28 Jun 2019 14:45

Hi, thanks for your feedback!
It looks like scanning the map indeed takes a lot of time on a large map. I used to test on much smaller maps, so I'll try to improve the performance on large maps in the next updates.
The usage of 2 different train types on a route is as intended: in my opinion it looks better with more different trains. Seemingly there was a DMU that can be used to transport wood. The length of a train might be short if the company didn't have enough money for a longer train yet. RailwAI should be able to adjust the train length after a while. Please let me know if it indeed increases the train length some day. :)

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

Re: [AI] RailwAI

Post by RailwAI » 30 Jun 2019 19:13

Version 18 is now available, in which I changed the "complete map scanning" to a different method (start with locations of vehicles and stations, then find adjacent tiles). It is faster, as long as the company owns less than 20% of all tiles on the map.

The changelog:
  • Bugfix: Do not convert electrified railway into diesel railway, even if there are no electric trains.
  • Heuristic map scanning, instead of interating the whole map (huge performance improvement on large maps)
  • A general performance improvement in computing tiles

User avatar
syl59
Engineer
Engineer
Posts: 19
Joined: 21 Jul 2017 10:27
Location: Paris, France

Re: [AI] RailwAI

Post by syl59 » 01 Jul 2019 20:02

Hello,

I tested your AI in the same game I did previously. Overall performance is improved :)

But ...
After one year of existance, it seems to be stuck in a loop where it scans industries on the map ...

Here is a screen of what the debug menu says :
Rail_AI_V18_Test.PNG
(30.07 KiB) Not downloaded yet

I can't link the save do to files reasons.
kiss
keep it simple, stupid

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

Re: [AI] RailwAI

Post by RailwAI » 02 Jul 2019 19:41

What it doesn't tell, is that it has not enough money to start a new connection. It should break automatically after a while if the company is able to make money, or after 300 times. I'll add an additional check in the code :)

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

Re: [AI] RailwAI

Post by RailwAI » 12 Jul 2019 09:38

A new version, number 19, is now available through BaNaNaS! I have had quite some spare time to let RailwAI play games, and I found some new (probably rare) bugs. Most could be fixed quickly.

The changelog:
  • Keep track of the reason a vehicle is sent to a depot, instead of guessing the correct action in the depot
  • Solve more train deadlocks by sending trains to a nearby depot for maintenance, and by changing signal types
  • Allow bidirectional transporation of cargo (e.g. valuables) if possible
  • Do not randomly connect a train station to adjacent rails
  • Speed optimizations in pathfinders
  • Rail pathfinder: found path is more often suitable for a double track railway line
  • Bugfix: do not accidentally remove rail below a bridge when only the bridge should be removed
  • Bugfix: do not remove a dead end rail track, if it can be connected easily
  • Bugfix: prevent disconnected rail track parts on the second track

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Wormnest and 5 guests