Jump to content

  • Log In with Google      Sign In   
  • Create Account

Is fuzzy logic much use in programming game AI?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1   Members   -  Reputation: 109


Posted 22 April 2013 - 09:05 PM

I've read a bit about fuzzy logic in the past few days and it's pretty darn hard to get your head around but i'm getting the hang of it now. And I'm already from a heavy math background at that. But I read an article earlier (here) which uses methods that has similar functionality to fuzzy logic, but seems a lot easier. Is there anything that fuzzy logic can handle which other methods cannot? I am wondering if it's worth studying it in depth (because there's an option to study it for my final year at university) or whether it's redundant in the game programming world, or is it simply criticized because it's hard for people to get their head around it compared to other similar methods out there?

Edited by Zukias, 22 April 2013 - 09:07 PM.

#2   Moderators   -  Reputation: 5570


Posted 23 April 2013 - 12:32 AM

Tell the truth, I'd be hard pressed to say what is and what is not fuzzy logic according to a true definition.  What I mean is that if you have five options and they are weighted, normalize them to be 0-1 portions of a continuous range and randomly select one.  I suppose the argument could be that true fuzzy logic has a better distribution, or more proper math basis etc, blah, screw it, the easy way always seemed to work quite well so why get overly complicated?  More important than some technical term for how you choose things is quite simple: is it fun?  Fuzzy logic has a place I'm sure, but the full blown 'technically correct' version seems like a lot of work for something which can be done pretty closely using greatly simplified methods.


Take the mentioned game from the article: The Sims.  If you have the original 1 version, install it and make a house with four of everything.  The Sim always does the most appropriate actions.  The selection of actions was just randomly selecting from the top four actions which will positively impact the motivations.  If the sim needs to go to the bathroom and there are four toilets, they will always use one when that it the highest motivation.  Without 4 items, they may go watch TV instead and end up peeing on the floor as a result.  It's simple 1 in 4 chance that they do the correct thing in the original implementation.  Of course, very few folks realized how simple the AI was because the emergent behavior was often so entertaining, sometimes smart, sometimes like watching a slow motion train wreck... smile.png

Edited by AllEightUp, 23 April 2013 - 12:35 AM.

#3   Moderators   -  Reputation: 49099


Posted 23 April 2013 - 12:48 AM

As above, the formal definition might not come up in games much, but games will do a lot of things that are similar.


When I wrote an AI for an FPS game, it had to find paths across the level. I didn't want them to always take the 'best' path, because they'd seem very "AI" and not very "human". Every step that the path-finding algorithm takes has a "cost", and the algorithm tries to find the path with the lowest total cost. So, to make them pick 'pretty good' but random paths, I just added a small random number to the cost variable. This kind of makes the path selection use "fuzzy logic" instead of regular logic.


e.g. say it's choosing between a path costing 10, a path costing 20 and a path costing 100. In a normal implementation, the first path is always chosen, because it's best.

If my "fuzzy" random number range is 20, then the costs for the paths are actually somewhere in 10-30, 20-40 and 100-120. Depending on which random numbers are chosen by each AI character, most will take the first path but some will take the second. None will ever take the third because the "fuzzyness" range isn't big enough.

#4   Members   -  Reputation: 109


Posted 23 April 2013 - 12:34 PM

Thanks for replies, I'm not sure about studying it in depth now. Even if fuzzy logic is slightly better, it'll take much longer to implement.

#5   Moderators   -  Reputation: 5639


Posted 23 April 2013 - 03:50 PM

Tell the truth, I'd be hard pressed to say what is and what is not fuzzy logic according to a true definition.

Fuzzy logic has quite a clear definition, just like many other areas of AI. Picking weighted random numbers is nothing to do with fuzzy logic and isn't an approximation of it in any sense. In fact there is no randomness involved at all in fuzzy logic. It's not about imprecise or varying outputs, but about being able to specify inputs as continuous ranges or function curves which all contribute some amount towards the output.

Zukias, to answer your question - it's not a technique commonly used in game development, at least in part because it's not always clear to see what effect the inputs will have on the outputs. It's not really hard to understand compared to other AI tools - in fact, I think it's one of the simpler ones, at least if you read about rather than assuming there's randomness involved.

#6   Moderators   -  Reputation: 49099


Posted 23 April 2013 - 08:12 PM

Looking at the example on wikipedia, this type of logic is actually extremely common in computer graphics.

For example, say we want to assign textures to different parts of a terrain, with grass on flat areas, rock on slopes, and snow on flat areas that are at a high altitude.
Using boolean logic, you'd write something like:
sloped = true/false
highAltitude = true/false
if( !sloped )
  set texture to grass
if( sloped )
  set texture to rock
if( highAltitude && !sloped )
  set texture to snow
However, this produces hard edges between the textures. To get some soft blending in the areas where these values transition from true to false, we can translate that logic over to it's 'fuzzy' version:
sloped = 0..1
highAltitude = 0..1
texture = RGB[0,0,0]
texture = linerInterpolate( texture, grass, 1-sloped )
texture = linerInterpolate( texture, rock,    sloped )
texture = linerInterpolate( texture, snow, min(1-sloped, highAltitude) )

#7   Moderators   -  Reputation: 5639


Posted 24 April 2013 - 12:18 AM

Yeah, that has similar numerical outcomes to fuzzy logic. But it hard-codes a lot of important aspects of fuzzy logic that are normally open to variation, such as the choice of rules, the shape of each of the functions for each fuzzy rule or 'set', and the way that membership of each fuzzy set is 'defuzzified' into a final value. Normally you'd want to have much more detailed control over what parts of the 0..1 range each of the 3 rules would apply to, and you wouldn't combine the results sequentially like that.

Usually you use fuzzy logic for behaviour rather than just selecting deterministic output values, because the main strength of the method is to allow a designer to supply fairly imprecise rules that apply to the input and get outputs that vary continuously but which are not too divorced from the input rules. The idea then is that the designers can easily tweak those inputs to get the sort of outputs they want, which is great for control systems where the desired values at certain points are known but points in between are not necessarily specified. The interesting part of fuzzy logic is really the form of the input rather than of the output.

#8   Crossbones+   -  Reputation: 7414


Posted 24 April 2013 - 03:13 AM

Tell the truth, I'd be hard pressed to say what is and what is not fuzzy logic according to a true definition.

Logic which is 100% defined by mathematical constraints is not fuzzy.
Logic which is 75% to 99% defined by mathematical constraints is not very fuzzy.
Logic which is 'a little bit' to 75% defined by mathematical constraints is moderately fuzzy.
Logic which is defined entirely by conceptual constraints is very fuzzy indeed.

Edited by Khatharr, 24 April 2013 - 03:14 AM.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.