Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Experimental AI: make AI recruit higher level units #4437
The ExpAI recruits almost no higher level units. In the scenarios I tested with default era units, there's maybe one L2 unit recruited every dozen or so recruits. Yet, it's reasonable to assume that if scenario designers give the AI higher level units to recruit, they expect that to happen not just sporadically.
The reason why almost no L2s or higher are recruited might be partially because unit cost is not as well balanced for the higher level units. But mostly it happens because cost is penalized by the ExpAI recruiting. This is in order "to avoid recruiting many expensive units -- there is a requirement for bodies in order to block movement" as per a comment in the code. I don't want to change that, as it would mess up the recruiting ratios of L1 units of different cost, so instead I am adding a bonus for higher level units that increases as the high-to-low-level units ratio decreases. A few comments on that:
Because unit cost is penalized in the ExpAI, it recruits almost no higher level units. This adds a bonus for such units to be recruited at approximately the ratio defined in 'high_level_fraction'.
I would definitely make
It can make sense under certain circumstances though which are likely very difficult to figure out automatically so a configurable parameter sounds perfect. Cicumstances I could imagine would be choke points where power density per hex is more important than absolute power or needing special abilities of certain high level units.
Btw, I think that the cost of high level units is not too bad nowadays. Given more special abilities being factored in for high level units, that the AI will often have trouble using effectively, the unit cost is necessarily a worse indicator for the AI.
Yeah, makes sense. An additional advantage of making
I've now looked into how we would do that it practice. I don't think there is an easy solution for adding that functionality when setting up the ExpAI using
However, it is easy to provide a macro that would be used like this:
Setting up the ExpAI in its default configuration could then be done as before, and for custom settings one would use the macro.
This also sets its default value to zero, in order to have consistent default behavior with versions from before this parameter was introduced. It also provides a macro so that the ExpAI can be used with custom parameters in a scenario config, and adds high_level_fraction as an optional parameter to the Recruit Rushers Micro AI.
Without this, the AI always starts with whatever it considers the best unit without taking the level bonus into account. This mostly only matters when one sets high_level_fraction to a very large value (1 or larger) in order to force only high-level recruits. In other cases it makes no, or no significant, difference.
I'd like to merge this before 1.15.2 is tagged this weekend. I'll do so within a day or two if I don't hear any objections by then. I'm also planning to backport this to 1.14, as the default behavior does not change and it gives UMC authors a chance to change potentially undesirable AI behavior (and we'll get more testing that way, as @sevu pointed out on Discord).
BTW, I'm not planning to squash this as each commit is functional and reasonably logical stand-alone, but if somebody has strong objections to that, let me know.