• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
GameGeazer

implimenting AI elegantly

17 posts in this topic

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
0

Share this post


Link to post
Share on other sites
Any recommendations for a book for utility based AI(or just a favored book on AI in general)?
0

Share this post


Link to post
Share on other sites
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
1

Share this post


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

[quote name='alexjc' timestamp='1343733758' post='4964809'] 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."
[/quote]

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.
1

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.
1

Share this post


Link to post
Share on other sites
[quote name='Kevin Dill' timestamp='1343763951' post='4964970']
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.
[/quote]

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
0

Share this post


Link to post
Share on other sites
I'm not familiar with those systems, but it sounds like they may be doing something much more complex than what I mean when I say "utility-based AI." To me, a utility-based AI is one that, in essence, takes the following steps:[list=1]
[*]Enumerate the possible choices (I usually call them options).
[*]For each option, run a heuristic function that calculates how appropriate that option is given the current situation. This heuristic function is typically constant time, so the cost of this step is O(n) on the number of options. What's more, this heuristic function can usually be made to be very fast, though obviously this depends on what you're doing.
[*]Pick an option based on the heuristics. Personally, I use a combination of taking the best and using weight-based random, which is also O(n) on the number of options. If you want to know more, read the articles I linked - there's lots of detail there. :)
[/list]
I can easily make a utility-based AI be hierarchical, reaping the benefits of a BT's O(log n) performance. To do this, I need a top-level reasoner that makes just the big decisions. For example, for a puppy game my doggy's top-level reasoner might decide whether he should eat, sleep, play, or pee. Once that top level reasoner has picked an option, such as pee, then I might have a mid-level reasoner that thinks about *how* to go to the bathroom. Should I pee on some nearby object, and if so then which one? Should I go scratch at the door until my owner lets me out? Should I pick up my leash in my mouth and carry it to my owner? Finally, I might have a low-level reasoner that handles the process of executing that plan. This is often just a sequence selector (if you're using a BT), or even an FSM, although it's not hard to set up either of those architectures within a utility-based reasoner. For the sequence selector, just make the utility of each option be a fixed value, with each step having lower value than the previous, and steps that have already executed having a value of 0. For an FSM, just ensure that the highest priority state is either the one currently executing or the one we should transition to, as appropriate.

So yes, if I'm having performance issues then hierarchy is one of the tools that I can pull out to address that - and it's fair to say that that would be "something like a BT" - but it would still also be utility-based. It would just be utility-based AI placed inside of a BT. Again, "BT" is just a fancy term for "hierarchical framework into which you can place any architecture that you want."

With all of that said, at least on the games I've worked on the AI hasn't been anywhere near the biggest optimization nightmare. The main reason that I go hierarchical is that it makes my job configuring the AI simpler, not that it makes the AI run faster.
0

Share this post


Link to post
Share on other sites
I just re-read Alvarro's post - and he sums up my feelings on utility-based AI *extremely* well. Nicely said.

One thing I wanted to respond to:

[quote name='alvaro' timestamp='1343708295' post='4964706']
The main problem people have with utility-based systems is that you cannot indicate rules like "in this situation, do this". Instead, you need to think of how to score every possible action, usually as the sum of multiple terms.
[/quote]

This is actually the reason I've started using the dual-utility approach I talk about in those articles I linked. I calculate two utility values: a priority and a weight. Options with higher priority will *always* be selected over options with lower priority if they are valid (i.e. if their weight is > 0). Among the highest priority options, I use weight-based random. So in essence I'm using the priority to divide my options up into categories, and then only selecting from among the most important category.

As an example I could have a bunch of options for reacting to hand grenades that all have a priority of 100, because reacting to hand grenades is really, really important - but those options would only be valid when there is a hand grenade to respond to. Then I could have normal combat options (e.g. shooting at the player(s)) with a priority around 10, give or take a point or two depending on the situation, and ambient options (e.g. getting a hamburger) with priorities around 0.

I can't take credit for inventing the approach - I stole it from Zoo Tycoon 2 (I'm not sure who originated it - maybe Nathan Sitkoff or Ralph Hebb?), but it's a pretty slick system.
0

Share this post


Link to post
Share on other sites
[quote name='Kevin Dill' timestamp='1343926452' post='4965589']
Among the highest priority options, I use weight-based random. So in essence I'm using the priority to divide my options up into categories, and then only selecting from among the most important category.[/quote]

Sounds like a behavior tree with localized utility :-) I like this approach better. Scales well and it's easy to author -- as you said.

I think BT is more specific than just a "hierarchical framework" that you can plug stuff into, but that's worth as separate discussion.

Alex
0

Share this post


Link to post
Share on other sites
[quote name='alexjc' timestamp='1344336424' post='4966972']
[quote name='Kevin Dill' timestamp='1343926452' post='4965589']
Among the highest priority options, I use weight-based random. So in essence I'm using the priority to divide my options up into categories, and then only selecting from among the most important category.[/quote]

Sounds like a behavior tree with localized utility :-) I like this approach better. Scales well and it's easy to author -- as you said.

Alex
[/quote]
While that could be duplicated as a behavior tree with utility-based selector nodes, that almost adds more complication than is necessary. In Kevin's design, all that would be necessary is the addition of a single integer value that represents the "priority" (or category as he referred to it above). When processing the decisions, you check things in a certain priority first... highest to lowest. If there are no priorities 9's, for example, you look for 8's, etc. The difference between this setup and a BT is that those priority numbers (as with anything in a utility-based system) can be modified at runtime by stimuli in the game. So something might not [i]always[/i] be a priority 9. Sometimes it might be a 2 and would be checked after all the other higher priorities. The short version is that even the priorities (which are acting as a higher level in the hierarchy) are fluid and reactive to the game dynamics rather than being "this is what we authored so this is what you get."

Anyway, we have wandered off the original topic... the point being there are many ways to do AI. You have to pick the one that suits your needs best. (Which was the point of my article in Game Developer last week.)
0

Share this post


Link to post
Share on other sites
[quote name='wodinoneeye' timestamp='1345125515' post='4970171']
Complex environments have too many endcases to have simple evaluation functions. Of course, the complexity of the decision logic increases exponentially with the complexity of the object's potential behaviors and its environment. (throw in handling uncertainty if you want it this be a magnitude harder and for temporally complex actions/results another magnitude).

Risk versus Reward (including Cost) analysis - how does the object's logic .judge a VECTOR of boiled down evaluation results adjusted for current preferences/historic success memories/changeable goal priorities --- to come up with a single value that it can competantly compare to another entirely different possibilities being 'considered'/evaluated?[/quote]

I think you are making it sound much harder than it is. Remember that we are in a Game AI context. We are trying to create behavior that is compelling and that makes for good gameplay, that's all. In particular, I don't see any need to do careful risk-vs-reward analysis here (although it is possible).


[quote]
You can try to find generalizations in the evaluation logic, but those endcases are legion.

Hand normalization (via cohesive judgement across the whole problem/solution space) . -- As usual the required human in the loop is the limitation.

A simple decision space you can probably comprehend and visualize it so as to tweak it into shape, but as it grows more complex it becomes a monster.
[/quote]

I don't know if you have actual experience working with a utility-based system, but my experience is quite the opposite.
It is useful to have some scale in mind. For instance, you can make the scale be dollars and ask "how much would this agent be willing to pay to take this action?". It's not always easy to answer everything that way, but in some contexts it might help you think about it.

If you have a specific type of game in mind for which you don't think this approach could be manageable, perhaps you can describe it, to make sure we are talking about the same thing. It is also possible that this approach is just not appropriate for every situation, which wouldn't surprise me. But I think the ability to handle complexity is a strength of the approach, not a weakness.
0

Share this post


Link to post
Share on other sites
Once you get past a certain level of complexity then 'being manageable' flies out the window with ALL the methodologies.

I didnt say dont use utility/priority-based logic, just that it is just the basic overall system (evaluating to one number to allow comparing/picking the 'best' solution) and FINDING that number (judging/evaluating) when you are dealing with a situation full of endcases and exception and multitudes of relevant factors becomes THE significant difficulty.

---

Example - your avatar gets injured and suddenly is in a mode/state where getting repaired is of prime importance.

The action of getting a Med-Kit suddenly zooms up as something of priority, but doesnt neccessarily override an easy opportunity to pickup some other useful item right next to the avatar. The 'repair' goal priority might best even be a curve function with the degree of being damaged (input) accelerating exponentially the priority (output) for attempting to achieve that goal. That is assuming the 'being damaged' itself can be expressed as a simple value and isnt a vector of factors itself (broken limbs vs blood loss vs burn damage etc... depending on complexity of your game mechanics).

Similarly, a Med-Kit that can be pathed-to as a shorter/easier movement distance versus another MedKit further/harder/riskier (and that evaluation might include potential for attack from any/all opponents/hazards). And what of a Big Med-Kit vs a Small one -- which one is better in relation to the risk/cost of obtaining it ??? The realistic decisions are not 'simple' and these ARE just for a fairly basic game mechanics (if your goal is to try to make the objects look 'smart' -- or rather NOT extremely 'dumb')

---

Players figure out quite quickly opponent behaviors that are simplistic and can often easily make use of them to their 'too easy' advantage.

Seeing objects that aught to be 'intelligent' make stupid moves over and over wont impress them.

----

You can start by assigning simplistic numeric evaluation numbers to actions just to get started, and then playtest to see where that simplicity falls down and then start adding more complex evaluations. (Unfortunately, that is almost immediately and in numerous cases).

Now you find you have to add the 'meat' of the AI system and will notice that that 'utility-based system' is only a tiny part of the whole as you add tools like pathing and influence mapping and fuzzy logic to try to get those 'simple numbers'. Suddenly because of the explosion of processing you now have to add culling of evaluated possibilities and time-scheduling of AI to fit resource requirements.

----

My real point is that for 'elegance' you might have one nice simple tool sitting there, but for the whole thing to work the rest grows mosterous and ungainly (its why AI is so difficult and most game companies avoid it like the plague)
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0