Topic: Introducing limits in building ratios of AI
king_of_nowhere Topic Opener |
Posted at: 2015-12-05, 05:12
I'm a bit sorry to put forward yet another suggestion when my latest three or four are still open discussions; I know programmers have limited time, and I should limit the amount of stuff i propose, otherwise they'd have to do nothing but working on my ideas. And yet, after my last game, I could not refrain from posting this. I've seen that the ai often has huge buildings imbalances. sometimes it makes 5 war mills with only a couple smelting works. or it makes 10 metalwork shops, one wonders what it does need all those tools for. or it makes 20 inns, when it only has a handful of farms to feed the bakeries that are needed to make them work. Apparently the algorithms that regulate the ai needs can malfunction sometimes. Also, AI tend to be highly inefficient: if you look at the "ware"statistic, you'll see ai tend to accumulate lots of wares - and those are unused wares, gathering dust in a warehouse; you'll want to minimize those. So I thought that setting some hard limits in the form of "don't build more than 1 war mill for every smelting work, but no more than 5 smelting works for one war mill either" could be introduced, to ensure that the ratio of primary producers to secondary producers do not stray too far from optimal levels. After a bit of work looking at working times in the lua files, I came up with the following table for barbarians. When there is more than one limit for the same building, the lower one applies. All values are rounded down.
If you like the idea of including conditions like those, I can work similar ones for empire and atlanteans. I tried to keep large intervals to let the ai be flexible enough. If you think I got some values wrong, or I forgot something, feel free to point it out. Edited: 2015-12-05, 05:23
Top Quote |
GunChleoc |
Posted at: 2015-12-05, 09:24
Before you continue to make our calculations, we should discuss how we want to implement this and what the restrictions are. At the moment, the only way to implement something like min or max would be hard coding it to specific buildings in C++. This should also not go into the tribe's init files, because the tribes shouldn't care about the AI. Maybe it is time to start thinking about a Lua interface for the AI to handle AI hints etc? Each AI would then have its own Lua files with its own hints and there would be an AI API. This would be a big change though and something we should only think about for Build 20. Busy indexing nil values Top Quote |
king_of_nowhere Topic Opener |
Posted at: 2015-12-05, 10:15
well, i was thinking, since currently in the lua files there is a mention of limits for the ai to build a specific building depending on the difficulty level in the form of
that it could be possible to add a limit depending not on difficulty level, but on the number of other buildings possessed by the player. Top Quote |
GunChleoc |
Posted at: 2015-12-05, 10:58
The AI hints are loaded only once at the start of the game. So, at the time the AI hints are loaded, the current number of buildings for all buildings will be 0. You could add a list of buildings with a minimum number for each building, but you can't do a min/max formula or a multiplication there, because it will always give you 0. Any formula will have to be programmed in C++ at the moment - the AI hints can only give you some variable configuration values. Edited: 2015-12-05, 10:59
Busy indexing nil values Top Quote |
DragonAtma |
Posted at: 2015-12-05, 11:00
If we're going with something like that,m it may be best to go with a smart/average/dumb setting for the AI.
Top Quote |
GunChleoc |
Posted at: 2015-12-05, 11:06
I made a similar suggestion in the bug At the moment, we just have a simple setup that lets us work with this at all - now we need to tweak the values we have in the init.lua files - maybe we should balance this for small maps first, then think about a territory size factor as a second step? Busy indexing nil values Top Quote |
king_of_nowhere Topic Opener |
Posted at: 2015-12-05, 11:07
so that means that the ai can only build one single smelting work, and will not be able to build another if that one is destroied? if it is so, seems like something that needs to be fixed. As for the rest, pity. there goes my hope that the worst parts of the ai could be fixed with a few equations. Top Quote |
GunChleoc |
Posted at: 2015-12-05, 11:18
No, that's not the case. The AI hint means "You are not allowed to build more than 1 Smelting Works". So, if it gets destroyed, the AI can build a replacement.
Maybe you could come up with a standardized formula that then gets fed a building list with number of buildings required? Then the AI cold check if those buildings have been built in the required number. Something like:
We should wait for Tibor's input though. Edited: 2015-12-05, 11:19
Busy indexing nil values Top Quote |
king_of_nowhere Topic Opener |
Posted at: 2015-12-05, 12:31
wouldn't work, because there is no required number, but an economy should keep growing as one expands. as i mentioned other times, the way i go is to look at stock-wares in warehouses, see what wares i am accumulating and what i am missing, and make buildings that use the stuff i am accumulating and other buildings that make the stuff i'm missing. I start from the more advanced wares and go down the line; a simplified logical process could be described as such
it works really well and it's fairly foolproof: if you are accumulating food, you can afford to build more mines, there's not much to argue. using productivity can get you in all sort of troubles instead: for example, you may see your mines are working at 100%, and decide you must have food and can make more mines, but in truth you have little food and your mines register high productivity only because they are skipping work because you have few smelting works. With a ware-oriented, top-down approach, you'd immediately see you have excess of metal ores and you need to build smelting works. hmm, now that i think about it, you can do it with productivity too, as long as you start form the top; so you'd see the smelting works at 100% and decide to make more. but if the smelting works are not working you'd need to look whether you're missing coal, iron or gold, so you still need to look at wares in warehouses. but apparently getting the ai to do that is very complex. in any case, setting a few hard limits in the ratios of primary and secondary producers should at least avoid the worst cases of imbalancement. if the ai works properly, it wouldd never stray out of those limits anyway. think of it as a safety check. Edited: 2015-12-05, 12:32
Top Quote |
DragonAtma |
Posted at: 2015-12-05, 12:31
I've thought about using map size in the limits, but there's two problems: (1) The amount of controlled land -- if a CPU is in last place in in a large map, it probably wouldn't help for them to spam a building just because it's a large map. (2) The amount of usable land varies from map to map. Maybe half of Riverlands is usable land, while Atoll is at least 90% water (and, therefore, only 10% land). So that's why I suggested using the amount of land currently controlled by the AI instead of the whole map. Top Quote |