sc2 artificial intelligence

animate_sea_transport_move_and_unload. · animate_naval_combat - run again after amphibious unloading. · animate_land_combat. 44. DEFENSIVE ...
129KB taille 9 téléchargements 325 vues
SC2 ARTIFICIAL INTELLIGENCE

AI ROUTINE ORDER

1. DEFENSIVE ASSESSMENT (PART A) ·

calculate_all_offensive_defensive_and_tactical_map_values

· · · ·

handle_plan_primary_assignment handle_plan_removals handle_plan_secondary_assignment handle_plan_build_ups

· · · · ·

animate_amphibious_transport animate_sea_transport animate_protective_movement_of_naval_units animate_protective_movement_of_hqs_rockets_air_bomber_units animate_protection_of_cities

12. DEFENSIVE ASSESSMENT (PART B) ·

calculate_all_offensive_defensive_and_tactical_map_values

· · · ·

animate_protection_of_capitals animate_opportunity_movement animate_restrengthening_of_units_in_capitals animate_restrengthening_of_units_in_cities_fortresses_and_fortifications

18. DEFENSIVE ASSESSMENT (PART C) ·

calculate_all_offensive_defensive_and_tactical_map_values

· · · ·

animate_protective_movement_of_land_units animate_fortification animate_replacement_of_garrisoned_positions animate_protection_of_land_garrison_positions

1

24. DEFENSIVE ASSESSMENT (PART D) · ·

calculate_all_offensive_defensive_and_tactical_map_values animate_protection_of_weak_fronts

27. OFFENSIVE PLANNING ·

calculate_all_offensive_defensive_and_tactical_map_values

· · · ·

handle_plan_primary_assignment handle_plan_removals handle_plan_secondary_assignment handle_plan_build_ups

· · · · · · · · · · ·

animate_air_combat animate_opportunity_movement - in case defender destroyed from air combat animate_paratroops_combat animate_naval_combat animate_fleet_staging animate_fleet_movement animate_naval_combat – run in case of surprise encounter from naval staging/movement animate_amphibious_transport_move_and_unload animate_sea_transport_move_and_unload animate_naval_combat - run again after amphibious unloading animate_land_combat

44. DEFENSIVE ASSESSMENT (PART E) ·

calculate_all_offensive_defensive_and_tactical_map_values

· · ·

animate_restrengthening_of_land_units animate_protective_movement_of_land_units animate_restrengthening_of_naval_units

49. REORGANIZATION (PART A) ·

calculate_all_offensive_defensive_and_tactical_map_values

· · · ·

handle_plan_primary_assignment handle_plan_removals handle_plan_secondary_assignment handle_plan_build_ups 2

· · · · · · · · ·

animate_amphibious_transport animate_sea_transport animate_land_unit_reorganization animate_air_unit_reorganization animate_naval_unit_reorganization animate_amphibious_transport_move_and_unload animate_amphibious_transport_move animate_sea_transport_move_and_unload animate_sea_transport_move

64. REORGANIZATION (PART B) ·

calculate_all_offensive_defensive_and_tactical_map_values

· · · ·

handle_plan_primary_assignment handle_plan_removals handle_plan_secondary_assignment handle_plan_build_ups

· · ·

animate_fleet_staging animate_naval_combat animate_fleet_movement

73. PURCHASES, DIPLOMACY, RESEARCH, UPGRADES ·

calculate_all_offensive_defensive_and_tactical_map_values

· · · ·

handle_plan_primary_assignment handle_plan_removals handle_plan_secondary_assignment handle_plan_build_ups

· ·

handle_purchases animate_purchases

· ·

handle_diplomacy handle_diplomacy_assignment

· ·

handle_research handle_research_assignment

· ·

animate_upgrades_of_land_units animate_upgrades_of_naval_units 3

AI ROUTINES – GENERAL CALCULATIONS calculate_all_offensive_defensive_and_tactical_map_values Calculates all the offensive and defensive values for units based on readiness and combat target values as well as the tactical situation maps for the AI. From these calculations the AI will have a better overview of where its strongest and weakest units are as well as where all potentially threatened ports, cities and other resources are located. Subsequent routines can then use this information to, for example, protectively move units, re-strengthen units, attack weak fronts and/or reorganize units in order to better protect weak fronts or threatened resources. Map wise, the tactical situation is assessed for each unit and resource based on each offensive/defensive unit within a 5 tile range (8 tiles for naval units) and by the tactical attack/tactical defense values divided by their distance. Note, air units are assessed if they are within general strike range of a unit or resource. A unit's tactical value is calculated as follows: LAND (ATTACK) = (SA + TA) / 2 * unit.readiness / 100 + unit.experience LAND (DEFENSE) = (SD + TD) / 2 * unit.readiness / 100 + unit.experience AIR (ATTACK) = (AA + BA) / 2 * unit.readiness / 100 + unit.experience AIR (DEFENSE) = (AD + BD) / 2 * unit.readiness / 100 + unit.experience NAVAL (ATTACK) = (NA + CA + UA) / 3 * unit.readiness / 100 + unit.experience NAVAL (DEFENSE) = (ND + CD + UD) / 3 * unit.readiness / 100 + unit.experience

Essentially the game engine is simply breaking down all the game information into numbers which are much easier to deal with than Corps, Armies, Tanks etc. as the AI really doesn't know what the heck that stuff is. Then it can assess the numbers and have an idea on a per unit/resource basis if it is in good shape or tactically threatened. At this point the AI can attempt, by moving units around, to get the numbers balanced and of course this is also used to assess plans, i.e. whether they should be continued or cancelled based on the tactical info. See the OFFENSIVE script header notes for more details. In terms of FoW, the AI still doesn't know what unit is what and where they are located but the idea here is to give the AI an equivalent of human intuition or feel (i.e. a fuzzy idea) for what is unfolding on the battlefield.

AI ROUTINES – PLAN ASSIGNMENT/CONVERSION/REMOVAL handle_plan_primary_assignment This is where plans from the Master Plan List are added to the Active Plan List. The Master Plan List contains all the scripted AI planning events found in the SCRIPTS\AI folder for each campaign. 4

If the plan event conditions are satisfied then the plan is added to the Active Plan List and all applicable units are assigned. If the event conditions are not satisfied the plan is either permanently removed from the Master Plan List if the event #TYPE= 0 otherwise subsequent passes will determine the activation status of remaining items. Unit assignment in this routine only assigns units up to the #SIZE value and does not include HQs, Rockets, Air Fleets and Bombers. These and any other unassigned units, which may bring the plan to a number of units greater than #SIZE, are added in handle_plan_secondary_assignment. Note: Once a unit is assigned to a plan, autom atically by the AI or via a scripted event, it cannot be re-assigned unless the original plan is either A) Cancelled freeing up this unit or B) #STEAL Offensive and/or Defensive flag has been used for the new event. In this case, as noted by the #STEAL flag param eters, the new event can only steal from plans that are either Offensive and/or Defensive (see

For reference, the Master Plan list is assembled when a campaign is saved in the Editor and it is assembled in the following script file order with events read top to bottom for each file: · · · · · · · ·

Garrison Fortify Build_Up_Offensive Build_Up_Amphibious Build_Up_Sea_Transport Build_Up_Amphibious_Minor Build_Up_Sea_Transport_Minor Build_Up_Fleet

This should be kept in mind when writing scripts since the game engine will, for example, assign available units to a Garrison plan prior to assignment of a Build_Up_Offensive plan as noted above. handle_plan_removals This is where plans are removed from the Active Plan List. Plans can be removed for #SIZE failures or for any other relative condition as outlined in the event script such as #FRIENDLY_POSITION failure and so on. In order to view a log of plan removals simply press the F2 key and it will generate a series of DEBUGLOGS that can be very helpful in understanding when and why plans have been cancelled by the AI script engine. The DEBUGLOGS subfolder will be found in your SC2 installation directory. handle_plan_secondary_assignment First stage in this routine is to assign all unassigned units, except HQs, Rockets, Air Fleets and Bombers, to generic Offensive/Defensive non-scripted plans. While the AI handles no other generic planning, these plans are helpful in giving unscripted campaigns at least some generic attack and 5

defense planning. Generic assignment of OFFENSIVE and DEFENSIVE plans depends entirely on the current tactical situation. See the OFFENSIVE script header notes for more details. Second stage is to assign at least one HQ, Rocket, Air Fleet and Bomber to an Offensive/Defensive plan that do not have any of these units respectively. Third stage is to assign any remaining HQs, Rockets, Air Fleets and Bombers to existing plans from largest plan to smallest, essentially by priority. At this point the AI will have assigned all assignable units to a plan on the Active Plan List. handle_plan_build_ups This routine handles the conversion of BUILD_UP plans to activated status. Declarations of War are also handled here if the BUILD_UP plan targets a currently Neutral country.

AI ROUTINES – PROTECTIVE MOVEMENT animate_protection_of_cities First stage of this routine is to look for empty friendly capitals that are threatened or have the potential of being captured and moving a friendly Corps to occupy this resource. First check is to see if a friendly Corps can reach the threatened capital under regular movement while a second check looks for Corps units that can be operated in. The final check, and only if the capital is still left unguarded, is to see we can purchase a Corps to immediately guard the capital. Before a Corps can be moved from its current position to guard an empty capital it typically undergoes a series of checks to determine its availability. For example it might currently be protecting its own position, i.e. a resource, from enemy units, or perhaps it is assigned to another more important plan. In either case it would be disqualified from potential movement and/or reorganization. A typical check looks something like the following: (resource = Null or else (resource.id = City and (plan = Null or else (plan.id /= Garrison or else resource.id /= Capital)) and not gam e.enem y_units_within_range_of_position(Hq) and not gam e.enem y_units_within_range_of_position(Corps) and not gam e.enem y_units_within_range_of_position(Arm y) and not gam e.enem y_units_within_range_of_position(Engineers) and not gam e.enem y_units_within_range_of_position(Paratroops) and not gam e.enem y_units_within_range_of_position(Tank_Group) and not gam e.enem y_units_within_range_of_position(Partisans)))

Second stage of this routine is similar to the first stage but here we just look for empty friendly cities that are currently threatened. The protection of these locations will use any available land unit starting from Corps->Paratroops. 6

animate_protection_of_capitals This routine attempts to even out the 'tactical land' threat against a particular capital with ‘tactical defense’ by moving in tactically superior elements. All units are valid for this protective movement with the exception of units that are already ‘tactically’ protecting another capital. animate_protection_of_weak_fronts This routine attempts to even out the 'tactical land' and ‘tactical air’ threat on the map against a particular city/capital/fortress by moving in tactically superior elements. Not all units will be considered valid for this move and the typical checks as outlined in animate_protection_of_cities apply. animate_protection_of_hqs_rockets_air_bomber_units This routine looks for any HQs, Rockets, Air Fleets and Bombers that are sufficiently threatened tactically by land or air units and attempt to move them out of harms way. It will also attempt to move any HQs, Rockets, Air Fleets and Bombers that can currently be reached and attacked by enemy units. animate_protective_movement_of_land_units This routine looks for any regular land units that are sufficiently threatened tactically and attempts to move them out of harms way. Note, these are typically low strength units that cannot be reinforced because of low supply or insufficient MPP. In this case, the game engine will attempt to move these units to the nearest non-threatened city and if this fails just to the nearest city. animate_protective_movement_of_naval_units First stage of this routine is to unload any transports at sea currently without a plan, if cancelled for some reason on the last turn, via Port. Second stage is to move vulnerable naval units, those with a strength = 5 in naval combat. Here the AI will seek out the weakest units to attack and intelligently make an effort to move, after combat, towards either a #WAYPOINT_POSITION, if scripted to do so, or towards a friendly port for optimal supply. 9

AI ROUTINES – NAVAL animate_fleet_staging This routine works with the FLEET scripts and essentially moves naval units towards the desired BUILD_UP position, i.e. stages the fleet for subsequent #WAYPOINT movement. animate_fleet_movement This routine works with the FLEET scripts and essentially moves naval units towards the pre-set #WAYPOINT positions once the FLEET script has been converted from BUILD_UP to full activation.

AI ROUTINES – TRANSPORT animate_amphibious_transport This routine handles the loading of units onto amphibious transports, as scripted, as well as the reorganization of units towards port locations for eventual transportation. animate_sea_transport This routine handles the loading of units onto regular transports, as scripted, as well as the reorganization of units towards port locations for eventual transportation. animate_amphibious_transport_move_and_unload This routine handles the movement and unloading of amphibious transports at sea, i.e. for those amphibious transports that can reach their ideal coastal unload position. Note, with this routine the game engine checks that at least 50% of the available amphibious transports, for the given PLAN, are within range of the ideal coastal unload position. This ensures optimal unload and attack of the desired #GOAL_POSITION. animate_sea_transport_move_and_unload This routine handles the movement and unloading of regular transports at sea, i.e. for those transports that can reach their port #GOAL_POSITION. animate_amphibious_transport_move This routine handles the movement of amphibious transports, that cannot reach their ideal coastal unload position, towards their desired #GOAL_POSITION.

10

animate_sea_transport_move This routine handles the movement of regular transports, i.e. those that cannot reach their scripted port #GOAL_POSITION, towards that position.

AI ROUTINES – REORGANIZATION animate_land_unit_reorganization Here the game engine reorganizes all unmoved units towards their OFFENSIVE, DEFENSIVE or BUILD_UP #GOAL_POSITIONS, or if the unit does not have a PLAN towards the nearest enemy unit or resource if an enemy unit is unavailable. AMPHIBIOUS/SEA_TRANSPORTS plans will of course have their units move towards the desired debarkation port position. Standard checks such as the one noted above in animate_protection_of_cities are applied before units are moved in order to ensure that the moved unit does not expose a vulnerable resource or position. Final retreats are also handled here if there are remaining weakened units that could not have been reinforced or moved previously in animate_protection_of_land_units and in this case they move back towards a friendly resource with an emphasis on non-threatened friendly resources first. Retreat movement overrides PLAN movement in order to help preserve the weakened unit. animate_air_unit_reorganization Similar to animate_land_unit_reorganization the game engine reorganizes all unmoved air units towards their OFFENSIVE, DEFENSIVE or BUILD_UP #GOAL_POSITIONS, or if the unit does not have a PLAN towards the nearest enemy unit or resource if an enemy unit is unavailable. Standard checks such as the one noted above in animate_protection_of_cities are applied before air units are moved in order to ensure that the moved unit does not expose a vulnerable resource or position. Final retreats are also handled here if there are remaining weakened units that could not have been reinforced or moved previously in animate_protection_of_hqs_rockets_air_bomber_units and in this case they move back towards a friendly resource with an emphasis on non-threatened friendly resources first. Retreat movement overrides PLAN movement in order to help preserve the weakened unit. animate_naval_unit_reorganization In this routine, subs without a FLEET plan are generically handled by the game engine and moved towards enemy convoy raiding positions. Note, if subs are more than 2X their AP away from an enemy convoy then they only move towards enemy convoys during Fall/Winter/Spring.

11

Cruisers without a FLEET plan are generically handled by the game engine and moved to patrol friendly convoy routes from enemy sub activity. Note, Cruisers are only moved for friendly convoy patrol activity if enemy subs are active. All remaining naval units without a plan are simply moved towards a friendly port with an emphasis on non-threatened ports first.

AI ROUTINES – PURCHASES, DIPLOMACY, RESEARCH, UPGRADES handle_purchases This is where purchase scripts from the Master Purchase List are added to the Active Purchase List. The Master Purchase List contains all the scripted AI purchase events found in the SCRIPTS\AI folder for each campaign. animate_purchases First stage is to buy back as many destroyed units, i.e. those with an * in their name due to the discounted price and reduced build time, first. Re-purchase order is from HQ -> Sub. See class UNIT_ID_CONSTANTS in the APPENDIX of this document for further details. Second stage is to work through the PURCHASE scripts in Active Purchase List order until either the Active Purchase List or all available MPP have been exhausted. Note, in terms of applicable upgrades, when a new unit is purchased, the game engine will max out available upgrades per unit, based on available MPP with a 50% chance that each applicable upgrade level will be reduced by a random amount, even possibly back to 0. This way upgrades are usually applied to new units with possible reductions as opposed to 50% chance there would be no upgrades at all. handle_diplomacy This is where diplomacy scripts from the Master Diplomacy List are added to the Active Diplomacy List. The Master Diplomacy List contains all the scripted AI diplomacy events found in the SCRIPTS\AI folder for each campaign. handle_diplomacy_assignment First stage is to remove/reclaim no longer applicable. For example the targeted country is now fully active etc. Second stage is to purchase/apply diplomacy chits for the AI in the Active Diplomacy List order up to the max chits allowable.

12

handle_research This is where research scripts from the Master Research List are added to the Active Research List. The Master Research List contains all the scripted AI research events found in the SCRIPTS\AI folder for each campaign. handle_research_assignment First stage is to remove/reclaim no longer applicable. For example the max research has already been achieved. Second stage is to purchase/apply research chits for the AI in the Active Research List order up to the max chits allowable for each category. animate_upgrades_of_land_units This routine handles the upgrades of land and air units but only if the capital position (of the unit's control id) is not threatened by land or air in order to save the money for potential defense purchases, reinforcement and/or reorganization. Upgrades have a 20% chance (per unit) during MUD conditions otherwise 10% during summer, and 15% otherwise. Possible upgrades for land and air units are sorted from strongest defensive unit to weakest. animate_upgrades_of_naval_units This routine handles the upgrades of naval units but only if the capital position (of the unit's control id) is not threatened by land or air in order to save the money for potential defense purchases, reinforcement and/or reorganization. Upgrades for naval units generally have a 15% chance (per unit) of occurring.

13

AI NOTES AND OBSERVATIONS It has been noted that units, those that are assigned to a plan do not seem to move/reorganize towards the desired #GOAL_POSITION as often as we would like. While the game engine does put an emphasis on scripted events it also must handle the real-time flow of battle, battle results and in turn several items of generic behavior such as protective movement, reinforcement and upgrades. One such example could be an offensive that eventually grinds to a halt either due to reduced tactical strength or superior enemy numbers. In the case of several weakened units that have been forced to retreat, generically handled by the AI, the overall offensive may eventually be cancelled if the original plan’s #CANCEL_RATIO has been met. Another example is the movement/reorganization of Air Fleets. In most cases, generic AI behavior automatically moves US Air units to the UK (when the US mainland is not threatened) since that location is usually the closest it can move towards enemy units/resources. Once there they may either begin to participate on attacks against enemy targets in France, reinforce and/or upgrade until a script assigns these units to a plan. Once assigned to a plan such as support combat in North Africa, unless the BUILD_UP length is sufficient in length to allow for air unit reorganization (see air_unit_combat for more details), these Air units may not immediately move down to North Africa if they can continue to attack targets in Northern France, as combat comes before reorganization as seen by the AI ROUTINE order. Essentially AI ROUTINE order and generic AI behavior should always be kept in mind when writing/handling scripts for your campaign.

14

APPENDIX

AI REFERENCE – TERRAIN ID CONSTANTS River :=0 Forest :=1 Mountain :=2 Marsh :=3 Depression :=4

AI REFERENCE – RESOURCE ID CONSTANTS Port :=0 Oil :=1 Mine :=2 City :=3 Capital :=4 Fortification :=5 Fortress :=6

AI REFERENCE – UNIT ID CONSTANTS Hq :=0 Corps :=1 Army :=2 Engineers :=3 Paratroops :=4 Rockets :=5 Tank_Group :=6 Air_Fleet :=7 Bombers :=8 Battleship :=9 Cruiser :=10 Carrier :=11 Sub :=12 Partisans :=13 Transport :=14 Amphibious_Transport :=15

15