Loading...
  OR  Zero-K Name:    Password:   

What Are You Doing, Smart Nano?

10 posts, 766 views
Post comment
Filter:    Player:  
sort

2 years ago
TL;DR: presenting a new nano automation widget. If you are dissatisfied with all currently available widgets, you may jump to part II.

I Limitations of the existing nano automation

Currently there are three relevant widgets shipped with ZK--'Auto Patrol Nanos', 'Auto Patrol Nanos v2', and 'Smart Nanos'; only the first is enabled by default, so if you have not tinkered with widgets configuration, this is the one you are using now.

'Auto Patrol Nanos' uses a hack: it gives to nanos the Patrol order, which, at first glance, is weird since nanos cannot move. Actually, what it does, is activating the unit AI, similar to Attack or Patrol move of the mobile units (as opposed to the regular "Move" order). Then the AI automatically performs the tasks it finds to be useful--reclaiming, repairing, assisting building. If you disable this widget (with other aforementioned widgets disabled as well), and build a nano, it will just sit there, waiting for your orders, not doing anything by itself. So far so good, but the problem is, the unit AI is not very intelligent. For example, if a nano is near your factory, and you are stalling metal even without the nano building power, and there is a damaged unit or metal reclaim available in nano's range, it will stupidly try to assist the factory instead of reclaiming the available metal or repair the damaged unit.

'Auto Patrol Nanos v2' tries to improve the situation by "Idle caretakers will be set to area repair units, area assist build (which includes repair units), area reclaim metal, area reclaim energy, or patrol, depending on available resources." (citing the widget's source). In the situation described above, the nano managed by this widget will do reclaim/repair instead of assist, but the widget is still far from optimal.

For example: in a slightly different situation, if a nano started to assist some building when there was enough metal, but after some time you are stalling, it will not switch to reclaim or repair until it finishes the build assisting, which may take a very long time in case you are building some heavy unit and/or have low income. Another example, if you are stalling energy and have a lot of metal, and your comm or a con starts an energy-producing building (e.g., a fusion), the nano, instead of helping this, will reclaim available metal nearby, which is totally useless.

This list can go on, so I decided to fix the code. Then I found that the code is, IMO, over-sophisticated in some parts and under-sophisticated in another ones. Examples for the first claim: it uses a complicated queue to track the nanos and the orders issued for them and thus nanos become unresponsive as in the situation described above, and over-complicated calculations (based on each nano's resource spending/acquiring) to decide a simple thing--what is our energy and metal situation? Do we need to spend or to acquire metal and/or energy?--which leads to a lot of edge cases where the algorithm gives weird results. Example for the second claim: it relies on Area-reclaim/repair commands, so, for example, it cannot give an order to reclaim only energy-containing features, since there is no such Area command. It also cannot decide which unit is the best to assist/repair since Area command relies on (not very intelligent) AI, thus it cannot assist energy-providing structure in case of energy stalling, as in the last example. And the situation with repairs is also not ideal.

'Smart Nanos' is, probably, the most advanced of the three. For instance, instead of using Area commands, it actually analyzes all the units and features in the nano's range, so for example, it decides which unit to repair comparing their HP. But it also has a list of issues, for example, due to faulty algorithm of the resources evaluation, it may reclaim metal, instead of assisting building even if you are overflowing metal. It is also not so responsive, and generally, suffers from the same architectural weakness as the previous one. It is also totally undocumented and uncommented, so it is a bit hard to follow.

All this, and the want to add some useful functionalities (e.g., I read in the lobby @hedkeaf's request/idea regarding automated nanos taking into account the building priority--functionality that all available widgets lacks--and liked it) led me to decide to write a new widget, according to the famous principle:



II Smarter Nanos Widget

How it works / How to use:

1. Upon installing, don't forget to disable all the alternative widgets: 'Auto Patrol Nanos', 'Auto Patrol Nanos v2', and 'Smart Nanos'.

2. The widget manages Caretakers, Strider Hubs, and Funnelwebs ("builders" hereafter). Funnelwebs will not be given move orders, only to do things in their current range. Commanders and mobile constructors aren't managed for several reasons, such as short range and buggeroff, but could be added easily in the code if one wishes so (in Config section).

3. Builders are automatically managed according to the following algorithm:

A. Player's resource situation is categorized as follows:

- Amount of Energy less than ~1/4 of the available storage considered as "low", otherwise "fine".
- Amount of Metal less than ~1/3 of the available storage considered as "low", more than ~2/3 of the available storage considered as "high", otherwise "medium".

Naturally, builders will try to keep the Energy in "fine" and the Metal in "medium" range.

B. General principles:

- For a certain resource situation, a builder will be given a prioritized list of tasks. It will try to do them one by one, starting from the best suited task. If it can do the task, it will do it, dropping rest of the list; if not (e.g., the task is to repair units, but there are no damaged units in range), it will try the next (less optimal) task. If it cannot do any task of the given list, it will become idle. This process (incl. resource re-evaluation of course) repeated frequently (3 times a second).

- In contrast to the alternative widgets, a builder may switch to another task without finishing the current task. For example, if in a given resource situation, repair task has higher priority than build assist, but there were no damaged units so a builder started to assist some building, and later a damaged unit appears in range, the builder will drop the build assist and will start to repair the damaged unit.

- A builder will never automatically assist building of allied units, but will repair allied units if there is enough E and there is nothing better to do.

- For Repair task, a builder will choose a unit with the least HP deficiency, in other words, with the shortest repair time.

- For Building Assist task, a builder will choose a unit with higher building priority; from the units with equal priority it will choose the unit having the least M deficiency, that is, with the shortest time to completion.

C. The prioritized lists are as follow (descending priority order for each If/Else clause):

If E is low:

------ Reclaim pure E features (such as trees);

------ Assist building (as mentioned above, 'assist building' always means own units, not allied) of E-producing structures (such as Fusion);

------ Reclaim features having more E than M;

(the order of the latter two tasks will be inverted if M is also low)

Else If (means E is fine and) M is high:

------ Assist building of M-spending structures (caretakers, factories, storage);


------ Assist any building having normal or high building priority;

------ Assist any building having low building priority;

------ Repair own units;

------ Repair allied units.

Else (means E is fine and M is not high, which usually is the most common situation):

------ Repair own units;

------ Reclaim M (wrecks, rocks etc.);

------ Reclaim anything;

------ Repair allied units;

------ Assist any building having normal or high building priority.

4. The automated management could be altered in several ways:

A. If a player issues a manual command (incl. queued commands using shift/space) to a builder, it will process them regardless the resource situation, then, upon finishing them, it will return to automatic management. For example, if you ordered a Strider Hub to build Paladin, it will continue to build it whatever happens. In order to put it under automated management, you need to give it "Stop" order to cancel the manual command.

B. The widget adds two new command buttons to builders' command panel ('orders' tab): 'Enable Automatic Management' (green 'AI' letters) and 'Disable Automatic Management' (red 'AI' letters). All the builders are automatically managed unless the auto-management of selected builder(s) is disabled by the latter command. Auto-management could be re-enabled then by the first command.

C. As per the algorithm, builders will prioritize assisting building of units/structures having higher building priority. Also, they will not assist building of units/structures having "low" building priority, unless M is high.
A player can utilize these features according to their needs.



Widget
+5 / -0
2 years ago
About:"
------ Reclaim M (wrecks, rocks etc.);

------ Reclaim anything;
"

Does it exclude stuff thats beeing rezed?
Are builders prevented from running between the frontlines and getting shot by enemy?
+0 / -0

2 years ago
quote:
Does it exclude stuff thats beeing rezed?

No, I haven't thought about it. Probably need to add this constriction.

quote:
Are builders prevented from running between the frontlines and getting shot by enemy?

As explained, it is only for Caretakers, Strider Hub, and Funnelweb, the latter isn't considered as a mobile unit, that is, it will only get Assist/Repair/Reclaim orders for stuff in its range, so it will not run as well.
+1 / -0
2 years ago
pretty interesting, but where do we put that ?

I don't find anything looking like widgets in the game folder...
+0 / -0

2 years ago
I think unknownrankShaman has an interesting thing for Smart nano/Reclaim units where it stops reclaiming if you or your party has reached the Metal limit.
+0 / -0

2 years ago
FRrankMirtille2, create folder Widgets in Zero-K/LuaUI and put it there.

Also read Using_custom_widgets
+0 / -0

2 years ago
ROrankForever, as you can see in the algorithm description, there is no Reclaim task if the Metal is high.
+0 / -0
2 years ago
This goes in a similar direction as my Smartest Builders widget which considers mobile builders as well. I had also started with such an if else priority list until I changed it to a more flexible multidimensional table of functions. It doesn't consider build priorities yet, though. That's included in my list for future updates to be done.
+0 / -0

2 years ago
DErankBrackman, I wasn't aware of your widget. Seems that there are indeed many similarities. I'm taking the idea of enemy nanoframes reclaiming (haven't thought of it) and of automated fallback (thinking to make some general widget to watch all my custom widgets) for a next version. Regarding priorities, I went the opposite direction, from two-dimensional table, to linear if/then, as a way to simplify things. I need to look closely at your table to see whether I over-simplified.
+0 / -0


2 years ago
quote:
B. The widget adds two new command buttons to builders' command panel ('orders' tab): 'Enable Automatic Management' (green 'AI' letters) and 'Disable Automatic Management' (red 'AI' letters). All the builders are automatically managed unless the auto-management of selected builder(s) is disabled by the latter command. Auto-management could be re-enabled then by the first command.

Ideally this would just use the unit AI toggle. Like how Solars have a unit AI toggle for automatically closing.
+0 / -0