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

[AI] RailwAI

Post by RailwAI »

Hi all!

I am happily proud to present you a new AI called RailwAI. RailwAI is a best-effort, random behaving artificial player that can use ships, trains and road vehicles. Available through Bananas.
Some features of RailwAI:
- Build railway lines with 2 tracks (I hope you like the building style)
- Build roads, tramways and canals
- Use different types of available trains, bridges etc.
- Connect multiple cities on a single passenger line
- Executing building plans will be continued when loading a savegame
- Sometimes things go wrong (blocked canals, too long trains), RailwAI will hopefully try to solve the problem
- Support for (hopefully) a lot of NewGRF without creating weird train combinations (like, putting freight carriages behind a passenger unit)
- Behaviour is random. A company might go bankrupt when expensive vehicles are bought.
- It is called RailwAI, but it might have a preference for roads (because those are cheap)

Image
Last edited by RailwAI on 24 Aug 2018 21:45, edited 1 time in total.
User avatar
RailwAI
Engineer
Engineer
Posts: 75
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: [AI] RailwAI

Post by RailwAI »

The AI was hardly transporting cargo in the intial version. I found a few bugs related to cargo, so I have pushed a second version to BaNaNaS.
Changelog of version 2:
  • Bus services should now always be between 2 different cities/villages, of which one is not too small.
  • Better search for suitable location to build a dock for ships
  • Faster switching from building 2 tracks over the full line to using 2 tracks partially
  • Bugfix: selecting a cargo type to transport now works properly
  • Bugfix: if ships are available, trains and trucks can still be used to transport cargo
User avatar
Hyronymus
Tycoon
Tycoon
Posts: 13233
Joined: 03 Dec 2002 10:36
Location: The Netherlands
Contact:

Re: [AI] RailwAI

Post by Hyronymus »

This sounds cool, a realistic railway building AI that also uses different vehicle types. When I run into spare time I will surely check this out.
User avatar
RailwAI
Engineer
Engineer
Posts: 75
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: [AI] RailwAI

Post by RailwAI »

Thank you. I am currently trying to make bus services and passenger train services between smaller towns more profitable, that will hopefully be the next update. It is rather hard to do so without timetables.
User avatar
RailwAI
Engineer
Engineer
Posts: 75
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: [AI] RailwAI

Post by RailwAI »

Version 3 is available. Changelog:
  • Bugfixes: more succes in building road tunnels
  • Bus stops within large cities will be less close to eachother
  • Road depots are built closer to a road station
  • More truck stations can be built around factories
  • Faster pathfinder for roads on longer distances
  • Loan is set dynamically
  • Old vehicles will be replaced or sold
  • Unused stations will be removed
Edit: forgot to correct a small mistake in the last mentioned feature. You can download version 4.
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: [AI] RailwAI

Post by Brumi »

This AI is amazing!

Left it running in a heavily NewGRF'ed (FIRS and various vehicle sets) game, and I have not seen a single error so far! And it's very good to see that it's a multi-profile AI, ships are especially welcome :)

The only unusual thing I saw was that the AI built a really long canal right at the beginning of the game. And I was thinking, "How on earth did it not crash the company?", but then I saw that canal costs are lowered with SQUID significantly. The company was a success, obviously.
User avatar
RailwAI
Engineer
Engineer
Posts: 75
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: [AI] RailwAI

Post by RailwAI »

Thank you! It took me quite some time to develop something that I found ready for publication. I currently like it more to adjust some changes and watch a few AI playing openttd, than to play the game myself :P

Building a long route as the first route can be a large risk however. During test runs, I have already seen RailwAI going bankrupt when the cost estimation before was too low, but it will always depend on game settings. In your case, it was probably a bit of luck too.

Version 5 is now uploaded. The changelog:
- Bugfix: Reloading a game after the AI had crashed, sometimes caused the AI to immediately crash again
- Bugfix: Always use the corresponding rail type to build rails in front of a depot (instead of sometimes a different, compatible one)
- Bugfix: an unconnected station track was sometimes allowed
- Building less level crossings, as those often cause accidents when there is heavy road traffic
- Do not always reduce length of passenger trains, only if there will be not enough passengers
- Better re-use of existing canals
- When the company has enough money, it now can build statues
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: [AI] RailwAI

Post by Brumi »

Found something that may be of interest to you:
railwAI_trams.png
railwAI_trams.png (186.77 KiB) Viewed 9035 times
The pink player (railwAI) tried to make a tram connection in the SW-NE direction. I don't know what happened here, but it is certain that some of the trams actually made it to the NE side. Does the AI try to avoid level crossings by building detours? I see that the AI is constantly trying to make adjustments to this route, but for some reason it fails to see that the tracks coming from the SW are not connected.

Savegame is attached.
Attachments
railwAI_test_trams.sav
(576.72 KiB) Downloaded 380 times
User avatar
RailwAI
Engineer
Engineer
Posts: 75
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: [AI] RailwAI

Post by RailwAI »

The AI is indeed trying to remove level crossings, because on those crashes can occur between road vehicles and trains. The disconnected tramway is a bug I knew of, and I was already working on that part of the problem. I don't see directly why it keeps failing to properly remove the roads. I'm definitely going to tackle the issue in the next update, thank you for the savegame.
User avatar
RailwAI
Engineer
Engineer
Posts: 75
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: [AI] RailwAI

Post by RailwAI »

If you now update the AI, it should stop panicking over the railroad crossings and most crossings will be removed.

The changelog for version 6:
- Bugfix: some corner combinations were not always allowed
- Bugfix: no more blocking of locks when building new canals
- Bugfix: selecting correct tiles when planning a detour for a railroad crossing
- No more weird U-turns ("large pools") in new canals
- Railway lines with single-track parts will take less time
- Removing dead-end roads built by the company
- Reconnect tramways that were accidentally disconnected (can happen when a detour is made for a railroad crossing)
- Cargo services cannot are not anymore allowed to pick up cargo at the drop off location
- Borrowing more money from the bank to buy a train, if required
User avatar
RailwAI
Engineer
Engineer
Posts: 75
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: [AI] RailwAI

Post by RailwAI »

Short changelog for version 7:
- Bugfix: no more accidental removal of tiles of a different station
Dr. B. Ching
Engineer
Engineer
Posts: 109
Joined: 14 May 2011 10:58
Location: Sausagewood

Re: [AI] RailwAI

Post by Dr. B. Ching »

I've used your AI in several test games and came away impressed. It's been completely crash-free thus far, uses a pleasingly wide variety of engines (even odd stuff like HEQS' freight trams or 600mm narrow gauge train) and seems to do quite well for itself most of the time. The only persistent problems encountered are centered around waterways:
  • If 90° turns for ships and trains are forbidden, the AI doesn't always take this into account when building canals, and this leads to ships stuck in infinite loops around locks, depots or docks.
  • Construction of docks sometimes interferes with locks, blocking access.
  • Some canals are simply an unnecessary expenditure. I don't know how the pathfinder is set up, but the shortest route (canal through a tiny island) doesn't make sense when you could just go around it for free.
Kind Regards,
The Axe
Attachments
Precombe Transport, 1936-07-08.png
Precombe Transport, 1936-07-08.png (161.23 KiB) Viewed 26235 times
My scenarios for JGRpp: Motor City (1910), Fortune Bay (1993)
xarick
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 26 Feb 2015 00:52

Re: [AI] RailwAI

Post by xarick »

RailwAI v7, the index '0' does not exist
Attachments
Unnamed, 1953-06-25.sav
(17.57 MiB) Downloaded 340 times
Unnamed, 1953-06-26.png
(188.08 KiB) Not downloaded yet
Formerly known as Samu
nihues
Engineer
Engineer
Posts: 85
Joined: 13 Jan 2015 10:26

Re: [AI] RailwAI

Post by nihues »

Just started a hard game (normally do alone) to see what happens with 6 RailwAI, only red made barelly profit in 10 years, with ships, trains never got money until now, saw this attached :roll: , otherwise it's all nice made, maybe too much double tracks for starting (low starting money, but high loans, high construction and running costs... ). Saw some trains with 1 cargo wagon only (using Polish PKP Set that need to use 2 types of cargo - one with brakes, maybe that's the problem? but saw trains with normal size too).

There was one option on NoNoCab AI wich I like, that could be implemented? "try to stay away from already serviced industries" so we don't get a lot of stations on same place
Attachments
Black & Co., Apr 10th, 1935.png
(1.31 MiB) Not downloaded yet
User avatar
RailwAI
Engineer
Engineer
Posts: 75
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: [AI] RailwAI

Post by RailwAI »

Thanks for your replies!

The pathfinder for ships is a modified version of the default A* pathfinder, in an attempt of realizing a fast pathfinder. Sometimes it indeed chooses an expensive option when going around an island would be a possibility too. I didn't know that the 90-degree-turn setting also affected ships. I even don't know why, but when I forbid ships to turn 90 degrees, they still can make 90 degree turns in canals (original pathfinder, YAPF or NPF). Only 180 degree turns go wrong, but I think those should already be avoided in most cases by the AI. Do you have a screenshot with an example of an impossible turn for ships? For the blocking issue I think how I can solve it.

The crash occured when the AI tried to add more stations on the route of a bus with empty orders. The crash should not occur anymore in the next version of the AI (not yet published, because I also made some other changes that do not have yet the results I was expecting). What a massive savegame by the way, my PC has real difficulties running that one.

I'll check the behaviour of the AI with the Polish PKP set and do my best to learn the AI to make more profitable routes in hard games. Nevertheless, a train with 1 cargo wagon could have been normal behaviour: when there is not enough money to buy more carriages, a short train is usually better than no train. The AI is able to buy more carriages later on (or sell carriages when it thinks a train is too long).
If you have an example of a lot of stations on the same place, it would be helpful for debugging. RailwAI should have a strong preference to choose industries that are not serviced yet, because the best way of making money is to have an own set of clients (industries).
Dr. B. Ching
Engineer
Engineer
Posts: 109
Joined: 14 May 2011 10:58
Location: Sausagewood

Re: [AI] RailwAI

Post by Dr. B. Ching »

To be fair, I don't fully understand ship pathfinding, but they normally seem to be restricted to 45° turns (one per tile to navigate a 90° bend of the canal) with the setting enabled. However, the game appears to be lenient with docks at least: should a ship be unable to depart in the "proper" way, for instance if the station is located at the dead end of a canal, no harm is done, but you do get a brief "ship xx is lost" notification. Regular pathfinding seems less forgiving.

Kind Regards,
The Axe
Attachments
AI_impossible turn_dock.jpg
AI_impossible turn_dock.jpg (99.38 KiB) Viewed 9035 times
AI_impossible turn_lock.jpg
AI_impossible turn_lock.jpg (78.92 KiB) Viewed 25036 times
AI_bad bouey placement.jpg
AI_bad bouey placement.jpg (69.86 KiB) Viewed 9035 times
My scenarios for JGRpp: Motor City (1910), Fortune Bay (1993)
nihues
Engineer
Engineer
Posts: 85
Joined: 13 Jan 2015 10:26

Re: [AI] RailwAI

Post by nihues »

RailwAI wrote:Thanks for your replies!

If you have an example of a lot of stations on the same place, it would be helpful for debugging. RailwAI should have a strong preference to choose industries that are not serviced yet, because the best way of making money is to have an own set of clients (industries).
Didn't know that! Thats a good news! I don't have a problem with AI getting my industries but if they do I'll report, for now no problems!

For the double track, forget it, it's good, saw some exemples using 1 track and only double track for bypass.
xarick
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 26 Feb 2015 00:52

Re: [AI] RailwAI

Post by xarick »

Hey. It seems the crash I last reported doesn't originate from the AI itself, https://github.com/OpenTTD/OpenTTD/issues/6968
Formerly known as Samu
User avatar
RailwAI
Engineer
Engineer
Posts: 75
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: [AI] RailwAI

Post by RailwAI »

I was already thinking that it probably was related to a corrupted order list. Nevertheless, the crash could (theoretically) also occur in some rare cases when a player uses the magic bulldozer to remove some stations, or when the AI buys another company (I'm planning to implement that in future). Crashes should always be avoided, thus it was worth 3 checks of 1 line of code each :wink:

I am currently testing with the PKP train sets and I'm able to get crashes when trains are used that consists of a locomotive and dining cars only: the train is then not able to carry passengers :bow:
User avatar
RailwAI
Engineer
Engineer
Posts: 75
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: [AI] RailwAI

Post by RailwAI »

I tried on hard settings, but I clearly see why trains probably are not used in the first years: when the maximum loan is only $100.000, I barely have enough money to buy a single train. Then ships and buses/trucks are more feasible.
When RailwAI is using a single-track railway line (with passing sections), it does because it couldn't build a proper two-track line (for whatever reason). I have improved, but I am still not really content with the difficulty this AI has with building passing sections. It's high on the to-do-list, as well as using less buoys when ships are used.

Changelog for version 8 that is now available:
- Rail: Building (slightly) more passing sections
- Passenger trains: do not use carriages that offer 0 additional seats
- Add setting to regulate the amount of trees that the company will plant when it has a lot of money
- First transport service is now preferred to not be operated with ships. RailwAI will get less often bankrupt.
- Build additional buoys 8 tiles before and after a lock, such that ships get lost less often
- An unprofitable ship can be sold quicker when a new dock is built nearby the location of the ship
- Disallow U-turns (double 90 degree turns) for ships
- Remove disconnected railway tracks (but first reconnect bridges that were accidentally not connected properly to the next tile with track)
- Do not build docks adjacent to locks
- More possible company names
- When the company has a lot of money, it will start building some tunnels in existing railway lines
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 9 guests