How should the AI handle it's army?

How should the AI handle it's army?

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

How should the AI handle it's army?

Post by yanom »

very broad question but... AI coders, what's your method(s) for the AI moving it's army around? How does it know what soldiers to send where? Does it simply respond to units being shot at (purely reactionary)? does it scout? does it launch well(or not-so-well) timed attacks? Please tell me your thoughts.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: How should the AI handle it's army?

Post by AF »

It is indeed a very broad question for which there are many, many answers.

Here are some:

Threat maps

This is the most basic, used by AAI and NTai and then most other AIs. You define a 2 dimensional matrix representing the map. At regular intervals poll the engine for enemy units and use their positions to weight a 'threat' value on the matrix. Count how many attackers you have and if it's bigger than a certain threshold, launch an attack aimed at the center of the cell with the highest threat level. Repeat until your dead or you've won.

There're various versions of this, such as different targetting heuristics, e.g. Shard targets the lowest threat value that isn't 0, AAI took into account unit types, and NTai modified the threshold based on how succesful or unsuccesful the attack was.

Herding

This was experimented with in NTai as a backup to make the above algorithm more flexible.
  • If a marker is found head to it
  • A unit would search for other attack units if none where within a certain radius.
  • It would then attempt to copy the attack orders of the other units.
  • If no attack orders where found it would copy the move orders of the other units ( unless they were already within a certain distance of the target )
  • If they still didn't have anything to do, find the closest unarmed enemy and head there
  • If still idle, find an armed enemy
  • If attacked, drop a marker

This had mixed results, and needed tuning. A very low level basic lightweight version of the above worked very well with NTai. Attempting to optimise it however ruined NTais attack systems ( see very loud complaints from IK ). Since most of the behaviours and benefits of this system were emergent, one had to be careful to make sure things didn't end up in feedback loops, e.g. some units would end up going back and forth because of the primitive flocking/grouping mechanism leading to long lines instead of groups of units attacking

Reactionary

Move your units around or let them build up, when someone attacks, send them all after the enemy unit

Mex Raiding

In XTA, the NTai config specified an alternate attack system for freakers/zippers. They'd go on a scouting run, but because these units had weapons, they would do damage too. One of these scouting algorithms was simply to navigate the map checking for metal extractors based on their last time of visit and proximity to different starting positions.

Pathfinder based raiding

See errors AI, it's a pretty nice attempt at micromanaging using a pathfinder and weights/influence maps
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: How should the AI handle it's army?

Post by PicassoCT »

You can also have a purely virtual AI with Units as visible "Enemy" until it knows better (by then you should shut it down) such AIs can lead to funny "crusades" into the nothing, giving it a human touch of faultyness.

Also depends what you want the AI to do. Is it there to beat the player and challenge him? Or is its biggest purpose to entertain, entertainment meaning providing the illusion of a real opponent, struggling with his doubts, trying cunning plans, copying succesfull playerstrategies . Naturally the second Sort is way more difficult to generate.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: How should the AI handle it's army?

Post by knorke »

This is my idea for an AI. It is more state machine than real AI.
It is somewhat inspired by an AI I did for an unfinished rts game in visual basic (haha oh wow) but it isn't in spring yet, so theoretic blabla follows.

The goal is more to have an AI that:
-is as simple as possible to make.
-plays interessting, does not matter so if it is not perfect.
-uses different tactics for different maps.

Basically the AI has "zones" where it likes to do stuff. In the picture the zones are those blue circles but they could as well be rectangles or whatever. For the topleft startposition it might look like this:
Image
(ignore dotted lines for now)
The zones are connected like nodes in a graph or something.

Idle units:
New units are randomly assigned to some zones and patroll there.
One could have some rules, like how many units of what unittype can be in one zone etc.
Could also add that the "next" zone is only filled with units when the previous has reached its unitlimit.

Defending:
If a zone is in danger, units from connected zones (note the lines) are send to help.
If no units can be send, the attacked units could also run away to a zone that is nearer to the startposition.

Attacking:
Maybe it would work to just put some zones into enemy land, but that is boring. So the dotted lines are attack routes.
When the AI wants to attack, it choses one route and sends units along that path. Different routes could have different unittpes assigned, eg the middle route in the picture goes down a cliff, so maybe only use air units for that.

Pathfinding:
Is not needed, because you can lay out the zones and routes in a way that units do not get stuck. The connections between zones do not have to be straight lines, they could also be a list of waypoints.
(eg to get around a lake)

So per map there would be a config like this:

Code: Select all

startposition[1]=
{
zones = 
{[1]x=450, z=800, radius=400, maxUnits=20, connectedTo={2,3,4}, whenAttackedgetsHelpFrom = {2,4},...
[2] = ...

attackRoutes = {
[1] = {{list of coordinates}, type = "ground"}
[2] = {{list of coordinates}, type = "airdrop"}
...
}
Could maybe have some tools to speed up creation of configs.

But that is all so rigid! The AI will be predicable!
Image
It will take a few games on the same map for players to notice.
If they play that much, that is a sucess :-)

Imo there is no need to come up with algorythms to have the AI figure out everything. Why should the AI analyze all units to find the best anti air defense? I made the game, so I already know the answer and can just tell it to the AI.
It is similiar with things like "where to place defense:" One quick look at the map and each player can tell where you should set up defences.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: How should the AI handle it's army?

Post by AF »

Which is NTai worked so well, the config builder played the game and knew what worked in PvP already.

The problem with your system is it needs to generate those zones. I investigated something like this, then applying basic circuit algorithms to the resulting graph, however I quickly ran into obstacles because I needed to generate that graph. My immediate solution was voronoi diagrams with adjacency connections, but then how do I generate the voronoi diagram? etc etc
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: How should the AI handle it's army?

Post by knorke »

The problem with your system is it needs to generate those zones.
oh, modder would set them. (see the code taged example) I think that would not be too much work.
iirc C&C Generals used something similiar: http://www.cnclabs.com/maps/generals/wo ... o-map.aspx
Of course one could also try to have the AI create the zones itself.
Ideally one would take terrain into account but that is not easy..so maybe just put a zone on startposition and on every resource spot.
Or the config only marks "areas of interesst" and each AI choses some of them to make its zone graph from that. (so you only have to make one config per map, instead of also for every startposition)
BaNa
Posts: 1562
Joined: 09 Sep 2007, 21:05

Re: How should the AI handle it's army?

Post by BaNa »

I had an idea like that for dsd knorke, imo it should be pretty easy to make a few ai profiles that can speedtech much better than most ppl if plopped down to teching positions or send a stream of tanks to the front-zone if not (also send cons on patrol). My evil plan would have been to make a fake clan with only ai players and me and then fuck up most dsd nubgames by playing a whole side alone with ai in back and me managing front with units i get given.

You may have guessed that nothing happened, but imo the idea is still golden.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: How should the AI handle it's army?

Post by Forboding Angel »

knorke wrote:Brilliance
+9001 to that entire post.
yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

Re: How should the AI handle it's army?

Post by yanom »

AF wrote: Threat maps
Herding
I dreamed up the following system:

>>There is a threatmap that threat markers can be dropped on.
>>Each time a threat marker is dropped it is assigned to a war unit* and that unit becomes a "leader". The leader marches toward the marker location.
>>All non-leader war units GUARD the nearest leader, thus joining it's herd.
>>Once a leader reaches it's threat marker, it loses leader status and the herd disbands.

>>If a unit dies it drops a threat marker
>>Threat markers are randomly dropped on resource locations. This will give the AI the effect of scouting for / raididing enemy mining operations, AND defeding it's own mining operations
>> threat markers are occasionally dropped on the AI's own base, to ensure the area around the base is well policed by units going in and out.

If a unit gets shot by the enemy drop a threat marker.


*Conflict Terra (the game I'm coding for) has a few unit types that are natural "squad leader" type units
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: How should the AI handle it's army?

Post by AF »

That leads to an obvious kill the leader before it reaches halfway and you'll never have an AI atatck reach your base syndrome.

Much in the way that almost all AIs fall flat on their faces when presented with a wall across the map
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: How should the AI handle it's army?

Post by PicassoCT »

On symmetric maps, you could have it mirror the players behaviour. Eternal Stalemate? And why doesent it attack you? And its using the exactly same strategys...


trololololloooo
yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

Re: How should the AI handle it's army?

Post by yanom »

AF wrote:That leads to an obvious kill the leader before it reaches halfway and you'll never have an AI atatck reach your base syndrome.

Much in the way that almost all AIs fall flat on their faces when presented with a wall across the map
Hrmm. Maybe code that when a leader is killed his leader status (and the orders he was carrying out) get transferred to a new unit?
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Re: How should the AI handle it's army?

Post by SanadaUjiosan »

yanom wrote:Hrmm. Maybe code that when a leader is killed his leader status (and the orders he was carrying out) get transferred to a new unit?
I would think assigning this "leader" status to just a "generic unit" (not one of the "squad leader" units you talked about earlier) would not only allow these herds to move without much worry of getting disbanded, but would also allow more herds. The squad leader units in CT, if you're talking about the ace mech and general's tank like I think you are, are few in number and are meant to fulfill the roles of quasi-hero units/a means to tech up rather than a "squad leader".

I for one agree with knorke, the amount of effort making fancy algorithms just doesn't quite equal the impact of the end product. Most AI are predictable to some degree (they're either going to rush me, or stay back and tech up! there's not a whole lot of inbetween) so making a playable one quickly sounds better in my book.

That is why I like SchwarmAI and YMSAI so much. They came about rather quickly and they get the job done. They can be improved rather easily (as opposed to writing new algorithms!) so that's a plus.

Of course, I say this never dabbling in anything resembling AI.
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: How should the AI handle it's army?

Post by PicassoCT »

but good Algos can lead to almost human behaviour.. mistakes.. copycating player sucesses.. desperate attempts.. acceptance of the defeat.. red Alert2 .. it would never give you the satisfaction of destroying his base. He would sell it all, send them towards you.

One freaking sun of a gun. I still salute to that.
yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

Re: How should the AI handle it's army?

Post by yanom »

SanadaUjiosan wrote:
yanom wrote:Hrmm. Maybe code that when a leader is killed his leader status (and the orders he was carrying out) get transferred to a new unit?
The squad leader units in CT, if you're talking about the ace mech and general's tank like I think you are, are few in number and are meant to fulfill the roles of quasi-hero units/a means to tech up rather than a "squad leader".
I was actually talking about tri drone rollers :shock:
Natural leaders because they project that shield umbrella around units nearby.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: How should the AI handle it's army?

Post by gajop »

btw, what do you think about creating a wiki page dedicated to storing links with brief descriptions of scientific papers regarding RTS AI?
i'm sure we can learn a lot from what other people have already done
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: How should the AI handle it's army?

Post by hoijui »

we already have that.
linked to form this page:
http://springrts.com/wiki/AI:Development

here it is:
http://springrts.com/wiki/AI:Links
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: How should the AI handle it's army?

Post by gajop »

good to know, i'll edit it a bit, hopefully add some interesting stuff as well!
User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Re: How should the AI handle it's army?

Post by 1v0ry_k1ng »

KAI at its best, when playing the mod EE... that is how it should handle its army.
100Gbps
Posts: 74
Joined: 30 Jan 2009, 13:19

Re: How should the AI handle it's army?

Post by 100Gbps »

knorke wrote:But that is all so rigid! The AI will be predicable!
Image
Yes, especially if AI saves its attack paths in plain format so they can be read and perfectly (flip)mirrored by enemy AIs for their attack paths.

Hmmm, maybe attack path could be renamed as attack vector. Maybe ...
Post Reply

Return to “AI”