top of page
Search
Loki Sanguine

Fuzzy Logic in Games

Updated: Feb 10, 2023

In case you're in a rush;

TABLE OF CONTENTS


Let's talk game AI;

If you've played a video game you know what AI is. A computer taking in the information the devs consider relevant to feed it to think and perform to some extent like a person or animal. Let's look into the decision making center of this. There are many ways this can be done. Some of these categories of algorithms are Planned Behavior systems, Finite-State Machines, Behavior Trees, and Utility AI. There are a couple others but today we're gonna talk about a form of Utility AI.


 

Utility / Fuzzy AI;

So the basics of Utility AI is the estimation of profit from an action based on dynamic values in the bounds of our game's rules. It's one of the more popular options currently for it's ability because it is a very scalable approach to NPC decision making systems. This process of computer estimation is part of what makes these systems of logic "fuzzy."


 

Applying Fuzzy Logic;

I am applying Fuzzy Logic to an AI that reads your in game performance. The rules of the game dictate dialogue between levels. This is just one use of fuzzy logic, based on performance within this simple game's rules accessing a small database of dialogue options. Let's look at how fuzzy logic works as a rigid dialogue system only though. How different do these look though?

 

So now Graphs & Code;

Let's go with the rigid example, there are three possible endings based on just a dialogue set. Well they look to be about the same honestly. Let's say there are three possible endings between just two dialogue options. Good, Bad, and Neutral.


As you can see, not very good as far as doing it as just the quick glance goes. This is messy and takes a lot more brain power to chug through then you would initially expect from endings that come off three options.

Much cleaner honestly. This saves a lot of time and energy to look at from just a little bit more work on the back end. This also gives room for the rule to be reused for other sections. Say you use this system for keeping track of someone's evil deeds like we have in one of my favorite games Fabled the Lost Chapter. As other things happen in the game we increment the in this case morality slider. This is just what I am using for an example we'll dig into how I used it for dialogue momentarily but first. Let's look at what's going on here? Let's bring up the graphs to help interpret this information before us. In the terms brought by these snippets of code I made to explain things before showing off dynamics in dialogue directly. So starting with our rigid if else system. Also note this issue is not something to worry about if there are two potential states but in AI there generally are three to four so that's why this is what we are using three as states within a single rule as our example.

In our if else setup we get this direct spanning tree that our function is hit with upfront having to hold onto many different cases.


Now we have the fuzzy logic in our one rule system showing off a quicker processing on this. So what do we actually do to get this? Well we can break a full scene into a few different functions. Let's dive into how this will look.

 

Pseudo code;

Player does something that triggers our skill sensor.

Either we increment it (won't go over max) or decrement it.

Player interacts with an NPC

Player answers NPC questions

Finishes Dialogue


 

My project with Fuzzy;

I made a very simple game with the following rules. Touch walls your skill goes down, go fast your skill goes up, touch too many red walls you die and lose a lot of skill but touching one opens more of the map. Finishing a level in general increases skill some. Then you get to conversation with NPC. If you are rude their opinion of you drops, polite it increases, in between it stays in the middle giving you in this case 9 combinations of endings possible.

 

Demonstration Video;


 

Where I got my information;

Highly recommend reading / watching the following things for they are were I gained my understanding of Fuzzy Logic as shared here. They may help you as well!

AI-driven Dynamic Dialog through Fuzzy Pattern Matching: https://www.youtube.com/watch?v=tAbBID3N64A

Applying Behavior characteristics to decision-making process to create believable game AI:

Ian Millington AI for Games Third Edition:

82 views0 comments

Recent Posts

See All

Comments


bottom of page