AI Territory valuation visibility?



  • The AI calculates the value of territories to figure out where it should move units. I think this is mainly used during non-combat move, though I could be wrong. The code for this is in games.strategy.triplea.ai.pro.util.ProTerritoryValueUtils.

    This valuation is currently calculated on an as needed basis but I'm wondering if it would make sense to perform the calculation before the non-combat phase and then make it available for users to see the values on the map. This would then help debug the AI since you would be able to see how the AI is valuating the territories.

    For instance, the recent Warcraft Heroes bug where the AI units would stack. If the valuation was visible, it would have shown that the home capital had a high value because of the nearby territories that it couldn't reach.

    To make this change, the AI valuation code would have to be changed so that it happens all at once instead of as needed (this could be a performance increase or decrease) and some work would need to be done in the UI so that the AI can be paused so that the user can view the valuations overlayed on the map. It will also need to handle different valuations, since there is a sea valuation, land valuation, air valuation, and I think a few sub categories in each one.



  • This reminded me of some AI techniques that I had read years ago. I went looking for it and found it. It is called "Collaborative Diffusion". The paper on it can be found at https://www.cs.colorado.edu/~ralex/papers/PDF/OOPSLA06antiobjects.pdf.

    Basically, you give a weight to the goals on the map (such as enemy capitals/factories, high value territories, canal controllers, etc) and then you diffuse the weight of those goals through out the map. So the territories immediately next to the goals have a weight that is greater than 0 but less than the original weight. Territories next to those are even less. But territories that are near two goals are better than territories only near one goal.

    Then, the AI only has to send its units to the territories with the best weight and if it does that each turn, the units will reach the goal.

    In addition to having goals with weights, you can have "anti-objects" which negate weights or zero them out. Things like walls, canals, restricted territories, etc. Enemy units can also be considered an anti-object.



  • @Trevan isn't this how it's kinda setup right now ?



  • Yes please display the weighting, but I think they are already displayed, but in a hard to understand format, does the bigger the number mean more attention/weight is required?

    As map designers can choose the order of delegates, then so too should the valuation of territories be done before each move delegate.

    I think the first step is to show the AI numbers and then we as players might have a chance to work out what might be happening.

    In the case Warcraft Heroes bug, it happens a lot on my Settlers: maps as well, I tried to work out what was happening.

    My unfounded conclusion is the weighting of the capital/factory is way too high when there is no threat, because the enemy cannot attack it within 3+ turns.

    Also there should be a big distinction between;

    • Air units that cannot capture the factory, as the counter is just Anti Air
    • Air units with paratroopers that can capture the factory
      .


  • @TheDog said in AI Territory valuation visibility?:

    Yes please display the weighting, but I think they are already displayed, but in a hard to understand format, does the bigger the number mean more attention/weight is required?

    Where are the weights displayed?

    @beelee said in AI Territory valuation visibility?:

    @Trevan isn't this how it's kinda setup right now ?

    My first comment is basically the current setup. But I'm not aware of seeing the weights in the UI so my proposal was to make them visible.

    My second comment (Collaborative Diffusion) isn't what the current engine uses. The current engine is closer to an A* pathfinder.



  • @Trevan so would this be map specific then ? One could tell the AI to defend this territory more than that one. Have it target these units more than others type thing ?

    Or it would be the current one size fits all and you have to figure out how to make your map so it will react the way you want it ?

    Either way, any improvement, even if just more information on the current process, would be a plus I would think.



  • @beelee The initial idea for making the valuation visible wouldn't really change the AI that much. It would just make it "easier" for players to figure out what it is thinking.

    The idea for the diffusion could be map specific. The map maker could mark certain territories with a high value. But I would hope the diffusion to be able to find most of "good" territories automatically.



  • @Trevan In the AI logs search for this heading

    Prioritizing territories to try to defend

    The AI log then lists the territories in the format below.

    Removing territory=Semigallia, value=52.85, CanHold=true, isLandAndCanOnlyBeAttackedByAir=false, isNotFactoryAndShouldHold=false, canAlreadyBeHeld=true, isNotFactoryAndHasNoEnemyNeighbors=false, isNotFactoryAndOnlyAmphib=false, tuvSwing=-1.0, hasRemainingLandUnit=false, maxEnemyUnits=0

    Above the value=52.85 I think is what you are after, this appears to be the weighting of the territory.

    It would be good to rename the "value=" above to TerritoryWeight= or similar.

    If you then search for that value in the AI logs you will find it is reused many times.

    Also I think the above value is what I was talking about here;
    https://forums.triplea-game.org/topic/2489/ai-and-over-stacking-of-defensive-units-on-capitals



  • @Trevan
    below is a link to one of my Settler maps, it has been customised for you,  I'm hoping it will give you a test AI map for over the winter break and will do the following things;

    • More often than not it will have a stack of units piled up in a factory/town/city territory, usually in/near Russia.
    • Gives economic victory in about 10 minutes
    • Plays 2v2 on Hard AI
    • Not World War 2
    • Of note, there is no victoryCity as it is a random start map.

    https://drive.google.com/drive/folders/18pc1M1-oqyHGgbmYU6R6F0MkLAaAmpXi?usp=sharing

    Open folder "For Trevan only
    Download it
    Select Settlers: Trevan Age of Tribes
    Load it and press Play



  • You are probably doing this anyway but just in case, is it worth coding your calculations as positive integers?
    Then we humans can easily read the values, as floating point with leading zeros is harder.
    The AI will probably execute faster with whole numbers.



  • Yeah, I'll be using longs as much as possible. I'd actually like to be able to show the valuation on the map itself, using something like a heatmap. I think that would be easier to understand vs having to look at a chart of numbers/territories.



  • Ambitious! I hope you can get it to work, you might have to put it on a white background as some maps are quite dark.


  • Admin

    @Trevan Unless I'm misunderstanding you, the current Hard/Fast AI pretty much does exactly what you describe for determining territory value during non-combat move. It values things like factories/capitals/number of nearby territories and then diffuses this value to nearby territories so that units essentially move towards higher value territories. This could be improved to consider additional values like canals, objectives, etc.

    https://github.com/triplea-game/triplea/blob/master/game-core/src/main/java/games/strategy/triplea/ai/pro/util/ProTerritoryValueUtils.java#L52



  • @redrum yes, the existing AI does calculate value and diffuse it. But it doesn't appear to do the entire map. It looks like it grabs a list of territories and then grabs neighbors of those territories and then calculates the values.

    My idea is also to not do battle simulations but instead try and incorporate that in the diffusion. That is one of the big unknowns on what I'm trying.


  • Admin

    @Trevan Not sure what you mean. If I recall it first finds all the "objective territories" which right now is capitals and factories then loops through all territories to find the distance each territory is from each objective and assigns value based on distance from each one. It also adds in some value based on territory production values that are nearby (within a few hexes).



  • Screen Shot 2020-12-17 at 9.07.58 PM.png

    Here's an initial attempt to showing the values of the territories as a heatmap. This is World at War. It is from Russia's point of view. The bluer the territory is, the better it is. So most of the Russian territories are very red since the units shouldn't stay there.


Log in to reply