project-navigation
Personal tools

Author Topic: Artificial Intelligence  (Read 33183 times)

Offline H-Hour

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

Offline DarkRain

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

Offline Duke

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

Offline Duke

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

Offline Duke

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

Offline kurja

  • Captain
  • *****
  • Posts: 504
    • View Profile
Re: Artificial Intelligence
« Reply #20 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 ;)

Offline H-Hour

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

Offline Thargor

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

hitch-22

  • Guest
Re: Artificial Intelligence
« Reply #23 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.

Offline H-Hour

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

Offline Duke

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

Offline Duke

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

Offline DexCisco

  • Rookie
  • ***
  • Posts: 41
    • View Profile
Re: Artificial Intelligence
« Reply #27 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.

Offline DexCisco

  • Rookie
  • ***
  • Posts: 41
    • View Profile
Re: Artificial Intelligence
« Reply #28 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.

Offline Duke

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