Latest Posts

Topic: Introducing limits in building ratios of AI

GunChleoc
Avatar
Joined: 2013-10-07, 14:56
Posts: 3324
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2015-12-05, 13:30

I agree - land controlled by AI or amount of flags controlled by AI would be better limits than mere map size.


Busy indexing nil values

Top Quote
king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 17:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2015-12-05, 14:25

I'd also agree that setting llimits based on the amount of land controlled would make more sense, but

GunChleoc wrote:

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.

it seems it's not possible with the current method. Introducing that would require a lot of reprogramming, and if that kind of effort is put into it, then imho it would be much, much better to make difficulty levels in other ways, namely either making the ai buildings to produce faster/slower (by reducing/increasing their sleep time), or by increasing/decreasing the ai soldiers' evade chance. as far as i understand, the current way of making difficulty levels was only picked because it was simpler to code.


Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 14:56
Posts: 3324
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2015-12-05, 17:12

You could have a starting value in the AI hints for each building, which then gets multiplied by a fixed percentage of the map size - or a scalable percentage of the map size. These percentages could be hard-coded, because they would be independent of the actual buildings. This way, the tribes would remain moddable.


Busy indexing nil values

Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-12-05, 18:45

GunChleoc wrote:

~~~~ required_buildings { farm = 3 micro_brewery = 1 } ~~~~

We should wait for Tibor's input though.

Doable, but what if there never be 3 farms (at least)?


Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-12-05, 19:01

I think fixed limits are good enough but needs to be tweaked.... I hope somebody will take there of this... This is no C++ work so should be trivial for anybody....


Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-12-05, 19:30

king_of_nowhere wrote:

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.

  • max bakeries = 1 + (farms/6) // a bakery takes 45 second to make a bread, and consumes 3 grain. a farm makes a grain in 100 seconds on average, as per experimets i did
  • max wells = 2+ (farms) // water is always consumed together with grain. there's no point in producing much more water than grain.
  • max (metal_workshop + ax_workshop + war_mill + helmsmiths) = 1 + smelting_works // a smelting works produce a metal in 70 seconds. the workshops consume at least one and have a working time of 60 seconds.
  • max smelting_works = 2 + 2 * metal_workshop + 4 * ax_workshop + 5 * war_mill
  • max metal_workshop = 2 // I never needed more than 1. The second is for upgrading
  • max helmsmiths = 1 + (war_mill + ax_workshop) // you need less helms than axes
  • max smelting_works = (2 + 4 * deeper_coal_mines + 3 * deep_coal_mines + 2 * coal_mines + charcoal_kilns)
  • max (iron_mine + 1.5 * deep_iron_mine + 2 * deeper_iron_mines) = 1 + 1.5 * (coal_mine + 1.5 * deep_coal_mine + 2 * deeper_coal_mines + 0.5 * charcoal_kilns) // IMPORTANT: for all kinds of mines, this limit should affect decision to build new mines, but not to upgrade existing ones. I can picture some situation where a mine is exhausted and need to be upgraded, but the ai won't because it already reached its limit, so ai should be allowed to break the limit to upgrade.
  • max iron_mine > 0 // sometimes the ai could have plenty of deep mines, but only have rations have food. this condition make sure it can continue to mine even if it lacks bread or beer
  • max coal_mine > 0
  • max gold_mine > 0
  • max (iron_mine + 1.5 * deep_iron_mine + 2 * deeper_iron_mines) = 2 + smelting_works
  • max (gold_mine + 1.5 * deep_gold_mine + 2*deeper_gold_mines) = ( 1 + (coal_mine + 1.5 * deep_coal_mine + 2 * deeper_coal_mines + 0.5 * charcoal_kilns))
  • max (gold_mine + 1.5 * deep_gold_mine + 2 * deeper_gold_mines) = ( 1+(iron_mine + 1.5 * deep_iron_mine + 2 * deeper_iron_mines)) // you never use gold without iron, so it's pointless to have more. exception for collectors win condition, where making gold ingots is the best way to make points
  • max (coal_mine + 1.5 * deep_coal_mine + 2 * deeper_coal_mines + 0.5 * charcoal_kilns) = 4 + 3 * (iron_mine + 1.5 * deep_iron_mine + 2 * deeper_iron_mines) + 3 * (gold_mine + 1.5 * deep_gold_mine + 2 * deeper_gold_mines) // I want the upper limit for coal production to be comfortably high to avoid malfunctions
  • max (tavern + inn + big inn) = 3 + 2 * (total mines) // I can't understand well how those buildings work, so I'm setting a prudentially high limit
  • max (tavern + inn + big inn) = 1 + (hunters + fishers) // none of those buildings can work without meat/fish. I am not putting a limit on inns and big inns alone because they can still make regular rations
  • max micro_breweries = 2 + (farms/1.5)
  • max breweries = 1 + (farms/1.5)
  • max cattle_famr = 0.8 + farms/10
  • max cattle_farm = 2 // I never needed more than 1 anyway
  • max reed_yard = 3 // I never needed more than 1 anyway; i'm setting a higher limit just in case the ai manages to block its fields
  • max farms = 5 + 8 * bakeries + 2 * breweries + 2 * micro_breweries // i limited cattle farms to 2, so i see no reason to include them in the equation
  • max charcoal_kiln = woodcutters/2
  • max battle_arena = 1 + training_camp/3 // the training camp takes much longer to train a soldier than the arena, so no point having 3 arenas with 1 training camp.
  • max training_camp = (0.5 + helmsmiths + ax_factory + war_mill)
  • max (battle_arena + training_camp) = 1.25 + bakeries * 0.75
  • max (battle_arena + training_camp) = 1 + (hunter + fischer)/2
  • max hunter = 2 + gamekeeper * 1.25
  • max gamekeeper = 2 + hunter * 1.25

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.

Current approach is to have "anonymous" buildings, it is based on whether an output is needed and current utilization. This here brings different approach and to some degree can be implemented alongside current logic. But I would rather improve current logic. If it works well, no hand-made rules would be needed.


Top Quote
king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 17:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2015-12-05, 21:52

But I would rather improve current logic. If it works well, no hand-made rules would be needed.

If

anyway, that set of rules would not substitute the current logic. they do not tell the ai what to build. they only tell what not to build. they are simply a way to ensure that if the logic malfunctions, it doesn't get too bad. if thhe logic works, they'll never even be called into question.


Top Quote