## 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

The difference with fuzzy rules is that unlike conventional rules where the
consequent either fires or not, in fuzzy systems the consequent can fire to a
matter of degree. Here are some examples of fuzzy rules:
IF Target_isFarRight THEN Turn_QuicklyToRight
IF Target_isFarAway AND Allegiance_isEnemy THEN
Shields_OnLowPower
IF Ball_isCloseToHole AND Green_isLevel THEN HitBall_Gently
AND HitBall_DirectlyAtHole
IF (Bend_HairpinLeft OR Bend_HairpinRight ) AND Track_SlightlyWet
THEN Speed_VerySlow
The antecedent, then, can be a single fuzzy term or the set that is the result
of a combination of several fuzzy terms. The degree of membership of the
antecedent defines the degree to which the consequent fires. A fuzzy infer-
ence system is typically comprised of many such rules, the number of
which is proportional to the number of FLVs required for the problem
domain and the number of membership sets those FLVs contain. Each time
a fuzzy system iterates through its rule set it combines the consequents that
have fired and defuzzifies the result to give a crisp value. More on the
details of this in a moment but first, before we delve deeper, let’s design
some FLVs we can use to solve a real-world problem. Given a practical
example you can sink your teeth into, I’m sure you’ll find it much easier to
see how all this stuff works together.
Designing FLVs for Weapon Selection
Because the rules a human player uses to decide when to change weapons
can easily be described using linguistic terms, weapon selection is a good
candidate for the application of fuzzy logic. Let’s see how this idea can be
applied to Raven.
To keep the example simple, we’ll say the desirability of selecting a par
-
ticular weapon from the inventory is dependent on two factors: the distance
to the target and the amount of ammo. Each weapon class owns an instance
of a fuzzy module, and each module is initialized with FLVs representing
the linguistic terms Distance to Target, Ammo Status (antecedents), and
Desirability (consequent), and also with rules pertinent to that weapon.
The rules infer how desirable that weapon is for any given scenario,
enabling a bot to select the weapon with the highest desirability score to be
the current weapon.
The FLVs Distance to Target and Desirability are defined identically
for each weapon type. Ammo Status and the rule set are custom built. The
examples given in this chapter will focus on designing the FLVs and rule
set for the rocket launcher.
Fuzzy Logic | 425
Fuzzy Rules
Designing the Desirability FLV
We’ll start by designing the fuzzy linguistic variable required to denote the
consequent set: Desirability. There are a couple of important guidelines to
adhere to when designing FLVs. They are:
n
For any vertical line (representing an input value) drawn through the
FLV, the sum of the DOMs in each of the fuzzy sets it intersects with
should be approximately 1. This ensures a smooth transition between
values over the FLV’s fuzzy manifold (the combined shape of all
membership sets).
n
For any vertical line drawn through the FLV, it should only intersect
with two or fewer fuzzy sets.
An FLV that breaks the first guideline is shown in Figure 10.11 A, and an
FLV that breaks the second is shown in Figure 10.11 B.
The FLV Desirability is required to represent the domain of all scores
from 0 to 100. Therefore its member sets must adequately cover that range
(while adhering to the guidelines). I have chosen to use three member sets:
a left-shouldered set, a triangular set, and a right-shouldered set, represent
-
ing the linguistic terms Undesirable, Desirable, and VeryDesirable as
shown in Figure 10.12.
426 | Chapter 10
Fuzzy Rules
Designing the Distance to Target FLV
Next, we’ll consider the antecedent: Distance to Target. Once again the
FLV is comprised of three sets, named Target_Close, Target_Medium, and
Target_Far. These three terms are perfectly adequate to enable an expert
(that’s us folks) to determine rules for weapon selection. When I’m playing
a game I think of the term “close” to mean almost next to me — at the sort
of range where you might consider hand-to-hand combat. Therefore I’ve
set the peak of the fuzzy set Target_Close at the distance 25 pixels, which I
feel is about right given the scale of a typical Raven map (a bot has a
bounding radius of about 10 pixels). I’ve chosen to use 150 pixels as the
peak for Target_Medium because that feels about right, and I’ve chosen to
make Target_Far a shoulder shape that peaks at 300 and then plateaus to
400. Notice how I’m not too concerned about the specific values; I’m just
using values that “feel” correct. Distance to Target is shown in Figure
10.13.
Fuzzy Logic | 427
Fuzzy Rules
Figure 10.12. Desirability
Figure 10.13. Distance to Target

## 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