FFH2 AI and Sun Tzu (AI Suggestions)

Discussion in 'Civ4 - Fall from Heaven' started by DerWille, Dec 27, 2009.

  1. DerWille

    DerWille Chieftain

    Joined:
    Dec 27, 2009
    Messages:
    25
    Before I start, Kael and everyone else who worked on this amazing mod, thank you. I enjoy it so much more than Civ4. I love the atmosphere and mechanics. Anyways, I just finished reading the AI patch bug thread for .41h+ and noticed that OMG SoD was a major problem for most people. While I like that the AI has 120+ units to throw at me, it's not using them intelligently and should be far more aggressive if it does have them. So while don't we combine the wisdom of Sun Tzu with the Civ4 AI so they can know when to attack?

    Combat Tactics
    What I suggest is that the computer do a quick analysis before every battle and do the following comparison (I don't know XML, so it'll look like C++ code):

    If ( myNumUnits > (theirNumUnits * 5 ) )
    Attack
    else if ( myNumUnits > (theirNumUnits * 4 ) && ( combatOdds >= 20% )
    Attack
    else if ( myNumUnits > (theirNumUnits * 3 ) && ( combatOdds >= 40% )
    Attack
    else if ( myNumUnits > (theirNumUnits * 2 ) && ( combatOdds >= 60% )
    Attack
    else if ( myNumUnits > (theirNumUnits ) && ( combatOdds >= 80% )
    Attack
    else if ( myNumUnits <= (theirNumUnits * 1.5 ) )
    Pillage Countryside //this effectively divides their forces. If the player comes out to stop them, they will attack the weaker of the two targets if it falls into the odds there.


    Stack Sizes
    Then for the stack of doom being literally 100+ units and actually not being effective, how about we put a hard cap on their stack size of 50 units? Units such as great people, settlers, and workers will not be included in this. This will make them have separate stacks to take multiple cities with. However, there needs to be this clause.

    if ( biggestEnemyStack >= myBiggestStack )
    Merge stacks until myBiggestStack > biggestEnemyStack

    This will let the AI be able to counter huge stack vs stacks in pure numbers.

    Stack Composition

    This needs to be flavorful to really capture the essence of FFH2, but there are certain units that the AI must have to be effective: Offense, Defense, Siege, and Support. We can split this into a few categories.

    Offense: Warriors/Axemen/Champions/Phalanx/Berserkers/Martial Heroes/Horsemen/Summon Focused Adepts/etc
    Defense: Archers/Warriors/Axemen
    Siege: Catapults/Cannons/Fireball - Maelstorm Adepts/Tsunami Cultists (Must have water near by!)/Pyre Zombies!!! (I hate these bastards)
    Support: Medic II + March Religious Units/Rust - Haste - Bless Mages

    Now assuming a stack size of 50 the average civ should break down like this:

    Offense: 25
    Defense: 10
    Siege: 10
    Support: 5

    If a unit can reasonably be two different things, like Pyre Zombies, give them a priority. Pyre Zombies are primarily a Martial Collateral source of damage. An Adept can be anything so let the AI have 3 different routines when making them (Offense, Siege, and Support)

    Attack Priority

    When the AI decides to attack a city it should do so in the following order.

    Bombard > Magical Collateral > Siege Collateral > Magical Buffs > Summons > Martial Collateral (i.e. Berserkers) > Strongest Unit > Weakest Unit

    The idea is that the AI will first destroy defenses then use spells like fireballs, maelstorm, and tsunami next. Then will use its siege engines to weaken enemies as much as possible. Afterward summons will do the remaining weakening. Then the best units (Ones with the highest combat odds will attack). Adepts/Mages/Archmages will never ever attack.

    City Defense

    After the AI has capture a city it should leave 4 to 5 of its defensive units behind then push ahead with the rest of the stack. Once the stack runs out of defensive units when capturing a city (Typically 2 or 3), the whole stack will defend until more defensive units appear.

    If it sees a large stack passing by and is within reach, it will leave 5 offensive units behind and then engage (Using the above rules).

    About First Turn Defense

    All the AI should use their first warrior to defend. If they don't have a warrior, their first scout. AI can't restart. They cannot take that risk early game.

    -----
    This is just a bunch of suggestions and will need fine tuning for optimal performance. Go with the spirit of it rather than the exact hard numbers. Remember that the AI needs to play like a player does. How can we make standard procedures and rules out of our strategies?
     
  2. notque

    notque Artificially Intelligent

    Joined:
    Nov 13, 2005
    Messages:
    1,657
    Interesting and useful post.
     
  3. ExMachina

    ExMachina Warlord

    Joined:
    Jun 5, 2008
    Messages:
    203
    I like this too. I think this sort of thinking is what we need for AI improvements.
     
  4. Tlalynet

    Tlalynet Emperor

    Joined:
    Aug 24, 2007
    Messages:
    1,048
    I think the AI behaving like this would knock people down a difficulty level pretty easily.

    Always defending with their first warrior would be very nice too. I get tired of losing a couple civs every time a map starts.
     
  5. Afforess

    Afforess The White Wizard

    Joined:
    Jul 31, 2007
    Messages:
    12,239
    Location:
    Austin, Texas

    While these general strategies are wise, I must make a comment on your last statement. The AI does not need to play like a player does. If it did, the game would be a lot less fun. If the AI played like a player, it would declare war on other players when they were close to victory (So everyone would dogpile on the leading player), it would ignore diplomacy and backstab everyone, and as you mentioned, it could re-load the game.

    Rather, the AI needs to play smarter, but not like a human.
     
  6. Sephi

    Sephi Deity

    Joined:
    Jan 25, 2009
    Messages:
    2,941
    combat tactics: Using % attack chance isn't good. A stack of one lvl 3 elite defender longbowman and several warriors would look tougher than several lvl 1 longbowman. However at the moment the Stack of Doom logic is mostly a copy and paste of the BTS function, I guess there is lots of room for improvement.

    Stack Sizes: I agree. Needs a lot of work though. I do not face AI stacks of a that size so often, maybe it's better to make improvements elsewhere first.

    Stack Composition: This depends a lot on the civ and its current technology. Amurites for example should mostly use firebows while other civs should use only few archers as stackdefenders.
    You can find some improvements to stack composition here
    http://forums.civfanatics.com/showpost.php?p=8613811&postcount=2

    Attack Priority:
    that's already how it works now. Only bombard AI needs an Improvement. I put some code into Wildmana which I think works pretty well. The AI checks how many turns it needs to bombarb away the defense with the current siege units available and if it is less than Y it will wait and only bombard.

    city defense: for very large stacks I agree. It seems pretty pointless though to engage a large stack with only 5 offensive units. That's more like free xp.

    About First Turn Defense: The starting warrior(s) will always defend the first city.
     
  7. DerWille

    DerWille Chieftain

    Joined:
    Dec 27, 2009
    Messages:
    25
    Notque, ExMachina, Tlalynet: Thank you.

    Afforess: I have to respectfully disagree. I enjoy a competition that plays to win. They aren't on my team and their own self interest should out weigh my interest. If an ally thinks that they can profit from my over sight, then they should capitalize on it. If someone is going for a cultural, altar, or tower victory, I should fully expect that someone wouldn't want me to do that. I see all the different options in the game as means to an end. I didn't include it in this post, but most of Sun Tzu revolves around how to achieve goals by not fighting.

    Let's use diplomacy as an example. Let's say that I as a player have two sources of copper and my AI neighbors have none. Its first attempt at obtaining it should be trying to trade some resource with me. Let's say a happiness resource. If that fails it should try a healthiness resource. If that doesn't work it should try paying me for it like, 10 gold a turn for 100 turns. And if that fails it should consider attacking me for it.

    However the problem with all of this is that it is extremely hard to implement.

    Sephi:

    Combat Tactics - I admit that the logic I showed still needs alot of improvement and the example you gave is a perfect example. I was attempting to mitigate the use of elite units with numbers.

    One idea that came to me is instead of having the computer compare just the top defender, but every defender in the stack. So in our hypothetical Elite Defender Longbowman + Generic Warriors case it might look like:

    Longbowman: 10%
    Warrior 1: 40%
    Warrior 2:45%
    Warrior 3: 45%
    Warrior 4: 45%

    One way to do this comparison is to have the computer compute the strength total for the defending stack vs its strength total and then treat those bodies of units as one unit. This would be after all modifiers.

    The second way to do it is to assume that the AI would need 5 units to beat the Longbowman, and 3 units each for warrior. Then once it had those units, it would try.

    Another thing that should be considered is maybe something like

    if (enemyCultureDefense > 0 )
    {
    Bombard
    Wait on attack decisions (Whether to attack the city or pillage)
    }

    Stack Sizes: I'm only running core FFH2 .41j, no other mods. Right now in my Bannor game that I'm probably going to lose, Hybrobem has a stack of at least 40 units outside of territory and that doesn't include him or his city defenses.

    Stack Composition: That was my intention. I apologize if I wasn't clear enough. Yes, for the Ammurites, Firebows should be a large section of their army. That one unit will count as their siege and their stack defender. The AI should make use of its unique advantages like that (Pyre Zombies are the same way).

    City Defense: Ah, I'll try to rephrase it. If we assume the player has a large stack, maybe 20 units running around and the city it is in has no city defenders. It will leave a few (To prevent lone horsemen taking cities back) and in engage the stack with the rest of its SoD.

    Another thought that came to me is something like this

    if (enemyAttackerSize > myDefenseSize )
    Retreat

    Like you said, 5 units defending a city against a SoD is just free xp. The AI should try to make every effort to win the war it's fighting.

    First Turn: They do? At times it really doesn't seem like it, but I'll take your word for it.
     
  8. Afforess

    Afforess The White Wizard

    Joined:
    Jul 31, 2007
    Messages:
    12,239
    Location:
    Austin, Texas
    In the Better AI forums, we already had a debate about this.

    The reason you don't want the AI to act like a human is because human behavior is often determined by AI behavior. You only are doing specific beeline strategies because the AI doesn't. If the AI did, the human would do something completely different. You won't be fixing the game then, just creating new exploits.

    Instead, you simply need to make the AI do better evaluations. Don't make it beeline for certain techs; make it analysize areas where all other players are not teching, and go for those techs. Then the AI can trade those techs around and get far ahead. Don't make the AI stockpile large armies, make it consider the diplomatic climate and evaluate it from there.

    Really? So, if you are only one legendary city away from a culture victory, you'd want the AI, even your friends, to all declare war and start razing your cities? That's basically what you are asking for. The AI should consider victory conditions in it's planning, but it shouldn't be the only consideration. I would have no fun playing if I new that 10 turns before I won everyone was going to Declare War on me. I'd rather play with a smarter AI, not a ruthless one.

    This page had some interesting discussions on the matter.

    There other ways too. You completely neglected the fact that if the resource was near the border, you could spam your culture to flip it. Or if it's inaccessable, get some of the enemies of the player with the resource to declare war. Then ten turns later, offer aid in return for the resource. Use espionage and destroy the improvement on the resource, if we can't have it, then neither can they...
     
  9. Emptiness

    Emptiness []

    Joined:
    Jan 7, 2009
    Messages:
    1,922
    Afforess, this is the FfH2 section of the forums. BtS AI insight isn't necessarily going to translate. For example, there is no espionage in FfH2.

    -------------

    Unfortunately, this is similar to what the AI does right now. If enough threat is marshalled against an AI city, the defenders will abandon it. The problem with this behavior is that city defenders translate into time. Time for reinforcements to arrive, time to research a new tech, time to save yourself. City defenders should always stay and die, to slow down the enemy advance. As it stands now, the AI yields cities more easily than it should (because of retreats, and also because it has a stack of units "guarding" its territory that does not defend cities but also does not move with purpose to engage incursing enemy stacks).
     
  10. Sephi

    Sephi Deity

    Joined:
    Jan 25, 2009
    Messages:
    2,941
    that's a good point. Also AI has different strength than human player (less information, a lot less memory, but doesn't get annoyed by micromanagement)

    no, beeling techs is a key concept of FFH (bannor fanatism for example) and teaching it to the AI in a smart way was a big improvement (though there is still work left to do, especially for tier4 / lategame)

    this is quite bad in FFH, see above. Also some people play with no tech trading.(multiplayer for example)

    In a dark fantasy world where armageddon is close and horseman can always show up, you always want a strong army. In my experience you have less time to mobilize in FFH compared to BTS (raider trait, movement improving spells, many unit abilities that make slow siege units optional)

    That's actually how FFH works. There are some scripts that make AI declare war if you start one of the victory buildings. I don't know when these scripts were added, but it must have been a long time ago and I haven't seen many complains about it. In fact if you can get AI to war each other they won't declare war. not sure, could be that friendly AI is blocked from DoW too.

    espionage doesn't exist in FFH
     
  11. DerWille

    DerWille Chieftain

    Joined:
    Dec 27, 2009
    Messages:
    25
    I don't want to distract this thread from the combat AI any further with overall AI strategy. I want this thread to be a place for suggestions on how AI can wage war more effectively and manage it's stacks of doom better. But I'll answer you here. Could we continue in another thread or private messages?

    Honestly, I don't believe human behavior is determined entirely by the AI. I believe it's determined by the situation. For example, in the beginning phases of the game I pay more attention to what resources are near me and how I can best exploit them. Then I consider how crowded it is around me. If there's only 1 AI, I'll go for getting my economy off the ground. If there are alot, I will try to find a source of copper ASAP.

    There are exceptions to this. Like if the Sheaim are near me I'll strongly consider getting some Life II mages ready. Or a general preference towards cavalry since the AI spams archers now.

    However my overall strategy when playing the game is decided by my situation. If I have four or five mana nodes near me in the beginning, I'll consider a Tower of Mastery win. If I'm an island all by myself (or kicked people off of my continent), I'll consider a cultural or altar victory. If I've had to fight my way out of a terrible start, I'll continue to fight to a domination or conquest victory. As for religious victories... I don't know how to do these without getting a domination victory first.

    Yep. That's exactly what I want. Victory should not be easy. If you're surrounded by three neighbors, each who have a ton more military might than you, and you decide that a cultural victory is a good idea. You should really expect the AI not to take that lightly. Part of those builder victories involves making sure it's safe to do that. I usually don't attempt cultural unless I'm by myself on an island or I have the military to protect my culture cities. Sort of like I remember when playing Civ4 vanilla that it was recommended that you have 9 cities when going for a cultural win. Some for research, one for great people, some for finance, and one or two to make troops to protect your cities.

    I however agree that if you've turned an AI to Friendly, they really shouldn't attack you. Diplomacy should be a means of covering your ass. However there needs to be a penalty of, "You're close to victory!" Not a super huge one, but there should be one.

    These are all great suggestions and some of them are even more ruthless than straight attacking. I believe all these different options is what should be different between the different civs and leaders. The Balseraph would consider your cultural flipping idea (I'll be honest here, I've never been able to make culture spam effective unless it involves a great bard and two cities that have next to no culture). The Dovellio would consider trade -> demand -> tech. The Svart would try the ally - war -trade tactic (I really think this devious and ruthless and awesome).
     
  12. Afforess

    Afforess The White Wizard

    Joined:
    Jul 31, 2007
    Messages:
    12,239
    Location:
    Austin, Texas
    Yeah I know. That's one of the "features" I like the least.

    I just made a passing comment, you guys turned it into a full debate. :p
    Notice anything with these two paragraphs? You claim human behavior isn't determined by the AI, but then mention how the AI is scripted to do the same action every time near the end-game. I know when I play, I always have to mass a huge army before getting close to a victory condition, because everyone will turn on me. That is a perfect example of the AI forcing human choices. The more times you add this, the more predictable the games get.

    In Reality, your weaker friends should all offer to become a vassal near your victory, since it's your TEAM that wins, not the player. The worst enemies should probably declare war, but everyone else should just keep plodding ahead.

    I'm not saying all human player's actions are all determined by the AI, but a majority are. Play a multiplayer game with only humans. Trust me, it's a very different game. Old strategies don't work. In fact, I would use human only multiplayer games as a way to figure out how to improve the AI, because when you take the AI out of the equation, then you can see what is the best way to play if there were no exploits with weak AI.
     
  13. Tasunke

    Tasunke Crazy Horse

    Joined:
    Mar 20, 2009
    Messages:
    2,800
    Location:
    the 1800s
    I concur
     
  14. DerWille

    DerWille Chieftain

    Joined:
    Dec 27, 2009
    Messages:
    25
    What the AI does right now is a bit weak. I was hoping this bit of logic wouldn't enter until the city defenders wouldn't even slow down the enemy. Maybe something like...

    if (enemyAttackSize > (myDefenseSize*5)) or if (enemyTotalStrength > (myTotalStrength * 5)
    retreat
    else
    defend

    The problem with always staying to defend no matter what is that the AI offers up more exp to the enemy and decreases its chances of winning because promotions are arguably more important than anything else. Perhaps instead of size we can use the collective strengths of the stacks as a means of comparison.

    I feel that in those situations where it is hopelessly outnumbered or overpowered (Not an individual unit, but a stack) the AI should abandon cities to consolidate into one large force that would then counter attack. The one large stack used aggressively would have a better chance of repelling an invasion than city defenders that suicide during defense. It feels like the AI is wasting its forces doing that.

    However in cases where it is not hopelessly overpowered, it should stay and defend.
     
  15. Emptiness

    Emptiness []

    Joined:
    Jan 7, 2009
    Messages:
    1,922
    Defending units will always slow down attackers, even if the city will be taken in one turn. Each enemy unit that attacks the city is an enemy unit that isn't advancing on another city. Unless we are talking about a situation where the attacking stack is composed of a stack of units with fast move and blitz, such that they will (on their next turn) be able to kill all the defenders and then advance on and attack another city in the same turn, the defenders are better off staying. Remember, units that fortify in defense of a tile can build up to a 25% defense bonus. If they flee to another city they will have to remain stationary for 5 turns (once they get to the city) to build up that bonus. If the AI retreats from a city (because the threatening army is strong), then it is very unlikely that the threatening army won't reach that new city in less than 5 + x turns (x being the travel turns of the retreating stack). In effect, the AI has ceded territory in return for the opportunity to defend at worse odds. Unless the city to which the units retreat happens to now have enough defenders that the approaching enemy stack has no chance of victory - which seems unlikely since that same stack was unstoppable just a few turns ago - this is a bad strategic policy.
     
  16. DerWille

    DerWille Chieftain

    Joined:
    Dec 27, 2009
    Messages:
    25
    Ah, I forgot about the fortify bonuses and the distance traveled through cultural borders, thank you. And in an argument against myself, this type of defense would encourage short campaigns threatening the AI will large stacks to make them retreat then capturing the city and holding it. Sort of like nickel and dimeing the AI to death.
     
  17. Neomega

    Neomega Deity

    Joined:
    Feb 9, 2002
    Messages:
    11,261
    Heh, I've read the art of war at least a dozen times. I definitely quote it in my mind when playing sometimes.
     
  18. Tlalynet

    Tlalynet Emperor

    Joined:
    Aug 24, 2007
    Messages:
    1,048
    Defending units won't always slow down magic heavy attackers like mages, golems, or firebows. If their fireballs and summons can finish off the opponent its just as if they weren't there at all. They might as well stack up somewhere else where they could be useful.

    It sounds really complex to teach the AI to take all that into consideration though, for almost all circumstances I agree that they should just stay put and cause what harm they can.
     

Share This Page