SuperSimpleAI v25 (Old Stable), v41 (Stable) and v47 (Testing)

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

Jaume
Engineer
Engineer
Posts: 54
Joined: 24 Aug 2007 15:43

SuperSimpleAI v25 (Old Stable), v41 (Stable) and v47 (Testing)

Post by Jaume »

Hi all!

This is a new AI, based of code of SimpleAI v12 (thank you so much, Mr Brumi), but isn't another (or better) SimpleAI: this AI makes very profitable single point to point large routes, with lots of long trains each one. It is very configurable, and is almost stable. The default configuration makes routes up to 1920 tiles long, with 24 tiles long trains. Of course, it can be configured to emulate SimpleAI, and it works better than this AI, it can recover unfinished routes when loading games (in some cases), and test if it can build new routes before spend money on its construction. Another features are statue of owner's company building, managing vehicles while pathfinding, better passing lanes and stations, bigger airports and replacement of small airports...

Goals: This AI was build to create more realistic cargo routes and trains. Like SimpleAI, this AI can manage trains, buses and trucks, and planes. But most of tests are done only with cargo trains, no other type of vehicles are well tested. This isn't a winner AI, but can do lots of very profitable cargo routes that looks real cargo lines. Of course, building air routes makes lots of money.

This is the changelog from SimpleAI v12 (not all modifications are documented, especially first of they, made too many years ago):

v13:
Don't remove unprofitable trains (I don't like how it works).
Longer trains, stations and passing lanes up to 7 tiles (configurable).
Single destination stations.
More than 2 trains per route.
Allow train routes up to 200 tiles.
Better passing lanes without unnecessary signals.

v14:
Allow 1, 3, 4 and 5 passing lanes.
Allow long train routes, up to 910 tiles (configurable).

v15:
New BuildPassingLanes function.
Allow up to 15 passing lanes (configurable).
Allow long road routes, up to 230 tiles (configurable).
Allow long train routes, up to 1640 tiles (configurable).
Allow long aircraft routes, up to 1640 tiles (configurable).
Disallow new/close industries logging.
Allow to add more trains on a route, then new routes are started with only one train.
Disallow large bridges and tunnels if we don't have more than 250k (inflated).
Wait if we need money to finish a rail/road route.
Check routes and events while pathfinding.
Don't send to depot fully loaded trains.
Don't reverse trains to find a depot.
Don't send to depot more than one vehicle if we can't paid it.
Restart unfinished routes when load a saved game, if it is posible.
Build statue if we have some money.
Prevent to add new train if empty train is waiting for cargo.
Forbid non-flat passing lanes (configurable).
Set name to stations.
Better aircraft manager.
Now works well if forbid_90_deg game setting is set to true.

v16:
Check if we can build all stations and passing lanes before build it.
Length of trains now depends of industry production.
Better passing lanes.
Updated max lenght of aircfraft and rail routes.

v17:
Prevent crash when GetLastMonthTransportedPercentage() runs while month change. (Fixed in SimpleAI v13)
Diagonal passing lanes.
Better order flags.
Bridges and tunnels on passing lanes.
Build stations as closest as possible to industry (configurable).
Permit 15 tiles long trains.
Allow double and triple traction.
Allow long train routes, up to 1920 tiles (configurable).

v18:
Don't destroy active routes when demolish join stations (SimpleAI bug).
Don't crash when load game with builded but not finished route (SuperSimpleAIbug).
Safer GetRailStationPlatformLength() function.

v19:
Disallow diagonal passing lanes when signals aren't PBS.
Better diagonal passing lanes.
Better passing lanes ubication.
Less railtrash when aborting passing lane building.
Capped the maximum amount of routes at 1000 to prevent "Took too long to save" errors. (Fixed in SimpleAI v13)
More fault tolerance when building road stations: the AI now should not leave C-shaped road pieces when failing to build a road station. (Fixed in SimpleAI v14)
Fixed running cost calculation in the train engine valuator (fix by SirkoZ in SimpleAI v14)

v20:
Disallow tunnels and bridges on passinglanes if this AI is configured in Old Style (TTO, TTD, SimpleAI).
Allow reverse trains only if not using PBS.
Replace non-empty trains to depot if they are 80 years old.
Replace non-empty road vehicles to depot if they are 40 years old.
Check if the heads of stations and passing lanes needs a bridge or tunnel, and if they can be build.
Build mandatory rails on stations and passing lanes heads.
Added better estimation tunnel cost with inflation.
Limit the minium length of cargo trains (configurable).
Fixed bad max distance for road routes and update it to 280 tiles.
Allow four engines in multiple traction.
Estimate inflated cost of a bridge head when they aren't on flat/well sloped tile.
Check if possible to build the destination road station before build the source road station.
Abort building rail route if source or destination industries closes.
Fixed problems with passinglanes and Sygnal Type == 3.
Build road stations as closest as possible to industry (configurable).
Build statue if we have some money, now configurable.
Don't build unnecessary temporaly depots to avoid 90 grade turns.
Limit the number of vehicles than a short road route can has.
Sell all trains and remove a rail route if source or destination industry closes.
Sell all road vehicles and close a road route if source or destination industry closes.
More checks before build road stations.
Fixed incorrect cost calculation of some bridges and wrong type of bridge.
Fixed wrong number of airplanes per route.

v21:
Fixed renaming used airports when build new route.
Optimistic GetInflationRate() function.
Use international and intercontinental airports and more agressive air model (configurable).
Better detection of industry closures.
Don't build a piece of track in "rail heads" if we can build a tunnel.
Fixed building mail rail routes when vehicles are unavailable.
More configurable options in settings.nut file.

v22:
Fixed closing mail routes if the station isn't close to town center.
Fixed incorrect calculation of distance in cargo rail routes.
Add road vehicles to a route faster.
Tries to reuse source airport with another existing airport if can't build destination airport.
Replaces small airports when reach their capacity with greater ones.
Forbid duplicate passenger routes, with no difference if they are road, rail or air.

v23:
Posible bugfix: restore previous rail type on UpgradeRailBridges() and AttachMoreWagons() functions.
Fixed crash after finish unfinished route when load a game with debug set to true.
Removed debug setting from info.nut and added SuperSimpleAI, cManager and cBuilder debug settings. (commented)
Fixed ingame setting to "build_statue" setting.
All settings in info.nut file are now optional, the default values are in settings.nut file.
Prevent infinite recursion loops in CheckRailHead() function.

v24:
New semidiagonal passing lanes (all railbuilder-passinglanes.nut code was rewrited).
Taken RailPathFinder library from WormAI, who was inspired by AdmiralAI to modify original library.

v25:
Build destination road stations without depot (configurable via settings.nut file).
Discarting RailPathFinder library from WormAI, but taken some ideas extending standard library.
Build local bus routes into a town (better code is needed, configurable).

v26:
Small bugfix with subsidied passenger routes.
Bugfix: Remove destination station if building source station was interrupted.
Another small bugfix with semi-diagonal passing lanes.
More mail wagons in passenger trains.
Upgrade road and rail bridges only if vehicles are faster than bridges.
Allow dual cargo train routes (for example, grain and livestock trains).
Allow dual destination routes with dual cargo.
Lengthening short trains only if source and destination stations are larger.
Permit up to 16 tiles long cargo trains.
Permit up to 6 tiles long passenger trains.

v27:
Clean remove of passing stations.
Configurable elictrifying lines.
Allow more station allocation.

v28:
Fixed crash with double cargo, when destination is a town.
Fixed crash when terraforming at same place that this AI try to build a passinglane with tunnels or bridges.
Better station allocation.
More passing lane options.
Better economics at start of the game.
Better rail tunnel cost estimation.
Better pathfinder: Penalty for tile heights over max height or under min height (some functions come from SuperLib, write by Leif Linse).

v29:
Fixed bottom to bottom stations bug.
More pathfinder: try to build cheaper at begining of the game, more direct routes if we have more income.
Replaced SimpleAI readme.txt by newer one about SuperSimpleAI (ufff).
Better passing lanes location.
Faster passing lane building.
Faster track building where building rail between stations and passing lanes.
Add more engines when freight_trains from Game Settings is greater than 1.

v30:
Fixed crash with engineblacklist when reloading game.
Fixed crash in myairoad.GetRoadCost.

v31:
Fixed crash when loading game and rail building was interrumped.
Fixed removing route after load game, if a vehicle was blacklisted or WaitForMoney timed out.
Max number of engines are increased to 5, and better power estimation.

v32:
Fixed cManager.CheckRoutes() malfunction when try to replace old passenger trains.
Fixed strange changes of rail type while building a route.
Fixed cBuilder.WaitForMoney() malfunction when needed money is bigger than maximum loan.
Better power estimation of train engines.
Better cash management.
Safer replacing trains: Sell old train only if we can build new one before (building train can fail because new engines that are not blacklisted).
Permit up to 20 tiles long freight trains.
Remove bridge from bridgeslist when this bridge is removed manualy.
Some changes in default configuration.
Better engine blacklist management.

v33:
Fixed failing search of passengers engines in cBuilder.ChooseTrainEngine() function with some sets.
Fixed malfunction in cBuilder.UpgradeRailBridges() and cBuilder.UpgradeRoadBridges() when other players creates their own groups.
Better engine blacklist management when loaded game has unfinished rail route.
More mail wagons in large passenger trains.

v34:
Fixed crash (since v33) in SuperSimpleAI.RestartUnfinishedRoute() function.
Readded type of rail lines in normal settings profile, in info.nut file.

v35:
More options when building passinglanes under bridges.
Adjust the number of wagons in dual cargo routes, when cargo production are not equal.
Permit up to 24 tiles long freight trains.
Better power estimation of train engines and up to 8 engines per train.
Allow double platform stations at large passenger routes (experimental, disabled).
Increased pathfinder itinerations to 300.
Slowdown effect doesn't stop building when date is changed to the past.
Manager.CheckRoutes don't use more than 20% of time. So not slowdown effect because checking routes too often.
More tests before build road or rail stations.

v36:
Fixed airbuilder missing functions (introduced in v35).

v37:
Fixed crash in settings.nut (introduced in v35).
Fixed crash produced while retrying building rail and last valid tile was a bridge.

v38:
Fixed crash because number of parameters of AIGroup.CreateGroup(), in older OpenTTD this function only need one parameter, but latest version requires two parameters.
Show the OpenTTD version at start of SuperSimpleAI.

v39:
Re-fixed last crash, because in some OpenTTD versions last fix does not work.

v40:
Removed MyAIGroup.CreateGroup() function because crashes were produced (in my case) because my libraries were broken.
Adding closeing unprofitable road and rail routes (experimental, disabled by default).
Fixed using trains when local buses are allowed but no road vehicles are available.
Setting the group name with the new name of the station, if they were renamed.

v41:
Bigger road stations.
Safer removing road depot when removing a road station, if the depot is not at same direction than station has then they don't be removed.

v42:
Fixed error building passinglanes over my tracks.
Don't build airports if no suitable planes are available.
Fixed changing the name of stations and airports when company's name is too long.
Fixed building passenger rail routes when they are disallowed by AI settings.
Prevent to use cars with non-zero cost and less than 5 passenger of capacity.
Fixed (un)recovery rail route after load game, because the engine was blacklisted or was waiting for money for long time.
Don't use elictrified rails at starting stages (it's too expensive!).
Wait for money before demolish a tunnel, bridge, station or depot, with this less rail/road trash are produced in negative bank balance situations.

v43:
Fixed crash loading game, if engine was blacklisted.
Fixed crash if try to replace after loading game.
Cache for compatibility between engines and wagons.
Faster and cheaper road building.

v44:
Fixed corruption of saved data. This bug was introduced in v43.
Changed the limit of maximum routes to 2400.
Added some cache to manager.

v45:
Fixed error with replacing trains, introduced in v44.
Fixed railtype error when restarting unfinished rail route.
Fixed crash with missing SetAirportThisName function, lost in v42.
Some changes in Load and Save functions.

v46:
Fixed crash in MyAIVehicle::MailWagonWorkaround() function when one parameter is null.
Don't try to build mail wagons if mail cargo is not available.
Use "ai_disable_veh_aircraft", "ai_disable_veh_train" and "ai_disable_veh_roadveh" from Game Settings.

v47:
Fixed crash in save function when building a road route.

DEPENDENCES: SuperSimpleAI, like SimpleAI, depends on the following libraries:
- Pathfinder.Road v4
- Pathfinder.Rail v1
- Graph.AyStar v4 (a dependency of the rail pathfinder)
- Graph.AyStar v6 (a dependency of the road pathfinder)
- Queue.BinaryHeap v1 (a dependency of Graph.AyStar)

BUGS: If the company's name is too long then fails to change stations names (since v15, fixed in v42).

Saved games: Version 41 and 47 are incompatible with version 25 or older.

Recomended settings: this AI may build 24 tiles long trains, so remember to set limits of trains and stations from configuration. In some cases this AI can build lines with 90º turns, so don't forbid this turns. Breakdowns may be set to none, because very large routes than have only one depot.

PD: Version 25 is now considered Old Stable (compatible with saved games with v25 or lower), version 41 is Stable and version 47 is Testing.

Enjoy it!
Attachments
SuperSimpleAI-25.tar
Old Stable
(400 KiB) Downloaded 279 times
SuperSimpleAI-41.tar
Stable
(540 KiB) Downloaded 128 times
SuperSimpleAI-47.tar
Testing
(550 KiB) Downloaded 92 times
Last edited by Jaume on 18 Jul 2023 16:37, edited 81 times in total.
Jaume
Engineer
Engineer
Posts: 54
Joined: 24 Aug 2007 15:43

How to remove manually a (unprofitable) route?

Post by Jaume »

How to remove manually a (unprofitable) route?

1.- Remove it's train depot.
2.- Build a new train depot in same place.
3.- Send all trains to depot.
4.- Sell all trains.
5.- Wait. This AI removes all routes that doesn't have vehicles.
Last edited by Jaume on 07 Jan 2021 11:51, edited 1 time in total.
Jaume
Engineer
Engineer
Posts: 54
Joined: 24 Aug 2007 15:43

Some images

Post by Jaume »

Some images:
SuperSimpleAI-3.png
(1.04 MiB) Not downloaded yet
SuperSimpleAI-1.png
(438.23 KiB) Not downloaded yet
SuperSimpleAI-2.png
(554.83 KiB) Not downloaded yet
User avatar
2TallTyler
Route Supervisor
Route Supervisor
Posts: 490
Joined: 11 Aug 2019 18:15
Contact:

Re: SuperSimpleAI

Post by 2TallTyler »

This looks nice. I’ll have to try it out.

EDIT: Would you care to upload this to Bananas? That would automate downloading the pathfinder dependencies and make installation easier.
Jaume
Engineer
Engineer
Posts: 54
Joined: 24 Aug 2007 15:43

Re: SuperSimpleAI

Post by Jaume »

Would you care to upload this to Bananas?

I'm sorry, but GitHub doesn't works on my old PC.I try it later.
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SuperSimpleAI

Post by Brumi »

Whoa, it's exciting to see another fork of SimpleAI, I have to try it :) Also it's funny to have an AI named SuperSimpleAI which is actually more advanced than SimpleAI ;)
I apologize for all the headaches my old code caused for you!

I only see one absolutely minor issue so far: I'm running two instances of this AI, and only one of them renames its stations (e.g. Brown Freight SRC_22 (1964)), the other one keeps the default names. The only difference between them in configuration is the log date format. If the AI reads station names for extra info (like, I've seen .tmp-named stations popping up here and there), this might be an actual issue instead of just visuals. Random guess: maybe the station names would be too long, given the company name F. Cuthbert Inforporated?

And I have a question for you:
Jaume wrote:v17:
Prevent crash when FindService() runs while month change.
Is this crash possible in SimpleAI as well? I'll also have to fix it if it's in my code :)
Jaume
Engineer
Engineer
Posts: 54
Joined: 24 Aug 2007 15:43

Re: SuperSimpleAI

Post by Jaume »

Hi Brumi, nice to meet you! :-)

I only see one absolutely minor issue so far: I'm running two instances of this AI, and only one of them renames its stations

Oh, yes, it's another bug. This is because the name of your second company is too long, then fails to renames its stations.

Prevent crash when FindService() runs while month change. Is this crash possible in SimpleAI as well?

EDIT: No, you fixed it in v13: Fixed possible division-by-zero error in cBuilder::GetLastMonthTransportedPercentage(). But returning 0 if LastMonthProduction is 0 may create a new route even if it is serviced. I think is better return 99.

EDIT2: I send a private message to you with bugs and improvements that I found in your code, because no other users of this forum may be interested to see code.

Thank you for you great code and inspiration! :-)
Last edited by Jaume on 04 Feb 2021 19:45, edited 9 times in total.
User avatar
Wuzzy
Engineer
Engineer
Posts: 66
Joined: 18 Aug 2019 18:04

Re: SuperSimpleAI

Post by Wuzzy »

Did you know there is a v14 of SimpleAI? Why didn't you fork off v14, but from v12 instead? :(

I really like to see forks of SimpleAI, as long they remain simple, and stay more or less true to the original behavior. :D

The biggest wish I have would be ship support. Then it would be perfect.

I really wish I have for OpenTTD to add a simple official default AI, which is then improved over time. SimpleAI is a strong candidate, and SuperSimpleAI might be even a stronger one. viewtopic.php?f=65&t=85812
Jaume
Engineer
Engineer
Posts: 54
Joined: 24 Aug 2007 15:43

Re: SuperSimpleAI

Post by Jaume »

Did you know there is a v14 of SimpleAI? Why didn't you fork off v14, but from v12 instead?

I'm sorry, I started this project too many years ago, simply disabling some functions for my funny games. Since SuperSimpleAI v19 all changes from SimpleAI v13 and SimpleAI v14 are included.

The biggest wish I have would be ship support. Then it would be perfect.

Yes, but this isn't easy, I don't know if some AI has a good code to share, but SimpleAI and SuperSimpleAI does't have. Maybe will writen from zero?
Jaume
Engineer
Engineer
Posts: 54
Joined: 24 Aug 2007 15:43

Re: SuperSimpleAI v21

Post by Jaume »

Now I'm finding an AI that manage ship routes to still their code. One of candidates is ShipAI-v10, works well without crashes (for the moment). No other AI with ship support were found without crashes (I don't have too much time for test all AIs).

What AI you know that manages ships, and are stable?
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SuperSimpleAI v21

Post by Brumi »

Here is a list on the wiki: https://wiki.openttd.org/en/Community/A ... s#features It's a bit outdated, but it still may be useful to you :)
From these, I remember DictatorAI (which also has some of its roots in SimpleAI), NoNoCAB, RailwAI and Terron AI being generally stable.

Also, I think you should add SuperSimpleAI to this list as well ;)
Jaume
Engineer
Engineer
Posts: 54
Joined: 24 Aug 2007 15:43

Re: SuperSimpleAI v23 (stable) and v24 (testing)

Post by Jaume »

Hi Mr. Brumi.

Well, I updated this list to include SuperSimpleAI.

I have a problem with my account in BaNaNaS, I forgot the email address wich I used to create and upload SuperSimpleAI, and for the moment I can't upgrade this AI. :cry: Maybe changing the name of this AI... I hate Github...
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: SuperSimpleAI v23 (stable) and v24 (testing)

Post by Brumi »

I think you should contact TrueBrain in this case, so that you won't have two different versions of this AI up on Bananas.
xarick
Transport Coordinator
Transport Coordinator
Posts: 335
Joined: 26 Feb 2015 00:52

Re: SuperSimpleAI v23 (stable) and v25 (testing)

Post by xarick »

Got a crash report:
SuperSimpleAI v19, downloaded from BaNaNaS, OpenTTD 12.0-beta2
Attachments
Unnamed, 1963-11-18.sav
(7.46 MiB) Downloaded 163 times
Unnamed, 1964-12-09.png
(382.88 KiB) Not downloaded yet
Formerly known as Samu
User avatar
3iff
Tycoon
Tycoon
Posts: 1093
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: SuperSimpleAI v23 (stable) and v25 (testing)

Post by 3iff »

Just found this, and as I exclusively use SimpleAI I'm going to have to give this a go.

I think I tried ShipAI. It tended to build some strange routes but otherwise was fairly stable. Adding ships to this would be wonderful. Good luck in achieving the dream!

Well, I've been testing this (just letting it get on while I develop my industry set) and I've found no problems at all with V23. I have 5 instances running and the game has run for 100 years with no problems (and definitely no crashes). I now need to get around to setting the parameters to something other than the default values...but I shall definitely be using this AI. Nice work.
User avatar
3iff
Tycoon
Tycoon
Posts: 1093
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: SuperSimpleAI v23 (stable) and v25 (testing)

Post by 3iff »

Just 1 odd crash in over 200 years of playing. Unfortunately I don't have the save or details but... (using V23)

An AI built a monorail route and didn't have enough cash to build a train. It crashed when checking root.blacklist (main: line 707) complaining that root didn't exist. I have been stopping the game a lot due to working on my industry set so I may have caught it at an unfortunate moment. On reloading, it just carried on (but ignored the monorail route).

I notice that routes sometimes run at a terrible loss (I'm playing with very low cash payments at the moment) but many road mail/passenger routes are running at a heavy loss with no attempt to close these routes. The same applies to trains.

However, I do like it that AI recognises an industry has closed and shuts the route. In my game where this happens a lot, it's far better that having to wait a year or so before the route shuts down.
srschacher
Engineer
Engineer
Posts: 41
Joined: 15 May 2017 12:48

Re: SuperSimpleAI v23 (stable) and v25 (testing)

Post by srschacher »

Hi.

I've been playing this game for awhile, but not with any AI. I was playing with various town growth game scripts, but I was ready for some competition and I decided to try your AI.

In my first game, the AI company eventually went bankrupt. I noticed that all the trains had run down to less than 10% reliability and were constantly breaking down (I'm playing with breakdowns turned on). I wonder if this is the root cause for the unprofitability of the AI company?

Are you currently accounting for maintenance in your AI script to keep the vehicles from breaking down so often?

Regards,
Steve
srschacher
Engineer
Engineer
Posts: 41
Joined: 15 May 2017 12:48

Re: SuperSimpleAI v23 (stable) and v25 (testing)

Post by srschacher »

My second AI company in the same game just went bankrupt.

I think the problem is that the AI is not replacing old train engines. The reliability drops to 0% and the trains can no longer move more than 1 square before breaking down. Eventually, the company runs out of money.

I suppose the fix is to put in logic to replace old engines?

Regards,
Steve
Jaume
Engineer
Engineer
Posts: 54
Joined: 24 Aug 2007 15:43

Re: SuperSimpleAI v23 (stable) and v25 (testing)

Post by Jaume »

xarick wrote: 11 Sep 2021 15:14 Got a crash report:
SuperSimpleAI v19, downloaded from BaNaNaS, OpenTTD 12.0-beta2
This code was rewritten at v20 version, try to use latest releases, they should be more stable than v19.
Jaume
Engineer
Engineer
Posts: 54
Joined: 24 Aug 2007 15:43

Re: SuperSimpleAI v23 (stable) and v25 (testing)

Post by Jaume »

srschacher wrote: 05 Nov 2021 01:16 My second AI company in the same game just went bankrupt.

I think the problem is that the AI is not replacing old train engines. The reliability drops to 0% and the trains can no longer move more than 1 square before breaking down. Eventually, the company runs out of money.

I suppose the fix is to put in logic to replace old engines?

Regards,
Steve
Well, this AI doesn't works well with breakdowns. Not only because this AI try to replace old vehicles only when getting (very) old, I think that this AI never will work well with breakdowns.

If you play with breakdowns, there are lot of AIs that works well with this settings. An AI that doesn't go to bankrupt with breakdowns will do:

1.- Routes as short as possible.
2.- Double track lines, with a lot of depots along every route. Or maybe a single rail track for every train.
3.- Lots and lots of signals.
4.- Short trains (15 tiles long trains spend a lot of time entering to and exiting from a depot at 61km/h).

I hate these kind of lines, and they are the oposite style of lines than this AI does. SuperSimpleAI is designed to use the minium railtracks, signals and depots as possible, with maximizing the bandwith with very large trains.

Regards!
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 14 guests