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

Studying the values, there are a number of interesting properties. First, note that for any input value `xi`, the results of membership don’t add up to 1.0. Remember, these are degrees of membership, not probabilities, so this is okay.

Secondly, for some `xi`’s the DOM falls within one or two different fuzzy variables. There could have easily been cases where an input fell into all three regions (if I made the triangles big enough). The process of selecting the size (range) of each triangle is called tuning, and sometimes you may have to do this repeatedly to get the results you want. I tried to pick ranges that worked out nicely for examples, but in real life you may need more than three FLVs. And they may not have nice endpoints that are all multiples of 50!

For an example of creating a fuzzy manifold for some input and a number of FLVs, check out `DEMO12_9.CPP|EXE` on the CD. It enables you to create a number of fuzzy linguistic variables—that is, categories for some input domain. Then you can input numbers and it gives you the degree of membership for each input. It’s a console application, so compile appropriately. The data printed for membership is also normalized to 1.0 each time. This is accomplished by taking each DOM and dividing by the sum of DOMs for each category.

At this point you know how to create a fuzzy manifold for an input `xi` that is composed of a number of ranges, each of which is represented by a fuzzy linguistic variable. Then you select an input in the range, compute the degree of membership for each FLV in the manifold, and come up with a set of numbers for that particular input. This is called fuzzifaction.

The real power of fuzzy logic comes into play when you fuzzify two or more variables, connect them with if rules, and see the output. To accomplish this step, first you have to come up with another input to fuzzify—let’s call it the power level of the AI bot that you’re moving around. Figure 12.42 shows the fuzzy manifold for the power level input.

Figure 12.42 The fuzzy manifold for the power level.

The fuzzy linguistic variables are as follows:

`WEAK` | Domain range (0.0 to 3.0)
`NORMAL` | Domain range (2.0 to 8.0)
`ENERGIZED` | Domain range (6.0 to 10.0)

Notice that this fuzzy variable domain is from 0 to 10.0, rather than 0 to 1000 as is the range to player variable. This is totally acceptable. You could have added more than three FLVs, but three makes the problem symmetrical. To process both fuzzy variables, you need to construct a rule base and then create a fuzzy associate matrix, so let’s talk about that next.

#### Fuzzy Associative Matrices

Fuzzy associative matrices, or FAMs, are used to infer a result from two or more fuzzy inputs and a given rule base and output a fuzzy or crisp value. Figure 12.43 shows this graphically.

Figure 12.43 Using a fuzzy associative matrix.

In most cases, FAMs deal with only two fuzzy variables because this can be laid out in a 2D matrix; one variable represents each axis. Each entry in the matrix is the logical proposition “if Xi AND Yi then Zi,” where Xi is the fuzzy linguistic variable on the x-axis, Yi is the fuzzy linguistic variable on the y-axis, and Zi is the outcome—which may be a fuzzy variable or crisp value.

To build the FAM, you need to know the rules and the outputs to put in each of the matrix entries. In other words, you need to make a rule base and decide on an output variable that is either crisp or linear. A crisp output would be {“ATTACK”, “WANDER”, “SEARCH”}, while a linear output might be a thrust level from (0 to 10). Obtaining either one is relatively the same; in both cases, you have to defuzzify the output of the FAM and find the output.

You’re going to see examples of both a crisp singular output that selects a class and one that simply outputs a value in a range. Much of the setup is the same. First, let’s see the example that computes a range as the final output:

  1. Select your inputs, define the FLVs, and build your manifolds.

  The inputs to your fuzzy system are going to be the range to the player and the power level of the AI-controlled bot.

  Input X | Range to player.
  Input Y | Power level of self

  Refer again to Figures 12.37 and 12.42—these are the fuzzy manifolds that you’re using.

  2. Create a rule base for the inputs that tie them to an output.

  The rule base is nothing more than a collection of logical propositions of the form “if X AND Y then Z” or “if X OR Y then z.” This makes a difference when you’re computing the `FAM` outputs. A logical `AND` means “minimum of the set,” while a logical `OR` means “maximum of the set” when dealing with fuzzy set theory. For now, use all `AND`s, but I’ll explain how to use `OR`s later.

In general, if you have two fuzzy inputs and each input has m FLVs, the fuzzy associative matrix will have dimension m×m. And since each element represents a logical proposition, this means you need nine rules (3×3 = 9) that define all possible logical combinations and the output for each.

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.