Map Database  •  FAQ  •  RSS  •  Register  •  Login

Combat AI for RTS

<<

Toxic

Rogue

Posts: 50

Joined: 22 Feb 2017, 19:04

Post 25 Apr 2018, 18:14

Combat AI for RTS

Combat Artificial Intelligence


This is the second part of my AI documentation. This topic is focused on combat AI in KaM. Combat AI includes everything from training soldiers through pathfinding to fight. More examples of my work: City-Building AI, Random Map Generator.

AI Fields
The more detailed description of AI fields can be found in my previous post (City-Building AI). Combat AI uses Navigation Mesh for 3 main purposes:
  1. Army influence - similary to polygon ownership in building AI, combat groups spreads around themselves influence.
    Image
  2. Pathfinding - polygon pathfinding is a faster way how to find a path between 2 points. This method also allows to consider other elements in pathfinding (size of actual road, army influence etc.) and provides easy way, how to detect walkable reas.
    Image
    There are 2 pathfinding methods:
    1. Avoid traffic - penalization of all polygons with units
      Image
    2. Combat pathfinding - penalization of polygons with "dangerous" units (for example pike vs cav) and advantage of weak units (for example cav vs archers) -> pathfinding automatically change path of units by situation and higher structure does not have to scan every tile for hostile troops - typicaly platoon just give order to attack and pathfinding should find best way.
      Image
  3. Detection of defensive positions (within the team) - the density of Navigation Mesh was increased and thus old algorithm for detection of defensive positions could not be used. Probably the best way how to create defence lines is to transform NavMesh into graph and apply one of graph-searching method. This approach can have quadratic complexity so I decided to use different method which will secure that new defence positions are flexible and can be automatically adjusted by enemy / owner influence. It consist from 4 steps:
    1. Polygon flood fill around owner's base and detection of hostile influences. The polygons are sorted by distance and first are inspected closer polygons. The distance is just relative - enemy influence also increase distance -> this is elegant way how to search large area without closing defensive positions to enemy city.
    2. Polygon flood fill from hostile influence back to the owner (from enemy influence which was discovered in first step) - this step will eliminate defence lines around "blind" and "empty" locations. During this step is calculated the evaluation of each possible defensive position (defences = all polygons which are in queue of flood fill algorithm). There are also performance improvements: defences are evaluated only from specific maximal distance and there are considered only polygons with 3 surrounding polygons (it is enought to create defence line).
    3. Polygon flood fill from owner city to actual defence positions - this step is necessary because common defence line does not have to be 1 line but multiple lines which are separated for specific owner
    Here is example of dynamically changed defence positions:
    Image
    Image
    Image
    Second team:
    Image

Description of classes
The combat AI consist of 3 main classes:
  1. TKMArmyManagement - recruiting, feeding and checking state of soldiers.
  2. TKMArmyDefence - distribution of soldiers in defence positions and detection of potential enemies around city.
  3. TKMArmyAttack - selection of main target (specific player) and commanding of attacking forces.

Attacking behaviour
During combat the AI divide available groups into several platoons where every platoon have several squads. Platoons represent the main attacking force which one task and "free hand". For example there is required only point / enemy unit / enemy house as a target and platoon will automatically move it's squads in formation close to target and destroy it. In case that platoon is attacked it will automatically try to destroy attacker but it will not try to pursue attacker over the whole map. Squads are simple class for interpretation of the combat AI commands into KaM group order system (for example when you want to attack something with archers you have to click just once and not spam RMB because otherwise archers does not shoot - same logic must be in squad class).
Last edited by Toxic on 25 Apr 2018, 18:30, edited 5 times in total.
<<

Toxic

Rogue

Posts: 50

Joined: 22 Feb 2017, 19:04

Post 25 Apr 2018, 18:14

Re: Combat AI for RTS

Reserved.
<<

RandomLyrics

User avatar

Sword Fighter

Posts: 293

Joined: 21 Jul 2013, 02:15

KaM Skill Level: Fair

Post 30 Apr 2018, 23:08

Re: Combat AI for RTS

Great work! Its already implemented i mean prototyped? Can you share some video/presentetion?:)
<<

sado1

User avatar

Moorbach's Guard

Posts: 1385

Joined: 21 May 2012, 19:13

KaM Skill Level: Skilled

Post 01 May 2018, 09:17

Re: Combat AI for RTS

RandomLyrics wrote:Great work! Its already implemented i mean prototyped? Can you share some video/presentetion?:)

I think all of this is present in the testing Remake versions which you can find on Discord: https://discord.gg/S6zmbeE
Rey's current Remake fork, which includes the stable changes from Toxic: https://github.com/reyandme/kam_remake
<<

RandomLyrics

User avatar

Sword Fighter

Posts: 293

Joined: 21 Jul 2013, 02:15

KaM Skill Level: Fair

Post 01 May 2018, 20:45

Re: Combat AI for RTS

sado1 wrote:
RandomLyrics wrote:Great work! Its already implemented i mean prototyped? Can you share some video/presentetion?:)

I think all of this is present in the testing Remake versions which you can find on Discord: https://discord.gg/S6zmbeE
Rey's current Remake fork, which includes the stable changes from Toxic: https://github.com/reyandme/kam_remake

Thanks for info sado!:)

Return to Ideas / Suggestions

Who is online

Users browsing this forum: No registered users and 4 guests