620 likes | 726 Views
Fuzzy Logic. CIS 488/588 Bruce R. Maxim UM-Dearborn. World Objects. Items Direct effect on player state (e.g. health or armor) No direct effect on player state (e.g. invincibility) Strategies to maximize benefits of object collection are important for game bots to appear smart
E N D
Fuzzy Logic CIS 488/588 Bruce R. Maxim UM-Dearborn
World Objects • Items • Direct effect on player state (e.g. health or armor) • No direct effect on player state (e.g. invincibility) • Strategies to maximize benefits of object collection are important for game bots to appear smart • Contraptions (puzzles) • Generally designed to slow down escape or impede access to weapons (e.g. ladder or switch) • A sequence of player actions must precede their use
Test Bed • Fairly easy to test object collection strategies (most game levels have lots of items) • Presence of contraptions is relatively rare since these elements are often architecture centerpieces, so it is harder to test animat abilities to use them without creating simplified custom levels for training
Human Behavior - 1 • Picking up Items • Picking up objects in many games is simply a matter of walking over them • Unlike obstacle avoidance that can be done while wondering, picking up objects requires intentional movement to be efficient • Handling Contraptions • Must combine specific skills (button pressing or waiting) with movement • Sequences of actions (plans) are often required to solve the puzzle of operation
Human Behavior - 2 • Behavior Enhancers • Special skills that improve game play (e.g. dodging projectiles or jumping) • Just like using contraptions these actions may require development of a sequence of actions (plan) and preconditions (e.g. location or timing) for its use
Criteria • To maintain illusion of realism the AI cannot be too good at using items or solving puzzles • Even if the AI is realistic do not over use it • Effectiveness • Make the behavior as efficient as possible (no wasteful moves or pauses) • Consistency • AI actions must be justifiable (follow up actions are taken)
Behavior Case Study - 1 • Opening door • NPC walks toward switch • Pushes switch on contact • NPC stands back while door opens • NPC goes through door • Getting onto platform • NPC press switch • Waits for platform to arrive • Gets on platform and it moves
Behavior Case Study - 2 • Getting on ladder • NPC moves till contact made • NPC must face ladder to avoid falling off • Climbing done by looking up and moving forward • Jump Pads • NPC needs to walk on pad • NPC tossed in the air • Moving while in the air controls the fall
Behavior Case Study - 3 • Dodging • Move away from line of fire for incoming projectiles and their predicted point of impact • Rocket Jumping • NPC needs to look down • Jump using standard command • Shoot a rocket at the ground
Interfaces - 1 • New movement functions (can be used in combination with movement) void Jump( ); void Duck( ); • New inventory functions void ItemsAvailable(vector<Entity>& items, const Entity::Type& unifier = 0); bool UseItem(Symbol& item);
Interfaces - 2 • Vision • No functional extensions needed only additional data past through it • AI will need to use of callback functions like void OnDoorOpen(const Event& event); • Physical State (collection of queries) bool isPlatform( ); bool isLadder( ); bool isWater( ); bool isAir( );
Greedy • Attempts to collect every object in sight • Moves on only after every item is picked up or is inaccessible • Built on steering behaviors • (animat not in archive)
Fuzzy Set Theory • In ordinary set theory every element “x” from a given universe is either in or out of a set S x S x S • In fuzzy set theory set membership is not so easily determined
When is a pile of chalk big? • If we have three pieces of chalk in the room is that considered a big pile of chalk? • Some people might say, yes that is a big pile and some would not. • Someplace between those three pieces of chalk and a whole room full of chalk the pile of chalk turns from a small pile into a big pile. • This could be a different spot for different people.
Membership Function A: X [0,1] x A(x) x X X is universe of discourse x X A(x) x X 1/x
Fuzzy Set • Collection of ordered pairs (x, A(x)) known as a fuzzy singleton • Consider a set A defined as the set of hostile game objects from X X = {door, gun, fred, bot1} a = [0 0 0.3 0.8] A = {(door,0), (gun,0), (fred, 0.3), (bot1, 0.8)}
Fuzzy Set Theoretic Operations Probability Theory Independent Events A(x) a a B(x) b b not A(x) complememt 1-a 1 - a A and B intersection min(a,b) a * b A or B union max(a,b) a + b – a*b A = B equality x: A(x) = B(x) A B subset x: A(x) < B(x)
Fuzzy Modifiers - 1 • In “very dangerous” the word “very” could be thought of as a fuzzy linguistic modifier dangerous = [0 0.1 0.4 0.8 1] very dangerous = [0 0.01 0.16 0.64 1] • More formally we could think of a fuzzy modifier m as a function that converts one fuzzy set a into another set m(a) m: X F(X) a m(a) | a F(X)
Fuzzy Modifiers - 2 • Possible fuzzy definitions very(a) = a2 extremely(a) = a3 moreorless(a) = a1/2 slightly(a) = a1/3 exactly(a) = a+ always(a) = a0 • Adverbs might be used as offset modifiers A(x) = m(A(x + k))
Fuzzy Variables and Values • Fuzzy variables can be considered as a term associated with a floating point value • A collection of fuzzy variables could be used to define an enemy profile {(healthy 0.9) (dangerous 0.3) (moving 0.3)} • Linguistic variables is a collection of fuzzy variables used to de
Liguistic Variables • Linguistic variables is a collection of fuzzy variables used to define a high level concept like “allegiance” term set: {enemy,neutral,friendly} values: [0.0, 0.4, 0.9] • A linguistic variable is defined over a base variable • Base variables can be either crisp or fuzzy values
Fuzzification • Creating a fuzzy variable from a crisp one • Define a membership function with the same range as the crisp variable • Evaluating the membership based on the crisp variable value indicates degree of set membership
Defuzzification - 1 • Converts a fuzzy value to a crisp value • Fairly easy for fuzzy variables • Can be tricky for linguistic values • Process often involves information loss, unless you are doing simple conversions • There is no unique equation, since humans use problem-dependent techniques to defuzzify linguistic concepts
Defuzzification - 2 • Maximum Approach • Uses highest points in membership function graph • First maxima – picks crisp value from highest of all membership function • Average maxima – weighted or unweighted average of all crisp values • Centroid Approach • based on finding center of gravity of the membership function graph • Very computationally intensive
Dead or alive Extremely nasty and more or less dead Shot and bleeding badly implies dying d a n3 d1/2 s b2 d Linguistic Expressions
Fuzzy Logic • Fuzziness is really deterministic uncertainty and depends on probability assumptions which may not be met • Fuzzy logic contains inconsistencies (e.g. the set of animats that are both dead and alive is not empty) • Seems to model human knowledge and reasoning better than standard truth functional logic
Fuzzy Control SystemsDecision Making • Working Memory • Similar to RBS, except fuzzy variables used in place of crisp symbols • Knowledge Base • Rules containing fuzzy variables are used if very confident or somewhat vulnerable then attack
Rule Extensions • Linguistic rules • Keyword is used to refer to fuzzy terms if allegiance is friendly then happy • Fuzzy modifiers • Can be applied to both antecedent and consequent variables
Creating Membership Functions • Knowledge engineer can try to extract information and heuristics from human experts • Survey can be used to collect information regarding several people’s understanding and membership function reflects average • Incremental tuning will be required for any approach chosen
Fuzzy InterpreterMatching • In crisp systems it is easy to identify rules that match WM, facts are present or they are not • In fuzzy systems, fuzzy variables are rarely zero so every rule needs to be checked during every match cycle • To reduce impact of combinatorial explosion, thresholds will be used to reduce the number of low probability matches
Fuzzy InterpreterInference • Purpose is to determine the degree of truth for the consequent part of each rule • Two techniques used • Min (uses the minimum of the rule antecedent values and treats this as the value for the output set – possibilistic reasoning) • Products (uses the product of the rule antecedent values and treats this as the value for the output set – probabilistic reasoning)
Fuzzy InterpreterComposition • Many rules have the same fuzzy variable in the rule body (consequent) • To combine support shown by multiple rules • Max (uses the maximum of the rule output values and uses this as the fuzzy variable value in WM – possibilistic reasoning) • Sum (uses the sum of the rule output values and uses this as the fuzzy variable value in WM – probabilistic reasoning)
Algorithm // current WM with latest fuzzy variable values // previous is copy of most recent WM for each value in WM { previous[value] = current[value]; current[value] = 0; } for each rule { result = evaluate(rule.expression,previous); current[rule/body] = max(current[rule.body},result); }
Discussion – 1 • Fuzzy systems are surprisingly robust • Can cope with noisy and incomplete data • Requires little feedback to perform well • Fuzzy expert systems mimic human reasoning surprisingly well • Fuzzy RBS are easy to extend incrementally • Rule syntax is easy enough for non-programmers to write rules
Discussion – 2 • Fuzzy systems use rules of thumb (heuristics) and not mathematical models of the problem • Every rule needs to be evaluated during every match cycle which is computationally expensive (for a large number of rules) • Creating membership functions is not easy • Combinatorial explosion of rules is possible for large numbers of input combinations, unless knowledge is represented implicitly
Dominator • Uses fuzzy expert system to control movement and shooting • Uses fuzzy logic for weapon selection • Supposedly has the best performance of all animats • (not found in the current archive)
Actions - 1 • Define linguistic variable move is defined with three values forwards, stop, backwards forwards = 1 if velocity is null and 0 if velocity is full backwards = 0 if velocity is null and 1 if velocity is full stop = not(forwards or backwards) • Fuzzy modifier extremely can be used to obtain steeper curve for stop
Actions - 2 • Define base linguistic variable turn is defined as yaw turning angle (0 membership function means no turn) • Fuzzy terms as used to direct turn toward: button, door, ladder, platform, exit • Linguistic variable look controls pitch separately up = pitch of 90 ahead = pitch of 0
Senses - 1 • Door is defined over opening height so value is 0 when closed and 1 when open • Fully open door (degree of membership) DoM is 1 if door can be walked through 0 if crawl through is needed • Button_pressed is really a pure boolean singleton not fuzzy variable
Senses - 2 • Platform is defined as two terms with DoM of 1 when at starting point and 0 when player needs to double jump off • Term ready is distance off floor and how easy it is to climb on • Term arrived is distance to final location • Additional terms • aboard is 1 when on platform and 0 when not (peaks near (x,y) at platform center)
Senses - 3 • Ladder is defined as two terms • Term held has DoM value of 1 after 1 full second of touching 0 when released for 1 full second • Term top has DoM defined over height and is 1 when animat can step off 0 when 1 step from the top
Rules for Using Doors - 1 • if not button_pressed then turn to button, move forward • if button_pressed then then turn toward door • if button_pressed and door not fully open then move stop • if door fully open move forward, turn toward door
Rules for Using Doors - 2 • Note these rules rely on the animat being interrupted once the doorway is crossed • A higher level AI needs to identify this case and stop calling the fuzzy behavior to prevent the animat from heading through the door (e.g. rule 1 needs to be disabled by have the membership function of its action drop to zero once the button is pressed)
Rules for Using Ladders • True then move forward • if ladder is not held then turn toward ladder • if ladder is held then look up • if ladder is top then look ahead, turn toward exit
Rules for Using Platforms - 1 • if not button_pressed then turn to button, move forward • if button_pressed and platform not ready then move stop • if button_pressed and not aboard turn to platform • if platform is ready then move forward
Rules for Using Platforms - 2 • if aboard then turn to exit • if aboard and platform has not arrived then move stop • if aboard and platform has arrived turn move forward • if platform is ready then move forward