Presentation is loading. Please wait.

Presentation is loading. Please wait.

Artificial Intelligence in Game Design Lecture 6: Fuzzy Logic and Fuzzy State Machines.

Similar presentations


Presentation on theme: "Artificial Intelligence in Game Design Lecture 6: Fuzzy Logic and Fuzzy State Machines."— Presentation transcript:

1 Artificial Intelligence in Game Design Lecture 6: Fuzzy Logic and Fuzzy State Machines

2 Problems with Discrete States Characters may be in multiple states simultaneously –Particularly emotional states Hit  angry Low HP  frightened May indicate contradictory responses –Frightened  run –Angry  attack Need “intermediate” states and actions –“Somewhat angry” –“Somewhat frightened”

3 Problems with Discrete States Abrupt transitions between states –Exact behavior from 100 down to 10 HP –Sudden behavior change at 9 HP More realistic if behavior gradually changes as HP approaches 10 Angry Snarling Moving forward Frightened Wincing Backing away HP < 10

4 Problems with Discrete States Serious problem if action is continuous value –Example: Racing games Actions: Speed of car Amount to steer … –Basic idea: Near curve  slow speed Far from curve  fast speed

5 Problems with Discrete States Bad solution (based on discrete states) –Distance to curve > 10  120 mph –Distance to curve <= 10  60 mph Sudden transition!

6 Problems with Discrete States Best solution: –As get closer to curve, gradually slow down –As get further from curve, gradually speed up

7 Fuzzy Logic Membership function µ S (x) –“Degree” to which entity X belongs in state S –Discrete states: µ S (x) = 1  X is in state S or 0  X is not in state S Fuzzy states: µ S (x) may be any number between 0 and 1 –X may be “somewhat” in state S

8 Fuzzy Logic and Language Often used to quantify “natural language” hedges Example: –“Not at all”  µ S (x) = 0 –“A little”  µ S (x) = 0.2 –“Kind of”  µ S (x) = 0.4 –“Pretty”  µ S (x) = 0.6 –“Very”  µ S (x) = 0.8 –“Absolutely”  µ S (x) = 1.0

9 Fuzzy Logic Example Example: Oswald the Orc –Very angry µ angry (Oswald) = 0.8 –Kind of frightened µ frightened (Oswald) = 0.4 –Not at all confident µ confident (Oswald) = 0.0 Note that fuzzy memberships don’t have to add up to 1 (unlike probabilities)

10 Fuzzification Converting a continuous valued attribute to a fuzzy state membership Racing example: –Attribute = car’s distance from curve –Fuzzy states: Near curve Far from curve –Goal: determine membership of car in these sets –First step to determine desired speed of car Start of curve

11 Fuzzification Often represent as simple graphs –X axis: continuous attribute –Y axis: membership in set(s) –Example: current distance = 60 distance to curve 020406080100120 NearFar 0.4 0.6 µ near (car) = 0.6 µ far (car) = 0.4

12 Fuzzy Rules Fuzzy antecedent  Fuzzy conclusion Fuzzy antecedent created from fuzzification Requires fuzzy definitions of logical connectives AND, OR, and NOT. Given fuzzy membership in this What is fuzzy membership in this?

13 Fuzzy Connectives Usual measures: AND: µ S and T (x) = min ( µ S (x), µ T (x)) OR: µ S or T (x) = max ( µ S (x), µ T (x)) Note: this also applies if combining separate rules NOT: µ not T (x) = 1 - µ T (x)

14 Fuzzy Rule Example Rules: IF near curve exit AND going slow THEN accelerate IF far from curve exit AND going medium THEN accelerate Question: If near, far, slow, medium all fuzzy measures What is resulting membership in accelerate? Speed: 100 mph Distance from exit: 80

15 Fuzzy Rule Example distance to curve 020406080100120 NearFar 0.4 0.6 µ near (car) = 0.4 µ far (car) = 0.6 speed 0306090120150180 SlowFast 0.3 1.0 µ slow (car) = 0.3 µ medium (car) = 1.0 Medium

16 Fuzzy Rule Example Rule 1: IF near curve exit AND going slow THEN accelerate µ accelerate ( car ) = µ near and slow ( car ) = min ( µ near ( car ), µ slow ( car )) = min(0.4, 0.3) = 0.3 Rule 2: IF far curve exit AND going medium THEN accelerate µ accelerate ( car ) = µ far and medium ( car ) = min ( µ far ( car ), µ medium ( car )) = min(0.6, 1.0) = 0.6

17 Fuzzy Rule Example Combining the rules: µ accelerate ( car ) = µ accelerate1 or accelerate2 ( car ) = max ( µ accelerate1 ( car ), µ accelerate2 ( car )) = max(0.3, 0.6) = 0.6 Membership of the car in accelerate = 0.6

18 Defuzzification Converting fuzzy state membership to appropriate actions –Higher membership in state  greater degree of action implied by state Possible problems –Conflicts if multiple actions indicated –Some actions not fuzzy (attack vs. no attack) –Many open problems!

19 Simple Defuzzification Create fuzzy set for action Map membership in set back to value –Assumes no conflicts with other actions based on same value –Assumes monotonic function for fuzzy set Example: µ accelerate ( car ) = 0.6  acceleration = 16 feet/second 2 feet/second 2 051015202530 Acceleration 0.6

20 Conflicts in Defuzzification Example rule: IF near curve entrance AND going fast THEN brake –Distance: 90  µ near (car) = 0.2 –Speed: 80  µ fast (car) = 0.15 –µ brake (car) = min (0.2, 0.15) = 0.15

21 Conflicts in Defuzzification Conflicting fuzzy actions: –µ accelerate ( car ) = 0.6 –µ brake ( car ) = 0.15 Intuitive idea: –Should accelerate since its membership is larger –Membership in brake should decrease acceleration to some degree

22 Conflicts in Defuzzification Methods: Just use largest rule (µ accelerate ( car ) = 0.6 ) –Fast to compute –Leads to uneven behavior Weighted center of mass of sets –Commonly used in AI –Slow and costly to compute -15-10-5-051015 Acceleration 0.6 feet/second 2 Braking 0.15

23 Conflicts in Defuzzification 1.Choose one value for each set –Usually its maximum value 2.Weight by memberships in each set 3.Determine average value Example: –Maximum acceleration = 30 feet/second 2 –Maximum braking = -40 feet/second 2 Weighted by membership: –Acceleration = 0.6 * 30 feet/second 2 = 18 feet/second 2 –Braking = 0.15 * -40 feet/second 2 = -6 feet/second 2 Resulting acceleration: 12 feet/second 2

24 Defuzzifying Discrete Actions Example: Attack/No attack (must do one or the other) Thresholding: –If fuzzy membership > threshold take action –Example: If µ angry ( orc ) > 0.7  attack If µ angry ( orc ) <= 0.7  no attack Conflicts: Take action with highest membership –Angry  attack, µ angry ( Oswald ) = 0.7 –Frightened  run, µ frightened ( Oswald ) = 0.3 Note: Fuzzy logic works best for continuous valued actions Oswald attacks!

25 Fuzzy State Machines Fuzzy membership in states –May be in multiple states –Transitions between states may be fuzzy –Resulting actions may be fuzzy Example: –May be confident and fearful to some degree –Transitions based on fuzzy measures “high” and “low” HP –Action (% chance of attack) is continuous valued Confident Attack 100% HP low Fearful Attack 20% HP high

26 Fuzzy State Machines Transitions of form treated like fuzzy and –Must be in state S1 –Stimulus T must be present µ S2 ( orc ) = min( µ S1 ( orc ), µ T ( orc ) ) Note that unless µ S2 ( orc ) = 1, it is still in S1 to some degree: µ S1 ( orc ) = 1 - µ S2 ( orc ) Note that state S2 may be indicated as a next state by many other states (including itself) –Will use max rule to determine final membership in S2 S1S2 T

27 Fuzzy State Machine Example Current state memberships –µ conf (Oswald) = 0.8 –µ fear (Oswald) = 0.4 Confident Attack 100% HP low Fearful Attack 40% HP high

28 Fuzzy State Machine Example Current HP = 13 (just took heavy hit by player) –µ low (Oswald) = 0.7 –µ high (Oswald) = 0.2 HP LowHigh 051015202530

29 Fuzzy State Machine Example Confident  Fearful transition –µ fear (Oswald) = min ( µ conf (Oswald), µ low (Oswald)) = min (0.8, 0.7) = 0.7 –µ conf (Oswald) = 1 - µ fear (Oswald) = 0.3 Fearful  Confident transition –µ conf (Oswald) = min( µ fear (Oswald), µ high (Oswald)) = min (0.4, 0.2) = 0.2 –µ fear (Oswald) = 1 - µ conf (Oswald) = 0.8

30 Fuzzy State Machine Example Combining effects of transitions –µ conf (Oswald) = max (0.3, 0.2) = 0.3 –µ fear (Oswald) = max (0.7, 0.8) = 0.8 Determining current action (defuzzification) –Attack % = ( µ conf (Oswald) * 100% + µ fear (Oswald) * 20% ) / 2 = (0.4 * 100% + 0.7 * 20% ) / 2 = 46%


Download ppt "Artificial Intelligence in Game Design Lecture 6: Fuzzy Logic and Fuzzy State Machines."

Similar presentations


Ads by Google