How can I go about creating an AI to execute build orders?

I’d like to do some work on creating build orders that extend the work already done by others. Some of them become a bit vague and don’t fully define what to do past a certain point. So I’ve found myself attempting to extend them, but the problem is that I can’t execute them well enough myself to accurately test them.

So I had the thought of programming the AI to execute my build orders, so I can see a perfect execution of them, and hence tweak them to optimise the allocation of villagers to activities at every point in time.

I saw this thread for a python AI creating app:

but it works in terms of fixed percentages of villagers on resources, whereas I need to micro-manage at the level of individual villagers.

I’ve looked at the source code for the above, and the per files included with it, and I can see that there would be much to learn to really get into creating an AI, but what I want to do is much more limited, so I was wondering if anyone who is already very familiar with AI creation could give me some pointers as to which specific things to research to do what I want to do? Is it even possible to make the AI micro-manage the villagers to exactly execute a build order at the level of detail they’re usually presented, e.g. send the nth villager to lure a boar, build a barracks when 60% of the way up to Feudal, move 2 from food to wood when you click up to Feudal etc.

Not entirely on topic but I wouldn’t go with AI in your case. A much better alternative would be to just play alone in single-player and pause regularly so you have time to perform the actions. (In single player you can queue actions while pausing, I believe it should be easy to do any BO even if you really lack mechanics)

There are 2 reasons why AI is bad approach. First, despite what you seem to think even the extreme AI is far from doing optimized BOs, it often misses sheep but sometimes it also misplaces mill/lumber camps. In fact I’m pretty confident that good human players do significantly better than AI especially with pause.

2nd reason, you shouldn’t look for a BO that is optimal in theory but that you cannot consistently do in practice. In a real game sometimes you don’t find your sheep, you can’t lure deer, you have very far boar, forest etc. and you also have to manage scouting the map and maybe walling yours while executing your BO, so it’s always better to plan a bit of margin in case you make mistakes or have a different map than the one you tested the BO on. Unless you’re really at the top level getting up 1-2 vills later will really not be that big of a deal, in any case it’s much better than going up earlier and having idle time due to lacking resources.

There are advantages to using AI though, mainly you could test a lot of BOs automatically in batch and see which perform better, but then they will not be optimized, you’d have to evaluate by how much first, and also I suspect they will strongly depend on the map.

Thanks for the feedback.

Re pausing, maybe I could perfectly execute that way, but with the number of variations I’d like to try, and the duration of each one, it would get really really tedious testing them that way.

Re the weaknesses of even extreme AI, I was hoping that my programming wouldn’t have those weaknesses and would perfectly execute a build order, but I don’t know how much can be controlled in the AI files vs being hard-wired into the application itself. I’d be happy with testing via a fixed map so I can program the AI to always put things in the same good place, and I could also incorporate it walling that fixed map. I think any resulting build orders would be at least as good as those I’ve seen published.

In terms of whether optimal is desirable, I’m really not looking at ways to get up 1 or 2 vills earlier, it’s more about optimal assignment of villagers within that. For example, in Hera’s Korean Trush build order, it doesn’t tell you what to do with villagers produced after reaching Feudal. I’ve made a guess that putting the first 4 on wood, then the next 15 on farms will get me to Castle with 18 farms, ready for a 3 TC boom, but I’d like to see if a perfect execution of that ever ends up short of wood to make those 15 farms, or if it always has enough wood that maybe only the first 3 need to go to wood. An imperfect execution in this case actually creates slack by resources having been collected for longer, i.e. the tightest possible build order wouldn’t fail if someone had idle time, it would actually become more relaxed.

Overall, I still feel like it would be a useful thing to do, if it’s possible, and it would be nice to be able to provide a “reference execution” video that performs all the actions exactly as specified in the build order.

Having said all that, a few hours later I’m coming round to thinking that it might be easier overall to just obtain all relevant parameters to do my own simulation, like this does for combat:

I was just thinking that if I use AI, I’ll pick up things like the gradual reduction in wood collection as they get farther from the lumber camp etc. I can maybe have a go without making it too complex and see if it at least predicts that some established build orders work as intended. It could maybe be good enough as a first pass, with manual testing of candidates for final versions.

Well if you’re going this way, that could lead to a useful tool (that’s probably the most reliable and parametrizable approach), but that’s probably going to be very tedious and more of a altruistic project rather than an efficient way I would advise to figure out good build orders for yourself. Some people already provided some useful data like SOTL villager gathering rate formula that you can use as a starting point. But for a full build order simulator there will be far more variables to simulate than gathering speed, like distance the villager has to walk before they start working, house/gathering points building time, but also subtle ones like sheep/boar decay, bumping/starvation when you put too much villagers on 1 resource (berries especially will be tricky, since they have gather speed close to farms but farms cost 60 wood I’m pretty sure your simulator would recommend to build 0 farms and put everyone on berries) and when to do loom. You’d have not only to make a model with lots of variables but also measure the average values of these variables in game to have default values in your simulator that make sense.

For your original concern, here would be my way to make a optimized build order, and I believe it’s the way common build orders have been established: start with a basic template (for example FC 27 pop), play it in a real game, then look at how much spare resources you have when reaching your goal. A good build order should leave you with close to 0 spare resources (except stone). If it doesn’t, then restart and adjust vils until you have resources as close to 0 as possible. For example, let’s say you use the FC 27 pop build order, but once in feudal when you should be clicking you realize you have 700 food - 200 gold - 350 wood (far too much wood, not enough food). Then since you have an imbalance between food and wood, adjust the build order next time to put 1 additional farm, or spawn farmers faster and delay your 2nd lumber camp. Additionnally since you have 250 spare resources (wood) that also means you could put 1 less vill on wood and go up earlier. Then you retry with 26 pop, maybe next time you have 900 food - 200 gold - 0 wood: so you adjust again by delaying farms. Repeat until you find a good compromise where your resources are balanced and have very low spare resources (ideally not too low because in a real game mistakes/randomness will happen). In 3-4 games you’ll find an optimized build with the benefit that it’s adapted to the way you play and mistakes you make. Drawback is that you have to figure yourself out how to fix the build order (eg: if you have 150 spare resources, is that enough margin to go up earlier ?) but you’ll quickly get a feeling for it, which will also help you play the game better. Another drawback is you’ll also have to rely on a few commonly-accepted constants like how many on berries and total number of farms to make which you can’t really change without seeing a big variation in your resource balance,

I remember I was also concerned with build orders when I started but it’s really overestimating the complexity of making a build order optimal. In aoe2 we have the “trick” that if you have 0 spare resources then you know your build order is optimal (of course there are a gazillon of other optimal solutions that your simulator would reveal).

1 Like