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

Anyway, you write each fuzzy degree of membership as an ordered pair of the form “{candidate for inclusion, degree of membership}”. Therefore, for the movie example you would write “{;ANTZ, 1.00}, {Forrest Gump, 0.20}, {Terminator, 0.75}, {Aliens, 0.50}, {The Matrix, 0.9}”. Finally, if you had the fuzzy class Rainy, what would you include today as? Where I live, for example, it’s “{today, 1.00}”!

Now you can add a little more abstraction and create a full fuzzy set. In most cases, this is an ordered collection of the degrees of membership (DOM) of a set of objects in a specific class. For example, in the class Computer Special FX, you have the set composed of the degrees of membership: A = {1.0, 0.20, 0.75, 0.50, 0.90}. There’s one entry for each movie—each variable represents the DOM of each movie as listed in Table 12.4, so the order counts!

Now, suppose that you have another set of movies that all have their own degrees of membership: B = {0.2, 0.45, 0.5, 0.9, 0.15&}. Let’s apply some of the set operations you’ve learned about and see the results. Before you do, there’s one caveat: Because we’re talking about fuzzy sets that represent degrees of membership, or fitness vectors of a set of objects, many set operations must have the same number of objects in each set. This will become more apparent when you see what the fuzzy set operators do below.

Fuzzy union ( )—The union of two fuzzy sets is the `MAX` of each element from the two sets. For example, with fuzzy sets:

    A={1.0, 0.20, 0.75, 0.50, 0.90}

    B={0.2, 0.45, 0.5, 0.9, 0.15}

The resulting fuzzy set would be the `MAX` of each pair:

    A  B  = {MAX(1.0,0.2), MAX(0.20,0.45),

              MAX(0.75,0.5), MAX(0.90,0.15)} = {1.0,0.45,0.75, 0.90}

Fuzzy intersection ()—The intersection of two fuzzy sets is just the `MIN` of each element from the two sets. For example, with fuzzy sets:

    A={1.0, 0.20, 0.75, 0.50, 0.90}

    B={0.2, 0.45, 0.5, 0.9, 0.15}

    A  B  = {MIN(1.0,0.2), MIN(0.20,0.45),

              MIN(0.75,0.5), MIN(0.90,0.15)} = {0.2,0.20,0.5, 0.15}

Subsets and elements have less meaning with fuzzy sets than with standard sets, so I’m skipping them. However, the complement of a fuzzy value or set is of interest.

The complement of a fuzzy variable with degree of membership x is (1-x), so the complement of A, written A’, is computed as

    A = {1.0, 0.20, 0.75, 0.50, 0.90}

Therefore:

    A' = {1.0 - 1.0, 1.0 - 0.20, 1.0 - 0.75, 1.0 - 0.50, 1.0 - 0.90}

          = {0.0, 0.8, 0.25, 0.5, 0.1}

I know this is killing you, but bear with me.

#### Fuzzy Linguistic Variables and Rules

All righty, then! Now that you have an idea about how to refer to fuzzy variables and sets, let’s take a look at how you’re going to use them in game AI. You’re going to create an AI engine that uses fuzzy rules, applies fuzzy logic to inputs, and outputs fuzzy or crisp outputs to the game object being controlled. Take a look at Figure 12.36 to see this graphically.

Figure 12.36 The fuzzy I/O system.

When you put together normal conditional logic, you create a number of statements, or a tree with propositions of the form

    if X AND Y then Z

or

    if X OR Y then Z

The X and Y variables are called the antecedents, and Z is called the consequence. However, with fuzzy logic, X and Y are fuzzy linguistic variables, or FLVs. Furthermore, Z can also be an FLV or a crisp value. The key to all this fuzzy stuff is that X and Y represent fuzzy variables, so they’re not crisp. Fuzzy propositions of this form are called rules, and ultimately they’re evaluated in a number of steps. You don’t evaluate them like this:

    if EXPLOSION AND DAMAGE then RUN

and execute the `RUN` consequence if `EXPLOSION` is `TRUE` and `DAMAGE` is `TRUE`. With fuzzy logic, the rules are only part of the final solution. The fuzzification and defuzzifaction are what produce the final result.

FLVs represent fuzzy concepts that have to do with a range. For example, let’s say that you want to classify the distance between the player and the AI object with three different fuzzy linguistic variables (names, basically). Take a look at Figure 12.37. It shows a fuzzy manifold or surface, which is composed of three different triangular regions that I have labeled as follows:

Figure 12.37 A fuzzy manifold composed of range FLVs.

`NEAR` | Domain range (0 to 300)
`CLOSE` | Domain range (250 to 700)
`FAR` | Domain range (500 to 1000)

> Note: You’ve already seen a similar technique used to select states in a previous FSM example (in the section Patterns with Conditional Logic Processing, earlier in this chapter). The range to a target was checked, which forced the FSM to switch states, but in the example with FSMs you used crisp values without overlap or fuzzy computations. There was an exact range where the crisp FSM AI switched from `EVADE` to `ATTACK` or whatever. But with fuzzy logic, it’s a bit blurry.

The input variable is shown on the x-axis and can range from 0 to 1000. This is called the domain. The output of the fuzzy manifold is the y-axis and ranges from 0.0 to 1.0. For any input value xi (which represents range to player in this example), you compute the degree of membership (DOM) by striking a line vertically, as shown in Figure 12.38, and computing the Y value(s) at the intersection(s) with each fuzzy linguistic variable’s triangular area.

Figure 12.38 Computing the degree of membership of a domain value in one or more FLVs.

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.