Article
files/fuzzy

Going All Fuzzy: When Do You Avoid Discrete Logic?

Alex J. Champandard on September 18, 2007

This week’s developer discussion is all about fuzzy logic. Click here to join the conversation by posting a comment.

Have you used fuzzy logic before? If so, how did you apply it to your game AI? If not, why didn’t you use fuzzy logic?

Nice and Crisp

There’s no argument here: discrete logic is the default in the game AI industry. Here’s my take on why that’s the case:

  1. Crisp logic is easier to implement, whether using finite state machines, behavior trees, or planners.

  2. It’s more efficient to consider the best choice rather than having to calculate probabilities for alternatives.

  3. Design is more intuitive when the choices are crisp. It’s easier to predict the outcome of an emergent system.

  4. Crisp decisions for the behaviors are easier to understand for the player, and less confusing.

In a way, these are points against fuzzy logic. Do you agree with them?

When to Go Fuzzy?

Like any tool, fuzzy logic certainly has its advantages. To name a few:

  • It’s easier to write logic for reasoning with probabilities.

  • The resulting probabilities take into account all the rules, not just the first/best.

The question is, when can you apply this in games? To what extent is it suitable?

Post a comment below to join the discussion!

Discussion 4 Comments

Dave Mark on September 19th, 2007

I would agree that discrete logic is the default in game AI today. However, I would also contend that it is also the primary weakness of game AI today. The first three points you listed are why it is being used (which can be summed up as "laziness" in large part). The fourth item - "easier for the player to understand" is why it is the greatest weakness. One of the major issues we face in game AI today is a lack of "realism" - which I admit is a fairly nebulous term. Much of that "realism" can be generated by the unknown. In robotics, there have been experiments that have shown that even in 2 seconds of visual exposure, a person can identify a still person from a mannequin. However, if the mannequin is given the tiniest facial tics or movements - almost not consciously readable - a significant portion of people will now identify the mannequin as human. They have picked up those minute inconsistencies - that is, imperfections - and processed those as being "human" rather than inhuman. By introducing these tiny variances into our AI agents, we can likely achieve much the same result. Over time, players will be able to intuitively ferret out discrete cause-effect cases if there are no other options in play. For example, "given weapon choices A and B, the AI will always choose A, therefore I will prepare for it." What if the AI sometimes chooses B? What if the player has realized that he doesn't always know what the enemy will choose? What if the player needs to plan for the contingency of B and be ready to react accordingly should he see that the AI has chosen B? By making that single cause-effect chain based on non-discrete logic, we have now deepened the gameplay in a number of ways. We have made the AI agent seem more "human" by introducing the aire of "free will" and, with it, fallibility. Perhaps A was the "MOST logical" choice but only slightly so. Well, the human players don't always choose the "most logical" choice, do they? In large part, our quest as AI developers has been driven by "how do I solve the problem" - which translates into a discrete "best" solution. We have been so enamored with finding that "best" that we have neglected the concept that there are other options. Why should an agent follow the absolute optimum path from A to B simply because we have now perfected A* to generate that optimum path? Sure, we don't want to have agents take ridiculous paths, but there are likely many paths that were just barely sub-optimum. This becomes especially obvious when there are either multiple agents traversing that A to B path or you play the same game/level over and over and it is always the same. Why? We have exposed our creatures for what they are - automatons bent on the best possible solution.

Sergio on September 19th, 2007

I believe the human recognition example is misleading. Humans are extremely well prepared genetically to recognize other humans and, in particular, faces. That's why we are so sensitive to those small details. Regarding behaviour however, humans tend to like patterns. In the extreme, a character that was totally unpredictable would be perceived as being insane. Players need to be able to create a mental model of the AI, or they wouldn't be able to relate to the AI-controlled characters at all. The mental model players use doesn't have to be extremely simple and fully predictable, they can learn to expect a little uncertainty here and there. However, especially in zero-sum games, a common development strategy is to create an opponent that plays the game as optimally as possible, so we offer a challenging experience for hardcore players. Then the AI will be tweaked to add variety and to adjust for the different difficulty levels. On top of that, and unrelated to it, developers need to understand the experience they are providing to the players, and an overly complex AI model would work against that. In that sense, more complex and unpredictable AI is probably not going to be better. More chaotic, sure, but the ability of developers to tailor the experience so players can get the maximum enjoyment is what makes great games great.

alexjc on September 20th, 2007

Thanks for dropping by Dave, and hi again Sergio :-) Nice points, both of you. My opinion is on fuzzy logic is fourfold: [B]1. Fuzzy Logic Does Not Scale[/B] I mentioned before that discrete is much faster, but it's also the case that fuzzy logic is much less efficient by definition. In the best case, computational complexity scales linearly at O(N) with the number of rules N (if you design your system well). Some implementations are even slower. That's not laziness, that's the essence of the solution. Fuzzy logic is designed to take all possibilities into account, yet it's not computationally feasible to do so. Particularly in games, processing power is a finite supply... [B]2. Fuzzy Logic Will Never Be Fast Enough[/B] Problem spaces are getting larger, so all gain in processing power is voided. If you look at recent problem solving competitions, they have huge search spaces. It would take huge amounts of time to consider all the options with fuzzy rules. It's no coincidence, in my opinion, that the best problem solvers are discrete. They make huge compromises early on in the search for a solution. This is not only an optimization; it's entirely necessary to be able to even finish the calculation. [B]3. Fuzzy Logic Is Hard to Make Realistic[/B] Even if you can take all the factors of your problem into account, a lot of the information will be conflicting... How do you deal with this grey-mess of possible choices? In practice, it's really tough to decide how to turn fuzzy into discrete, so most of the time you end up with a democratic approach which ends up ignoring many of the factors you wanted to take into account. [B]4. Fuzzy Logic Requires Too Much Assistance[/B] Since fuzzy logic it doesn't scale well, you have to baby-sit your fuzzy system. Don't give it too much information; limit your problem space; don't add too many rules... but still make sure it solves a useful problem! Even with the best of intentions, putting up with these requirements needs to be justifiable... [B]SOLUTION: Go Fuzzy on Small & Well-Identified Problems[/B] In summary, the way fuzzy logic works, we just don't have the development time or computational power to use fuzzy logic everywhere. It's not laziness, it's the essence of the solution. I would use fuzzy logic quite happily on isolated problems to support the main crisp/discrete behaviors. For example, identifying if an actor is friend or foe, modeling emotional response, etc. Alex P.S. The topic of "why is there a lack of realism in game AI" is ideal for next week's discussion, so keep some ideas in reserve on that subject. :-)

avok23 on January 29th, 2008

Fuzzy logic would be great for sports games, beat em ups, fighters and adventure games where combat takes place in relatively small confined areas (yes they do have ai) but shamefully everyone seem to rely on FSM for these genres

If you'd like to add a comment or question on this page, simply log-in to the site. You can create an account from the sign-up page if necessary... It takes less than a minute!