UFO:Alien Invasion

Development => Newbie Coding => Topic started by: Latino210 on May 22, 2012, 12:41:38 pm

Title: Artificial Intelligence
Post by: Latino210 on May 22, 2012, 12:41:38 pm
Hi

I am trying some mapping and I was wondering about the artificial intelligence of the aliens. In my map the aliens spend a turn slaughtering all civilians on sight, then they proceed to charge towards my soldiers pinpointing them like IR guided missiles. They all behave the same, no matter their race and/or equipment. Is this behavior normal? It's because the map is so small and streamlined? Sometimes in the game an uninjured alien just "get lost" and waits in a corridor to be found and slaughtered. I d'like to know more about enemy AI because I am building another map and I want to know how the enemy will act.

If anyone is interested, my map is here: http://ufoai.org/forum/index.php/topic,6428.msg52284.html#msg52284 (http://ufoai.org/forum/index.php/topic,6428.msg52284.html#msg52284)
Title: Re: Artificial Intelligence
Post by: H-Hour on May 22, 2012, 03:17:08 pm
Alien AI is very basic. What you describe is roughly what aliens will do: they will generally target the nearest enemy (soldier or civilian). They will move towards the enemy they are targeting. If they can not move without moving closer, they will not (this is why they often get "stuck" in the Harvester).

There is no independent AI for different alien races.

Of course, we hope to develop the AI in the future.
Title: Re: Artificial Intelligence
Post by: kurja on May 23, 2012, 01:38:58 pm
do aliens have a completely "individualistic" ai, as in, there's no common "team ai" to coordinate them in any way?
Title: Re: Artificial Intelligence
Post by: H-Hour on May 23, 2012, 04:27:21 pm
do aliens have a completely "individualistic" ai, as in, there's no common "team ai" to coordinate them in any way?

I believe so, yes. But morale effects them, so teammate deaths matter. There is no, "you go that way, I'll go this way, and we'll flank them."
Title: Re: Artificial Intelligence
Post by: kurja on May 23, 2012, 07:05:07 pm
I believe so, yes. But morale effects them, so teammate deaths matter. There is no, "you go that way, I'll go this way, and we'll flank them."

imho if ai gets a complete overhaul (which it needs) it should be a "team ai", as they're supposed to share the same consciousness and even if it wasn't that they're still soldiers of some kind and should work as a unified group.
Title: Re: Artificial Intelligence
Post by: geever on May 23, 2012, 07:28:55 pm
imho if ai gets a complete overhaul (which it needs) it should be a "team ai", as they're supposed to share the same consciousness and even if it wasn't that they're still soldiers of some kind and should work as a unified group.

Patches are welcome, as always...

-geever
Title: Re: Artificial Intelligence
Post by: kurja on May 23, 2012, 08:30:09 pm
Patches are welcome, as always...

-geever

I know, I know  :-X
Title: Re: Artificial Intelligence
Post by: Latino210 on May 24, 2012, 12:06:51 pm
Don't ask me, I am an electrician and I cannot tell a line of code from a wheelbarrow!
Title: Re: Artificial Intelligence
Post by: kurja on May 24, 2012, 03:19:20 pm
Don't ask me, I am an electrician and I cannot tell a line of code from a wheelbarrow!

if we constructed an intelligent wheelbarrow, would Geever implement it to the game?
Title: Re: Artificial Intelligence
Post by: bayo on May 24, 2012, 07:33:16 pm
Maybe we should first search an artist modeler for the wheelbarrow, before thinking about his AI.
Title: Re: Artificial Intelligence
Post by: Duke on May 24, 2012, 11:50:40 pm
Imho the current AI is even a little worse than the one in 2.3 coz the guy who worked on it was MIA half way down :(

I don't think we'll have a 'team AI' anytime soon. I have put some thoughts into it and have to say it is *incredibly* difficult. Here's a small example (just to give you an idea):
Try to write down the rules to *precisely* detect whether an actor is inside or outside a building. Oc those rules must work for *every* map and every sort of building.

Don't be afraid to post them. Even a 'stupid' rule might give *me* an idea for the perfect rule ;)

Title: Re: Artificial Intelligence
Post by: Sandro on May 25, 2012, 02:38:35 pm
Try to write down the rules to *precisely* detect whether an actor is inside or outside a building. Oc those rules must work for *every* map and every sort of building.

Writing those rules down: we shouldn't. It is not important when unit is inside, or outside. Amount of cover is. You want to have a unit to have maximal angular range of opening in front, and have a minimal linear range of openings all around.
That's the key to good tactical position.

Don't be afraid to post them. Even a 'stupid' rule might give *me* an idea for the perfect rule ;)

See above :)
Title: Re: Artificial Intelligence
Post by: H-Hour on May 25, 2012, 11:27:35 pm
You want to have a unit to have maximal angular range of opening in front, and have a minimal linear range of openings all around.

What does that mean?
Title: Re: Artificial Intelligence
Post by: bayo on May 26, 2012, 12:07:43 am
It mean you must be a sniper in a turret.
If you only have a knife... no luck.
Title: Re: Artificial Intelligence
Post by: DarkRain on May 26, 2012, 12:27:44 am
Ok, here goes my stupid idea:

Duke, IIRC you're trying to help the poor aliens get out of their UFO, instead of crowding in some place inside and get slaughtered by through-wall weapons, right?

Forget about inside/outside -- even if both sides are outside (or inside for that matter) they could still be lured to the other side of a wall or some other large (and concave) obstacle -- instead, if they can shoot their intended target from their intended destination good, if not, use the routing/pathing system to check how long they'd need to walk form their intended destination to the target position, and pick the one with the shortest route (yes, I know its probably extremely costly, stupid idea I said), maybe have them prefer destinations from where they can shoot their target but cannot walk to it (they probably have some sort of cover).
Title: Re: Artificial Intelligence
Post by: H-Hour on May 26, 2012, 01:00:05 am
I believe the routing code only goes out a certain number of squares to keep its costs down. I can't speak about that.

Here's another stupid idea: let them explore. If an alien is unable to move closer to its target in one turn, have it pick a grid it can reach (not in the direction of its target) and walk to it. If possible, set a flag for the alien that tells it to move in that same direction a second turn. Then, after two turns, it can revert back to its normal routines. Maybe it will have a different outcome.

Alien movement doesn't necessarily have to be smart to seem smart. Chance and luck will make for some great encounters in the game, even if they happened because the player expected one behaviour but got something totally different.
Title: Re: Artificial Intelligence
Post by: DarkRain on May 26, 2012, 01:13:27 am
I know that pathing goes only to 33 TU max, I think, but I thought that routing info was available for the whole map, no need to measure the length in TU, the number of 'steeps' can be used instead, extremely costly anyway, the point is I think inside/outside is not as important if there's other way to make sure that "approaching" the intended target doesn't actually worsens the situation.
Title: Re: Artificial Intelligence
Post by: Duke on June 04, 2012, 10:50:52 pm
Writing those rules down: we shouldn't. It is not important when unit is inside, or outside.
1. Let's note that nobody managed to define inside/outside ;)
2. It's not too important, but it's just *one* small part of something I call 'situation awareness'. And that's important for a truly smart AI.
Amount of cover is. You want to have a unit to have maximal angular range of opening in front, and have a minimal linear range of openings all around.
Plz elaborate on that. Especially the difference between angular and linear opening.

That's the key to good tactical position.
Already falsified by Bayo :(
Title: Re: Artificial Intelligence
Post by: Duke on June 05, 2012, 12:28:02 am
Duke, IIRC you're trying to help the poor aliens get out of their UFO, instead of crowding in some place inside and get slaughtered by through-wall weapons, right?
Yes and No. As we are talking about AI in general here, that 'harvester prob' is just a minor one.
Forget about inside/outside -- even if both sides are outside (or inside for that matter) they could still be lured to the other side of a wall or some other large (and concave) obstacle --
True.
... use the routing/pathing system to check how long they'd need to walk form their intended destination to the target position, and pick the one with the shortest route (yes, I know its probably extremely costly, stupid idea I said),
Not as stupid as you might think. At least I had a similar idea long since (or I'm at least as stupid as you ;) )
The idea (for one alien) was:
1. find the shortest path to the nearest target (can be multi-turn long !)
2. find the first place on that path where you can shoot at that target.
3. walk towards that place.
However, that would establish something very new to our AI: a multi-turn plan. And I hesitate to implement something like that without an (almost) complete design.

Checking *all* aliens to find the one who is the best to shoot the target is certainly overkill performancewise.
AND it would be the beginning of some even more complex thing: a team effort plan. See above.

maybe have them prefer destinations from where they can shoot their target but cannot walk to it (they probably have some sort of cover).
That's probably the 'stupid' part of your idea ;)
Though feasible and easy for the human, for a computer/program it's just the *opposite* of the above algo:
Walk *away* from the target and find the nicest place to shoot from.
But it perfectly illustrates our dilemma: we have to take *everything* (here: weapon range) into account to make the right AI decision.
Title: Re: Artificial Intelligence
Post by: Duke on June 05, 2012, 12:51:56 am
Alien movement doesn't necessarily have to be smart to seem smart. Chance and luck will make for some great encounters in the game, even if they happened because the player expected one behaviour but got something totally different.
True for simple games. But battlescape is like *chess* imho. Or probably even more complex.
And a pretend-to-be-smart algo will never cover 100% of the situations.
So at least smart players will recognize the patterns for those remaining %s and either file *bug reports* or exploit them.
Title: Re: Artificial Intelligence
Post by: kurja on June 05, 2012, 08:25:34 am
As for ai team effort, maybe some simple rules to that effect could be put in place without too great effort to at least make the ai seem smarter, such as when choosing a target, first check the targets already in sight (if such function already exists?) and prefer to choose a target that has already been fired at during that turn (if there is such target)? Would make the alien fire more effective.

...now that I think about it, that's probably not a five minute implementation either ;)
Title: Re: Artificial Intelligence
Post by: H-Hour on June 05, 2012, 10:00:07 am
And a pretend-to-be-smart algo will never cover 100% of the situations.
So at least smart players will recognize the patterns for those remaining %s and either file *bug reports* or exploit them.

Hmm, I would think that a "smart" AI would actually be much more predictable than a dumb AI, as long as the dumb AI was programmed to take different decisions randomly.
Title: Re: Artificial Intelligence
Post by: Thargor on August 08, 2012, 02:24:57 pm
I think a better AI is something that can be done if we keep in mind that AI serves one purpose only:
Enhance the gameplay/immersion

Currently two things break the immersion/realism:
- AI getting stuck
- predictability

To fix this we don't need super intelligent code, but something that makes users believe it's intelligent.
Randomness is a big help here. If the AI has a list of reasonable actions and chooses randomly from them it will appear smarter.

Rember good ol' pacman, where the "AI" when at a junction chose randomly between moving towards the player or away from it.
It therefore on avarage chased the player but not in a game-breaking-impossible-to-beat way.
By giving different enemies different chances of choosing the direction of the player the programmers made the player believe some enemies were more aggressive than others

Randomness may also help prevent AI getting stuck. Almost any algorithm has weak points where AI can get stuck, but by randomly switching chances of getting stuck for a long time reduce drastically.

As another example:
In a FPS an enemy is running towards the player and we want it to dodge incoming fire.
one option would be to let the AI check for fire, determine dodge options, taking into account travel time, bullet speeds, ammo of player etc..
A much more CPU-friendly option is to assume the player is trying to hit the enemy and just randomly dodge left and right.
Most human players will assume the enemy is actually responding to their fire.
Title: Re: Artificial Intelligence
Post by: hitch-22 on August 10, 2012, 09:36:25 pm
New forumite here. Love the idea and execution so far, loved the original game back when etc etc...

I've tried my hand at (very little) coding and in some project ideas for games we've kicked around with my game-industry friends I've put some thought into implementing AI rulesets. I'd like to contribute something to this discussion if I possibly can. As it currently stands, if the latest release were as stable as 2.4 was for me and had less predictable AI, it would already be a true gem of an open source game, or a game in general.

Currently two things break the immersion/realism:
- AI getting stuck
- predictability

To fix this we don't need super intelligent code, but something that makes users believe it's intelligent. Randomness is a big help here. If the AI has a list of reasonable actions and chooses randomly from them it will appear smarter.

I strongly agree with this. This game most definitely is not chess, and coding should not or at least need not IMHO be bogged down by overly ambitious goals like aliens actually "thinking" about their situation. I think a few RNG-determined behavioral options and just perhaps some very basic tactical awareness might make for some surprisingly immersive moments, and it really might take surprisingly little to improve gameplay by leaps and bounds.

That having been said, I'd like to know a few things about the scope that might be possible. For instance, is it possible to implement...

..different rulesets for different species? (Or at least, bloodspiders do the kamikaze run that all aliens currently do, and all the more tactically versatile ones do something else?)

..different rulesets for attacking and defending missions? (Aliens roughly hunt you in base attack, and seek to ambush when you attack them.)

..rulesets depending on weapon characteristics? (Mainly range, just maybe, possibly area of effect?)

..rules about the alien's current surroundings? (Partial cover / good field of fire in one direction, good cover behind = great place to camp.)

..multiple random choices for behavior, where the likelihood of each is affected by certain parameters (distance to enemy, whether in good position currently, whether things have been going well up to this etc)?

..situationally assigned, temporary or permanent flags for actors, locations, objects, etc? ("Don't return to this area until enemy is there", "Since I'm unarmored, RUN from this guy / type of gun that mauled my friend!", "Hmm.. that dude seems to be out of ammo, maybe I'll eat him...")



As I said, I'd like to pitch in with silly ideas if I can.
Title: Re: Artificial Intelligence
Post by: H-Hour on August 10, 2012, 11:04:05 pm
Everything you mention is possible. None of it is already performed in the code, except some weapon characteristics.
Title: Re: Artificial Intelligence
Post by: Duke on August 14, 2012, 12:40:01 am
hitch-22, rulesets are fine.
But the current AI is far away from using rulesets.
It's merely (in a nutshell):
Walk to the place where you can inflict the most damage and preferably hide afterwards, else close in on the nearest enemy. That's it.
Title: Re: Artificial Intelligence
Post by: Duke on August 14, 2012, 12:46:53 am
Oh, and to all those who consider randomness as the solution:
You have to figure out the *options* to randomly pick from first, don't you ?
Title: Re: Artificial Intelligence
Post by: DexCisco on November 17, 2012, 06:55:06 pm
To answer the skill testing question:  If you can see the sky, you are outside.

The AI really has 3 levels:  Team tactics, individual tactics, and pathfinding.

To address the simplest, pathfinding, there are two types of pathing: physical pathing (moving from A to B) and visual pathing (I need to see/shoot what is over there).  Perhaps some of the heavy lifting could be done beforehand during the compilation of the map.  For instance, for visual pathing, for every given space, store the coords of every space that can be seen from there.  Then when the AI decides that it needs to see a given unseen coord, it can select physical pathing destinations from the list of coords that can see the target.

For physical pathing, perhaps some pre-processing could identify pathing wayponts.  Large, open areas could be identified by selecting points and testing pathfinding to all nearby spaces.  The lowest overall pathing score gets chosen as a waypoint.  Then test pathing out from those points to a pre-determined max waypoint distance.  Anywhere that the pathing score exceeds a threshold amount are identified as further waypoints.  Pathing tests that find other waypoints within their radius record a connection between those two waypoints.  The network of waypoints is stored with the map and can then be used for larger scale pathing choices (like finding your way out of a building or Harvester).

Individual tactical AI is a bit more tricky, but might be helped by the visual data mentioned earlier.  It would involve at least four steps:  exploration to find targets, choosing a target, moving to a valid attack position, and then the TU usage in a given turn to move before attacking, attack, and return to cover if possible.  This whole system might be aided by some sort of aggression variable used to determine how concerned with cover it is, etc.
Exploration would involve keeping track of everywhere the team can see and then choosing pathing destinations that can see the maximum number of unseen coords with the minimum move time.
Once one or more targets are available, the unit could either opt to continue exploring (e.g. if the target is too far away to be reasonably targeted), or to move to a firing position.  Firing position would of course be limited to coords within the maximum effective range of the weapon.  Negative modifiers would be given to positions exposed to enemy fire (determined by the visibility data attached to the map).  Higher aggression units would weight these modifiers as less of an issue.  Prime firing positions are determined as adjacent, pathable coords where one (cover) has low visibility of enemy units and the other (firing) has visibility of the target at an acceptable range.  Turn-by-turn pathing destinations are chosen from the reachable coords based on distance to the next pathing waypoint, visibility of enemies and aggression.  If there is no way to get to a good firing position, either the aggression is raised, a new target is chosen, or the unit goes back into explore mode to find another target or another way around.
Once the unit arrives at its firing position, its next turn can be used to move from the cover position to the firing position, fire, and return to cover if possible.

Team tactics could be very tricky, but perhaps it should be limited to concentration of fire (more than one unit choosing the same target), and spreading out (minimum distance between chosen firing positions).  Perhaps coordinated fire (synchronizing attack to the same turn).  The rest might just happen naturally as a result of using good cover and scouting tactics.
Title: Re: Artificial Intelligence
Post by: DexCisco on November 17, 2012, 09:18:59 pm
The whole pre-processing thing is complicated by the fact that maps are built from smaller pieces, so map-wide visibility and pathing is not really possible.   Waypoints could still be determined for each sub-map component and then linked when the map is assembled in game.  Determining visibility into adjacent map components could not be done during map compiling.  Depending on how long it takes it may be done after the map is assembled pre-mission.
Title: Re: Artificial Intelligence
Post by: Duke on November 17, 2012, 11:00:13 pm
DexCisco, thx for your proposal :)

In short: some things you propose are not possible (eg. "for every given space, store the coords of every space that can be seen from there"=>calculate!) and the others are already in place (in the same or similar way => look at the code).

But one idea is good: to detect open areas from the pathfinding time. I'll have to think a bit more about this.
Thx again :)
Title: Re: Artificial Intelligence
Post by: krilain on November 20, 2012, 12:22:30 pm
Patches are welcome, as always...

-geever
Hi all, hi geevers,

I downloaded the code or I'm missing something (as usual). There's a lot of scripting, I think quake2 scripting. That's fine but is that all the code? I mean, playing around with the scripts will cover all comportements in the game? Is that this part about which you are talking when you ask for patches? Or did I miss some code. I didn't find files I excepted to find, as .h, .cpp, ..etc. even if some Eclipse editor parameters were included in xml style.

I'm not really a programmer, so feel free not to answer me too much precisely if you think it would be a waste of detals. Whatever I can distinguish between scripting code and C or other langages classical code.

I know too that AI is generally coded in the script part, but not necessarily. My interest on AI comes from the problem of alien trying to fire through the walls, or impossible position. That's could be limited in my opinion by making alien able not to repeat twice a failed fire. Here is my interest on AI for now.
Title: Re: Artificial Intelligence
Post by: geever on November 20, 2012, 05:20:57 pm
We have 2 AIs, the scripted you may see base/ufos/ai is not in use because it is not finished (could be activated in game with some cvar IIRC). The current working AI is coded in C, look for g_ai.cpp, but from there it is quite much like programming.... :)

Patch == Contributed changeset in "unified diff" format.

-geever
Title: Re: Artificial Intelligence
Post by: krilain on November 21, 2012, 11:53:59 am
We have 2 AIs, the scripted you may see base/ufos/ai is not in use because it is not finished (could be activated in game with some cvar IIRC). The current working AI is coded in C, look for g_ai.cpp, but from there it is quite much like programming.... :)

Patch == Contributed changeset in "unified diff" format.

-geever
Ok :)
I'm getting into it slowly. Thanks again.
Title: Re: Artificial Intelligence
Post by: Leviathan on April 28, 2014, 05:21:47 am
Good evening,

This is a great game and I am already greatly enjoying it, however as many others have noted boosting the AI would be a great improvement to the experience.

Some suggestions from my experience so far…

Disclaimer – I have not yet cracked open the C code.  I wanted to give it a top down look without assumptions about what is there.  That may mean some of my suggestions do not mesh well with the existent code body.  In particular, I am assuming an object-oriented programming structure. 

1.   Some of my underlying ideas come from a book that discusses how extremely simple processors (like a hunting spider’s tiny brain) parse environmental data to create the appearance of cunning thought. http://www.amazon.com/Beyond-Brain-Environment-Shape-Animal/dp/0691126445

2.   One could create the illusion of complexity, and even some team effort, if you implemented a “personality object” for each alien.  By that I mean a set of flags and weights that influence the rules governing each alien’s basic decisions so that certain types of alien, and even individual aliens exhibit different hunting patterns.

3.   Using the spider as a model I can envision a simple process for generating an alien’s turn.  Each turn the alien makes three basic choices: destination, path to destination and whether to attack along the way.  If I understand the current code correctly, this is already the general structure.  It could be as simple as; choose a path toward cover that brings you closer to your target and attack when in range.

4.   To add complexity and challenge you could add the concepts of “hunting” and “senses” to the first decision.
a.   Hunting – An alien will choose a destination that brings it closer to a target it is aware of.  A set of flags determine if an alien hunts for specific prey.  Weights determine how aggressively it pursues prey.  Flags can be set to lock on a target, once chosen.
b.   Senses – Aliens can have awareness of targets beyond line of sight, determined by flags.
5.   Examples:
a.   Eager – The alien moves in the direction of the most recent hostile gunshot.  This could also be extended to include a chance to perceive and move toward those lumbering in heavy armor.
b.   Heightened senses – Line of sight is determined only by a distance.  Walls and obstructions do not prevent the alien from perceiving the chosen prey.  Groups of aliens sharing this flag would appear to swarm on a scout who overextends.
c.   Bloodhound – The alien chooses a path to bring it closer to a wounded enemy.  If flagged to lock on a target, this gives the illusion of a “pittbull” mindset that chooses a target and tracks its blood-trail.  Multiple aliens in close proximity with this flag set give the illusion of working together to concentrate fire.  If allowed to track wounded without direct line of sight it gives the illusion of an enemy tracking by scent or blood trail.
d.   Kill Stealer – If there is a wounded soldier available the alien piles on, if not the alien moves closer to another alien.  Multiple of these quickly give the impression of a formation working together to form up and focus fire, particularly if they fall in to file behind an alien hunting by one of the other senses.
e.   Sniper – The alien hunts a target based upon highest (or lowest) rank.  Highest rank appears to be an alien coordinating fire to pick off those in command of the unit.  Lowest rank appears to be singling out rookies to deliberately target the weakest first.  Flagging for this without line of sight would indicate aliens intercepting radio traffic (or even thoughts) to zero in on who does what.
f.   Tactical – Alien prefers to hunt for a particular high stat or equipped weapon.  This would allow for the creation of an alien squad that focuses fire to eliminate long range snipers or heavy weapons specialists as a first priority.
g.   Scalp hunter – The alien hunts the teams best (highest average stats) or most notorious (highest kill count) elite soldier. 
h.   Territorial – The alien does not hunt, but instead chooses a destination such that it patrols in a tight loop and aggressively defends a small area.
i.   Butcher – Prefers to hunt available civilian targets over available soldiers.
j.   Randomized – A random personality for each alien would at least give variety in behavior from battle to battle and alien to alien.  This would approximate a recently crashed UFO, where the commanding officer of the alien force were killed on impact.
k.   Templates – assigning a personality template, perhaps with random variance within a species band, would make Ortnoks feel like Ortnoks and Tamans feel like Tamans.  This would approximate a crash with minor damage, allowing the aliens to begin to regroup.

One of the advantages of such a scheme, in my opinion, is the ability to start simply and expand in terms of complexity as the code evolves.
Title: Re: Artificial Intelligence
Post by: Duke on April 28, 2014, 01:39:08 pm
Great ideas to extend the AI. But before extending it, we should imho implement the missing basics.

So may I direct your thoughts towards this:
Quote
...choose a path toward cover...
The current AI does not really know about 'cover'. It merely selects a place with no LoS to all enemies. That's why they try to hide behind your soldiers.
Title: Re: Artificial Intelligence
Post by: Leviathan on April 29, 2014, 06:58:50 am
Perhaps I am oversimplifying, due to a lack of familiarity with the code, but I think the hiding behind soldiers problem could effectively be eliminated by coding for Targets of Opportunity.  By that I mean the "and attack when in range" part of an alien's simple turn. 

For a simple scheme, an alien could attack a soldier when they first come into range, again at some randomized point in movement (some species could get a different # of these, or it could even be modified as part of the individual personality), and again at the end of their movement if a valid target is in LOS.  I would assume this code would be very similar to what already exists for calculating the alien's reaction fire during player movement.

The key, in my opinion, is to hard code for at least one attack at the end of the alien's movement if there is a valid target in LOS and to switch to a melee weapon if range is zero.  Then the effect of the simple AI interpreting a soldier as a place to hide would become, from the players perspective, an alien attempting to charge forward shooting from the hip and then, if successful in closing to melee, gutting them with a kerrblade or sticking them with a plasma blade.  This would make letting the alien get that close a lethal mistake, rather than a comical and exploitable eccentricity in the AI.   
Title: Re: Artificial Intelligence
Post by: H-Hour on April 29, 2014, 10:16:03 am
  Then the effect of the simple AI interpreting a soldier as a place to hide would become, from the players perspective, an alien attempting to charge forward shooting from the hip and then, if successful in closing to melee, gutting them with a kerrblade or sticking them with a plasma blade.  This would make letting the alien get that close a lethal mistake, rather than a comical and exploitable eccentricity in the AI.

If an alien moves, then fires, then moves, then fires, they'll be spending an enormous amount of TU in view of the player's units. This would expose them to a lot of reaction fire. For all the complaints about the AI, they actually seemed reasonably savvy about RF the last time I played.
Title: Re: Artificial Intelligence
Post by: DarkRain on April 29, 2014, 05:35:20 pm
@Leviathan
You might be interested in this: http://ufoai.org/wiki/Combat_AI (http://ufoai.org/wiki/Combat_AI), it's a bit outdated, but things haven't really changed much.
Title: Re: Artificial Intelligence
Post by: Leviathan on April 30, 2014, 12:57:53 am
H-hour:  That is a consideration to take into account.  However, them taking more reaction fire would be at least partially balanced by them delivering more.  My observation of the AI so far is that the way I move my soldiers I take many more shots at they enemy then they return and one of my key disappointments was the item Duke brought up of an enemy that moves to melee and hides behind him instead of finishing off the soldier.  Personally, I do not mind the aliens having more TUs, not only are they alien beings in game context, but I also assume an AI is going to need such an advantage to make it competitive with a human players brain.  An alternative that would be less of a deviation, both in TU and RF, would be to simply add a check at the very end of action:  Am I standing behind a valid target?  If yes, then melee attack.  This would amount to 6 or 7 bonus TUs and a single extra exposure to RF, balanced by all but eliminating the occurrence of an alien hiding in the shadow of a man with a flame thrower and calmly waiting to be invited to the BBQ. :)

DarkRain:  Thank you, the wiki is helpful in understanding your decision tree algorithm.  After reading it, I believe many of my suggested options for enhancing the AI could be coded by giving each alien a set of "personality weights" that alter leaf weights that already exist.  This would allow for both more variation in alien behavior, and the ability of map editors to place squads of aliens that give the appearance of coordination into their maps.  Alternately, the personality choices could be added as what the wiki refers to as "mission targets", but I think the former would be an easier code change.

Duke:  Another item to consider is a set of guidelines for map designers to help them work with instead of against the AI.  For example, earlier this evening I encountered a map with a crashed Harvester that included a hole torn in the side of the hull as a part of the map layout.  The aliens that would normally get stuck in the Harvester waiting for me to flush them out, this time came spilling out the side of the wreck with some of them leaping down from the top floor to suddenly engage as I approached.  The AI was the same, but the ship layout funneled them together and then out instead of keeping them trapped which gave the illusion of an organized push toward my forces.
Title: Re: Artificial Intelligence
Post by: Duke on April 30, 2014, 11:49:43 am
Leviathan: if you come up with a 1st draft of such guidelines, we could easily add it to our wiki.
Title: Re: Artificial Intelligence
Post by: Leviathan on May 01, 2014, 12:40:08 am
I will give it some thought.  I am still learning that part of how the AI behaves.
Title: Re: Artificial Intelligence
Post by: ShipIt on May 01, 2014, 09:34:01 am
Nice first step would be to see aliens using their granades again.
Title: Re: Artificial Intelligence
Post by: DarkRain on May 01, 2014, 08:44:37 pm
Actually aliens already use grenades.... in the (very rare) cases when they decide to come into throwing range, it's usually the first thing they'll do (even against single targets) because it maxes the expected damage
Title: Re: Artificial Intelligence
Post by: Harkhanam on November 23, 2014, 05:52:03 pm
Hello, I'm trying to dig in the AI code. Originally created a new topic but this one is good enough :p

It's been a long time since I coded in C++ and I'm a little bit confused about a function call.

Code: [Select]
g_ai.cpp AI_PrepBestAction(...)
[...]
G_ActorMoveLength(...)
=>  g_move.cpp G_ActorMoveLength(...)
= = > const pos_t length = gi.MoveLength(path, to, crouchingState, stored);

I can't find what is "gi" nor any "MoveLength" function in the source.

I'm trying to figure out which case create the "null or "ROUTING_NOT_REACHABLE" returns.
more specifically, I want to make sure the code doesn't discard the current position of an alien while looking for a best action : I read somewhere they were discarding position already occupied, and I want to check if this include his own position.

I'm using the 2.5 source code provided with the downloaded game from the site.

The general goal is to get familiar enough with the AI code to fix some weird behavior, no revolution yet.

Title: Re: Artificial Intelligence
Post by: DarkRain on November 23, 2014, 06:18:53 pm
Hi Harkhanam, welcome to the forum

Lets see: gi is the game import (see sv_game.cpp: SV_InitGameProgs()) you will find the implementation you are looking for at: grid.cpp: Grid_MoveLength(), as for ROUTING_NOT_REACHABLE it is returned only when there aren't ehough TUs to move to that position or if the position is blocked (the actor for which the move table was calculated is skipped in when checking for obstructions)
Title: Re: Artificial Intelligence
Post by: Harkhanam on November 23, 2014, 10:59:52 pm
Thanks for the reply, I'm compiling the project for the first time and it gave the satisfactory : ||=== Build finished: 0 errors, 24 warnings ===|

First thing is to mess with the cost function of the search, I'll be back for more questions sooner or later. (-:
Title: Re: Artificial Intelligence
Post by: DarkRain on November 24, 2014, 12:27:27 am
Hi,

Good to know you could compile without problems :)

And I must correct myself... typed that reply in a hurry before going out to an appointment, I was bound to make a mistake... anyway, ROUTING_NOT_REACHABLE is returned not when the actor doesn't have enough TUs but when the pathing cost is too high (currently max lenght is 50 TUs IIRC)
Title: Re: Artificial Intelligence
Post by: Harkhanam on November 25, 2014, 04:48:09 am
Ok so I've compiled the maps and launched the compiled .6 version :o)

I have a much more clear view of AI limits now

Basically, it's :

Move to a shooting spot by the shortest path where you can shot at a visible ennemy
Shot as much as you can
Find cover if possible

However, the "find cover" seems very rare and that would be because there's no saving of TU for it : AI select its target & its move, then, a cover if TU's left permit it (if I'm right).
But, AI will more likely try to use every TU available because the score function depend on the damage inflicted.

There's another interrogation :
g_ai.cpp : AI_FighterCalcActionScore(...)
Code: [Select]
if (!(AI_IsExposed(hidingTeam, actor)) && !AI_HideNeeded(actor)) {
bestActionScore += SCORE_HIDE + (aia->target ? SCORE_CLOSE_IN + SCORE_REACTION_FEAR_FACTOR : 0);
} else if (aia->target && tu >= TU_MOVE_STRAIGHT) {
It seems those line are for Aliens to make ambush : They don't want to risk reaction fire so they find a spot out of ennemy sight and gives it value, it lacks a check to see if the alien has reaction fire turned on.
It would require AI_HideNeeded(actor) without the negation ( ! )
I made a change an tested it, aliens start to play more passively once they start suffering losses. (and killed one of my soldier with reaction fire)

I'm wondering, is there a way to print data into the console while the game is playing ?
Title: Re: Artificial Intelligence
Post by: Sandro on November 25, 2014, 03:30:25 pm
However, the "find cover" seems very rare and that would be because there's no saving of TU for it : AI select its target & its move, then, a cover if TU's left permit it (if I'm right).
But, AI will more likely try to use every TU available because the score function depend on the damage inflicted.

IIRC, that is not exactly true -- if AI is NOT in the "brave" mode, it will try to hide at the end of turn, but on most maps it is quite hard to find a safe spot, since they are outdoors. Also, window between "brave" and "panic" modes is quite narrow IIRC. Maybe DarkRain could give a better explanation.

It seems those line are for Aliens to make ambush : They don't want to risk reaction fire so they find a spot out of ennemy sight and gives it value, it lacks a check to see if the alien has reaction fire turned on.

Aliens always have reaction fire turned on. And yes, there are some attempts to implement ambuses, though not very effective on most maps.

I'm wondering, is there a way to print data into the console while the game is playing ?

Com_Printf(...), syntax is like classic printf(...)
Title: Re: Artificial Intelligence
Post by: DarkRain on November 25, 2014, 06:06:21 pm
Re: AI and cover as Sandro says AI will not always look for cover only if they are not brave or if they see an enemy with a powerful weapon, but the problem you mention with them using all TUs for shooting is also true as expected damage is currently the main part of the AI action scoring.

No aliens don't always have reaction fire enabled ̣— see AI_InitPlayer() is only a 75% chance they do — and it can change during battle (the AI won't their change RF status once spawned by themselves, but losing their weapon, flashbangs and the shaken status)
Title: Re: Artificial Intelligence
Post by: Harkhanam on November 25, 2014, 08:07:41 pm
HDD went dead today.

Thanks for the Com_Printf(...), will be priceless to check scoring while skirmishing once I've redownloaded, reinstalled and recompiled all the things needed :p

Another thing that may be clear for you : the visibility of aliens. I've read that "we" believe they see everyone because the way they search for target "move them" to the position before checking visibility. However, if the visibility check is a simple "flag test" that is only set when the correct "move procedure" is done, maybe that flag is not reset when the position of the alien is changed, hence negating the assumption that they can see everyone.

I'll go check ASAP if you can't say without looking at it, and I'll do my first Com_Printf(...) on it to be sure :P


Title: Re: Artificial Intelligence
Post by: DarkRain on November 25, 2014, 11:44:18 pm
Sorry to hear that :(

The AI should be doing actual visibility tests (which involve line tracing) if there are places that are using flag test that should be regarded as a bug (for the reason you mentioned)