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

However, this is not necessary. If you only have four rules, the other outputs are just set to 0.0 in the FAM. Nevertheless, I will use up all nine slots in our example to make it more robust. For an output, I’m going to use the fuzzy output thrust level, which I’m going to make a fuzzy variable that is made up of the following fuzzy categories (FLVs):

`OFF` | Domain range (0 to 2)
`ON HALF` | Domain range (1 to 8)
`ON FULL` | Domain range (6 to 10)

The fuzzy manifold for these FLVs is shown in Figure 12.44.

Figure 12.44 The output fuzzy manifold for the thrust level.

Note that the output could have more categories, but I decided to pick three. Here are my somewhat arbitrary rules:

Input 1: Distance to player.

        NEAR

        CLOSE

        FAR

Input 2: Power level of self.

        WEAK

        NORMAL

        ENERGIZED

Output: Internal navigational thrust level (speed).

        OFF

        ON HALF

        ON FULL

Rules: Somewhat made up (I’m a doctor, not a magician).

    if NEAR AND WEAK then ON HALF

    if NEAR AND NORMAL then ON HALF

    if NEAR AND ENERGIZED then ON FULL

    if CLOSE AND WEAK then OFF

    if CLOSE AND NORMAL then ON HALF

    if CLOSE AND ENERGIZED then ON HALF

    if FAR AND WEAK then OFF

    if FAR AND NORMAL then ON FULL

    if FAR AND ENERGIZED then ON FULL

These rules are heuristic in nature, imparting knowledge from an “expert” about what the AI should do in these conditions. Although the rules may seem somewhat contradictory, I did think about them for about two minutes! Seriously, now that you have the rules, you can finally fill in the fuzzy associative matrix completely, as shown in Figure 12.45.

Figure 12.45 The FAM, complete with all the rules.

#### Processing the FAM with the Fuzzified Inputs

To use the FAM, do the following:

  1. Get the crisp inputs for each fuzzy variable and fuzzify them by computing their DOM for each FLV. For example, let’s say that you have the following inputs:

  Input 1 | Distance to player = 275
  Input 2 | Power level = 6.5

  To fuzzify these, input them into the two fuzzy manifolds and compute the degree of membership for each fuzzy variable for each input. Refer to Figure 12.46.

Figure 12.46 Some inputs plugged into the fuzzy variables.

For Input 1 = 275, the degree of membership of each FLV is as follows:

`NEAR` | 0.16
`CLOSE` | 0.11
`FAR` | 0.0

For Input 2 = 6.5, the degree of membership of each FLV is as follows:

`WEAK` | 0.0
`NORMAL` | 0.5
`ENERGIZED` | 0.25

At this point, refer to the fuzzy associative matrix and test the rule in each cell to see what its output value is based on in the preceding fuzzy values. Of course, many of the FAM’s cells will be 0.0 because two of the FLVs (one from each input) are 0.0. Anyway, take a look at Figure 12.47, which depicts your FAM along with all the cells that have non-zero outputs shaded in.

Figure 12.47 The fuzzy associative matrix showing active cells and their values.

Now here comes the tricky part… Each one of those cells in the FAM represents a rule. For example, the upper-left cell represents

    if NEAR AND WEAK then ON HALF

To evaluate this rule, take the antecedents and test them using a `MIN()` rule for the logical `AND`. In this case, you have that `NEAR = 0.16` and `WEAK = 0.0`, hence:

    if (0.16) AND (0.0) then on HALF

This is computed using the `MIN()` function as

    (0.16) | (0.0) = (0.0)

Thus, the rule doesn’t fire at all. On the other hand, let’s take a look at the rule

    if CLOSE AND ENERGIZED then ON HALF

This means

    if (0.11) AND (0.25) then ON HALF

which, computed using the `MIN()` function, is

    (0.11) | (0.25) = (0.11)

A-ha! The rule `ON HALF` fires at a level of 0.11, so you place that value in the FAM associated with the rule `ON HALF` at the intersection of `CLOSE` and `ENERGIZED`. Continue this process for the whole matrix until you’ve found all nine entries. This is shown in Figure 12.47.

At this point, you’re finally ready to defuzzify the FAM. This can be accomplished in a number of ways. Basically, you need a final crisp value that represents the thrust level from (0.0 to 10.0). There are two main ways to compute this: You can use the disjunction or `MAX()` method to find the value, or you can use an averaging technique based on the fuzzy centroid. Let’s take a look at the `MAX()` method first.

Method 1: The MAX Technique

If you look at the FAM data, you have the following fuzzy outputs:

`OFF` | (0.0)
`ON HALF` | {0.16, 0.11, 0.16}, use sum which is 0.43
`ON FULL` | (0.16)

Note that the rule `ON HALF` has fired within three different outputs, so you have to decide what you want to do with the results. Should you add them, average them, or max them? It’s really up to you. For this example, choose sum: 0.16+0.11+0.16 = .43.

This is still fuzzy, but looking at the data, it looks like `ON HALF` has the strongest membership. So it makes sense to just go with that:

    output = MAX(OFF, ON HALF, ON FULL)

           = MAX(0.0, 0.43, 0.16) = 0.43

Using the disjunction operator v:

    (0.0) v (0.43) v (0.16) = (0.43)

And that’s it. Simply multiply (0.43) times the scale of the output, and that’s the answer:

    (0.43) * (10) = (4.3)

    Set the thrust to (4.3).

The only problem with this method is that even though you’re taking the variable that has the highest membership, its total area of influence in the fuzzy space may be very small. For example, a 40% `NORMAL` is definitely stronger than a 50% `WEAK`. See my point? It might be better to plug some of the values into the output fuzzy manifold for (`OFF`, `ON HALF`, `ON FULL`), compute the area of influence, and then compute the centroid of the whole thing and use that as the final output.

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.