Page 1 of 1

ShipAI

Posted: 21 Nov 2016 11:46
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

Re: ShipAI

Posted: 04 Jun 2017 15:19
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.

Re: ShipAI

Posted: 09 Jun 2017 14:25
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.

Re: ShipAI

Posted: 12 Jun 2017 13:46
by lucj@n
mjm wrote:...
ok, that makes sense.
Dzięki.

Re: ShipAI

Posted: 09 Aug 2017 12:20
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.

Re: ShipAI

Posted: 27 Nov 2017 10:57
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.

Re: ShipAI

Posted: 26 Feb 2018 19:05
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

Re: ShipAI

Posted: 07 Mar 2018 22:48
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.

Re: ShipAI

Posted: 30 Apr 2019 16:50
by xarick
Excessive cpu usage in valuator function

Re: ShipAI

Posted: 02 May 2019 07:24
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.

Re: ShipAI

Posted: 01 Oct 2019 17:29
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.

Re: ShipAI

Posted: 30 Oct 2019 20:58
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

Re: ShipAI

Posted: 19 Nov 2019 13:20
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.

Re: ShipAI

Posted: 20 Nov 2019 09:40
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).

Re: ShipAI

Posted: 10 Dec 2019 16:52
by xarick
excessive cpu usage in valuator function again, on v10