1 / 30

Artificial Intelligence in Game Design

Artificial Intelligence in Game Design. Fuzzy Logic and Fuzzy State Machines. 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

gunnar
Download Presentation

Artificial Intelligence in Game Design

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. Artificial Intelligence in Game Design 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 gamesActions: • 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 Near Far 0.6 0.4 distance to curve 0 20 40 60 80 100 120 µ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. What is fuzzy membership in this? Given 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 measuresWhat is resulting membership in accelerate? Speed: 100 mph Distance from exit: 80

  15. Fuzzy Rule Example Near Far 0.6 0.4 distance to curve 0 20 40 60 80 100 120 µnear (car) = 0.4 µ far (car) = 0.6 1.0 Slow Fast Medium 0.3 speed 0 30 60 90 120 150 180 µslow (car) = 0.3 µ medium (car) = 1.0

  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/second2 Acceleration 0.6 feet/second2 0 5 10 15 20 25 30

  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 Braking Acceleration 0.6 0.15 feet/second2 -15 -10 -5 -0 5 10 15

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

  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  attackIf µ 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 HP low Confident Attack 100% Fearful Attack 20% HP high

  26. Fuzzy State Machines T • Transitions of formtreated 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 maybe indicated as a next state by many other states (including itself) • Will use max rule to determine final membership in S2 S1 S2

  27. Fuzzy State Machine Example • Current state memberships • µ conf(Oswald) = 0.8 • µ fear(Oswald) = 0.4 HP low Confident Attack 100% 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 Low High HP 0 5 10 15 20 25 30

  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%

More Related