## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required Rule 1. IF Target_Far AND Ammo_Loads THEN Desirable
Rule 2. IF Target_Far AND Ammo_Okay THEN Undesirable
Rule 3. IF Target_Far AND Ammo_Low THEN Undesirable
Rule 4. IF Target_Medium AND Ammo_Loads THEN VeryDesirable
Rule 5. IF Target_Medium AND Ammo_Okay THEN VeryDesirable
Rule 6. IF Target_Medium AND Ammo_Low THEN Desirable
Rule 7. IF Target_Close AND Ammo_Loads THEN Undesirable
Rule 8. IF Target_Close AND Ammo_Okay THEN Undesirable
Rule 9. IF Target_Close AND Ammo_Low THEN Undesirable
Note that these rules are only my opinion and will reflect my level of
expertise in the game. When you design the rules for your own game, con
-
sult the best player you have on your development team because the more
expert the player you derive the rules from, the better your AI will perform.
This makes sense in the same way that Michael Schumacher will be able to
describe a much better set of rules for driving a Formula One racing car
than you or me.
Fuzzy Inference
It’s now time to study the fuzzy inference procedure. This is where we
present the system with some values to see which rules fire and to what
degree. Fuzzy inference follows these steps:
1. For each rule,
1a. For each antecedent, calculate the degree of membership of the
input data.
1b. Calculate the rule’s inferred conclusion based upon the values
determined in 1a.
2. Combine all the inferred conclusions into a single conclusion (a fuzzy
set).
3. For crisp values, the conclusion from 2 must be defuzzified.
Let’s now work through these steps using some of the rules we’ve created
for weapon selection and some crisp input values. Let’s say the target is at
a distance of 200 pixels and the amount of ammo remaining is 8 rockets.
One rule at a time then…
Rule One
IF Target_Far AND Ammo_Loads THEN Desirable
The degree of membership of the value 200 to the set Target_Far is 0.33.
The degree of membership of the value 8 in the set Ammo_Loads is 0. The
AND operator results in the minimum of these values so the inferred con
-
clusion for Rule 1 is Desirable =0. In other words, the rule doesn’t fire.
Figure 10.15 shows this rule graphically.
Fuzzy Logic | 429
Fuzzy Rules Rule Two
IF Target_Far AND Ammo_Okay THEN Undesirable
For the second rule the degree of membership of the value 200 to the set
Target_Far is 0.33. The degree of membership of the value 8 in the set
Ammo_Okay is 0.78. The inferred conclusion for Rule 2 therefore is Unde-
sirable = 0.33. See Figure 10.16.
Rule Three
IF Target_Far AND Ammo_Low THEN Undesirable
Appling the same values to the third rule, the degree of membership of the
value 200 to the set Target_Far is 0.33. The degree of membership of the
value 8 in the set Ammo_Low is 0.2. The inferred conclusion for Rule 3
therefore is Undesirable = 0.2. See Figure 10.17.
430 | Chapter 10
Fuzzy Rules
Figure 10.15. The value enclosed by the circle indicates the inferred conclusion.
Figure 10.16. Rule 2
Figure 10.17. Rule 3 I’m sure you’ve got the gist of this by now so to spare a lot of repetition the
inferred results for all the rules are summarized by the matrix shown in
Figure 10.18. (This type of matrix is known as a fuzzy associative matrix,
or FAM for short.)
Note that VeryDesirable has fired once to a degree of 0.67. Desirable has
fired once to a degree of 0.2, and Undesirable has fired twice with the
degrees 0.2 and 0.33. One way to think of these values is as confidence
levels. Given the input data, the fuzzy rules have inferred the result
VeryDesirable with a confidence of 0.67 and the result Desirable with a
confidence of 0.2. But what conclusion is inferred for Undesirable, which
has fired twice? Well, there are a few ways of handling multiple confi
-
dences. The two most popular are bounded sum (sum and bound to 1) and
maximum value (equivalent to ORing the confidences together). It doesn’t
make a vast amount of difference which method you choose. I prefer to OR
the values together, which in this example results in a confidence for Unde
-
sirable of 0.33.
To summarize, Table 10.1 lists the inferred conclusions of applying the
values of distance to target = 200 and ammo status=8toalltherules.
Fuzzy Logic | 431
Fuzzy Rules
Figure 10.18. The FAM for the weapon selection rule base given the input values tar-
get distance = 200 and ammo status = 8. The shaded cells highlight rules that have
fired. Table 10.1
Consequent Confidence
Undesirable 0.33
Desirable 0.2
Very Desirable 0.67
These results are shown graphically in Figure 10.19. Notice how the mem
-
bership function of each consequent is clipped to the level of confidence.
The next step is to combine the inferred results into a single fuzzy mani
-
fold. See Figure 10.20.
432 | Chapter 10
Fuzzy Rules
Figure 10.19. The inferred results of processing the rule set for weapon selection

## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required