project-navigation
Personal tools

Author Topic: Artificial Intelligence  (Read 37430 times)

Offline krilain

  • Squad Leader
  • ****
  • Posts: 171
    • View Profile
Re: Artificial Intelligence
« Reply #30 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.
« Last Edit: November 20, 2012, 12:24:01 pm by krilain »

Offline geever

  • Project Coder
  • PHALANX Commander
  • ***
  • Posts: 2561
    • View Profile
Re: Artificial Intelligence
« Reply #31 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

Offline krilain

  • Squad Leader
  • ****
  • Posts: 171
    • View Profile
Re: Artificial Intelligence
« Reply #32 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.

Offline Leviathan

  • Cannon Fodder
  • **
  • Posts: 6
    • View Profile
Re: Artificial Intelligence
« Reply #33 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.

Offline Duke

  • Administrator
  • PHALANX veteran
  • *****
  • Posts: 1037
    • View Profile
Re: Artificial Intelligence
« Reply #34 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.

Offline Leviathan

  • Cannon Fodder
  • **
  • Posts: 6
    • View Profile
Re: Artificial Intelligence
« Reply #35 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.   
« Last Edit: April 29, 2014, 07:32:19 am by Leviathan »

Offline H-Hour

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 1923
    • View Profile
Re: Artificial Intelligence
« Reply #36 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.

Offline DarkRain

  • Project Coder
  • Captain
  • ***
  • Posts: 746
    • View Profile
Re: Artificial Intelligence
« Reply #37 on: April 29, 2014, 05:35:20 pm »
@Leviathan
You might be interested in this: http://ufoai.org/wiki/Combat_AI, it's a bit outdated, but things haven't really changed much.

Offline Leviathan

  • Cannon Fodder
  • **
  • Posts: 6
    • View Profile
Re: Artificial Intelligence
« Reply #38 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.

Offline Duke

  • Administrator
  • PHALANX veteran
  • *****
  • Posts: 1037
    • View Profile
Re: Artificial Intelligence
« Reply #39 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.

Offline Leviathan

  • Cannon Fodder
  • **
  • Posts: 6
    • View Profile
Re: Artificial Intelligence
« Reply #40 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.

Offline ShipIt

  • Project Artist
  • Captain
  • ***
  • Posts: 906
    • View Profile
Re: Artificial Intelligence
« Reply #41 on: May 01, 2014, 09:34:01 am »
Nice first step would be to see aliens using their granades again.

Offline DarkRain

  • Project Coder
  • Captain
  • ***
  • Posts: 746
    • View Profile
Re: Artificial Intelligence
« Reply #42 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

Offline Harkhanam

  • Cannon Fodder
  • **
  • Posts: 4
    • View Profile
Re: Artificial Intelligence
« Reply #43 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.


Offline DarkRain

  • Project Coder
  • Captain
  • ***
  • Posts: 746
    • View Profile
Re: Artificial Intelligence
« Reply #44 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)