Orders Assistant AI v7 (2014-04-03)

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
Xycor
Engineer
Engineer
Posts: 29
Joined: 17 Mar 2014 01:28

Orders Assistant AI v7 (2014-04-03)

Post by Xycor »

Version 3 has many improvements to performance and stability.

This is my first "AI". It does not play on its own. It manages routes for a player which has joined its company.

Special thanks to the author of SuperLib whose library taught me how to code in Squirrel and how the AI API worked.


Orders Assistant AI
====================

What it does
------------

Orders assistant does the best it can to route vehicles for the player or an AI.

Orders assistant still allows manual control of vehicles which exist in
groups. Users can decide how many vehicles the Orders AI should be routing.

My vision for orders AI is to be a library for other AI's that don't want to
bother with routing and players who want to eliminate the more mundane routing
chores while retaining control over specific routes as needed.


How it works
------------

Each time a vehicle loads or delivers cargo OrdersAI does its best to estimate
which station should be appended to the orders queue based on the station
ratings, stockpiled cargo, number of other vehicles enroute/loading, and
hopefully other factors in the future. Orders AI also handles station
construction and deletion gracefully.

OrdersAI is stateless, decisions are made based on the current game state as
interrogated from the NoAI API and SuperLib. There should be no issues with
saving/loading of games when using the assistant.


Getting Started
---------------

Players must be on the same team as the AI. This is accomplished by ensuring
OrdersAI has started a company and joining that company.

Add Orders Assistant AI to the list of AI players at game start.

Open the console with the tilde "`" key.

Type "start_ai" and hit enter. OrdersAI should launch.

Open the cheat menu with CTRL+ALT+C and switch to the same company as OrdersAI.


How to use OrdersAI
-------------------

Once the transport network is built one can add capacity by purchasing new
vehicles and hitting "Go" to kick them out of the depot. Once outside Orders
AI will figure it out where they need to go.

During play ensure all industries of the same type are connected on the same
network. Isolated networks which service the same industry type will cause
Orders AI to send vehicles to unreachable destinations.


Future Work
-----------

Weight distance and vehicle speed into decisions

Random stuff
------------

The console command "reload_ai" sells the entire company for reasons unknown.

Originally developed on 1.4 RC1
Last edited by Xycor on 04 Apr 2014 06:57, edited 7 times in total.
Xycor
Engineer
Engineer
Posts: 29
Joined: 17 Mar 2014 01:28

Re: Orders AI

Post by Xycor »

Version History
===============

1
-

* Initial release

2
-

* Fixed readme formatting
* Fixed SuperLib version dependency typo to 37 from 27

3
_

* Typo fix that was causing a problem at load.
* Fixed crash when vehicle was sold
* Vehicles travel to new stations even if they have not been visited before.
* Vehicles are not counted as being enroute to a station unless they are moving.
* Vehicles loading at a station have their already loaded cargo subtracted from
their reservation.
* Many fixes for order list management. Duplicates should be eliminated.
* Bumped SuperLib version from 37 to 38

4
_

* Forgot to bump version in info.nut

5
_

* Added support for transfer pickups by checking stations for existing stockpiles.

6
_

* Airport type taken into consideration. No more jumbo jets being sent to heliports.
Xycor
Engineer
Engineer
Posts: 29
Joined: 17 Mar 2014 01:28

Re: Orders Assistant AI v7 (2014-04-03)

Post by Xycor »

7
_

* Vehicles are sent to a random station if there is a tie for best station weight
* Vehicles loading at a station where the producing industry shuts down now move on correctly
* Optimized the search for stations with supply. Vehicles get order updates more quickly
* Automatically create groups for the AI vehicles according to cargo type.
viki2
Engineer
Engineer
Posts: 11
Joined: 23 Dec 2011 01:06

Re: Orders Assistant AI v7 (2014-04-03)

Post by viki2 »

Great. Makes fun to play with. Just 2 Future requests:

1. Check if the user change an order of an vehicle. If it is the case move it to the manual orders group, so you don't need to do it by hand.

2. Check if the station is reachable for the vehicle and go to another if not. This would be useful for example if you have bigger feeder networks or two islands with street traffic, and no road (bridge) in between.


Do you think this things would be possible?
Xycor
Engineer
Engineer
Posts: 29
Joined: 17 Mar 2014 01:28

Re: Orders Assistant AI v7 (2014-04-03)

Post by Xycor »

viki2 wrote:Great. Makes fun to play with. Just 2 Future requests:

1. Check if the user change an order of an vehicle. If it is the case move it to the manual orders group, so you don't need to do it by hand.
1. I am not aware of a NoAI event which indicates a train has a new order. This might be do-able by storing the last specified order issued to each vehicle, and if a check indicates the order has changed then it is moved to a new group.

I don't anticipate making that change without further inspiration or API insight. I've already been provided some patches from other users so if a pull request shows up in Github I'll try it out and add it if it works.

When I play I tend to clone vehicles already in the manual group if I want manual control.
viki2 wrote:2. Check if the station is reachable for the vehicle and go to another if not. This would be useful for example if you have bigger feeder networks or two islands with street traffic, and no road (bridge) in between.
I would love to do this. The best way to do this would be to get some new features in the OpenTTD NoAI API. I've been asking about how to do it here:
http://www.tt-forums.net/viewtopic.php?f=65&t=70338

A contributor to OrdersAI almost had a workaround using the "Vehicle Lost" notifications. However the notification was only sent once per vehicle.
Xycor
Engineer
Engineer
Posts: 29
Joined: 17 Mar 2014 01:28

Re: Orders Assistant AI v7 (2014-04-14)

Post by Xycor »

v8 (2014-04-11? This version broke airplanes and boats over the weekend, sorry.)
_____________________________________________________________________

* If pickup stations have equal weight, route to the nearest station
* non-stop flag added to pickup orders
* option to specify load flags for passengers and cargo
* Stations with a rating below a minimum amount do not have available supply considered

v9 (2014-04-14)
______________

* Fixed non-stop orders preventing Airplanes and Boats from getting orders OpenTTD would respond to
* New stations check whether any vehicles are scheduled to visit after the current station or
actively running to the station. This should prevent multiple vehicles from visiting new
stations
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Orders Assistant AI v7 (2014-04-03)

Post by 3iff »

V9.

I'm getting a high proportion of "duplicated station" where a vehicle has orders A-B-A.

I have a wood to papermill route with this happening. There are just 2 stations on the route and no other wood/papermills being serviced. Cargodist is off for freight.

I'm also seeing it to a lesser extent on my bus passenger network that connects 3 towns with about 8 interconnected stations.
Xycor
Engineer
Engineer
Posts: 29
Joined: 17 Mar 2014 01:28

Re: Orders Assistant AI v7 (2014-04-03)

Post by Xycor »

3iff wrote: I'm getting a high proportion of "duplicated station" where a vehicle has orders A-B-A.
The warnings can be obnoxious. This happens because I keep past orders in the list so I can see where vehicles have been going.

For version 10 I just added a parameter to control the depth of the history. The new default is no history. Keeping only one order on each vehicle prevents the duplicate order warning... and less often generates "too few orders in the schedule" warnings. Users can have any warning they want. :roll:

I thought there may be a way to turn off these warnings in the advanced settings, but I can't find it.
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Orders Assistant AI v7 (2014-04-03)

Post by 3iff »

Ok. I wasn't sure if the problem was be design or an unexpected bug. I'll have a look at V10 if I get some time. Thanks.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 38 guests