Tricks of the Windows Game Programming Gurus:Making Silicon Think with Artificial Intelligence

All ITKnowledge Source Code Search Tips Advanced Search |

| Tricks of the Windows Game Programming Gurus by Andre LaMothe Sams, Macmillan Computer Publishing ISBN: 0672313618 Pub Date: 09/27/99

Search this book:

Previous | Table of Contents | Next

Each triangle in the fuzzy surface represents the area of influence of each fuzzy linguistic variable (`NEAR`, `CLOSE`, `FAR`). In addition, the regions overlap a little—usually 10-50 percent. This is because when `NEAR` becomes `CLOSE` and `CLOSE` becomes `FAR`, you don’t want the value to instantly switch. There should be a little overlap to model the fuzziness of the situation. This is the idea of fuzzy logic.

Let’s recap for a moment. We have rules that are based on fuzzy inputs from the game engine, environment, and so on. These rules may look like normal conditional logic statements, but they must be computed using fuzzy logic because they’re really FLVs that classify the input(s) with various degrees of membership.

Furthermore, the final results of the fuzzy logic process may be converted into discrete crisp values, such as “fire phasers,” “run,” or “stand still,” or converted into a continuous value such as a power level from 0-100. Or you might leave it fuzzy for another stage of fuzzy processing.

#### Fuzzy Manifolds and Membership

It’s all coming together, so just hang in there. Now you know that you’re going to have a number of inputs in your fuzzy logic AI system. These inputs are going to be classified into one or more (usually more) fuzzy linguistic variable FLVs (which represent some fuzzy range), and then you’re going to compute the degree of membership for each input in each of the FLV’s ranges. In general, at range input `xi`, what is the degree of membership in each fuzzy linguistic variable `NEAR`, `CLOSE`, and `FAR`?

Thus far, the fuzzy linguistic variables are areas defined by symmetrical triangles. However, you can use asymmetrical triangles, trapezoids, sigmoid functions, or whatever. Take a look at Figure 12.39 to see other possible FLV geometries.

Figure 12.39 Typical fuzzy linguistic variable geometries.

In most cases, symmetrical triangles (symmetrical about the x-axis) work fine. You might want to use trapezoids, though, if you need a range in the FLV that is always 1.0. In any case, to compute the degree of membership (DOM) for any input `xi` in a particular FLV, you take the input value `xi` and then project a line vertically and see where it intersects the triangle representing the FLV on the y-axis. This is the DOM.

Computing this value in software is easy. Let’s assume that you’re using a triangular geometry for each FLV, with the left and right starting points defining the triangle labeled `min_range`, `max_range`, as shown in Figure 12.40.

Figure 12.40 The details of computing DOM for an FLV.

To compute the DOM of any given input `xi`, the following algorithm can be used:

    // first test if the input is in range

    if (xi >= min_range && xi <= max_range)

       {

       // compute intersection with left edge or right

       // always assume height of triangle is 1.0

       float center_point = (max_range + min_range)/2;

       // compare xi to center

       if (xi <= center_point)

          {

          // compute intersection on left edge

          // dy/dx = 1.0/(center - left)

          slope = 1.0/(center_point - min_range);

          degree_of_membership = (xi - min_range) * slope;

          } // end if

       else

          {

          // compute intersection on right edge

          // dy/dx = 1.0/(center - right)

          slope = 1.0/(center_point - max_range);

          degree_of_membership = (xi - max_range) * slope;

          } // end else

       } // end if

    else // not in range

       degree_of_membership = 0.0;

Of course, the function can be totally optimized, but I wanted you to see what was going on. If you had used a trapezoid instead, there would be three possible intersection regions to compute: the left edge, the plateau, and the right edge.

In most cases, you should have at least three fuzzy linguistic variables. If you have more than three, try to keep the number odd so there’s always one variable that is centered. Otherwise you might have a trough or hole in the center of the fuzzy space.

In any case, let’s take a look at some examples of computing the degree of membership of your previous fuzzy manifold, shown in Figure 12.37. Basically, for any input `xi`, you project a line vertically and determine where it intersects each of the FLVs in the fuzzy manifold. The line might intersect more than one FLV, and this needs to be resolved. But first, let’s get some DOMs.

Assume that you have input ranges `xi` = {50,75,250,450, 550,800}, as shown in Figure 12.41.

Figure 12.41 Your range manifold with a number of inputs.

In that case, the degrees of membership for each `FLV`—`NEAR`, `CLOSE`, `FAR`—can be computed with the algorithm or read off graphically. They’re listed in Table 12.5.

Table 12.5 Computations of Degree of Membership for Range Manifold

| Degree of Membership
--- | ---
Input “Range to target” xi | NEAR | CLOSE | FAR

50 | 0.33 | 0.0 | 0.0
75 | 0.5 | 0.0 | 0.0
250 | 0.33 | 0.0 | 0.0
450 | 0.0 | 0.88 | 0.0
550 | 0.0 | 0.66 | 0.20
800 | 0.0 | 0.0 | 0.80

Previous | Table of Contents | Next

Copyright © Macmillan Computer Publishing, Inc.

Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.