AI purchasing units ...

Discussing the game, editor (Suite) and the related tools.
Post Reply
User avatar
LuisGuzman
General, Special Forces
General, Special Forces
Posts: 639
Joined: 2019-03-10 08:35, Sunday
Location: Spain
Contact:

AI purchasing units ...

Post by LuisGuzman » 2019-10-23 16:45, Wednesday

As I posted at viewtopic.php?f=6&t=169&p=837#p837 I am opening this topic to discuss what could/should be changed to omproved AI 3 when purchasing new units.

Anyway, I don't think that improving this area should not be a high priority, as designers have better options to control, like assigning reinforces in different turns.

As anytime the AI changes, I must keep the previous version working the same (more or less, as sometimes is not possible), the code is basically the same but using different functions or using conditional branches.

I'll start explaining how AI 0.91 purchase units, as its rules are the default rules if designers don't use customization (AI's $Vars).
Then I'll add how AI 2.0 can purchase when using the $Vars and finally I'll post a few lines explaining the changes that can be tested using current version.
  Visit my website to get my latest tools.
* Click Open General banner to get more info about the game
Image

User avatar
LuisGuzman
General, Special Forces
General, Special Forces
Posts: 639
Joined: 2019-03-10 08:35, Sunday
Location: Spain
Contact:

Re: AI purchasing units ... Default rules

Post by LuisGuzman » 2019-10-23 16:48, Wednesday

These rules always apply for 0.91 and also for 2.0 if no .buy4 (nor old .ai file) or $Vars for AI are not enabled in the file.

Obviously AI cannot buy anything if:
- no prestige.
- no SH or no place to deploy ground units.
- no Airfields or no place air units.
- no units available to purchase.

AI tries to purchase units while prestige is not less than the cheapest unit available, using these sub-phases
  1. First action AI checks is if there are any VH in danger with an SH closer than 11 hexes.
    Then AI looks for the cheaper infantry unit able to reach the VH in danger. If none available it look for cheaper AT
    After checking the VH in danger, it also checks if any SH is in danger to garrisoning it.
    Notice the AI can spend all its prestige in this first action.
     
  2. With the remaining prestige, AI saves prestige to refit its units, but never more than 70% of the remaining prestige
     
  3. If AI owns any airfield, it tries to buy one or more planes expending no more than 50% of the prestige available.
    • if AI has more fighters than the enemy, it tries to buy a TB.
    • If enemy has more fighters than the AI, it tries to buy a fighter.
     
  4. Finally AI select one SH to buy a sequence of units based on relative number of own/enemy units within a range and the AI stance.
    Range is 10 for counting enemy units and 3 for own units
    • for defensive stance, the sequence to check number of own/foe units is:
      INFANTRY, ARTILLERY, FLAK, ANTI_TANK, INFANTRY, INFANTRY, ARTILLERY, TANK, AIR_DEFENSE/FLAK
      So first, infantry AI/player units will be compared and AI will buy cheapest infantry if it has less than enemy, then arty will be checked and so on.
       
    • for aggressive stance, sequence is:
      INFANTRY, TANK, ARTILLERY,AIR_DEFENSE/FLAK, ANTI_TANK, INFANTRY, INFANTRY, ARTILLERY, RECON, TANK
      For this stance AI wil try to buy SP(self-propelled) ARTILLERY, ANTI_TANK, AIR_DEFENSE and FLAK units when available.
Unless designer gives the AI a lot of prestige, only the first 3-4 first items in the sequence are usually checked.
  Visit my website to get my latest tools.
* Click Open General banner to get more info about the game
Image

User avatar
LuisGuzman
General, Special Forces
General, Special Forces
Posts: 639
Joined: 2019-03-10 08:35, Sunday
Location: Spain
Contact:

Re: AI purchasing units ... Customizing AI 2.0

Post by LuisGuzman » 2019-10-23 16:53, Wednesday

When using this AI version, purchasing can be customized by using a (scenario_name).buy4 file, and enabling (ticking) the option:
"Enable $Vars to customize AI purchasing" , in the AI $Vars tab. If the option is not ticked, AI will still use default rules as written before.

Note: .buy4 file is a merging of old .ai plus .buy files into one unique file, allowing also to define a custom purchase list for any player (not limited to 2 players only).
But if don't exist a .buy4 file, old .ai and .buy are checked and loaded eventually.

All $Vars has a tooltip in Suite, explaining what they do.

These picture shows the tool in Suite, with all the $Vars disabled (grayed)
Image

The different $Vars are:
  • $buy_minpres:
    Minimal prestige to start AI buying units. AI won't buy if prestige is less than this value.
     
  • $Buy_refit:
    Percentage of the prestige needed to refit all AI units, that won't be used to buy new unit. Remaining prestige can be used to buy units ("buy-prestige").
     
  • $Buy_newair:
    Percentage of "buy-prestige" that AI can use to buy air units, rest of "buy-prestige" will be used to buy ground units
     
  • $Buy_pick_method:
    0 = Cheapest unit.
    1 = random in a range of cheapest unit
    2 = random in a range of most expensive unit.
    * For 1 and 2, the range is defined in $Buy_pick_range
     
  • $Buy_pick_range:
    Range of units when pick method is 1 or 2, otherwise not used.
     
  • $Buy_turn:
    First value is the first turn to buy, so AI won't try to buy anything before this turn.
    Second value, means: "buy every x turns". Example: 2,2 won't try to buy until 2nd turn and will try to buy every 2 turns
     
  • $AI_class_cap:
    AI units cap by class. Can define a list of numbers separated by commas (usort by unit class id)
    AI won't buy new units from a class unless it has less units of tat class than the cap for that class.
     
  • $Buy_aggresive:
    Sequence of unit-class-ids to check to buy, when aggressive stance.
    Used by AI in the last purchase phase if still has prestige.
    Default for AI 2.0 is: 2,1,9,5,1,4,2,3 .. (TANK, INF, ATY, FLAK, INF, AT, TANK, RECON)
     
  • $Buy_defensive:
    Sequence of unit-class-ids to check to buy, when defensive stance.
    Default for AI 2.0 is: 1,1,9,10,1,4,9,2 .. (INF, INF, ATY, AD, INF, AT, ATY, TANK)
When $Vars are enabled to customize AI purchasing, the AI doesn't compare its number of units in range 3 with the enemy's units in range 10, so it buys units in the sequence as far as it has enough prestige.
  Visit my website to get my latest tools.
* Click Open General banner to get more info about the game
Image

User avatar
LuisGuzman
General, Special Forces
General, Special Forces
Posts: 639
Joined: 2019-03-10 08:35, Sunday
Location: Spain
Contact:

Re: AI purchasing units ... Customizing AI 3.0

Post by LuisGuzman » 2019-10-23 16:54, Wednesday

The AI 3.0 included in the official release, does basically the same than 2.0 except that it doesn't use $Buy_aggresive nor $Buy_defensive
and uses a fix and shorter sequence:

When aggressive: 2,1,9,2,5 ... (TANK, INF, ATY, TANK, FLAK)
When defensive: 1,9,1,4,5 ... (INF, ATY, INF, AT, FLAK)

And it always buys first a RECON if AI has none.

Now is your turn ... :howdy
  Visit my website to get my latest tools.
* Click Open General banner to get more info about the game
Image

User avatar
lvjtn
General, VII. Upper Danubian Corps
General, VII. Upper Danubian Corps
Posts: 769
Joined: 2019-03-09 23:23, Saturday
Location: budapest / hungary
Contact:

Re: AI purchasing units ...

Post by lvjtn » 2019-10-23 16:58, Wednesday

imo ai 2.0 shouldn't be touched (majority voted for "no more changes", and hacking ai is a very significant change), as you wrote, the best option is giving ai a reinf, if the designer wants adding strong and expensive stuff like a fighter or a :monster tank and the current existing $vars give lots of options too + nobody used them, so before touching ai, the designers should check what can be done with the existing tools. however, improving ai 3.0 is a better option, if necessary :2cents
»my real name is csaba (tʃɒbɒ)«
efiles:
Image Image Image Image Image

campaigns:
Image

User avatar
LuisGuzman
General, Special Forces
General, Special Forces
Posts: 639
Joined: 2019-03-10 08:35, Sunday
Location: Spain
Contact:

Re: AI purchasing units ...

Post by LuisGuzman » 2019-10-23 17:04, Wednesday

lvjtn wrote:
2019-10-23 16:58, Wednesday
imo ai 2.0 shouldn't be touched (majority voted for "no more changes"
Of course AI 2.0 won't be changed, except by mistakes :bonk

All changes in AI will be isolated for AI 3, and will be very slowly added.
I basically wanted only to document how the different versions work and the tools already available in this AI area.
:howdy
  Visit my website to get my latest tools.
* Click Open General banner to get more info about the game
Image

User avatar
REDrake
First Lieutenant
First Lieutenant
Posts: 108
Joined: 2019-09-27 05:44, Friday

Re: AI purchasing units ...

Post by REDrake » 2019-10-24 08:05, Thursday

You said that AI checks if a VH is in danger. Does the AI determine this from the distance of the spotted player units from VH or from actual un-spotted distance? In other words does it cheat when comes to checking the place of player units?

User avatar
LuisGuzman
General, Special Forces
General, Special Forces
Posts: 639
Joined: 2019-03-10 08:35, Sunday
Location: Spain
Contact:

Re: AI purchasing units ...

Post by LuisGuzman » 2019-10-24 09:37, Thursday

REDrake wrote:
2019-10-24 08:05, Thursday
You said that AI checks if a VH is in danger. Does the AI determine this from the distance of the spotted player units from VH or from actual un-spotted distance? In other words does it cheat when comes to checking the place of player units?
No, AI doesn't cheat.
AI evals all spotted enemy units, assigning a "danger" level to any important hex, according:
- If any enemy unit can enter in next turn (and higher if can be captured).
- if enemy units can attack the units garrisoning that important hex.
- the type of hex (VH is more important, then SH and so on).
- the difference between enemy units in a range and own units in same range.

and set up a list of the important hexes sorted by danger level, and scans the list trying to buy a unit able to move in the hex.

In a previous phase, AI has set up the list of important hexes in danger to move units to protect them, when possible so buying units is the last choice the AI has.
  Visit my website to get my latest tools.
* Click Open General banner to get more info about the game
Image

Post Reply