WormAI

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

Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

WormAI

Post by Wormnest »

WormAI is an ai that tries to be competitive. It currently supports pax air transport and since version 5 also train support for all cargos.
In the tests I have done it usually performs fairly well as long as you haven't turned on infrastructure maintenance.

Minimum OpenTTD version 1.4.

WormAI is available on Bananas.

Current version: 10
Released: 2024-02-13

Changelog

Version 10, 2024-02-13
  • Fix: crash when there is no mail cargo.
Version 9, 2023-03-20
  • Fix: divide by zero when production is zero.
  • Doxygen documentation improvements.
  • Use https links.
  • Use python3 for making releases.
Version 8, 2019-09-09
  • Fix: Determination of 90 degree turn in rail pathfinder was wrong causing rollercoaster tracks and difficulties finding a path.
  • Fix: Remove rail tracks by using RemoveRailTrack as much as possible since that is cheaper than using DemolishTile which makes it less likely that we run out of money early in the game with a failed train route.
  • Fix: Not building airports in spots where the noise level will equal the maximum allowed noise level.
  • Fix: Take station spread setting into account when determining best airport type.
  • Add: Manage over saturated air routes by either removing planes from route or upgrading airports.
  • Add: Upgrade airports to International airports in certain cases.
  • Add: Regular checks that industries we use on a rail route are still accepting/producing our cargo. If not we will sell the vehicles and close the route.
  • Add: Extra pathfinding penalties to make it less likely the pathfinder continues a path far away from our destination.
  • Change: Improve finding airport spots adding towns to blacklist more often and only checking towns within distance limits.
  • Change: Adjust max aircraft route distance in early starting games depending on plane speed and reliability.
  • Change: Rail: Increase length of train routes if we have enough money.
  • Change: Lower minimum town for airport size in easy setting from 2500 to 1500.
  • Change: Use Graph.AyStar version 6 instead of version 4.
  • Change: Moved repository and issue tracker to Github.
Version 7, 2017-04-16
  • Fix: Not checking air route range at startup under certain conditions.
  • Change: Adjust maximum distance for air routes when we have limited money.
  • Change: Adjust aircraft selection when we have limited funds and high prices of longer range aircraft.
Version 6, 2016-05-28
  • Fix: Crash when loading a savegame saved when building a rail route or when replacing trains.
  • Fix: Crash when we get loaded into a savegame without getting any saved data.
  • Fix: We need to make sure we have at least some money to build a rail route.
  • Fix: Make sure that the vehicle we share orders with is valid.
  • Fix: 90 degree turns near a passing lane.
  • Fix: border of map starts at 1,1 not 0,0. (We were not building airports in towns near the left and upper borders.)
  • Change: more checks before building a passing lane, we should see less land is sloped wrong messages.
  • Change: Improved airport upgrading.
  • Change: Better handling of airplane NewGRF's that have high prices.
  • Change: Rail pathfinding tweaks.
  • Change: Don't cancel and remove routes just because we don't have money for vehicles. Just add them later when we do have the money.
  • Change: Don't use airplanes that are hardly profitable.
  • Change: Blacklist airports that we failed to upgrade for a while.
Version 5, 2016-05-14
  • Add: Train support. Based on SimpleAI but with changes and more to come.
  • Change: Take inflation into account.
  • Change: blacklist towns where we failed to build an airport for a while.
  • Change: Don't remove airports we just built if we don't have money to buy the airplanes. We build them later when we have the money.
  • Change: Don't waste time trying to upgrade airport if there's too much noise.
Version 4, 2016-04-30
  • Fix: Airplanes could get stuck when an airport upgrade failed.
  • Fix: After loading a savegame that had airplanes stopped in depot to be sold WormAI didn't know about them being in depot and tried to send them to depot again which failed causing them to not be sold.
  • Add: Build HeadQuarters (normal or fast setting).
  • Add: Build Statues in towns with an airport (fast setting only).
  • Change: Updated SuperLib to latest version (39).
Version 3, 2015-06-12
  • Add basic support for upgrading airports.
  • Fix: Don't use large aircraft on small airports.
  • Fix: Don't crash when there isn't a best engine at all.
  • Change: Don't add more airplanes to a route when there are too many planes waiting in the landing queue.
  • Change how we are starting tasks. Do it monthly/yearly instead of based on a tick count.
  • Some changes in the min/max and default values of some settings.
  • Increased required OpenTTD version to 1.4.
Version 2, 2013-08-02
  • Add support for vehicle breakdowns by adding depot maintenance orders.
  • Add vehicle management: send old vehicles to depot and sell once a month.
  • Fix: Incorrect tile rectangle near map borders.
Comments and bug reports are welcome :)
Last edited by Wormnest on 13 Feb 2024 18:40, edited 10 times in total.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: WormAI

Post by Kogut »

It may be a good idea to publish it on BaNaNaS - see http://bananas.openttd.org/en/ai/
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: WormAI

Post by planetmaker »

Kogut wrote:It may be a good idea to publish it on BaNaNaS - see http://bananas.openttd.org/en/ai/
Quite so. During NewGRF testing I usually have a handful of random AIs active in the test game and I'm happy to share any problems they encounter. But I'm usually too lazy to pick them from other places than the convenient ingame download :-)
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: WormAI

Post by Wormnest »

It certainly was (and is) my intention to post it on bananas.
My main reason for not having done that yet was the problem I had in signing up for an account as posted in this thread.
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: WormAI

Post by Wormnest »

Version 2 is now available from the first post and also on Bananas.

Changelog

Version 2, 2013-08-02
---------------------
+ Add support for vehicle breakdowns by adding depot maintenance orders.
+ Add vehicle management: send old vehicles to depot and sell once a month.
+ Fix: Incorrect tile rectangle near map borders.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: WormAI

Post by Zuu »

While testing your AI, I noticed that you have large planes scheduled to transport passengers between small airports. This give a significant increased risk of aircraft crashes. I would recommend against using large airplanes on small airports (Small & Commuter).
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: WormAI

Post by Wormnest »

Thanks for reporting this.
I added it to my list of things that need looking at. However I currently don't have time so it might be a while.
Jabbo
Engineer
Engineer
Posts: 1
Joined: 27 Aug 2014 17:11

Re: WormAI

Post by Jabbo »

error script
error script.jpg
(652.17 KiB) Downloaded 2 times
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: WormAI

Post by Wormnest »

Jabbo wrote:error script
Thanks for the report. I think I know what went wrong.
As soon as I can find some time I will have a look at it but there are some other unfinished changes I need to work on too so it might be a while before I can release a new version.
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: WormAI

Post by Wormnest »

A new version that fixes the reported bugs is now available from Bananas and the first topic in this thread.

Changes:

Version 3, 2015-06-12
  • Add basic support for upgrading airports.
  • Fix: Don't use large aircraft on small airports.
  • Fix: Don't crash when there isn't a best engine at all.
  • Change: Don't add more airplanes to a route when there are too many planes waiting in the landing queue.
  • Change how we are starting tasks. Do it monthly/yearly instead of based on a tick count.
  • Some changes in the min/max and default values of some settings.
  • Increased required OpenTTD version to 1.4.
Still some things left that could be improved but I haven't had a crash in 50 years of running it.
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: WormAI

Post by Wormnest »

A small update with mostly minor fixes and improvements.

Changelog

Version 4, 2016-04-30
  • Fix: Airplanes could get stuck when an airport upgrade failed.
  • Fix: After loading a savegame that had airplanes stopped in depot to be sold WormAI didn't know about them being in depot and tried to send them to depot again which failed causing them to not be sold.
  • Add: Build HeadQuarters (normal or fast setting).
  • Add: Build Statues in towns with an airport (fast setting only).
  • Change: Updated SuperLib to latest version (39).
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: WormAI

Post by Wormnest »

Finally WormAI can do more than just airplanes. With this release I have added train support. It is based on SimpleAI but with several changes and more planned.
Trains currently require that 90 degree turns are allowed I will work on fixing that in a future version.

It was doing pretty well in a test game started in 1940. By 1975 WormAI was in second place on operating profit after Terron.


Changelog

Version 5, 2016-05-14
  • Add: Train support. Based on SimpleAI but with changes and more to come.
  • Change: Take inflation into account.
  • Change: blacklist towns where we failed to build an airport for a while.
  • Change: Don't remove airports we just built if we don't have money to buy the airplanes. We build them later when we have the money.
  • Change: Don't waste time trying to upgrade airport if there's too much noise.
Attachments
AI Test 1940 start inflation on, 1975-01-01.png
(473.84 KiB) Not downloaded yet
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

Re: WormAI

Post by Brumi »

Cool, it's exciting to see code from my AI getting forked :) Although my code is quite a mess, I wrote SimpleAI before I actually started studying programming :P

I'm giving it a test run now, so far it's going really steady.

EDIT: There's one thing I've noticed: the log says that the AI is not building more aircraft because of the aircraft limit, despite the fact that it has only 11 aircraft while the limit is 20. Maybe it reached the limit some time in the past?
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: WormAI

Post by Wormnest »

Thanks for your comments. There's certainly room for improvements in both what I've done to your code so far as well as the original code :) but all in due time.

I thought I saw something similar to the aircraft limit message but I was thinking it might have to do with airplanes being more expensive than it expects. I will have to take a look at that code again sometime. Did you use a NewGRF for aircraft? If so which one. Airport upgrading also needs some improvements which I'm aware off.
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

Re: WormAI

Post by Brumi »

No, I wasn't using any aircraft NewGRFs. And I'm positive that the AI had more than plenty of money to buy them :)
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: WormAI

Post by Wormnest »

Are you sure it didn't say it wasn't going to build more airports instead of aircraft. Because I do have a similar message about not building more airports which it decides based on the max allowed airplanes.
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

Re: WormAI

Post by Brumi »

Uhm, now that you bring it up, I think you're right. I can also confirm it by loading the last autosave, it's not building more airports. It even has 13 aircraft compared to the 11 when I last reported.
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: WormAI

Post by Wormnest »

Ah good that part is working as expected then.
xarick
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 26 Feb 2015 00:52

Re: WormAI

Post by xarick »

I finally finished that 1st testing with 15 WormAIs we talked about at IRC. My prediction was that Pink was going to win in profits, but I was wrong. Pink is Company 1. Here are the parameters I used:

WormAI = min_town_size=2000,start_date=1
WormAI = start_date=1
WormAI = max_airport_distance=250,min_airport_distance=25,min_town_size=100,start_date=1
WormAI = max_airport_distance=4000,min_airport_distance=500,min_town_size=10000,start_date=1
WormAI = start_date=1,use_planes=0
WormAI = start_date=1,use_trains=0
WormAI = ai_speed=2,start_date=1
WormAI = ai_speed=1,start_date=1
WormAI = max_airport_distance=400,min_airport_distance=300,start_date=1
WormAI = max_airport_distance=450,min_airport_distance=350,start_date=1
WormAI = max_airport_distance=500,min_airport_distance=400,start_date=1
WormAI = max_airport_distance=600,min_airport_distance=500,start_date=1
WormAI = min_town_size=100,start_date=1
WormAI = min_town_size=1000,start_date=1
WormAI = min_town_size=1500,start_date=1

'openttd.cfg' lists 'none = start_date=1' for the first company, but I started this game in multiplayer, moved myself to spectator, killed my company, configured the 15th WormAI in the free'ed slot with min_town_size of 2000, then went to console and typed 'startai'.

Beware of the savegame, it has over 16000 vehicles, AIs with 250k #ops each, and a map size of 4096x4096!
Attachments
screenshot#19.png
(200.33 KiB) Not downloaded yet
WormAI #15, 2051-01-01.sav
(21.34 MiB) Downloaded 423 times
openttd.cfg
(11.19 KiB) Downloaded 401 times
Formerly known as Samu
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: WormAI

Post by Wormnest »

Thanks for the extensive test :)

I think that the min/max distances for WormAI 8-11 were probably chosen a little close together, they perform pretty similar. A larger distance between minimum and maximum might show a bigger difference possibly.

The train only one not doing anything was a bug that I had already fixed. Hopefully I can release a new version soon.
Another bug that's also fixed in the development version is the crash that happened for 2 of the WormAI's when I tried loading the savegame.
For the rest it's nice to see that they managed to reach 2051 without crashing.

Remarkable also that #5 has the highest company value but is only subtop in Operating Profit. Probably related to only using airplanes.
There's ofcourse different ways to look at who's performing best but still an interesting test.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest