Game Development Reference

In-Depth Information

Rule evaluation involves substituting the degrees of membership into the

rules given. For example, if the value for
health is good
was 17% and the value

for
shield is adequate
was 25%, Rule 1 would become:

if 17% and 25%
then mood is (17%) happy

Only the part of the rule in the
if statement
(shown in bold) has the fuzzy

values substituted. If the values are connected by an AND, the smallest degree

of membership is assigned to the
then
part. If the values are connected by an

OR, the larger degree of membership is assigned. Assuming
health is bad
is

50% and
shield is moderate
is 25%, Rule 2 would become:

if 50% or 25%
then mood is (50%) indifferent

These values are then used to
clip
the fuzzy sets for happy and indifferent

pertaining to mood. In brief, 17% of the happy set and 50% of the indifferent

set are merged to create a new fuzzy set as shown in
Figure 5.17
. This is the

third step of Rule Aggregation.

The final step is defuzzification. This takes the final aggregated fuzzy set

and converts it into a single value that will be the fuzzy output. The final

fuzzy set contains the value; all that is needed is to extract it. The simplest

method for doing this is called the
centroid
technique, which finds the

mathematical center of gravity of the set. This involves multiplying all the

values in the set with their degree of membership, adding them together,

and dividing by the sum of all the degrees of membership in the set. This

gives a percentage value, in this case, pertaining to the
mood
value. For

example, the result might be a 40% mood that would result in the mood

being
indifferent
.

Developing a fuzzy logic engine requires a great deal of understanding

in programming and mathematics. There is certainly not enough room in

this chapter to provide a full example. Therefore, the next workshop uses

an Open Source fuzzy logic engine called DotFuzzy (available from
http://

havana7.com/dotfuzzy/
) written in C#.

FIG 5.17
Merged fuzzy sets.