public double GetDesirability(float hunger, float fatique) { fuzzyModule.Fuzzify("Hunger", hunger); fuzzyModule.Fuzzify("Fatique", fatique); return(fuzzyModule.DeFuzzify("Desirability")); }
public double GetDesirability(float distance) { // Fuzzify antecedent 1 fm.Fuzzify("DistToRegion", distance); // Fuzzify antecedent 2 fm.Fuzzify("RegionWealth", resourceCount); // Defuzzify consequence return(fm.DeFuzzify("Desirability")); }
public override float GetDesirability(float distanceToTarget) { // fuzzify distance and amount of ammo FuzzyModule.Fuzzify("distanceToTarget", distanceToTarget); LastDesirabilityScore = FuzzyModule.DeFuzzify("desirability", FuzzyModule.DefuzzifyMethod.MaxAv); return(LastDesirabilityScore); }
public void FuzzyLogic_Test1() { FuzzyModule fuzzyModule = new FuzzyModule(); FuzzyVariable distanceToTarget = fuzzyModule.CreateFLV("DistanceToTarget"); FzSet Target_Close = distanceToTarget.AddLeftShoulderSet("Target_Close", 0, 250, 500); FzSet Target_Medium = distanceToTarget.AddTriangularSet("Target_Medium", 250, 500, 750); FzSet Target_Far = distanceToTarget.AddRightShoulderSet("Target_Far", 500, 750, 1000); FuzzyVariable AmmoStatus = fuzzyModule.CreateFLV("AmmoStatus"); FzSet Ammo_Low = AmmoStatus.AddLeftShoulderSet("Ammo_Low", 0, 250, 500); FzSet Ammo_Okay = AmmoStatus.AddTriangularSet("Ammo_Okay", 250, 500, 750); FzSet Ammo_Loads = AmmoStatus.AddRightShoulderSet("Ammo_Loads", 500, 750, 1000); FuzzyVariable Desirability = fuzzyModule.CreateFLV("Desirability"); FzSet Undesirable = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50); FzSet Desirable = Desirability.AddTriangularSet("Desirable", 25, 50, 75); FzSet Very_Desirable = Desirability.AddRightShoulderSet("Very_Desirable", 50, 75, 100); fuzzyModule.AddRule(new FzAND(Target_Close, Ammo_Loads), Undesirable); fuzzyModule.AddRule(new FzAND(Target_Close, Ammo_Okay), Undesirable); fuzzyModule.AddRule(new FzAND(Target_Close, Ammo_Low), Undesirable); fuzzyModule.AddRule(new FzAND(Target_Medium, Ammo_Loads), Very_Desirable); fuzzyModule.AddRule(new FzAND(Target_Medium, Ammo_Okay), Very_Desirable); fuzzyModule.AddRule(new FzAND(Target_Medium, Ammo_Low), Desirable); fuzzyModule.AddRule(new FzAND(Target_Far, Ammo_Loads), Desirable); fuzzyModule.AddRule(new FzAND(Target_Far, Ammo_Okay), Desirable); fuzzyModule.AddRule(new FzAND(Target_Far, Ammo_Low), Undesirable); fuzzyModule.Fuzzify("DistanceToTarget", 200); fuzzyModule.Fuzzify("AmmoStatus", 400); double value = fuzzyModule.DeFuzzify("Desirability", FuzzyModule.DefuzzifyMethod.MaxAV); Assert.Equal(12.5, value); fuzzyModule.Fuzzify("DistanceToTarget", 1000); fuzzyModule.Fuzzify("AmmoStatus", 600); value = fuzzyModule.DeFuzzify("Desirability", FuzzyModule.DefuzzifyMethod.MaxAV); Assert.Equal(50, value); }
/// <summary> /// Retrieves target with the highest desirability and uses the weapon with the highest desirability to attack the Enemy. /// </summary> /// <returns>Enemy to attack</returns> public Enemy GetDesiredTarget() { Enemy toReturn = null; double highestOverall = -1; foreach (Enemy e in GameWorld.Instance.enemies) { double highestForThisLoop; if (position.Distance(e.pos) < (sniper.attackRange + 1) * BaseTile.size && !e.dead) { double shotgunDesirability = 0; if (position.Distance(e.pos) < (shotgun.attackRange + 1) * BaseTile.size) { towerShotgunFuzzyModule.Fuzzify("Health", e.health / e.maxHealth * 100); towerShotgunFuzzyModule.Fuzzify("DistanceToEnemy", position.Distance(e.pos) / ((sniper.attackRange + 1) * BaseTile.size) * 100); shotgunDesirability = towerShotgunFuzzyModule.DeFuzzify("ShootDesirability", DefuzzifyMethod.MAX_AV); } double sniperDesirability; towerSniperFuzzyModule.Fuzzify("Health", e.health / e.maxHealth * 100); towerSniperFuzzyModule.Fuzzify("DistanceToEnemy", position.Distance(e.pos) / ((sniper.attackRange + 1) * BaseTile.size) * 100); sniperDesirability = towerSniperFuzzyModule.DeFuzzify("ShootDesirability", DefuzzifyMethod.MAX_AV); if (shotgunDesirability > sniperDesirability) { highestForThisLoop = shotgunDesirability; if (highestForThisLoop > highestOverall) { weapon = shotgun; } } else { highestForThisLoop = sniperDesirability; if (highestForThisLoop > highestOverall) { weapon = sniper; } } if (highestForThisLoop > highestOverall) { highestOverall = highestForThisLoop; toReturn = e; Console.WriteLine(sniperDesirability + " " + shotgunDesirability); if (!enemiesInRange.Contains(e)) { Console.WriteLine(weapon); } } } } return(toReturn); }
public override float GetDesirability(float distanceToTarget) { if (RoundsRemaining == 0) { LastDesirabilityScore = 0; } else { // fuzzify distance and amount of ammo FuzzyModule.Fuzzify("distanceToTarget", distanceToTarget); FuzzyModule.Fuzzify("ammoStatus", RoundsRemaining); LastDesirabilityScore = FuzzyModule.DeFuzzify("desirability", FuzzyModule.DefuzzifyMethod.MaxAv); } return(LastDesirabilityScore); }
public double FuzzyGetDesirabilitySeek(int hungerVar, double moneyVar) { FuzzyModule fuzzyModule = new FuzzyModule(); FuzzyVariable hunger = fuzzyModule.CreateFLV("Hunger"); FzSet No_Hunger = hunger.AddLeftShoulderSet("No_Hunger", 0, 5, 10); FzSet Hunger = hunger.AddTriangularSet("Hunger", 5, 10, 15); FzSet Very_Hunger = hunger.AddRightShoulderSet("Very_Hunger", 10, 15, 20); FuzzyVariable AmmoStatus = fuzzyModule.CreateFLV("Money"); FzSet Poor = AmmoStatus.AddLeftShoulderSet("Poor", 0, 5, 10); FzSet Normal = AmmoStatus.AddTriangularSet("Normal", 5, 10, 100); FzSet Rich = AmmoStatus.AddRightShoulderSet("Rich", 10, 100, 1000); FuzzyVariable Desirability = fuzzyModule.CreateFLV("Desirability"); FzSet Undesirable = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50); FzSet Desirable = Desirability.AddTriangularSet("Desirable", 25, 50, 75); FzSet Very_Desirable = Desirability.AddRightShoulderSet("Very_Desirable", 50, 75, 100); fuzzyModule.AddRule(new FzAND(No_Hunger, Poor), Undesirable); fuzzyModule.AddRule(new FzAND(No_Hunger, Normal), Undesirable); fuzzyModule.AddRule(new FzAND(No_Hunger, Rich), Undesirable); fuzzyModule.AddRule(new FzAND(Very_Hunger, Poor), Very_Desirable); fuzzyModule.AddRule(new FzAND(Very_Hunger, Normal), Very_Desirable); fuzzyModule.AddRule(new FzAND(Very_Hunger, Rich), Undesirable); fuzzyModule.AddRule(new FzAND(Hunger, Poor), Desirable); fuzzyModule.AddRule(new FzAND(Hunger, Normal), Desirable); fuzzyModule.AddRule(new FzAND(Hunger, Rich), Undesirable); fuzzyModule.Fuzzify("Hunger", hungerVar); fuzzyModule.Fuzzify("Money", moneyVar); double value = fuzzyModule.DeFuzzify("Desirability", FuzzyModule.DefuzzifyMethod.MaxAV); return(value); }
public virtual double GetDesirability(float distToTarget) { fm.Fuzzify("DistToTarget", distToTarget); fm.Fuzzify("Durability", stats.durability); return(fm.DeFuzzify("Desirability")); }
public double GetDesirability(double hunger, double sleep) { fuzzyModule.Fuzzify("Hunger", hunger); fuzzyModule.Fuzzify("Sleep", sleep); return(fuzzyModule.DeFuzzify("Desirability"));; }
// TODO: REFACTOR Split this up into multiple methods // and call it only when neccesarry; this is too heavy now // Do not have time to split it up bool ThinkIfShouldEat() { FuzzyModule fuzzyModule = new FuzzyModule(); /// define FLVs and underlying sets FuzzyLinguisticVariable distToFood = fuzzyModule.CreateFLV("DistToFood"); // distance numbers are measured in pixels. For a visualisation of this FLV, // see the "DistanceFromFood" antecedent FLV graph in the documentation. FuzzySet food_ShortDistance = distToFood.AddLeftShoulderSet("ShortDistance", 0, 1, 200); FuzzySet food_MediumDistance = distToFood.AddTriangularSet("MediumDistance", 100, 200, 300); FuzzySet food_LongDistance = distToFood.AddRightShoulderSet("LongDistance", 200, 200, 400); FuzzyLinguisticVariable hunger = fuzzyModule.CreateFLV("Hunger"); FuzzySet hunger_full = distToFood.AddLeftShoulderSet("Full", 0, 1, 50); FuzzySet hunger_hungry = distToFood.AddTriangularSet("Hungry", 30, 50, 70); FuzzySet hunger_starving = distToFood.AddRightShoulderSet("Starving", 50, 100, 100); FuzzyLinguisticVariable foodDesirability = fuzzyModule.CreateFLV("DesirabilityToEatFood"); FuzzySet desirability_Undesirable = distToFood.AddLeftShoulderSet("Undesirable", 0, 1, 50); FuzzySet desirability_Desirable = distToFood.AddTriangularSet("Desirable", 25, 50, 75); FuzzySet desirability_VeryDesirable = distToFood.AddRightShoulderSet("VeryDesirable", 50, 100, 100); // implement rules List <FuzzySet> rule1Antecedent = new List <FuzzySet>() { food_ShortDistance, hunger_full }; fuzzyModule.FuzzyRules.Add(new FuzzyRule(rule1Antecedent, desirability_Undesirable)); List <FuzzySet> rule2Antecedent = new List <FuzzySet>() { food_ShortDistance, hunger_hungry }; fuzzyModule.FuzzyRules.Add(new FuzzyRule(rule2Antecedent, desirability_VeryDesirable)); List <FuzzySet> rule3Antecedent = new List <FuzzySet>() { food_ShortDistance, hunger_starving }; fuzzyModule.FuzzyRules.Add(new FuzzyRule(rule3Antecedent, desirability_VeryDesirable)); List <FuzzySet> rule4Antecedent = new List <FuzzySet>() { food_MediumDistance, hunger_full }; fuzzyModule.FuzzyRules.Add(new FuzzyRule(rule4Antecedent, desirability_Undesirable)); List <FuzzySet> rule5Antecedent = new List <FuzzySet>() { food_MediumDistance, hunger_hungry }; fuzzyModule.FuzzyRules.Add(new FuzzyRule(rule5Antecedent, desirability_Desirable)); List <FuzzySet> rule6Antecedent = new List <FuzzySet>() { food_MediumDistance, hunger_starving }; fuzzyModule.FuzzyRules.Add(new FuzzyRule(rule6Antecedent, desirability_VeryDesirable)); List <FuzzySet> rule7Antecedent = new List <FuzzySet>() { food_LongDistance, hunger_full }; fuzzyModule.FuzzyRules.Add(new FuzzyRule(rule7Antecedent, desirability_Undesirable)); List <FuzzySet> rule8Antecedent = new List <FuzzySet>() { food_LongDistance, hunger_hungry }; fuzzyModule.FuzzyRules.Add(new FuzzyRule(rule8Antecedent, desirability_Undesirable)); List <FuzzySet> rule9Antecedent = new List <FuzzySet>() { food_LongDistance, hunger_starving }; fuzzyModule.FuzzyRules.Add(new FuzzyRule(rule9Antecedent, desirability_VeryDesirable)); /// pass variables //TODO: Actually get distance to food in-game // Not implemented (its used for debugging) because it // seemingly doesn't accuratly produce wanted results // To implement, get the nearest food source from an entity // and get the distance squared towards target double pixelsFromFood = 300; distToFood.Fuzzify(pixelsFromFood); //TODO actually implement hunger // Does not change the defuzzified value for some reason. // I don't know how and I do not have the time to fix it. // First step would be to check if it changes the consequent value, etc. double hungerAmount = -1 * OwnerEntity.FoodEaten; hunger.Fuzzify(hungerAmount); fuzzyModule.RunRules(); double defuzzifiedValue = fuzzyModule.DeFuzzify("DesirabilityToEatFood"); // I don't know what I did wrong here. I don't have time to fix it. // Value does not correspond to the value in the docs. // Unpredictable results. return(defuzzifiedValue < 109); }