Results 1 to 20 of 20

Thread: Tweaking the AI to build balanced armies

  1. #1
    Senior Member Senior Member Duke John's Avatar
    Join Date
    May 2003
    Location
    Netherlands
    Posts
    2,917

    Post Tweaking the AI to build balanced armies

    I am currently playtesting and balancing the WotR campaign and it's coming along nicely. I have balanced AI stacks within a few turns. Below are some important things to look for:

    Unitsize setting
    I believe the AI trains units much more when the unitsize setting is set on huge. The reason is probably because the AI has been coded to have X number of men in a provence on default unit size. On huge unitsize the AI will then train 2*X number of men.
    The AI will thus have twice as many men, but to also get twice as many units you will need to set column 21 to No. All units are now unscalable. Not only can you have twice as many men in a stack (still 16 units max though), you can also have alot of huge battles I think this is a big improvement compared with the many 8 unit battles in normal M:TW.

    Unitcost
    All my units can be build from a single building. Even when the build probability in column 15 was the same for all units I noticed that the AI built the more expensive units a lot more. Apparently the AI has been coded to build expensive units more than others.
    This may seem all well since more expensive units are usually better but this is horrible if you want balanced armies In my mod Longbows originally costed less then mounted MAA. The result was that the AI built 6 cavalry and only 2 missile units, while it should be the opposite. I then ran a test where a Longbow unit was twice the cost and then the armies were mostly made out of Longbows.
    My conclusion is that unitcost is a very important factor in balancing the AI.
    However the bad thing of this is that you want the rare units to cost more, this will mean indeed less of those in player armies but more of them in AI armies. If you make rare units cost less you will see them less in AI armies but more in player armies since he will of course train the best for cheap.
    I think the best solution will be making the units cost all the same and tweak with column 15 (unit choice).

    Unitchoice
    In column 15 you will see numbers for the different AI behaviours. AI behaviours change during the game. If you set a faction to be Catholic_defensive then it may well be Muslim_peacefull a few turns later So you need to balance all of them. I keep it simple and give all the behaviours the same number.
    It seems that the higher the number the more the AI will build that unit. However the probability is much more influenced by the unitcost so the next test will be when I give all units the same cost and see what the effect of column 15 is.

    Cheers, Duke John




  2. #2
    Senior Member Senior Member Duke John's Avatar
    Join Date
    May 2003
    Location
    Netherlands
    Posts
    2,917

    Default

    I made a few more testruns and for some reason the AI builds Cavalry alot more then other units. In the WotR mod there are only 2 cavalry units and 8 infantry units. Yet there is about 1:1 ratio of cavalry to infantry even when unitcost/build probability are the same for all units.

    Edit: looking more closely at the AI controlled armies I saw that castle garrisons are balanced but once the castle is full the AI will start to fill armies with cavalry...




  3. #3
    Senior Member Senior Member Duke John's Avatar
    Join Date
    May 2003
    Location
    Netherlands
    Posts
    2,917

    Lightbulb

    And then I found the solution is dead easy. I find it strange that nobody else discovered it or bothered to post it here. Anyway here comes the big secret to balancing AI armies:

    Unit type
    You can find this in column 2. And it seems to be one of the most important columns. The AI is apparently coded to train cavalry units for field armies. Column 2 tells the engine which units are cavalry units. By setting all units to eiter infantry or cavalry this preference is now eliminated.

    Why should set all units to one type? During testing I found out that the AI trains cavalry to the extreme causing unbalanced armies. If you set all units to inf/cav then you can finally tweak the AI with the things that really matter: unitcost and buildprobability. I will make further tests to see how much these two affect the AI without the influence of column 2.


    ... excuse me.... WOHOOOOO FINALLY BALANCED ARMIES

    Ok, I'm done.

    Edit: one last thing. If everybody who is interested in this could help me researching how you can tweak the AI then we might be able to compose a guide. I think this is one of the most important elements in the game. You can have beautifull graphcis, an excellent campaignmap and loads of new factions and units. If the composition of AI armies is screwed then alot of the fun is taken away. But I with the discoveries above we can get alot closer to dangerously balanced AI armies.




  4. #4
    For England and St.George Senior Member ShadesWolf's Avatar
    Join Date
    Aug 2001
    Location
    Staffordshire, England
    Posts
    3,938

    Default

    Question: So why have the flag in the first place ?
    ShadesWolf
    The Original HHHHHOWLLLLLLLLLLLLER

    Im a Wolves fan, get me out of here......


  5. #5
    Senior Member Senior Member Duke John's Avatar
    Join Date
    May 2003
    Location
    Netherlands
    Posts
    2,917

    Default

    You mean why they coded it like that? Well it isn't that weird to differentiate infantry and cavalry. The bad thing is that CA coded it a bit too one-sided. The flag also helps in unitselection.

    CA made a mess with this, but luckily we can clean up this one.

  6. #6
    Member Member VikingHorde's Avatar
    Join Date
    Mar 2004
    Location
    Denmark, Aarhus
    Posts
    1,047

    Default

    Great stuff Duke John, keep it up. I have been playing with the production files for over a mounth and this makes it a bit more easy. Good work

    MTW XL version 3.0 out now! Get it here:
    https://forums.totalwar.org/vb/showthread.php?t=31201

  7. #7
    Clan Takiyama Senior Member R'as al Ghul's Avatar
    Join Date
    Jan 2003
    Location
    ignores routers who aren't elite
    Posts
    2,554

    Default

    Hey Duke,

    do you mind if I put a Link on the Lordz site?
    The Nap mod has the same problem: Ottomans for example build to many Cav. It seems to me that this hint could help the developers to improve the oncoming version 4.



    R'as

    Singleplayer: Download beta_8
    Multiplayer: Download beta_5.All.in.1
    I'll build a mountain of corpses - Ogami Itto, Lone Wolf & Cub
    Sometimes standing up for your friends means killing a whole lot of people - Sin City, by Frank Miller

  8. #8
    Senior Member Senior Member Duke John's Avatar
    Join Date
    May 2003
    Location
    Netherlands
    Posts
    2,917

    Thumbs up

    Sure, and please let us know if it works for them.

  9. #9
    Clan Takiyama Senior Member R'as al Ghul's Avatar
    Join Date
    Jan 2003
    Location
    ignores routers who aren't elite
    Posts
    2,554

    Default

    Thx mate,

    you're linked now. Feedback will follow.

    Cheers

    R'as

    Singleplayer: Download beta_8
    Multiplayer: Download beta_5.All.in.1
    I'll build a mountain of corpses - Ogami Itto, Lone Wolf & Cub
    Sometimes standing up for your friends means killing a whole lot of people - Sin City, by Frank Miller

  10. #10
    Aktacy Bei Member Eastside Character's Avatar
    Join Date
    Aug 2003
    Location
    somewhere in the endless steppes
    Posts
    1,080

    Default

    Great info DJ

    Regards,
    EC

  11. #11
    Urwendur Ûrîbêl Senior Member Mouzafphaerre's Avatar
    Join Date
    Nov 2003
    Location
    Mikligarðr
    Posts
    6,899

    Thumbs up

    -
    Great info Keep up the good work Hertog Sama
    _
    Ja mata Tosa Inu-sama, Hore Tore, Adrian II, Sigurd, Fragony

    Mouzafphaerre is known elsewhere as Urwendil/Urwendur/Kibilturg...
    .

  12. #12
    Member Member komninos's Avatar
    Join Date
    Mar 2003
    Location
    Greece
    Posts
    752

    Default

    Hi all,

    I also had this in HTW and had to experiment a lot with it till I finally came to the desired result.
    First of all I DO NOT USE ANY EDITOR that simply edits values.
    I have developed the Production XLS files to the extreme to produce my units one of the pages there was the personality matrix.
    In there they had a zillion of values that were calculated in. One of them was a handicap value that depended on cost to balance in the costly units.
    After sum experimenting I go nowhere but then I got a brake and totally redesigned the way things were calculated.
    This is how.
    I have generated a series of columns that represent things I like to take in consideration (Attack, Defense, Armor, Moral, Cost with 10 year support) then I divided these values with the maximum of each column. So this gave values from 0 till 1 and that was the unit with the best of each of the attributes.
    Then depending on the Personality I made the calculations so:
    The Poverty stricken needed units that will have some defense values but they will mostly be cheap to main tain this was represented by the formula 100*int((Attack+Defense+3*Cost)/5) this gives for each unit a value between 1 and 100. The higher the unit is the more it will be produced.
    In more detail what is in the int function is the sum of the coefficients times the weight over there total number (in this case 5) so the end result will be 0 till 1.

    It works perfectly the armies of HTW depend on the units that are mostly loved by each faction. You can also make extra column for missiles to promote the missile units.

    I have also used the same technique for the buildings so the factions are very aggressive in building the buildings they need and producing the units they need to win the game.

  13. #13
    Senior Member Senior Member +DOC+'s Avatar
    Join Date
    Jul 2002
    Location
    Athens of the North, Scotland
    Posts
    514

    Default

    Interesting theories, but I'm not entirely convinced that it's as simple to create balanced armies as has been stated above, unless of course you plan to go by the one building builds all route. I did a lot of work on tweaking the AI many moons ago, the threads are probably still located on these org forums somewhere....

    Anyway, one of the major issues which hasn't been mentioned is the issue of infrastructure hierarchy. This is probably the single most problematic issue for the AI failing to create balanced armies. Let me give you an example. Take the feudal men at arms unit, which is aruguably one of the most staple unit types in any human player's army, and yet the AI faction armies' rarely consist of them. To build they require a swordsmith and this building is a castle tier above what is required for the basic spearmaker and bowyer. Therefore, all the time the AI doesn't improve that province, it can only build peasants, archers and/or spearmen. Couple this with the sacking of provinces knocking the tech levels down constantly and you can see why building the better units can be extremely difficult for the AI.

    Now, a sensible human player will usually target building the swordsmith early in the game. Conversely, it is relatively low down on the AI's priority and therefore, the crux of the matter is the AI rarely allows itself the opportunity to build this building in a timely enough manner. Couple this with the relatively low AI build values for sword units due to their innate cheapness and this makes the AI even less likely to build these units.

    The fact that peasants require a basic fort explains why even if given an almost 0 probability to build, the AI regularly has its provinces loaded with them. One of the things I did in my mod was make peasants require a more difficult combination of structures to build and make them become obsolete after the Early period. What I learned is that making units become obsolete is a very useful way of restricting and controlling what the AI can and will build and the game progresses. One should consider this for other weak units like urban militia, spearmen, slav warriors, woodmen, etc.

    I won't go into it now, but one also has to consider seriously the implications of unit provincial bonuses. These have pronounced effects on the way the AI techs up in a given province; if done carefully, this can be used benefically to improve AI army makeup. However, more often than not, it'll result in the AI teching poorly, getting stuck, or ignoring other vital improvements (e.g. gold mines).

    There's a lot of excellent stuff archived away in the various nooks and crannies of the org forums. Have a search and see what you come up with.

    Regards

    Doc
    =MizuDoc=

  14. #14
    Member Member komninos's Avatar
    Join Date
    Mar 2003
    Location
    Greece
    Posts
    752

    Default

    Hi +DOC+

    I never said it is easy The tools make it easer than what it was. In HTW we have a fairly complex building / production structure that forces the AI to build up and a the army structure is also quite complex. The problem was that the Hellenic armies of the period were fairly simple at the beginning (70-80% Heavy infantry, ~20% light infantry, 0-10% light cavalry) but at the end the armies were very complex fielding light artillery, cavalry heavy and light infantry.
    I can’t say I am 100% there but I am at least 90%. For my tool it all comes down to making the correct function with the needed coefficients for the correct behavioral pattern.
    It took me ~3 months to find the way to do it and about 1 weak to make the functions. I am no still 100% confident with them but for now they work
    When I have time I will pass them to the VI and MTW production files and make these ones public so you can also test them.

  15. #15
    Senior Member Senior Member +DOC+'s Avatar
    Join Date
    Jul 2002
    Location
    Athens of the North, Scotland
    Posts
    514

    Default

    komninos, apologies, but my post wasn't in fact referring to your direct post above, but rather the original few posts by Duke John. My apologies for the confusion.
    =MizuDoc=

  16. #16
    Member Member komninos's Avatar
    Join Date
    Mar 2003
    Location
    Greece
    Posts
    752

    Default

    No problem M8,

    I think you all have to wait a bit till I pass all the HTW refinements to the MTW and VI files and make them public.

  17. #17
    Member Member VikingHorde's Avatar
    Join Date
    Mar 2004
    Location
    Denmark, Aarhus
    Posts
    1,047

    Default

    Quote Originally Posted by [b
    Quote[/b] (komninos @ July 22 2004,09:00)]No problem M8,

    I think you all have to wait a bit till I pass all the HTW refinements to the MTW and VI files and make them public.
    Sounds cool. How much time is there untill you make them public (estimated, no rush).




    MTW XL version 3.0 out now! Get it here:
    https://forums.totalwar.org/vb/showthread.php?t=31201

  18. #18
    Clan Takiyama Senior Member R'as al Ghul's Avatar
    Join Date
    Jan 2003
    Location
    ignores routers who aren't elite
    Posts
    2,554

    Default Re: Tweaking the AI to build balanced armies

    Hi Duke John,

    I tried a different approach for unit balance and posted it at the Lordz' board:
    My dear Lords,

    a few weeks ago I posted a Link to a topic on the .org.
    Duke John suggested there, that by setting all the unit types in column 2 to one label, you could then concentrate on cost and value to influence the AI's building habit.

    I think, I discovered a better solution to this.
    As it is right now in my campaign, after this tweaks, the AI starts to build a lot of Line Inf with light Cav in the beginning. It then continues to produce a good amount of Artillery and Heavy Cav and Inf units.
    After about 30 turns you will encounter AI armies which will always include 1-3 pieces of Art, 2-4 Cav and the rest Line, Light, Guard or Grenadiers.
    I'd say that's a good mixture.
    What did I do?
    Well, you know that I've been working on formations. I figured that to distinguish between the units on the battlefield, there have to be good distinctions/ differences between the abilities of the single units. I then tinkered with the column 18 "Unit Label". At first I thought this is the important column for the formations. Alas, I had no luck with it.
    But, as an interesting side effect, after changing the labels to what I thought was plausible the AI (noticed this at first for the Ottomans) started to build huge stacks of Line. After further tweaking, it also build fair amounts of Cav and, as said above, good amounts of all kinds of Artillery.
    Here are the new labels I used:

    Rebels DEFENDER,MISSILE,SPEAR,ANTI_SPEAR,WEAK
    Militia DEFENDER,MISSILE,ANTI_SPEAR,WEAK
    Cavheavy ATTACKER,ANTI_INFANTRY,CAVALRY,ANTI_MISSILE,STRONG
    Cavlight ATTACKER,AMBUSH,ANTI_MISSILE,CAVALRY
    Art MISSILE, DEFENDER,ANTI_SPEAR,ANTI_INFANTRY,ANTI_MISSILE

    Heavy foot ATTACKER,DEFENDER,MISSILE,SPEAR,ANTI_SPEAR,STRONG
    Line DEFENDER,MISSILE,SPEAR,ANTI_SPEAR,STRONG
    Light/Jäger ATTACKER,MISSILE,ANTI_SPEAR,AMBUSH

    As I said, the Ottomans, who used to build nearly Cav only armies, appeared with huge stacks of Line and Guard Inf. This made me investigate further with the above results.
    What I also did, and which may have contributed to it, was to develop classes for the units. I altered the combat stats as well as the cost (initial & upkeep) to give the units distinct values:
    Line: main allround unit, decent combat stats
    Rebels/ Militia: the same but weaker
    Light/ Jaeger: lower combat stats then Line but good morale and faster or higher range.
    Guard + Grenadiers: higher combat/ charge and morale compared to Line
    The initial costs are altered to reflect the value.
    for Cav it's like this: Hussars->Uhlans->Dragoons->Cuirassiers
    They differ in Charge/ melee/ armour and honour.
    I used common sense here. Cuirassiers have the best armour and morale. Uhlans the highest charge(10). Hussars have morale 4.Charge and morale are higher than the generic 3x version. Melee stats are slightly higher.
    Again, the initial costs are altered to reflect the value and the upkeep cost is somewhat reduced.

    If you'd like to have a closer look, I'd send you the unit_prod_file.

    Kind regards

    von Reiswitz
    While some of this isn't equal to your mod, you may look into the column 18 to see if it may be possible to do something similar. BTW, it really bugs me that we still don't know what several columns do.
    For example: There has to be a connection between the formation files and the unit_prod. Something in the unit_prod tells the engine where to put a unit in a formation. Likewise, it seems that the the engine reads the unit_prod to determine which units to build. This is not only the column 15 (unit choices), it's rather a combination of columns.
    It would be groundbreaking to find this out.
    Anybody has a good wire to CA?

    R'as (Baron von Reiswitz at TheLordz)

    Singleplayer: Download beta_8
    Multiplayer: Download beta_5.All.in.1
    I'll build a mountain of corpses - Ogami Itto, Lone Wolf & Cub
    Sometimes standing up for your friends means killing a whole lot of people - Sin City, by Frank Miller

  19. #19
    Member Member Serpent's Avatar
    Join Date
    Jan 2004
    Location
    Porvoo, Finland
    Posts
    89

    Default Re: Tweaking the AI to build balanced armies

    If you want balanced armys then here is one way.

    Horse Archer , Bailey+ Horse farmer
    Peasant , Fort and Church
    MuslemPeasant , Fort and Mosque

    Then build in these places Church
    MILAN
    MERCIA
    CARPATHIA
    TOULOUSE
    And more if you want.

    I have moded a lot more my game in past week and Im not sure what more you should do that game would be completely balanced. But there is change that Germany will come a lot stronger and Byzantine will be weaker if you also take slavs from them.

    But they will manage and turks will get some land or if they wait too long they will be slaugtherd.

    Game will be allot more interesting for sure.

    These changes may most likely effect your Netplaying if you don't build separate MOD. If someone didn't know that already.
    Minä puhu suomi ja kirjota huono engklanti.

  20. #20
    Member Member sunsmountain's Avatar
    Join Date
    Sep 2003
    Location
    Netherlands
    Posts
    414

    Default Re: Tweaking the AI to build balanced armies

    I was wondering if anyone could give a step by step guide to mod my crusaders_unit_prod11.txt file, so the AI builds balanced armies. I like what i read in R'as al Ghul's post, but i dont understand what he changed exactly, and it seems to be for a mod of some sorts.

    So i'm looking for a better AI in the Vanilla MTW 1.1 version, no expansion, no mod. Just balanced AI armies.
    This probably also means a necessity for the AI to pick better buildings as well.
    Anyone?

    The real problem is AI rebellions though. They (the rebellions) should be composed of units better than peasants, not because they were so historically, but because over time most AI troops will have been created by rebellions at some point.

    How do you change the make up of these rebellions? Factions re-appearing are cool and have a good (if somewhat powerful) makeup.
    Last edited by sunsmountain; 08-03-2005 at 22:52.
    in montem soli non loquitur

    (\_/) (>.<) That's what happens with bunnies
    (x.X)(_)(_) who want to achieve world domination!

    becoming is for people who do not will to be

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO