Using Fuzzy Logic to Control a Videogame Defenseman


Introduction

Fuzzy Logic Primer

Fuzzifying Hockey

FFLL API and Spark!

Rule Generation

Final Results

Downloads

Contact Me

Fuzzifying Hockey

As with any fuzzy control system, a crucial part of the design is determining what your inputs and outputs would be. Another question is to answer is, how many outputs do I want?

For my project I decided to control two aspects about the defenseman: length-wise desired position and skating velocity. You might be wondering why I don't use fuzzy logic to control cross-ice positioning. For one, I wanted to keep things simple. The position along the length of the ice is the most important thing and defenseman usually keep to a narrow lane along the ice anyways. Instead, I used a non-fuzzy, puck following control scheme for cross-ice positioning.

Once I determined what outputs I wanted, I need to figure out what inputs would be related to each output. For Velocity, I determined that it would be dependent on a single input called Separation. This input would measure the distance between the current position and the desired position. The larger this value, the faster the defenseman would skate to get to the desired position. Additionally, if this value was negative, he would skate back towards his own goal. If this value was positive, he would skate towards the opposition goal.

For the output desired_position, things were a little more complicated. I decided it would depend on four inputs: puck_position, possession, game_score, and game_time.

The inputs and outputs to the system as summarized below.

The next step is to then fuzzify the linguistic variables by assigning membership sets to each variable. This is where creativity and experience can determine how good your fuzzy logic control system is. Having too many membership sets can be unnecessary and lead to longer computation times and too many rules. The key is to define only as many membership sets as your system requires for proper control behaviour. The shape of each membership set is also important in determing what kind of response your system will give.

The following figures show how I fuzzified my inputs and outputs. More detailed descriptions of these variables can be found in section 3.1 of my report.

For Puck_Position, I divided the length of the ice into seven zones representing the various defensive, neutral, and offensive zones. This variable has a range of -100 to +100 feet, with 0 being the red line.

For Possession, I decided not to make this a fuzzy variable. This variable can only have three values (three membership sets), -1 (the other team has the puck), 0 (no one has the puck), or +1 (the defenseman's team has the puck). That's not to say that I could have made this a fuzzy variable, but I'm not sure what a 0.5 possession value means.

For Game_Score, I decided on using three membership sets as well. This variable measures the difference in score between the defenseman's team and the opponents team. If this difference is positive, then the defenseman's team is ahead. If the difference is negative, the defenseman's team is behind. If the difference is zero, then the score is tied.

For Game_Time, I decided on four membership sets. Three are used to indicate the three periods in a hockey game. The last membership set is used to indicate the importance of the last few minutes of a hockey game. Starting about the ten minute mark of the third period, this membership set starts its influence. For this variable, the values can range from 0 to 60 to coincide with the number of minutes in a full game.

The output variable Desired_Position has the exact same representation as Puck_Position. Look at Puck_Position for the diagram.

For Separation, I used seven membership sets. The middle is kinda squished but what's there is SM_NEG, ZERO, and SM_POS. Since this variable represents the distance between the defenseman and the puck along the length of the ice, the largest absolute value possible is 200 ft. I further encode more information by making it possible for this variable to negative values. Positive values mean the puck is in front of the defenseman (towards the offensive zone) and negative values means the puck is behind the defenseman (towards the defensive zone). Thus, the valid range of values is -200 to +200.

For Velocity, I again used seven membership sets. The range of values are -29.3 to 29.3. The 29.3 value comes from a web site I found which gave me the top skating speed of NHL hockey players. In this case, the value is in feet per second. Take this value with a grain of salt because I saw no real data for this value. It does, however, look fairly realistic. A positive value means the defenseman is skating towards the offensive zone. A negative value means the defenseman is skating towards the defensive zone.