AI Improvement

According to documentation from Povelitel AI receives 50% more gold from towns when complexity level is maximum. But the same 10 000 initially. Maybe some map events can change this behavior so.

It gives some extra complexity for human player and keeps them more interested in game. I believe it was done accidently so. If we can modify our Battle AI to be able to exploit issues in Stupid AI and thus fight against stronger enemy it will make things easier for AI in general. It does not look as super hard task also, does it? We even can try to simulate battle using stupid AI and see outcome. At the same time all these cheats does not work against humans. Maybe we can cheat internally and say that when battle AI fights against Stupid AI it gains additional 20% of damage or something (like he can exploit stupid AI but actually he can’t). this way we will save some development effort trying one AI exploit issues of another AI.

Our goal is not to mimic original H3 behavior, but make AI “good”, both battle and adventure. I am not sure if making stupid neutral monsters battle AI is good approach to develop adventure AI. And we do not have that “very strong battle AI for AI players” so to develop VCAI this way you would need to also make battle AI to cooperate with this design. Definitely not very friendly work to do.

I really dislike idea to anyhow adjust one AI to exploit weakness of another or make any other adjustments.

If player want to make AI more competitive with cheating we can always introduce H3 difficultly levels or options to make AI see whole map, exact army strength or something. Yet AI code itself should not be hardcoded for any of these cases.

BTW just in case: it’s not like we didn’t have arbitrary limit in past to make AI build capitol. Yet there is absolutely no reason to have any such limit at all: reserved amount of resources should depend on whatever needs AI currently have.

Some simple thinking:

  1. Check what buildings we can build in owned cities, what we’ll able to build on next turn?
  2. Obviously we shouldn’t reserve anything if we have nothing to build at all.
  3. Go further and introduce some dynamic priorities of what is most important for AI in this exact moment: army strength right now (e.g if there is superior army right next to our important town), town development, etc.

Obviously it’s won’t be easy to find that balance, but it’s exactly where Fuzzy logic and might be even small neural networks might kick in. After all there nothing magical about them.

Sounds reasonable. So I can introduce fuzzy logic or even small neural network as soon as I see that some condition is too complex. As a second stage.

Take no offense, but both fuzzy logic and NN are not here to solve “complexity” for you. They are just a tools to save you from spending days to manually adjusting some priorities out of your head. Making two AIs play 100,000 - 10,000,000 games against each other with reinforced learning is just much better way to determine priorities.

So please don’t waste time on micromanaging priorities or goal / task tree. Instead try to work on whatever design flaws you can solve or add missing features you see most important. Otherwise once someone will come and add any new code on top of what you’ve achieved all your hard manual work will crumble and this is what Warmonger try to warn you about.

PS: Since we all volunteers here you’re obviously free to do as you wish and any of your code will be merged if it’s make gameplay for average player more fun. In worst case we’ll just have to label it as “SmirmishAI” and keep it separate from VCAI. Yet it’s will be much better to get one feature complete AI instead of bunch of incomplete. :yum:

But the deal is: you do keep all game rules in your memory. When you look at map you can list all possible actions you can take with any object regarding any hero. As I see same way goal / task system should provide AI with every action possible and not even reasonable ones.

As I said in post above NN it’s another way to do code generation.
You just feed it with let’s say said virtual values:

  • Our AI score.
  • Nearest enemies danger. Some score of heroes who can attack you soon.
  • Worst enemies danger. Score for most powerful player.
  • Total enemies danger. To know where our AI stand comparing to ALL enemy players.
  • Might be some more values.

Then we use NN to determine whatever we can afford to waste some army to get some artifact or conquer new town. I’m sorry if you already understand all of it, but it’s important to know you do.

This approach have serious flaw because very few people can actually make good decomposition of their own way of thinking. I already tried it myself and also asked @Povelitel (and quite a few other people) to write down their own H3 play style. This is not easy thing to do and if you didn’t tried it yet then it’s might be worth to check how much details you can handle.

Personally I just come up with ideas that AI need more helpers like:

  • Static danger heat map based on pathfinding data and danger points like enemy towns or teleporters where entry is unknown to us. So AI can avoid sending heroes without army there like one’s who going on routines like collecting resources.
  • Dynamic danger heat map that also take into account disposition of recently seen enemy heroes and their kind of movement. Like if they can fly or teleport they’re significantly more dangerous. Then again we can avoid these areas in some cases.
  • Hero / player / team scores like mentioned above. Of course it’s will be much more precise if you give AI full access to game state, but even without it we can determine many things based on what we seen elsewhere.

And there could be many such things that we can play with afterwards.

@sxx, do you think I should start from scratch? Small steps and so on. It is now the most important question for me. I feel like I should but still I can not understand some things. Wandering logic is a good example. Why we should not prioritize it? Maybe there is something more behind current design than I can understand from code. Btw any idea where to start learning this fuzzy logic?

I thought about something like this at the very beginning. Goals give tasks. Than tasks are priorityzed and top tasks are executed. This way task should have enough info to prioritize it. Also I thought about some economics and battle scores which can tell how strong are our economics and army and how a particular task affects them. Also it will affect performance.

So far only advice I could give is that if you’ll decide to try implement player-like behavior then you must first write it all into the text, block diagram, mind map or whatever. Then if you actually manage it you can try to make good AI out of it. If you can’t manage it on paper it’s would mean it’s will be only worse in code.

You basically need to write down every nuance of how you decide what to do next in game and then you’ll start to see how much of your “experience” could be implemented into code. Unfortunately at least in mine and @Povelitel cases there just too many things you do in game because you “feel so” or because it’s “obvious” and when you try to implement ideas into AI it’s all breaks.

As for the other questions I would hope @Warmonger could find some time and at least try to explain them here since VCAI it’s mostly his code.

PS:

Performance should be your last concern in game like H3. Just forget it’s even a problem and do anything you want. Once you get there we’ll help to optimize it since it’s much easier than making working AI.

Personally I just come up with ideas that AI need more helpers like:

  • Static danger heat map based on pathfinding data and danger points like enemy towns or teleporters where entry is unknown to us. So AI can avoid sending heroes without army there like one’s who going on routines like collecting resources.
  • Dynamic danger heat map that also take into account disposition of recently seen enemy heroes and their kind of movement. Like if they can fly or teleport they’re significantly more dangerous. Then again we can avoid these areas in some cases.
  • Hero / player / team scores like mentioned above. Of course it’s will be much more precise if you give AI full access to game state, but even without it we can determine many things based on what we seen elsewhere.

These are interesting ideas, but…

  1. How does this relate to what VCAI already does?
  2. How does it relate to what you did in your pull request?

See? We don’t need any more ideas, we need proper implementation of what there already is. We also need to cover missing features and AI loopholes.

I think you’re missing the bigger picture and just want to quickly patch something “here and now”, without considering long-term consequences.

This comment was not mine. It was @SXX comment.

You all said that in a lot of places it is a mess. How can I see this big picture behind this heap of trash? Could you give me one? Describe me current design and how do you want to see it. Give me a place where to start from? Othervise I will do it alone the way I want it.

There isn’t anything better than Wiki entry. The idea is in fact pretty simple.

The big picture I’m talking about is:

  • AI must be able handle any situation: singleplayer, multiplayer, campaign or random map, empty map or whatever extreme scenario one could imagine. Keep in mind that mapmakers come up with weird things.
  • Player goals in this game unfortunatelly create circular dependencies. This can’t be avoided. On the other hand, AI shouldn’t get stuck in infinite loops (even across multiple turns).
  • AI should be able to realize long-term goals without skipping quick opportunities. This is a big problem, for instance you may want AI to save and gather money for Capitol, but on the other hand you don’t want it to stall if it can’t afford Capitol at all.
  • AI can’t follow simple if-else condition, as this will be easily noticed and exploited by human opponent. Also, this will explore only certain conditions picked by AI designer but ignore the others. This is why fuzzy logic is used, as it can process multiple conditions simultaneously.

This is why AI design is very difficult. Now, you have TODO list on Wiki for what else AI should do to be complete in terms of gameplay.

Ok, for now I stop work in my branch.

Danger hitmap will be good for detecting danger for towns and heroes. It will be good for implementing survival instinct. I really like this idea and thought about it myself. Also I think we can precalculate it for a few days to see danger early enough.

Regarding build in my branch I searched for each town the next building for economics and next dwelling. 6 - 7 day I also considered citadel/castle. I tried to enforce balance so I can afford all army grows. I use army = income/3 to have some money for building. What if I use balance army = income and some resource reservations? We can use balance state as a parameter to fuzzy. Kind of armyCost/income*7. If it is high we need more economics.

Can it be useful to have more army grows than you can afford? Probably yes because we can develop economy later and only if we have money to develop town. We can try to use fuzzy to decide what to build dwelling or economy building. We can use income, army grows, and current amount of gold. What else? Maybe alternative gold sources as not captured mines? Capturing mine is equivalent to building city hall but usually more cheap. Also some army pressure might shift as to build dwelling. Small area and strong desire to explore sectors blocked by monsters/enemy? Garrisons?

Guys, do you always use all 7 levels of creatures in town? Is there any sense to skip some?

Also I think that towns are not absolutely equal and some are better for army development than others. I try to calculate overall town development cost needed to build all dwellings. Also it might be worth to consider strength of creatures and disabled buildings and amount of towns with such alignment.

Any other ideas?

What do you think about AIValue? Could we trust it? Or is it also considered as a hardcode and should be calculated dunamically?

What point in hardcoding them in any case?

In good proper building algorithm dwellings should be evaluated exactly same way as other buildings. E.g as you said yourself in Building city hall vs capturing gold mine. Obviously AI shouldn’t strive to build dwellings if it’s don’t have budget to purchase creatures from it.

I’m hate this AIValue thing and in long run it’s should be replaced. Yet it’s not as important as it’s will be only required for modded game.

Simple, I need to understand that this is a dwelling or its upgrade so I can extract its creature and evaluate them. I think I can add army score and economics score for each building in town and use them together with amount of gold, income and so on. I just take all possible buildings with all these parameters and feed fuzzy with them so it can answer which is more important now? and rules like if armyCostRatio is high and economicsScore is high than value is high. armyCostRatio = cost of all grows/weekly income. I do not know exactly how fuzzy works so I have to understand it first. Same for citadel, its army score is 50% of current grows. Still some things do not fit in this schema, some walls of knowledge and so on. They have to be considered separately.
Also I need to track down dependencies like I need to build mage guild in order to build some dwelling so mage gild also receives army score.

I do not suggest to hardcode which level to skip, I suggest to analyze if we should skip some particular unit because we do not have enough gold income but can build/already built a dwelling with some better units. I expect that damage per each gold coin is less for higher level units also they usually have better speed and skills. Fact of skipping does not tell us to not build dwelling but we can avoid counting it in army cost ratio and avoid buying them until we have no other chose.

Lets go back to wandering. I have an empty map. It has just a few things on it. AI finds a mine which it can’t get and just wants to capture it badly. So it stops exploring. And there is no visitable objects so wandering do nothing. They just stand and do nothing. Wait until there is some army in town. What I think should be done:

  • wandering should be able to explore
  • wandering should prioritize objects to get because now it just takes nearest one
  • wandering logic should understand when it is better to explore and when to take objects
  • wandering should consider if current hero is the nearest one to an object it wants to get
  • conquer should understand when it is more important to explore rather than gather army
  • gather army could do nothing if it understands that it can’t get enough army anyway. Do not try to get half of it.

Lets go back to wandering. I have an empty map. It has just a few things on it. AI finds a mine which it can’t get and just wants to capture it badly. So it stops exploring. And there is no visitable objects so wandering do nothing. They just stand and do nothing. Wait until there is some army in town.

Could you please upload that map in question? AI shouldn’t behave that way to my knowledge.

In map list it is called a test map AI is not frozen completely, it waits capitol and army. It starts moving on 3rd week or something and captures that mine. Also there are a lot logs saying that not all mp are spent. I suspect problem with goal switching. AI can’t switch from ClearWayTo to Explore on the same turn.
Test.h3m (9.8 KB)
Saves.zip (495.1 KB)

1 Like

Also there is a problem when AI wants to take a thing on the adjacent tile. We use movement logic which checks if AI hero has actually moved and fails if not. But AI does not need to move because his path contains only one node with BLOCKVIS. It just takes the thing without move but logic crashes and wandering exits for this hero so he has some movement points left. I will address this issue on a separate PR. You can see the issue very often when there is a mine and a resource near it. AI first captures the mine and then the resource and then the hero is skipped even if he still has movement points…

1 Like