ShipAI

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

Post Reply
mjm
Engineer
Engineer
Posts: 11
Joined: 23 Oct 2016 21:37

ShipAI

Post by mjm »

AI that operates only ships (both freight and passenger cargos).

It supports:
- building canals, locks and aqueducts (only for freight)
- autoreplacing vehicle model when the new, better model appears
- selling unprofitable vehicles
- autoreplacing old vehicles with new ones
- demolishing stations with no cargo production/acceptance

Current version: 10
Download: https://github.com/mmuszkow/ShipAI/archive/master.zip
The code is available on my github: https://github.com/mmuszkow/ShipAI
Last edited by mjm on 24 Nov 2019 02:14, edited 3 times in total.
lucj@n
Engineer
Engineer
Posts: 10
Joined: 21 Jul 2008 16:11
Location: Polska/Poland

Re: ShipAI

Post by lucj@n »

Hi. Is this normal for this AI to place so many buoys?
And another thing, have a look at this screenshot: http://imgur.com/W7hbh5q . This yellow line is the route ship takes. It's really unefficient.

I like this AI and it's really great that ships are used to transport a lot of different cargos but my map full of islands was extremely cluttered with buoys after few years. And those poor ships which wasted a lot of time going along the coast when it was 5x closer to cut the way like on the screenshot above.
mjm
Engineer
Engineer
Posts: 11
Joined: 23 Oct 2016 21:37

Re: ShipAI

Post by mjm »

lucj@n wrote:Is this normal for this AI to place so many buoys?
Yes, boys are placed every 25 tiles. This is made to avoid ships getting lost and to improve the pathfinder performance ( see: viewtopic.php?t=75339 ).
lucj@n wrote:And another thing, have a look at this screenshot: http://imgur.com/W7hbh5q . This yellow line is the route ship takes. It's really unefficient.
The 2 pathfinders used by the AI (straight line, coast) were chosen because of their speed. The price for that, in case of the coast pathfinder, is that it sometimes gives sub-optimal routes.
lucj@n
Engineer
Engineer
Posts: 10
Joined: 21 Jul 2008 16:11
Location: Polska/Poland

Re: ShipAI

Post by lucj@n »

mjm wrote:...
ok, that makes sense.
Dzięki.
mjm
Engineer
Engineer
Posts: 11
Joined: 23 Oct 2016 21:37

Re: ShipAI

Post by mjm »

Update, v4 (available on bananas)

The biggest change is that ShipAI can now use canals for the freight cargo.
In order to use canals, AI needs to have it enabled in settings and 2x max loan in it's budget.
The max canal length is limited to 50 tiles and no aqueducts or inner-locks are used to reduce the costs.

There are also few minor changes regarding the main AI logic (improved maintenance time, more expensive cargo first) and performance.
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: ShipAI

Post by Wormnest »

Crash of ShipAI version 4 right after starting because using a valuator inside a valuator on the latest versions of OpenTTD are time limited.
This is without any NewGRF, 1024x1024 map.

PS. It might be useful to upgrade your API compatibility to a newer version than 0.7. That would give you access to newer API functions.
Attachments
Unnamed, Jan 23rd, 1955.png
Crash log ShipAI v4.
(291.99 KiB) Not downloaded yet
xarick
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 26 Feb 2015 00:52

Re: ShipAI

Post by xarick »

cpu evaluator crash

Code: Select all

dbg: [script] [0] [I] Building LVST ship between Trudingville Farm(producer) and Gronfingley Factory(acceptor)
dbg: [script] [0] [E] Failed to build dock: ERR_AREA_NOT_CLEAR
dbg: [script] [0] [I] Building LVST ship between Keston Farm(producer) and Grenningpool Falls Factory(acceptor)
dbg: [script] [0] [I] Building LVST ship between Quarnbury Farm(producer) and Nindham Factory(acceptor)
dbg: [script] [0] [I] Building LVST ship between Hunnway Farm(producer) and Hunnway Factory(acceptor)
dbg: [script] [0] [I] Building LVST ship between Nuntborough Farm(producer) and Drundworth Factory(acceptor)
dbg: [script] [0] [I] Building LVST ship between Barningpool Farm(producer) and Fruham Factory(acceptor)
dbg: [script] [0] [I] Building LVST ship between Wrondingville Farm(producer) and Garfinghill Factory(acceptor)
dbg: [script] [0] [S] Your script made an error: excessive CPU usage in valuator function
dbg: [script] [0] [S] 
dbg: [script] [0] [S] *FUNCTION [GetCargoAcceptingCoastTiles()] shipai-4\town.nut line [20]
dbg: [script] [0] [S] *FUNCTION [_val_TownCanHaveDock()] shipai-4\town.nut line [43]
dbg: [script] [0] [S] *FUNCTION [Valuate()] NATIVE line [-1]
dbg: [script] [0] [S] *FUNCTION [GetTownsThatCanHaveDock()] shipai-4\freight.nut line [27]
dbg: [script] [0] [S] *FUNCTION [BuildTownFreightRoutes()] shipai-4\freight.nut line [55]
dbg: [script] [0] [S] *FUNCTION [Start()] shipai-4\main.nut line [30]
dbg: [script] [0] [S] 
dbg: [script] [0] [S] [tiles] INSTANCE
dbg: [script] [0] [S] [cargo] 5
dbg: [script] [0] [S] [range] 20
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [cargo] 5
dbg: [script] [0] [S] [range] 20
dbg: [script] [0] [S] [town_id] 51
dbg: [script] [0] [S] [this] TABLE
dbg: [script] [0] [S] [towns] INSTANCE
dbg: [script] [0] [S] [cargo] 5
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [producers] INSTANCE
dbg: [script] [0] [S] [min_capacity] 160
dbg: [script] [0] [S] [cargo] 5
dbg: [script] [0] [S] [cargos] INSTANCE
dbg: [script] [0] [S] [ships_built] 0
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [new_freights] 302
dbg: [script] [0] [S] [ferry] INSTANCE
dbg: [script] [0] [S] [freight] INSTANCE
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] Your script made an error: excessive CPU usage in valuator function
dbg: [script] [0] [S] 
dbg: [script] [0] [S] *FUNCTION [GetTownsThatCanHaveDock()] shipai-4\freight.nut line [27]
dbg: [script] [0] [S] *FUNCTION [BuildTownFreightRoutes()] shipai-4\freight.nut line [55]
dbg: [script] [0] [S] *FUNCTION [Start()] shipai-4\main.nut line [30]
dbg: [script] [0] [S] 
dbg: [script] [0] [S] [towns] INSTANCE
dbg: [script] [0] [S] [cargo] 5
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [producers] INSTANCE
dbg: [script] [0] [S] [min_capacity] 160
dbg: [script] [0] [S] [cargo] 5
dbg: [script] [0] [S] [cargos] INSTANCE
dbg: [script] [0] [S] [ships_built] 0
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [new_freights] 302
dbg: [script] [0] [S] [ferry] INSTANCE
dbg: [script] [0] [S] [freight] INSTANCE
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] The script died unexpectedly.
One of the running scripts crashed. Please report this to the script author with a screenshot of the AI/Game Script Debug Window
Attachments
ShipAI, 1st Jan 1957.sav
(1.17 MiB) Downloaded 257 times
Formerly known as Samu
mjm
Engineer
Engineer
Posts: 11
Joined: 23 Oct 2016 21:37

Re: ShipAI

Post by mjm »

Please check the new version (v5) from https://github.com/mmuszkow/ShipAI/archive/master.zip
I've splitted the problems AI was lagging on into smaller chunks and now the operations should take short enough not to raise the "excessive CPU usage in valuator". If everything is Ok, I'll put it on bananas shortly.
PS. It might be useful to upgrade your API compatibility to a newer version than 0.7. That would give you access to newer API functions.
I always use the doc for trunk version and functions from there. I never lacked any. Is there any other point in increasing the min compatibile version?

edit: v5 was put on bananas.
xarick
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 26 Feb 2015 00:52

Re: ShipAI

Post by xarick »

Excessive cpu usage in valuator function
Attachments
Unnamed, 1941-10-17.sav
(605.88 KiB) Downloaded 198 times
Unnamed, 1943-04-12.png
(484.76 KiB) Not downloaded yet
Formerly known as Samu
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: ShipAI

Post by Zuu »

mjm wrote:Quote:
PS. It might be useful to upgrade your API compatibility to a newer version than 0.7. That would give you access to newer API functions.
I always use the doc for trunk version and functions from there. I never lacked any. Is there any other point in increasing the min compatibile version?
Min compatible version is where you declare the minimum OpenTTD version required to run your AI. If you use APIs from later versions than your min compatible version in ways that would crash the AI in older versions of OpenTTD, you should raise it to properly declare what OpenTTD version is required to run your AI.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
xarick
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 26 Feb 2015 00:52

Re: ShipAI

Post by xarick »

Your ships never service. There are ships with 255 breakdowns.
Vehicles don't automatically service if you have a go to depot order in your order list. You have such order, but it's through the condition that they're old it's executed. Makes it so that during most of its life it never visits a depot for service.
Attachments
Unnamed, 2085-12-08.png
(249.86 KiB) Not downloaded yet
Unnamed, 2086-03-17.sav
(5.1 MiB) Downloaded 177 times
Formerly known as Samu
mjm
Engineer
Engineer
Posts: 11
Joined: 23 Oct 2016 21:37

Re: ShipAI

Post by mjm »

Version 7 is available on Bananas (built-in updater). The problem with servicing has been fixed, other improvements:
- pathfinding was completely reworked
- vehicles now share orders
- HQ building and trees planting was added
xarick
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 26 Feb 2015 00:52

Re: ShipAI

Post by xarick »

excessive cpu usage in valuator function

Savegame is too big, had to create a multi-file 7z archive. First extract the 2 tars separately, put the extracted files in the same folder, then use 7-zip to extract the 7z.001 and 7z.002 files in one go.
Attachments
Unnamed, 1961-08-09.png
(403.07 KiB) Not downloaded yet
Unnamed, 1961-08-09.7z.001.tar
(20 MiB) Downloaded 160 times
Unnamed, 1961-08-09.7z.002.tar
(10.65 MiB) Downloaded 162 times
Formerly known as Samu
mjm
Engineer
Engineer
Posts: 11
Joined: 23 Oct 2016 21:37

Re: ShipAI

Post by mjm »

Thanks for reporting that, I've never tested it long enough to reach 5000 vehicles. The fix is available on bananas (v9).

The new version also includes some minor changes in the way AI is looking for the possible connections (max 6 months are spent on that, order of industries/towns approached is randomized).
xarick
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 26 Feb 2015 00:52

Re: ShipAI

Post by xarick »

excessive cpu usage in valuator function again, on v10
Attachments
Unnamed, 1968-07-09.png
(369.44 KiB) Not downloaded yet
Unnamed, 1968-07-21.sav
(16.79 MiB) Downloaded 169 times
Formerly known as Samu
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests