Interesting, thanks for the info and link
With the massive caveat that I've never coded AI before, I thought I'd set out some thoughts on possible approaches to having the AI avoid some of the more detrimental issues regarding performance that I'd hope wouldn't be too resource intensive, in case my ramblings are of any use (although I expect better solutions to the below have probably already been worked through!)
-
Have a choice of several (pre-planned) initial build orders which is decided when the map loads (e.g. based on no. of mexes, proximity of those mexes, and the distance of the nearest hydrocarbon, a preset build order is settled on, which would be setup for the preferred AI strategy - in this case an AI turtle), the idea being to get to a certain initial goal assuming minimal attacks from the enemy (e.g. for a turtle it might be getting t2 defences up). At its simplest level this could just be a build order for if there's a hydrocarbon in the main base area, a build order for if there's a hydrocarbon relatively near the initial base, and a build order for if there's no near hydrocarbon, with further subsequent adjustments re the no. of T1 power to be built and when to upgrade the first T2 mex based on how many nearby extractors and reclaim there is. This would only need calling once which may allow CPU overload issues to be avoided.
-
Assuming it's possible to have some sort of event occur when an engineer is either idle or has finished construction (?), then before an engineer starts a new construction it considers the current resource expectations based on what's being built, and then decides if it should proceed or wait. If it was possible, then the accuracy of this approach would be improved if this check took place just before an engineer started building (i.e. when it's within range), to avoid the risk of say 10 engineers queuing up production that they have to move to, and all 10 thinking there's enough resources to start construction. If its not too resource intensive it could also check if the same building is already being built nearby, and assist that instead, with a few exceptions (e.g. t1 mex are so cheap that it's usually better to send engineers to multiple extractors at once instead of having them assist 1 at a time). If such a check would be too tough, could a variant be to store a temporary variable/array recording details of buildings that start being constructed, allowing a cycling through such variables once there're sufficient resources to resume construction
-
If the engi chooses to wait, then either via a delayed command or a new construction event that causes idle engineers to be cycled through the engineer would then commence construction (once sufficient resources will be available)
The delay command wouldn't apply where the unit/building to be built will help with the resource shortage (e.g. you don't stop a T1 engineer building a t1 mass extractor if there won't be enough mass, or stop them building a power generator if there won't be enough power) -
Certain 'critical' events cause a reprioritisation of existing engineers, with two of these critical events being power stall and mass overflow (or ideally the point at which such an event in the near future looks likely rather than waiting for it to actually occur). Assuming there's no way to create an event based off this, code relating to such a reprioritisation could be checked for at the point at which an engineer decides what to build (i.e. just before construction/when construction is completed), assuming there's some sort of event linked to this. Where such an event occurs then all engineers near the base get re-assigned (with any part-completed buildings recorded in an array to be referred to/resumed later). In the case of a power stall, the solution would be building more power (requiring an assessment of whether it's better to get t1, T2 or T3 where there's access to more than 1 tech level). In the case of mass overflow it'd be a bit harder to code a fix -if not at the experimental stage then a temporary fix is to upgrade mexes assuming enough power, while also getting more build power and if necessary energy as a priority so that the mass can be used.
More generally though, if the aim is to get the AI to improve it's 1v1 performance, it may be worth considering whether to always go for an 'eco/turtle' initial approach. That is, if I was to try and turtle/eco, on the majority of ladder 1v1 maps I reckon I'd get crushed by a rank 700+ player, since the preferred strategy seems to be mass t1 land spam coupled with a map that has loads of extractors and reclaim. If I dont do t1 land spam and instead try to e.g. upgrade my mexes to t2 early on with the mass that woudl've been spent on units I find I'll lose almost all the map control, and since t1 mexes are vastly more efficient than T2 mexes my opponent will be able to out-eco me, while also applying lots of pressure with their land spam (since unless the map is huge, they'll probably be able to have t1 arti attacking my core base before I can get t2 pd up).
I figured I'd have a go on a slightly more conventional 1v1 map for a comparison, and go with a more conventional mix of T1 spam units (although this is less t1 spam than I normally face as I need to work on my initial build order for 1v1 maps so I ended up upgrading my T2 mexes quite early instead) - see replay ID #14660835:
- As expected the AI still has similar issues with the initial build order (although my build order also wasn't great on this map!) and is slow to expand - due to this, about 4m in I've got about twice the mass income with a similar build power (and sufficient energy for my needs)
- I was pleased to see the AI reclaiming the nearby mass deposits
- My attack was slower this time, and the AI ACU did a much better job of defending, both dealing with an initial push by a handful of land units, and then having energy storage which it used effectively with overcharge to kill clumped up t1 land units, so I expect the previous map was just that I was a bit too fast with my rush.
- However, most of the ACU's shots were missing units (I purposively wasn't microing my units - just sent an attack command for all land units to attack the ACU) - if you check 7m30s in, almost all the shots miss. Not sure if this is due to the microing of the com again?
- It also failed to get any defence against me (bar a couple of land units) so my com could stroll in with no upgrades and do lots of damage (as the AI sent their com to hold off my land attack)