Author Topic: Artificial intelligence  (Read 22573 times)

Vanguard

  • Rogueliker
  • ***
  • Posts: 1112
  • Karma: +0/-0
    • View Profile
Artificial intelligence
« on: July 14, 2009, 01:17:23 AM »
What do you think is a good way to do ai for npc characters?

My current plan is to have a score system, where a point value is kept for each possible action, and whichever one scores the highest is what the character does, so if an enemy is in sight, some points go to the "attack enemy" option, and if they're nearby or lower levelled, then it gets a few more points.  Is that a good way to do it?

AgingMinotaur

  • Rogueliker
  • ***
  • Posts: 805
  • Karma: +2/-0
  • Original Discriminating Buffalo Man
    • View Profile
    • Land of Strangers
Re: Artificial intelligence
« Reply #1 on: July 14, 2009, 08:49:01 AM »
I think an important advice for implementing npc intelligence, is to try and keep things as simple as possible. It's easy to get caught up in very subtle implementations, that the player won't experience as enrichening. Ie. something like: "Orcs have a greed value of 75, as opposed to farmers' greed value of 25, making orcs exponentially more likely to pick up gold." If, on the other hand, farmers never go for gold, and orcs always do, it gives the player a much clearer illusion of personality and intelligence. I think this was epitomized by a debate on rgrd, about wand wielding monsters. Posters were discussing how to calculate cost/gain ratios etc., when Jeff Lait said that in POWDER, if a tool capable monster is carrying a wand, there's simply a fixed probability of it zapping the wand.

The best place to start is probably to have a more or less clear idea of what you want your npcs to be able to do, and try to tailor a system to meet your needs without becoming unnecessarily complex. Your idea of a point-driven system sounds like it may work. I think Incursion uses something like this, combining it with a "gravitational value", so that closer foes attract more than foes that are further away. This should probably help circumvent erratic monsters.

And, even though I'm sure you already read Bear's article series on AI, I think it's so enlightening that it cannot be linked to enough: http://roguebasin.roguelikedevelopment.org/index.php?title=Roguelike_Intelligence

For my own project, I'm currently using a statemachine, something like what Bear describes. Put briefly, a monster is always in a certain state of mind towards a certain target. Each state contains a set of switches. The basic offensive state is something like: if can_attack: attack ; else if can_approach: approach. Switches can even point to new states, so that a casual state (the one where orcs pick up gold and farmers cultivate a garden) can contain switches to enter a combat state if an enemy comes into sight. I find it slightly messy to use (no doubt owing to my implementation), but it does mean I can make monsters do mostly anything: lock a door, sound an alarm, pray at an altar, eat some carrion ...

As always,
Minotauros
This matir, as laborintus, Dedalus hous, hath many halkes and hurnes ... wyndynges and wrynkelynges.

Vanguard

  • Rogueliker
  • ***
  • Posts: 1112
  • Karma: +0/-0
    • View Profile
Re: Artificial intelligence
« Reply #2 on: July 14, 2009, 01:34:47 PM »
Wow, thank you.  That's really very in depth.

I think I'm going to have their abilities be binary - by that I mean, either they can use ranged attacks, or they can't, and so forth.  It might be a little bit less personality than making orcs greedier than farmers or whatever, but it's also simpler and has less room for error.

Allowing enemies to pick up items or money would cause problems with my anti-grind design I'm going with, so that's one thing I can just avoid dealing with altogether.

rdc

  • Newcomer
  • Posts: 41
  • Karma: +0/-0
  • You hear a *bump* in the dark...
    • View Profile
    • Clark Productions
    • Email
Re: Artificial intelligence
« Reply #3 on: July 15, 2009, 12:48:20 AM »
I took a behavior based approach that worked well and was simple to implement. Each monster had a set of behaviors and would proceed based on the current state:

1) Look for player character.
2) If not seen listen for pc.
3) If not heard then move to last seen location or roam.

Now if the monster sees the pc:

4) Move toward pc while in sight; remember last location.
5) If pc moves out of sight, move toward last seen location, goto 1.

Each monster had a preferred distance to the pc and other monsters depending on what type of main attack it had. A monster that had multiple attacks would first pick the most effective based on results but would switch to another attack if needed or the range prohibited an attack, for example, if it was cornered.

Each monster also had an aggression factor that would come into play depending on how much damage it was taking. If the damage exceeded the aggression factor, the monster would attempt to flee.

Fairly simple but effective.

Ex

  • IRC Communications Delegate
  • Rogueliker
  • ***
  • Posts: 313
  • Karma: +0/-0
    • View Profile
Re: Artificial intelligence
« Reply #4 on: July 15, 2009, 06:41:58 AM »
I've always liked simple state machines. Even NPCs that wander randomly and monsters that always move toward the player when in range I find are "good enough" for most situations. The most recent AI that I did had about a 2/3 chance to move toward the player and a 1/3 chance to move randomly, when the player is in range. Works pretty well.

rdc

  • Newcomer
  • Posts: 41
  • Karma: +0/-0
  • You hear a *bump* in the dark...
    • View Profile
    • Clark Productions
    • Email
Re: Artificial intelligence
« Reply #5 on: July 15, 2009, 01:24:28 PM »
Just another thought on this. I go by the philosophy that if the player can't see it doesn't exist. What I mean is that you may have a very sophisticated system, but if all the player sees is a monster roaming around, moving toward the player or running away, then is your sophisticated system any better than a more simple system that exhibits the same behavior?

The player can't see inside the program as it is running, all they know is what they see. For a programmer it is cool to have all these threshold values, fuzzy logic, decision trees, etc., but in the end it is all about the playing experience and what the player can see and do.

That is why I am not one of these people that get caught up in all the nuances of FOV for example. It is fun as a programmer to discuss and explore these things, but the real differences between raycasting-permissive-digital (et. all) are nits and picks really, and are not that noticeable in the actual game play. Even the so-called problems of symmetric FOV for example, which seems to be a point of many of the discussions, is an issue that most players never notice or worry about. It seems the programmers are more worried about it than anybody else. :)

Getting back to ai, I read an article once about game ai in commercial games and I wish I could remember where I saw it since it was quite interesting, because the focus was about this subject: game ai. In the article the programmer said, we don't have to create smart actors, just make them look like it. That really stuck with me. The point was that appearance is everything in a game, and why spend a lot of time building something complex (where time really is money) that looks no different than something simple.

george

  • Rogueliker
  • ***
  • Posts: 201
  • Karma: +1/-1
    • View Profile
    • Email
Re: Artificial intelligence
« Reply #6 on: July 15, 2009, 02:44:48 PM »
I got a lot out of reading the Tale of Tales development journal for Drama Princess, a very detailed autonomous actor program, but one of their conclusions is exactly as rdc described.
« Last Edit: July 16, 2009, 12:59:31 AM by george »

Vanguard

  • Rogueliker
  • ***
  • Posts: 1112
  • Karma: +0/-0
    • View Profile
Re: Artificial intelligence
« Reply #7 on: July 15, 2009, 11:39:00 PM »
Hmm... your link doesn't seem to work.

getter77

  • Protector of the Temple
  • Global Moderator
  • Rogueliker
  • *****
  • Posts: 4957
  • Karma: +4/-1
    • View Profile
Re: Artificial intelligence
« Reply #8 on: July 16, 2009, 12:46:12 AM »
http://tale-of-tales.com/DramaPrincess/wp/

Just had to dial it back a bit I guess.   :)
Brian Emre Jeffears
Aspiring Designer/Programmer/Composer
In Training

george

  • Rogueliker
  • ***
  • Posts: 201
  • Karma: +1/-1
    • View Profile
    • Email
Re: Artificial intelligence
« Reply #9 on: July 16, 2009, 01:00:10 AM »
Yep, missing a closing bracket.  :P

Conal

  • Newcomer
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: Artificial intelligence
« Reply #10 on: September 01, 2009, 04:00:14 PM »
AgingMinotaur , as mentioned in another post Im just on here for incentive :) Anyway Im reading through the article you mentioned and it is excellent, my current AI is stateless I believe then from what I have read however thanks to the articles I think I may manage to upgrade it since its given me some ideas.

Im in the process of a rewrite even though things worked and I also notice in the article what the writer says about making you methods general so they can be reused.

Anyway keep those articles comming :)