1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

M:C AI improvements, tweaks etc.

Discussion in 'Civ4Col - Medieval: Conquests' started by Kailric, Feb 19, 2015.

  1. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    We can talk about all kinds of AI improvements here.

    I recently took the time to cypher out why the AI will attempt to produce things even though it doesn't have all the materials. This was due to the multi yields code of course but I finally took some time to pin point where. When the AI checks for Profession value it was only programed to check for 1 of the multi yield inputs, so I added code to cycle all of them, keeping the lowest amount as the modifier. This fixed two issues the AI was having in my current saved game as they changed those Units professions. A Minor Civ was still attempting to produce Hammers even with out Lumber though, so I'll need to check into that. Natives and Minor Civs get treated a bit different lots of times in the AI. I added an Assert to the UnsatisfiedProfessions code that will trip if an AI has unsatisfied yields to test this out for a bit. I'll push the changes when I have tested a bit more.

    One handicap the AI has is that it uses way to many units as Defenders. These units could be set to work in the Cities instead of just standing around gawking at each other.

    And they need improvements at war times so they don't send defenseless units walking past the enemy.
     
  2. orlanth

    orlanth Storm God. Yarr!

    Joined:
    Nov 17, 2001
    Messages:
    1,759
    Yeah the vanilla code is full of stuff that seems designed to cripple any civ with <bisNative>1 , or make them obsessed with only YIELD_HORSES and YIELD_FOOD and spawning UNITCLASS_BRAVE (to be fair, in vanilla that is basically all they can do lol). Not to mention, there is a function somewhere called Native Yield Destruction that basically evaporates any Yields they produce. In 2071 I basically had to try to inactivate most of the vanilla isNative specific functions to let them behave more normally, I'm not sure how good of a job I ended up doing with that but it did seem to make playing against (or as) them much more interesting. If you want to keep vanilla native stuff as an option, maybe some of the vanilla behaviors like Native Yield Destruction could be moddable separately by a CivEffect tag like <bSubsistenceEconomy> ; that way it would still be possible to mod very primitive Vanilla-like Natives or Barbarians with almost no economy, but still be able to mod Minor Civs that had the capacity to grow and develop by gradually advancing from primitive Civics to become more of a full fledged civ that's a more competitive threat :viking:

    It would be especially cool if these Tech/Civic advances could be earned by them researching using more advanced Yields you trade with them; this would create an interesting double-edged sword where you can earn big profits initially selling them advanced goods, but this trading is simultaneously helping them to advance :king:


    Both true, but the combat AI badness would in turn make them even more helpless if they start having less defenders. It does seem too easy to walk all over opponents cities if you plan a bit and focus on military buildup, if you defeat and capture them it can be a tremendously rapid way to gain lots of productive citizens and territory quickly and pull far ahead. I can't really tell though what the core causes are of the poor military performance in vanilla AI code, any ideas Kail or Night? I think there are some mods of BtS that focused on improving AI behavior (and of course TAC/RaR as well), maybe one of these has some good strategies.

    :spear:
     
  3. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,987
    We do that as well. It's called not having invented the yield yet :p

    We talked about moving bIsNative features into CivEffects, allowing changing and custom hybrids. However the native/"European" civ difference isn't the issue here. It's the AI for all players.

    I will likely look into improving the AI at some point. I already planned a cure for YIELD_HORSES addiction. It will change into a lust for any yield, which can be used to make military professions with and this will be dynamic since allowed professions aren't static through the game. There is one limitation in my plan though. They will sell the horses like cloth or any other "worthless" trading goods until it unlocks a profession, which actually uses the horses. Then it will turn around, stop selling and start producing and buying to stockpile for war. Being able to make the AI aware that they will be needed with some future invention is kind of tricky.

    The civilian units next to enemy is a tricky one. The problem is that the AI checks for hostile at a certain distance. The answer is to increase that distance, but increasing the range is performance intensive as the number of plots increases rapidly.
    Column 1 Column 2
    range plots
    1 8
    2 24
    3 48
    4 80

    We can see the enemy unit just fine when we look at the map. The AI can't and will have to make this check every single time a unit moves one plot. Pathfinding and moving is already a real slowdown as it is and adding additional slowdown would be quite bad.

    I can't think of a good solution for this problem. It would have to be some cached stuff, but I can't think of a good solution.
     
  4. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    We could make a new attribute for Yields, for bIsMilitary, then if the natives have an iNativeBaseValue for it, that means they will eventually use it. Although, in reality if there is some Yield that they know they can use for a purpose, why not go ahead and use it:confused: If they don't know then, yeah, they would just sell it. The Natives are not restricted in their use of Horses, however, but they don't use them in vanilla because they don't have any. In M:C they can produce them themselves, which reminds me, I haven't really seen any Minor Civs riding horses so I should check this out.

    Yeah, the AI doesn't use its visibility very well at all. I am guessing these defenseless units are using their own AI and visibility, moving one plot at a time, thus will walk right up next to an Enemy unit. We players do the same thing sometimes, like moving a Treasure Unit one spot to reveal a Bandit.. well, that treasure is gone, SOB! But, the AI needs a cached visibility on known Enemy locations, especially for defenseless units.

    Ok, Night, let's figure this out. At the start of each turn each Player is given warnings of Enemy units spotted in their territory. This could be a chance to add those units or plots to a Cache. Then when weak or defenseless units move about that turn they can check this cache against the plots they are moving. We could use the distance formula (distance between two points on a graph) to check the Unit's distance to that plot instead of doing path finding if it would be faster. Also, the Cache could save the Power value of the present Enemy units and the AI could send out enough troops to handle the situation. What's your input on these?
     
  5. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,987
    I have actually been thinking something like that. Adding a cache in CvPlot telling danger level. This is cleared on turn start and then each enemy (visible) unit assigns a number to the plot it is on. Just like distance to trade screen access plots, assigning a value to a plot will make the surrounding plots gain values, like
    Column 1 Column 2 Column 3
    5 5 5
    6 6 6
    7 7 6
    8 7 6

    Automated civilian units then gain the restriction that they can't move into a plot with a higher threat level than the one it is on, possibly with the exception that they can flee into cities for protection, though if it is losing the city, then it isn't safe. When a new enemy unit is revealed through fog of war, it updates the thread level.

    Different units might have different thread levels. Wild animals are relatively safe (like a safety distance of 2-3 plots) while enemy soldiers might chase you and requires a better safety distance. Also thread level should likely be affected by the unit's movement points meaning civilians keep a greater distance to cavalry than to foot soldiers.

    Animals without the ability to attach should have a thread level of 0. This will be useful for human players too as automated transport are... well automated and that mean the rules of not moving towards danger applies.

    The only time this fails is in network games where the other player can move during your turn. However let's forget about that for now as network games doesn't work now and will not be fixed for quite a while.
     
  6. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    That sounds like a good plan. How do we calculate threat level? For defenseless units it is easy, any unit with Power is a threat, plus you would have to add any units that can attack like Workers can. As you could then cheat and send Workers in to capture defenseless units.

    We need a good way to really define a unit's threat. Like Power isn't all that accurate as some units work best against others, plus I am not sure if things like Promotions add to a unit's power, doesn't look like it, but we should make them as so. Professions mostly add to a Units Power value. The Power value could be used to get a rough estimate of a Plots Enemy Strength, then the AI can decide what it wants to do by doing a more invasive query into the plots actual enemy makeup to see what kind of defense he wants to mount against it.
     
  7. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,987
    I was thinking of a threat level as how far away the civilian units should move. A civilian unit will not care if the enemy has a combat strength of 1 or 10, it will be captured or killed either way. The civilian units only care to outrun the enemy meaning they keep a longer distance to fast units. We could make them keep a great distance to all units, but the higher the threat level, the more plots will have to be assigned as a threat (performance issue) and getting all units to move into the cities within a 20 plot radius is a bit overkill for a single unit. This is a balance issue between no unneeded danger vs business as (almost) usual in low threat situations.

    I think we should have a different system for getting the soldiers to attack the enemy. Something like making a list of plots with enemy units. That way it can quickly loop all of them to get distance and check out the units on those plots and then (hopefully) do something clever.
     
  8. Commander Bello

    Commander Bello Say No 2 Net Validations

    Joined:
    Sep 3, 2003
    Messages:
    3,794
    Location:
    near Koblenz, Germany
    Two remarks:
    1) In the past (I remember such discussion from Civ3), players complained about the AI "knowing the map". Helping the AI is one thing, frustrating the player with AI bonuses which are regarded as being "unfair" is the other.
    2) I don't think the threat level has to be calculated to the last decimal. After all, you want to use it for protecting weak units, no? So, something very basic should do fine.
    Something like baseCombatStr() times maxMoves() would sufficiently do, as far as I see it.
    All you need to know it that plot X/Y is more dangerous than plot Y/Z, you are not that much interested in how much more dangerous it is.
     
  9. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,987
    I completely agree. I will try to make my plan this more clear.
    On turn start, the threat level is reset to 0 on all plots (it is set for the previous player).
    All plots are looped. On VISIBLE plots, the threat level applies if there is an enemy unit. By visible it is explored and not hidden by fog of war.
    Plots keep their threat level even if the unit on it becomes hidden by fog of war. Both humans and AI will be able to figure out that the unit is still there until the owner's next turn.
    Threat level can be increased by exploring and detecting units, which were hidden on turn start.

    I see no real AI cheating compared to what a human can do. If a human detects an enemy, leave it to let it hide in fog of war and then forget about it the same turn, then the issue is poor player memory because the majority can remember the unexpected and unpleasant surprise of an enemy unit approaching. You can set a sign if you want to remember precisely which plot if that is important.

    I don't see a need for using combat strength at all. The concept is about making civilian units free from units, which can capture them without a fight. For this only enemy movement will be relevant.

    Units with combat strength needs to do more calculations than simply look at the distance to the enemy.
     
  10. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    Right, sorry, my last comment was meant for Military maneuvers and not civilians, I didn't make the distinction clear enough.

    Also, in this case we are not planning to give the AI any more info than what a Player should know. We just need a good system to help the AI setup his military moves.
     
  11. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,987
    Actually that gives me an idea. We could cache in plots which plots you have seen this turn. Drawing stuff like enemy units will then be done based on what you have seen, not what you can see. This mean if you move and a plot is covered by fog of war, the enemy unit (which can't move during your turn) will still be drawn. Next turn you have to explore the plot again to see it again because it might have moved.
     

Share This Page