Jump to content
  • Advertisement
Sign in to follow this  
GameGeazer

implimenting AI elegantly

This topic is 2137 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For the 2D-top-down game I'm writing(in Java) I've written pathfinder using A* and simple AI around that(if player is in line of sight move towards player, if close enough to player attack player). However I'm looking to make more intricate AI as well as different AI for each of my enemies.I have the logic for my AIs mapped out, but am unsure of how to implement anything too complicated elegantly. What is the best way of writing AI, should I be reading lua scripts, hard coding it in java? Edited by GameGeazer

Share this post


Link to post
Share on other sites
Advertisement
I'd agree with Alvaro's advice. I've found utility very suited to managing relatively simple decisions (limited number of outputs) from arbitrary information (large number of inputs). There was a lecture at the AI Summit by Kevin Dill and he emphasized the modularity of input "criteria" above all. I asked him about modularity of decisions/output and he said something like: "Sure, for that you need a BT-style structure."

If you have large numbers of possible outputs, and want to express a large variety of special cases that can combine together, then behavior trees or hierarchical planners are my recommended option. Utility has been found not to scale up very well in these areas (e.g. performance), and games like the SIMS 3 famously moved away from "utility everywhere" for these reasons.

Alex Edited by alexjc

Share this post


Link to post
Share on other sites
P.S. Looking at Alex's quote again:

There was a lecture at the AI Summit by Kevin Dill and he emphasized the modularity of input "criteria" above all. I asked him about modularity of decisions/output and he said something like: "Sure, for that you need a BT-style structure."


I'm not sure what I would have meant by that. I think modularity of *everything* is the key to both rapid configuration and reusability. I've been pushing really hard in that direction - as you can see in the articles I posted above, and also in my upcoming I/ITSEC article on the topic (but that won't be out until December). That said, I don't know what connection I might have been thinking of between modularity and BTs.

As I said above, a BT is really just a hierarchical framework onto which you place your AI. Modularity and hierarchy are both useful, powerful tools to have in your box - but they're orthoganal. You can have modular systems that are not hierarchical, and hierarchical systems that are not modular.

Share this post


Link to post
Share on other sites
When I did it I made a small scripting engine which would read a .txt file which would contain a script in an assembly-type language. Gets a little complicated if the script gets too big but at least it means you java code doesn't get too messy.
Another way of doing it is by doing it in java. I would imagine every object has a behaviour so have a class called Behaviour then what you can do is just add an instance of behaviour to an entity. You could have child classes like RunAwayBehaviour extends BaseBehaviour then just add that to an entity. You could even cross both methods to have behaviours assigned to scripts. BaseBehaviour runaway = new BaseBehaviour("runAwayScript.txt").
entity.addBehaviour(runaway);
By doing this it makes it so you don't have to have multiple copies of the same script to assign to entities but have public static behaviours that are assigned instead which can be copied into the entities in java. Making a script parser isn't to hard if one line does one thing like the assembly language. I'm trying to find ways of making a High level script compiler but at the moment it seems like too much work.

Share this post


Link to post
Share on other sites

I'm not sure what I would have meant by that. [...] That said, I don't know what connection I might have been thinking of between modularity and BTs.


We were walking out of Moscone North and heading towards West on Monday evening after your lecture that afternoon. The conversation started something like this...

I pointed out that while you focused your lecture on modularity of inputs and setting up criteria, I just haven't been faced with this problem in the past. I haven't had unmanageable inputs since the information I need is often expensive; every additional input costs you. I asked you about modularity of actions / outputs, since it doesn't seem to be talked about anywhere near as often, and that's a problem I've faced significantly more often.

That's when you said the line I quoted, which for some reason is burned in my brain (it made sense :-) "Ah, for that you need something like a BT."


I can see how hierarchy would help make it manageable, but a full utility-based hierarchy (like MASA's DirectIA aka. behavioral network, or Spir.Ops' drive system) would potentially have a huge performance impact since you have to simulate the whole thing to get a decision. If you don't simulate the whole thing and "prune" space with Boolean conditions for example, then you're basically moving towards decision-tree style AI.

For this reason, I tend to take the approach of BT first, then sprinkle utility around where necessary. It's easier to work with, it's modular, and it's fast as hell -- O(log n). The alternative, having an elegant utility architecture that you need to hack for performance, hasn't been as appealing for me.

Alex

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!