FuSM

From GameStudio Wiki

Jump to: navigation, search

Fuzzy State Machines (FuSM) are similar to Finite State Machines except they use fuzzy logic to handle transitions between states and/or the actions inside those states.

Contents

Fuzzy Logic

Instead of have two discreet values (e.g. true or false, hot or cold, alive or dead), fuzzy logic works on degrees (e.g. sort-of true, kind-of hot, mostly dead).


Advantages

  • Can result in "more realistic" behavior when used correctly.
  • Unpredictability can increase the difficulty for the player (not always good).
  • Fewer conditions and actions can be used for the same level of interactivity.

Disadvantages

  • Much more difficult to debug then traditional logic.
  • Unpredictable AI can confuse the player and make the AI appear random (which isn't intelligent).
  • Fuzzy conditions tend to be much more expensive to calculate then normal ones.
  • Fuzzy actions may not give desired results.


Details

Making Data 'Fuzzy'

Since computers deal only with non-fuzzy values, we must first convert (map) those values into a fuzzy set. Each member in the set will have a degree of membership (percent) to the original value. This value is calculated using a membership function.

In our example, lets map the distance to the player to an engagement range set:

  • Range (non-fuzzy value): 1327 units.
  • Range (fuzzy set): Close (0), Long (0.75), Extreme (0.08), Outside (0)

We can also calculate the amount of ammo the AI has:

  • Ammo (non-fuzzy) : 32 rounds.
  • Ammo (fuzzy): Out (0), Low (0.25), Good (0.65), Plenty (0.05)

Membership Function

Calculates the degree of truth a value has to a particular member. The resulting value falls between 0 (absolutely false) and 1 (absolutely true).

This function can use simple boolean logic (if v<x return 0, else 1) but that defeats the point of fuzzy logic.

A slightly more 'fuzzy' function would use boolean logic only for extremes (if v<x0 return 0, if v>x1 return 1, where x1>x0) with the area between those extremes varying linearly using the Point-slope Equation (return (v-x0)/(x1-x0) ). This results in a grade from absolutely false at x0 up to absolutely true at x1.

You can also come up with functions for peaks (triangles), plateaus (trapezoids), curves, etc. Almost any function can be used as long as the resulting value falls between 0 and 1. In a real-time game environment however, it is normally best to stick with the cheaper functions (unless you pre-compute the values). And normally this is good enough.

Using Fuzzy Data

Now that we have our fuzzy set, we can preform fuzzy operations on them.

If A and B are "degrees of truth" (a value between 0 and 1), we can use the following operators:

  • A OR B = max(A,B)
  • A AND B = min(A,B)
  • NOT A = 1-A

Using our range & ammo data we can convert it into fuzzy actions:

  • Close OR Long = Aim attack (0.75)
  • Long AND Plenty = Harassment fire (0.05)
  • NOT Close = Switch to ranged weapon (1.0)

As you can see, fuzzy logic on fuzzy data produces fuzzy results.


Make Results Real

The easiest way to convert fuzzy results to real actions, it to just choose the highest value (in our example, an "Aim attack").

We could also use a function that takes the results and calculates a non-fuzzy action ( (Aim attack)*(1-Harassment fire) = RoF). One such function used often with fuzzy results is a singleton function.

Singleton Function

The singleton function takes all the resulting truth values and multiples them by a constant value. The output is the sum of all these values.

For example, let our RoF depend on the amount of ammo we have left (RoF = 10*Plenty + 5*Good + 1*Low).

Given two sets of fuzzy results, we could use a fuzzy associative matrix to get our results.


References

Personal tools