A rtificial I ntelligence for Games
description
Transcript of A rtificial I ntelligence for Games
![Page 1: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/1.jpg)
Artificial Intelligence for Games
Lecture 5
1
Minor Games Programming
![Page 3: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/3.jpg)
Theory: Fuzzy Logic,(see study book: chapter 10)
3
Crisp and Fuzzy Sets with Operators Fuzzy Rules Fuzzy Inference Procedure
Coding a Fuzzy Logic Module Fuzzy Logic Classes in Raven The Combs Method
![Page 4: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/4.jpg)
Fuzzy Logic:how to make perfect cheese on toast:
4
1. Cut two slices of bread medium thick.2. Turn the heat on the griddle on high.3. Grill the slices on one side until golden
brown.4. Turn the slices over and add a generous
helping of cheese.5. Replace and grill until the top of the cheese
is slightly brown.6. Remove, sprinkle on a small amount of
black pepper, and eat.
![Page 5: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/5.jpg)
intermezzo
5
What is medium thick ?
1 cm?
And what about 0,999 cm?
Discrete intervals are sometimes to rigid.
![Page 6: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/6.jpg)
Fuzzy Logic
6
Fuzzy logic, invented by a man named Lotfi Zadeh in the mid-sixties, enables a computer to reason about linguistic terms and rules in a way similar to humans
![Page 7: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/7.jpg)
Fuzzy rule-based inference
7
![Page 8: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/8.jpg)
Crisp Sets,an object belongs to a set or it doesn’t
8
![Page 9: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/9.jpg)
Crisp Sets,a graphical way of showing your IQ
9
Dumb = {70, 71, 72, … 89} Average = {90, 91, 92, … 109} Clever = {110, 111, 112, … 129}
![Page 10: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/10.jpg)
Fuzzy Sets
10
Dumb = {60, 61, …, 100} Average = {80, 81, … 120} Clever = {100, 101, … 140}
![Page 11: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/11.jpg)
Defining Fuzzy Boundaries with Membership Functions
11
DOM (degree of membership)
![Page 12: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/12.jpg)
fuzzy set, Membership value, DOM
12
The dotted line shows the IQ of 115, which is a member of two sets:m(115) = { Average/0.25, Clever/0.75 }
Another example:m(80) = {Dumb/1.0, Average/0.0} = {Dumb/1.0}
Note:0.25 = membership degree (DOM)
![Page 13: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/13.jpg)
Exercise Time -1-
13
Student X owns a IQ of 110 What are his degrees of membership in Dumb,
Average and Clever?
![Page 14: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/14.jpg)
Figure 10.6: The set of people who are Average AND Clever
14
![Page 15: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/15.jpg)
Figure 10.7: The set of people who are Average OR Clever
15
![Page 16: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/16.jpg)
Figure 10.8: The complement of Clever
16
![Page 17: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/17.jpg)
Exercise Time -2-:Draw Fuzzy Sets
17
1. The fuzzy set A = NOT (Average OR Dumb)2. The fuzzy set: B = (Average AND Clever) OR
(NOT Dumb)
![Page 18: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/18.jpg)
Exercise Time -3-
18
1. What is DOM of student X with an IQ of 110 in fuzzy set A?
2. And in fuzzy set B?
3. Which IQ belongs to a DOM value of 0.5 in fuzzy set A?
4. And in fuzzy set B?
![Page 19: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/19.jpg)
Hedges
19
Hedges are unary operators that can be employed to modify the meaning of a fuzzy set. Two commonly used hedges are VERY and FAIRLY
![Page 20: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/20.jpg)
Fuzzy Modifiers
20
Possible fuzzy definitionsvery(a) = a2
extremely(a) = a3
moreorless(a) = a1/2
slightly(a) = a1/3
exactly(a) = a+
always(a) = a0
Example: DOM(90) in fuzzy set: Very(Dumb) is (0.5) 2
![Page 21: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/21.jpg)
Fuzzy Linguistic Variables (or FLV)
21
A fuzzy linguistic variable (or FLV) is the composition of one or more fuzzy sets to represent a concept or domain qualitatively.
Given our earlier example, the sets Dumb, Average, and Clever are members of the fuzzy linguistic variable IQ.
This can be written in set notation as:
IQ ={Dumb, Average, Clever}
![Page 22: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/22.jpg)
Designing FLV’s
22
There are a couple of important guidelines to adhere to when designing FLVs. They are:
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).
For any vertical line drawn through the FLV, it should only intersect with two or fewer fuzzy sets.
![Page 23: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/23.jpg)
Badly designed FLV’s:
23
![Page 24: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/24.jpg)
Fuzzy Rules
24
Fuzzy rules are comprised of an antecedent and a consequent in the form:
IF antecedent THEN consequent
The antecedent represents a condition and the consequent describes the consequence if that condition is satisfied. This type of rule is familiar to all programmers.
![Page 25: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/25.jpg)
Fuzzy Rules Examples
25
IF Target_isFarRight THEN Turn_QuicklyToRight
IF VERY(Enemy_BadlyInjured) THEN Behavior_Aggressive
IF Target_isFarAway AND Allegiance_isEnemy THEN Shields_OnLowPower
IF MOREORLESS(Coffee_Break_Time) AND EXTREMELY(Sleepy) THEN Take_A_Cup
![Page 26: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/26.jpg)
Fuzzy Inference
26
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,a) For each antecedent, calculate the degree of
membership of the input data.b) 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.
![Page 27: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/27.jpg)
Fuzzy rule-based inference
27
![Page 28: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/28.jpg)
An Example:Weapon Selection in RAVEN
28
Steps:1. Designing FLVs for Weapon Selection2. Designing the Rule Set for Weapon Selection3. Fuzzy Inference
To keep the example simple, we'll say the desirability of selecting a particular weapon from the inventory is dependent on two factors: the distance to the target and the amount of ammo
![Page 29: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/29.jpg)
Example Raven:FLV Desirability (consequent)
29
![Page 30: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/30.jpg)
Example Raven:antecedent: Distance to Target
30
![Page 31: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/31.jpg)
Example Raven:Designing the Ammo Status FLV (for each weapon type)
31
![Page 32: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/32.jpg)
Example Raven:Designing the Rule Set for Weapon Selection -1-
32
To cover all the possibilities, a rule must be created for each possible combination of antecedent sets.
The FLVs Ammo Status and Distance to Target each contain three member sets, so to cover every combination nine rules must be defined.
The rules must be defined by an expert user!
![Page 33: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/33.jpg)
Example Raven:Designing the Rule Set for Weapon Selection -2-
33
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
![Page 34: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/34.jpg)
Example Raven:Fuzzy Inference
34
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…
![Page 35: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/35.jpg)
Example Raven:Fuzzy Inference, Rule One
35
IF Target_Far AND Ammo_Loads THEN Desirable
![Page 36: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/36.jpg)
Example Raven:Fuzzy Inference, Rule Two
36
IF Target_Far AND Ammo_Okay THEN Undesirable
![Page 37: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/37.jpg)
Example Raven:Fuzzy Inference, Rule Three
37
IF Target_Far AND Ammo_Low THEN Undesirable
![Page 38: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/38.jpg)
EXERCISE TIME
38
Fuzzy Inference, Rule 5:
IF Target_Medium AND Ammo_Okay THEN VeryDesirable
Draw and compute the inferred conclusion for VeryDesirable
![Page 39: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/39.jpg)
Example Raven: Rules one to nine in fuzzy associative matrix (FAM)
39
![Page 40: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/40.jpg)
Inferred conclusions
40
Undesirable 0.33 (maximum value of 0.33 and 0.2)
Desirable 0.2 Very Desirable 0.67
![Page 41: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/41.jpg)
The inferred results of processing the rule set for weapon selection
41
![Page 42: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/42.jpg)
Combining the conclusions
42
![Page 43: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/43.jpg)
Defuzzification
43
Now that we have a composite fuzzy set representing the inferred conclusion of all the rules in the rule base, it's time to turn the process around and convert this output set into a single crisp value. This is achieved by a process called defuzzification.
Many techniques are possible (see study book): Mean of Maximum (MOM) Centroid Average of Maxima (MaxAv)
![Page 44: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/44.jpg)
Example Raven:Defuzzification
44
Mean of Maximum (MOM) 83
Centroid 62
Average of Maxima (MaxAv) 60.625
![Page 45: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/45.jpg)
Example Raven:Selection
45
If this whole process is repeated for each weapon type a bot is carrying, it's a simple matter to select the one with the highest desirability score to be the weapon the bot should use given its current situation.
![Page 46: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/46.jpg)
Homework
46
Homework Study Chapter 10 Fuzzy Logic, pages 415 to 437.
![Page 47: A rtificial I ntelligence for Games](https://reader036.fdocuments.net/reader036/viewer/2022062501/56816334550346895dd3ba67/html5/thumbnails/47.jpg)
Practice (next TUESDAY)
47
Program a fuzzy (console) application in C++.
You must use the FuzzyModule Class (and others) of Buckland, see study book pages 437 to 452. The sources will be on Blackboard.
For an example see weapon selection code in Raven.
TIP: Use your study book during next practice!