1 / 47

A rtificial I ntelligence for Games

Minor Games Programming. A rtificial I ntelligence for Games. Lecture 5 . Artificial Intelligence for Games. Theory: Short introduction to Fuzzy Logic. Jan Verhoeven j.verhoeven@windesheim.nl. Theory: Fuzzy Logic, (see study book: chapter 10). Crisp and Fuzzy Sets with Operators

dacian
Download Presentation

A rtificial I ntelligence for Games

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Minor Games Programming Artificial Intelligence for Games Lecture 5

  2. Artificial Intelligence for Games • Theory: • Short introduction to Fuzzy Logic Jan Verhoeven j.verhoeven@windesheim.nl

  3. Theory: Fuzzy Logic,(see study book: chapter 10) • Crisp and Fuzzy Sets with Operators • Fuzzy Rules • Fuzzy Inference Procedure • Coding a Fuzzy Logic Module • Fuzzy Logic Classes in Raven • The Combs Method

  4. Fuzzy Logic:how to make perfect cheese on toast: • Cut two slices of bread medium thick. • Turn the heat on the griddle on high. • Grill the slices on one side until golden brown. • Turn the slices over and add a generous helping of cheese. • Replace and grill until the top of the cheese is slightly brown. • Remove, sprinkle on a small amount of black pepper, and eat.

  5. intermezzo • What is medium thick ? • 1 cm? • And what about 0,999 cm? • Discrete intervals are sometimes to rigid.

  6. Fuzzy Logic • Fuzzy logic, invented by a man named LotfiZadeh in the mid-sixties, enables a computer to reason about linguistic terms and rules in a way similar to humans

  7. Fuzzy rule-based inference

  8. Crisp Sets,an object belongs to a set or it doesn’t

  9. Crisp Sets,a graphical way of showing your IQ • Dumb = {70, 71, 72, … 89} • Average = {90, 91, 92, … 109} • Clever = {110, 111, 112, … 129}

  10. Fuzzy Sets • Dumb = {60, 61, …, 100} • Average = {80, 81, … 120} • Clever = {100, 101, … 140}

  11. Defining Fuzzy Boundaries with Membership Functions DOM (degree of membership)

  12. fuzzy set, Membership value, DOM 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)

  13. Exercise Time -1- • Student X owns a IQ of 110 • What are his degrees of membership in Dumb, Average and Clever?

  14. Figure 10.6: The set of people who are Average AND Clever

  15. Figure 10.7: The set of people who are Average OR Clever

  16. Figure 10.8: The complement of Clever

  17. Exercise Time -2-: Draw Fuzzy Sets • The fuzzy set A = NOT (Average OR Dumb) • The fuzzy set: B = (Average AND Clever) OR (NOT Dumb)

  18. Exercise Time -3- • What is DOM of student X with an IQ of 110 in fuzzy set A? • And in fuzzy set B? • Which IQ belongs to a DOM value of 0.5 in fuzzy set A? • And in fuzzy set B?

  19. Hedges • Hedges are unary operators that can be employed to modify the meaning of a fuzzy set. Two commonly used hedges are VERY and FAIRLY

  20. Fuzzy Modifiers • Possible fuzzy definitions very(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

  21. Fuzzy Linguistic Variables (or FLV) • 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}

  22. Designing FLV’s 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.

  23. Badly designed FLV’s:

  24. Fuzzy Rules • 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.

  25. Fuzzy Rules Examples • 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

  26. Fuzzy Inference This is where we present the system with some values to see which rules fire and to what degree. Fuzzy inference follows these steps: • For each rule, • For each antecedent, calculate the degree of membership of the input data. • Calculate the rule's inferred conclusion based upon the values determined in 1a. • Combine all the inferred conclusions into a single conclusion (a fuzzy set). • For crisp values, the conclusion from 2 must be defuzzified.

  27. Fuzzy rule-based inference

  28. An Example:Weapon Selection in RAVEN Steps: • Designing FLVs for Weapon Selection • Designing the Rule Set for Weapon Selection • 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

  29. Example Raven:FLV Desirability (consequent)

  30. Example Raven:antecedent: Distance to Target

  31. Example Raven:Designing the Ammo Status FLV (for each weapon type)

  32. Example Raven:Designing the Rule Set for Weapon Selection -1- • To cover all the possibilities, a rule must be created for each possible combination of antecedent sets. • The FLVs Ammo Status and Distance toTarget each contain three member sets, so to cover every combination nine rules must be defined. • The rules must be defined by an expert user!

  33. Example Raven:Designing the Rule Set for Weapon Selection -2- • 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

  34. Example Raven:Fuzzy Inference • 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…

  35. Example Raven:Fuzzy Inference, Rule One IF Target_Far AND Ammo_Loads THEN Desirable

  36. Example Raven:Fuzzy Inference, Rule Two IF Target_Far AND Ammo_Okay THEN Undesirable

  37. Example Raven:Fuzzy Inference, Rule Three IF Target_Far AND Ammo_Low THEN Undesirable

  38. EXERCISE TIME • Fuzzy Inference, Rule 5: • IF Target_Medium AND Ammo_Okay THEN VeryDesirable • Draw and compute the inferred conclusion for VeryDesirable

  39. Example Raven: Rules one to nine in fuzzy associative matrix (FAM)

  40. Inferred conclusions • Undesirable 0.33 (maximum value of 0.33 and 0.2) • Desirable 0.2 • Very Desirable 0.67

  41. The inferred results of processing the rule set for weapon selection

  42. Combining the conclusions

  43. Defuzzification • 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)

  44. Example Raven:Defuzzification • Mean of Maximum (MOM)  83 • Centroid 62 • Average of Maxima (MaxAv)  60.625

  45. Example Raven:Selection 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.

  46. Homework • Homework • Study Chapter 10 Fuzzy Logic, pages 415 to 437.

  47. Practice (next TUESDAY) • 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!

More Related