Advertisement

Prolog and decision making in RPGs

Started by January 28, 2009 07:20 PM
4 comments, last by aaron_ds 15 years, 9 months ago
I'm looking for a beginners tutorial for NPC AI in RPGs implemented in Prolog. Usually my Google-fu is strong, but there appears to be a genuine lack of material on the subject. The Game Programming Wiki has a page on building an inference engine, great but I already have one up and running as a Ruby DSL. Are there any tutorials/article/books/videos that you can recommend?
Why are you interested in Prolog beside the inference engine ? That's its main feature and it becomes pretty old by now, in my humble opinion.

You'll find more easily suggestions of rules to use for your agents on internet. Using prolog or a custom made inference engine is just a matter of implementation.
Advertisement
Your Google-fu is probably still strong. i know the area decently well and know of no work on NPC AI in Prolog

Prolog is not exactly a language of choice. Like lisp, it's popular in AI courses in college but not in the real world, which i suppose includes the video game world. Prolog is a logic-based language and there is some work on logic-based AI for games. The best known is Soar, which is used at USC and UMichigan. Again, this is academia, but academics, unlike most game studios, are happy to publish lots of papers on their work

Inference engines are not popular in games (i only know of two games that claim to have one of them, and i know one of those was wrong). There are various Web sites that will tell you how to build an inference engine. i'm personally working on an inference engine right now for my employer and was on a rule-based reasoning in games committee but my personal opinion (not shared by my coworkers, obviously) is that it's no better than hand-writing logic in a scripting language. It's not fast compared to compiled code, it's hard for most programmers to think of their programs as a set of independent rules, you either need to manage your rules closely with guard clauses or deal with conflict resolution (which is a fairly complex issue in itself) and it's non-trivial/obvious how to write anything that deals with more than one object (meaning, if you have three enemies and need to decide who to attack, there's no obvious way to decide which is the best)

As an aside, there really isn't such a thing as "NPC AI". One of the big problems people have entering the AI world is thinking too vaguely. They think "i want AI, i should find what technique to use to make AI", which assumes that AI is one big problem, which it isn't. It's a lot of small and normally very simple problems. It's pathfinding, steering, target selection, weapon selection, magic selection, personality, memory, dialog, inventory management, trading and all sorts of things, each of which might have its own solution. How you decide which target to attack is not necessarily how you'll decide whether to attack, heal or run away. You probably know that (since you're asking for a tutorial, not a technique) but when solving AI, my opinion is that it's best to first figure out how you want your AI to behave, then decide what types of decisions are being made or problems solved (and literally write them out and number them) and only then try to figure out how to solve them. Some you'll realize you can solve with common sense, others you'll realize need a solution tailored to that specific problem, something that won't work for the other problems. Of all these, doing a good job on step 1 is probably the hardest

But if you want to go the rule-based route for NPCs, take a look at Soar (although they haven't done much RPG work) and maybe Peter Spronck's work on rule learning (he tested some logic approaches to combat in a Baldur's Gate clone)
Way back when I used Turbo Prolog in the (internal) development tools for a game that was actually sold. But yes, nobody uses that heavy-weight platform for AI in a commercial game runtime.
Quote: Original post by baylor
... Peter Spronck's work on rule learning (he tested some logic approaches to combat in a Baldur's Gate clone)


To aid your Googlu-fu, that's Pieter Spronck. In further research he also set up a self-learning combat AI in Neverwinter Nights, using an approach dubbed Online Adaptation. Unfortunately he moved to another university (booh! [wink]), but it looks like his research can now be found over here.

Like baylor mentioned, this is just a part of AI that focusses on NPCs learning to make optimal use of their talents/skills in combat, so it doesn't magically provide overall intelligent behavior for NPCs in other areas. To get a life-like NPC, you'd likely have to combine multiple domain-specific techniques (combat, pathfinding etc) and tie them together somehow. Based on my (very!) limited experience, I'd agree with baylor that manually written scripts are the most flexible and reliable glue to implement this general behavior in NPCs.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
@baylor, you're absolutely right. I very much agree that path-finding, while possible to implement in Prolog, is not the best use of an inference engine, certainly the same applies to a combat engine, applications of machine learning, etc.

I probably should have given more detail as to what I wanted to accomplish with an inference engine. Applying it to an agent's decision making is my goal and only at the highest level.

Certainly, it is possible to categorize and enumerate a list of possible NPC actions. Travel to a location, pick up an item, steal an item, kill another agent, drop an item, craft an item, kidnap an agent, etc. Since NPC's drive the plot, actions that allow for Propp's functions to be constructed is my starting place. NPC's actions like traveling to a location would then be delegated to a path-finding engine, kill another agent to a combat engine, and so on and so forth.

AI is not my forte, but I'm trying!


This topic is closed to new replies.

Advertisement