Results 1 to 30 of 30

Thread: Simple way to modify the AI towards a better direction

  1. #1
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Simple way to modify the AI towards a better direction

    Anyone ever wondered that although there's a load of different formations in the formation files, why we only see the one-and-only AI line we all know so well?

    Here's why. It's set as standard formation, with an AI priority of 2.0. Most of the other formations have 0.6 priority. When you lower the priority of ai_standard_line to lower than 0.6 you will encounter the other formations on the battlefield. AI will still be stupid but a bit less stupid than before.

    Try it, and we'll see if we can give AI some better formations.

  2. #2
    Member Member Malachus's Avatar
    Join Date
    Jul 2004
    Location
    Flint, MI
    Posts
    212

    Default Re: Simple way to modify the AI towards a better direction

    What file is this in?

  3. #3

    Default Re: Simple way to modify the AI towards a better direction

    I would be interested in this too, also curious are there more AI formations out there than the choices we have?

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

    Default Re: Simple way to modify the AI towards a better direction

    Open Data\descr_formations_ai.txt, then search for (second formation entry):
    Code:
    ;****************************************************************
    ;Standard formation. Infantry line in front, missiles behind
    ;cav on the wings
    ;****************************************************************
    
    begin_formation ai_standard_line
    
    	;;; purpose flags
    	attack
    	defend
    
    	ai_priority			2.0
    Change ai_priority 2.0 to 0.6 or even less.

  5. #5

    Default Re: Simple way to modify the AI towards a better direction

    Somebody plz explain how AI decide which formation it will use.

    And how not using standard formation will improve the AI behavior?

  6. #6
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: Simple way to modify the AI towards a better direction

    Quote Originally Posted by parrrrk
    Somebody plz explain how AI decide which formation it will use.
    It depends on the formations priority, available units and in case of special formations on AI flags.. Other than that, I don't know, but I will be researching it.

    And how not using standard formation will improve the AI behavior?
    The standard formation consists of 2 lines: first all infantry units in one line, followed by line of missile inf. Cav on the wings, general is behind all that. Now, as a player will use a more compact formation (e.g. roman manipular), AI's line will be even 3 times as long as player's. This leads to AI's weak center (mostly consist of light infantry) collapsing fast, and AI's troops on the flanks (which are mostly their heaviest troops) can't support their center, as they are too far away.
    After blasting through AI's center the player will encounter AI's flank infantry sent in piecemeal and this leads to player defeating them in detail.

    In the few tests I have made with standard formation "disabled" I have encountered AI army using different formations, which are MUCH better than the standard one. For one, AI will use its heavies in the center, where they are needed and will try to flank with light infantry and cavalry. Secondly, depending on formation, they will have reserves, a few heavies stashed behind the center. Sure, it's still stupid, and it will try to attack your flanks with cavalry. Just... they will attack with a single cav unit... and *almost* flanking your troops, i.e. unsupported frontal charge on flank unit.

    Another thing is, AI will actively rearrange its formation. Dunno if this is a good thing or bad. There has been some strange situations, e.g. AI marches up to archer range and then rearranges its whole form.

    Anyways, it's still much better than the standard.

  7. #7
    One of the Undutchables Member The Stranger's Avatar
    Join Date
    Dec 2004
    Location
    Nowhere...
    Posts
    11,757

    Default Re: Simple way to modify the AI towards a better direction

    well let's see if i can meet the AI alexander

    We do not sow.

  8. #8
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: Simple way to modify the AI towards a better direction

    With standard formation "disabled" I just had a custom battle on med. difficulty, Julii vs. Dacians, that ended in an average victory for me. AI was defending with Dacians. They had 3 chosen swords, 4 falxes, 5 WBs, 3 archers and 2 barb cav. I had 3 triarii, 4 principes, 5 hastati, 3 l. aux. and 2 equites. AI marched up to missile range and rearranged. I waited for them to get ready, then AI charges with 1 cav to my "flank" = rout. Sent skirmishers forward to pepper them, moved up my equites to cover them from remaining cav. AI tries to flank my cav on right flank, I pull them back a bit so they are covered by my battle line. They withdraw, without trying to drive off my skirmishers (In that case my equites would've been on their rear, while they'd have been engaged with skirmishers). On my left flank my equites rout one WB which had advanced too far and was getting back to its position.

    I run out of ammo, one aux. routing after taking casualties from arrow fire, other has only 20 men left, one in pretty good shape, withdraw my skirmishers. I rearrange my manipular formation (It'd get crushed), principes forward, two hastatis on each of their flanks. One hastati stays in reserve, triariis stay in reserve also. Cav gets ready to flank.

    AI was formed as: falxes, 2 chosens in the center, WBs on the flanks. General's chosens in reserve. I advance, pila fly, charge. Line holds and battle ensues. My left flank is winning, right is losing slightly, as their chosens were massed on that side of their center. My cavs are engaged with theirs.

    I send my reserve hastati to flank from right, AI tries also flank my right. I send more reserves, so I can flank them quickly, as my right is not going to last long. I check my left flank, my men have routed their flank and are in pursuit. I order them to quickly attack their center and the remaining flank which was kicking my flank's butt. I return to my right, to find my flankers nowhere and one WB getting ready to charge my shaken right. My reserves had pursued the original WB some ways away from the battle, but had just caught up with the WB. AI had pulled my troops away from battle!

    The WB was quickly routed by my reserves, which were then hurried to support my flank. One remaining reserve triarii was ordered to reinforce my flank. My left flank had charged their rear, but was in turn attacked from rear by rallied AI troops. The Dacian general was killed! I wait eagerly to see white flags pop up in front of my wavering troops, but no. The chosens didn't rout. My flank crumbled, leaving only the one triarii standing their ground. My flanking troops arrive, but too late; the triarii had routed.

    Most of my army was running for their lives, with one WB and one falx on their tail. One triarii and one hastati were still holding the chosens, but not for long. My cav was spread out, in the chase of whatever I had ordered them to rout; I was too busy to assign them new targets. I look up from my last, soon-to-die units to gaze upon my running troops. Red flags flashing white, small red dots under them, two brown lines under brown banners behind them. Then.. one flag stops flashing. ~20 principes had rallied, and near them a second unit in similar condition. They regroup, comrades running past them, to face fierce Dacians chasing them. Would they hold? Dacians charge them, a small fight ensues. Encouraged by their comrades, some other units rally, just in time to flank the falxmen which had just joined the fight. Dacians get crushed, rest of my running soldiers halt and get ready to face the fierce chosens a second time.

    Chosens were defeated, and battle won. A victory, but after grievous moments. Over 1300 Dacians were killed in that battle, but 900 Romans perished too.

    That had to be one of the best battles I have ever fought against AI, and I didn't even use any mods at the moment.

  9. #9
    Swarthylicious Member Spino's Avatar
    Join Date
    Sep 2002
    Location
    Brooklyn, New York
    Posts
    2,604

    Default Re: Simple way to modify the AI towards a better direction

    Nice find The_Mark, thanks for the info and the custom battle report. I'll have to give that a try. Have you tried testing this with other factions in custom battles? I'd be curious to hear how cavalry or phalanx oriented factions fare with the removal of the standard formation.
    "Why spoil the beauty of the thing with legality?" - Theodore Roosevelt

    Idealism is masturbation, but unlike real masturbation idealism actually makes one blind. - Fragony

    Though Adrian did a brilliant job of defending the great man that is Hugo Chavez, I decided to post this anyway.. - JAG (who else?)

  10. #10
    Magister Vitae Senior Member Kraxis's Avatar
    Join Date
    Feb 2002
    Location
    Frederiksberg, Denmark
    Posts
    7,129

    Default Re: Simple way to modify the AI towards a better direction

    Quote Originally Posted by Spino
    Nice find The_Mark, thanks for the info and the custom battle report. I'll have to give that a try. Have you tried testing this with other factions in custom battles? I'd be curious to hear how cavalry or phalanx oriented factions fare with the removal of the standard formation.
    Actually phalanx armies and cavalry armies have their own formations, also set at 2.0. So they will behave like they always have, depending on the boundary of the sizes needed for the formations to be used.
    You may not care about war, but war cares about you!


  11. #11
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: Simple way to modify the AI towards a better direction

    Cav or phalanx armies are not affected (well, this limits the benefits of this tweak to barbs only..), as they have their own formations, with 2.0 priority.
    /EDIT Or what Kraxis said..

    I guess the formation selection system first tests if the army can fill the requirements for highest-priority formation, if not it checks the next one etc.

    We could also write some better formations for AI to use.
    Last edited by The_Mark; 03-14-2005 at 21:35.

  12. #12
    Magister Vitae Senior Member Kraxis's Avatar
    Join Date
    Feb 2002
    Location
    Frederiksberg, Denmark
    Posts
    7,129

    Default Re: Simple way to modify the AI towards a better direction

    Indeed... And a lot of it could be copied from the present ones, such as distance to each other (lower it and I suspect our initial formations would be condensed too). I might get to it at some point.
    The formation missing is one where we have the heavy infantry in center, light in front and cavalry on the flanks (general behind as usual). I can't understand why it doesn't show up. That is the way I always deploys, and it is possibly the most historical formation.
    You may not care about war, but war cares about you!


  13. #13
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: Simple way to modify the AI towards a better direction

    That shouldn't be too hard to make, I'll check it out tomorrow. Me might even get a formation pack together, it would add some more variation to campaign battles also.

    (lower it and I suspect our initial formations would be condensed too).
    No, that won't work, frontage per unit is set in descr_units. Though you can remove the gaps between units.
    Last edited by The_Mark; 03-14-2005 at 22:55.

  14. #14
    Magister Vitae Senior Member Kraxis's Avatar
    Join Date
    Feb 2002
    Location
    Frederiksberg, Denmark
    Posts
    7,129

    Default Re: Simple way to modify the AI towards a better direction

    That was what I meant... Decreasing the gaps between units. I hate that there is such a large gap between phalanx units.
    You may not care about war, but war cares about you!


  15. #15

    Default Re: Simple way to modify the AI towards a better direction

    Hello.

    I did some pretty extensive testing back with RTW 1.1 with the AI formation file. I did tests with custom formations, toying with priorities, blocks etc... to see what happens in custom battle.

    At that time I concluded that the AI formation selection algorithm looks like that, it applies successive filters, selecting a subset of formations at each step:
    1) select formations that fit purpose (attack, defend...)
    2) select formations with min_units and max_units constraints satisfied with the army the AI has.
    3) finally select the formation with the highest priority; in case of conflicting equal priorities the 1st as it appear in the file is picked.

    So that means that given the same army composition the AI will always pick the same formation.
    So my most important finding in 1.1 was that ai_priority is really a priority not a probability and min/max has precedence over priority.

    I cant confirm if this has changed in 1.2 but I hope so.

    My testing procedure to test ai_priority influence was:
    1) clear descr_formations_ai of all vanilla formations.
    2) write a limited set of dumb formations that all are exactly the same, expect for some visual difference (block relative placement); this way I can see which formation the AI picks.
    3) try different values for ai_priority, launch custom battles with the same army each time and see which formation is picked.

    The same protocol was applied for min/max_units testing.

    I'll see if I can reproduce it with 1.2. Be carefull with the formation fellow RTW scientists, the parser for descr_formations_ai is very sensitive.
    (I hope my explanations are clear, English is not my mother tongue)

    As a side note, there are so many obvious features missing in descr_formations_ai it's depressing : no faction/culture specific formations, no strategic hint on how to use the formation (flanking? frontal charge?...), no effect of terrain, no comparison of forces...

  16. #16
    Senior Member Senior Member Jambo's Avatar
    Join Date
    Jul 2002
    Location
    Athens of the North, Scotland
    Posts
    712

    Default Re: Simple way to modify the AI towards a better direction

    Good topic this! I should add that modders should pay particular attention to the affect modding can have on certain types of battles, e.g. bridge battles. I used a mod which closed the gaps between units in blocks (interunit spacing) and the AI was then unable to move their unit columns across the bridge. I could hear the AI units shouting "move", so it was trying to move the units.. On returning to the original formations, the AI was then able to move their units across the bridge.
    =MizuDoc Otomo=

  17. #17
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: Simple way to modify the AI towards a better direction

    Quote Originally Posted by SEH
    ai_priority is really a priority
    It says it is, doesn't it?
    Ahh.. couldn't resist the temptation...

    Thanks for the info, we appreciate it. Did you find out if the AI picks only the formation with highest priority (other filters passed), disregarding all the ones with lower priority, or does it apply a small random factor to its checks?

    Yes, the parser is quite sensitive. e.g. you can't use the normalised_rot without using normalised_pos, and both of those commands exclude the relative_ -commands. There's not going to be phalanx lines with angled flanks. /EDIT actually that's not the case

    Quote Originally Posted by SEH
    As a side note, there are so many obvious features missing in descr_formations_ai it's depressing : no faction/culture specific formations, no strategic hint on how to use the formation (flanking? frontal charge?...), no effect of terrain, no comparison of forces...
    Yes, it's a shame. Although, we don't know all the possible AI flags that affect the formation selection checks. There could be more than the regular attack/defend and bridge flags, but I doubt it.

    Quote Originally Posted by SEH
    I hope my explanations are clear, English is not my mother tongue
    They are as clear as a sunny day in Sahara, no need to get worried.

    Quote Originally Posted by Jambo
    Good topic this! I should add that modders should pay particular attention to the affect modding can have on certain types of battles, e.g. bridge battles. I used a mod which closed the gaps between units in blocks (interunit spacing) and the AI was then unable to move their unit columns across the bridge. I could hear the AI units shouting "move", so it was trying to move the units.. On returning to the original formations, the AI was then able to move their units across the bridge.
    Thanks!
    Had they changed the interunit spac. in bridge-specific formations, or was it because some other formations had been tinkered with? (Now, it wouldn't be anything new if AI got bugged because of a legal command in another section of the script )

    Quote Originally Posted by Kraxis
    That was what I meant... Decreasing the gaps between units.
    Oh.. My bad.
    Last edited by The_Mark; 03-15-2005 at 17:54.

  18. #18

    Default Re: Simple way to modify the AI towards a better direction

    Quote Originally Posted by The_Mark
    It says it is, doesn't it?
    Hehe well "very_hardy" should have really meant "very_hardy" and not "very_lazy", "secondary" should not have been "primary", "very hard battles" not "very fast battles" etc... so who knows what ai_priority really does

    Did you find out if the AI picks only the formation with highest priority (other filters passed), disregarding all the ones with lower priority, or does it apply a small random factor to its checks?
    No randomness .

    I have just done some quick tests with 1.2 to confirm, crossed my fingers but had the same results :
    I wrote 2 very simple test formations A and B. They are perfectly identical, except a difference in spacing so we can see which formation the AI pick : A is a tight phalanx-style line, B has gaps between units.
    Then the idea is to tweak A and B ai_priority to see what happens.
    I created various custom battles with more than 1 units, run them a various number of time, and see what formation the AI picks for me and for itself.
    Results:
    With both ai_priority at 0.5 the AI always choose A, because it appears first.
    With B's ai_priority set to a higher value (say B=0.6 A=0.4) it will always choose B, because it has a higher priority.

    Here's the code for descr_formations_ai:
    Code:
    ;
    ; TEST 1
    ; purpose: AI priority 
    ; context: RTW vanilla 1.2, custom battles.
    ;
    
    ; A: a single compact line.
    begin_formation A_compact_line
    
    	attack
    	defend
    
    	ai_priority 0.5
    
    	begin_block 0
    		unit_type any 1.0
    		block_formation line
    		block_relative_pos 0 0.0 0.0
    		inter_unit_spacing 0.0
    		priority 1.0
    	end_block
    
    end_formation
    
    ; B: a wide line.
    begin_formation B_wide_line
    
    	attack
    	defend
    
    	ai_priority 0.5
    
    	begin_block 0
    		unit_type any 1.0
    		block_formation line
    		block_relative_pos 0 0.0 0.0
    		inter_unit_spacing 10.0
    		priority 1.0
    	end_block
    
    end_formation
    I did more tests than that with 1.1 but I don't feel like doing them all over again for 1.2, I think nothing changed there.
    Maybe there are some magic combination of ai_priority and block's priority to enable/disable randomness, or as you said some ai tag, but I doubt it. We can only experiment and guess until we get an official hint.

  19. #19
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: Simple way to modify the AI towards a better direction

    Quote Originally Posted by SEH
    Hehe well "very_hardy" should have really meant "very_hardy" and not "very_lazy", "secondary" should not have been "primary", "very hard battles" not "very fast battles" etc... so who knows what ai_priority really does
    Heh.. too true..

    Quote Originally Posted by SEH
    No randomness .
    I suspected that.. When I "disabled" the standard one I saw two different formations: The one in which AI deployed, and another one if I hadn't set AI on defensive; then it would swap its first formation to an "attack only" formation.

    Quote Originally Posted by SEH
    Maybe there are some magic combination of ai_priority and block's priority to enable/disable randomness, or as you said some ai tag, but I doubt it.
    I doubt that too. So in order to have AI use multiple different formations we'd have to define lots of different formations with specific unit counts.. Bad. Unless there are more of those AI flags.. There could be, but I doubt that too.

  20. #20
    Member Member Tritio's Avatar
    Join Date
    Oct 2004
    Location
    Singapore
    Posts
    6

    Default Re: Simple way to modify the AI towards a better direction

    This has been a most excellent and educating thread thus far. With the intention of exposing others to the information here, I have quoted and linked this thread over at TWC. Thank you all for your work in this. Keep it up!

    Edit: My notice has been pinned at the TWC Apparently, Spartan thinks this is great info too
    Last edited by Tritio; 03-17-2005 at 15:28.
    >Fear less, hope more,
    >eat less, chew more,
    >whine less, breathe more,
    >talk less, say more,
    >love more,
    >and all good things
    >will be yours.
    >
    >- Swedish Proverb

  21. #21
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: Simple way to modify the AI towards a better direction

    Thank you, Tritio!

    I'd like to know how this has affected gameplay for others as well, in campaigns, how AI behaves etc. It'd help in making new formations

  22. #22
    Senior Member Senior Member Jambo's Avatar
    Join Date
    Jul 2002
    Location
    Athens of the North, Scotland
    Posts
    712

    Default Re: Simple way to modify the AI towards a better direction

    Here's eagerly anticipating the first AI formation mod...

    =MizuDoc Otomo=

  23. #23

    Default Re: Simple way to modify the AI towards a better direction

    There is a connection between the amount of blocks within a formation that an army would assign units to that also determines whether the formation will be used. This can have quite a big effect. eg I tried a custom formation set at priority 2.0 and had to up the phalanx formation to 3.2 to get it to be chosen! Depending on types of units sometimes this had to be increased to 3.4 to get it to be used.

    Not sure if the block connection is a percentage weighting (to the priority) or some other calculation. The increase to 3.4 occurred when the army could fill 13 of 15 blocks (excuding a dummy Block) compared with 11 of 15.

  24. #24
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: Simple way to modify the AI towards a better direction

    Yes, I have noted this, And it comes in handy when trying to et some more randomness to the selction routine, although I haven't figured out how it exactly works.

  25. #25
    Lesbian Rebel Member Mikeus Caesar's Avatar
    Join Date
    Nov 2004
    Location
    Ostrayliah
    Posts
    3,590

    Default Re: Simple way to modify the AI towards a better direction

    You know, this is quite handy. It would be very handy if someone was to put this up at TW-Center as a mod, for all those people who would mess up if they did this themselves, like me.

    Kudos to you, The_Mark!!!
    Last edited by Mikeus Caesar; 03-30-2005 at 16:59.
    Quote Originally Posted by Ranika
    I'm being assailed by a mental midget of ironically epic proportions. Quick as frozen molasses, this one. Sharp as a melted marble. It's disturbing. I've had conversations with a braying mule with more coherence.


  26. #26

    Default Re: Simple way to modify the AI towards a better direction

    The_Mark
    I tried many different formations and it's certainly quite tricky. The problem I was having was trying to prevent the phalanx formations falling into a more depth orientated formation that I introduced to replace the single line with missiles behind. Having said that the way to control it is by working on the more critical formations first (i.e. for the larger armies) and then making them slightly more demanding. e.g.demand that one or two individual blocks of cavalry be filled or a single unit in a reserve line etc. Note - It doesn't seem to like it if you don't allow all units to be able to be selected (it didn't crash just gave an eerror message) - on the other had it doesn't object if you restrict below the maximum units. Basic objective seems to be to set the highest priority for the biggest and more complex formations first.

  27. #27
    Bug Hunter Senior Member player1's Avatar
    Join Date
    Feb 2005
    Location
    Belgrade, Serbia
    Posts
    1,405

    Default Re: Simple way to modify the AI towards a better direction

    bump,
    this could be useful...
    BUG-FIXER, an unofficial patch for both Rome: Total War and its expansion pack

  28. #28
    Amanuensis Member pezhetairoi's Avatar
    Join Date
    Apr 2005
    Location
    South of Sabara
    Posts
    2,719

    Default Re: Simple way to modify the AI towards a better direction

    I see we've finally gotten so tired of the AI we're changing things ourselves. Way cool! Here we are, an amateur CA that's making RTW a better game for the bright future! *RTW Roman Triumph fanfare plays in background*

    One thing's for sure, that'd mean that my current swordsmen strategy will no longer work, where I try to force the enemy single line to move to the right by threatening a right outflanking with cavalry, so the real blow--dealt unconventionally by infantry on the left--will be concealed and facilitated by the enemy uncovering of flanks.

    A question, though-- does it mean I will have a chance to face all different formations if I set all priorities to an equal 0.5?
    Last edited by pezhetairoi; 07-13-2005 at 01:29.


    EB DEVOTEE SINCE 2004

  29. #29
    Member Member BobTheTerrible's Avatar
    Join Date
    Sep 2003
    Location
    Ansonia
    Posts
    151

    Default Re: Simple way to modify the AI towards a better direction

    DarthVader has done extensive ai formation modding over at twc. The base AI is the same, but he's done a lot of stuff to improve it. You won't be blown away, but it's definately an improvement.
    If cockroaches can survive nuclear fallout, then what's in a can of RAID?

  30. #30
    Idiot Slayer Member bubbanator's Avatar
    Join Date
    Apr 2005
    Location
    Look behind you...
    Posts
    161

    Default Re: Simple way to modify the AI towards a better direction

    Quote Originally Posted by pezhetairoi
    A question, though-- does it mean I will have a chance to face all different formations if I set all priorities to an equal 0.5?
    I don't believe so. Based on the results of Screeching Elephant Hurler if all of the formations are set to an equal priority, the one the appears first is the one that is chosen.

    It could also be that it goes by alphabetical order if the priorities are equal. SEH, you should do another test with AB, BB, and AA with AA being last in the order. That would get acurate results if it goes by alphabet or sequential order.
    Never underestimate the power of stupid people in large groups...

    "Incompetence - When you earnestly believe you can compensate for a lack of skill by doubling your efforts, there's no end to what you can't do. "

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