Results 1 to 30 of 30

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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

    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...

  9. #9
    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=

  10. #10
    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.

  11. #11

    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.

  12. #12
    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.

  13. #13
    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

  14. #14
    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

  15. #15
    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=

  16. #16

    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.

  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

    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.

  18. #18
    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.


  19. #19

    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.

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