/// <summary> /// FUZZY 'AND' RULE /// /// "IF /// val1 is a member of fs1, /// AND /// val2 is a member of fs2 /// THEN /// fs3 IS fs4 /// </summary> /// <param name="val1">Antecedent 1</param> /// <param name="fs1">Antecedent Set 1</param> /// <param name="val2">Antecedent 2</param> /// <param name="fs2">Antecedent Set 2</param> /// <param name="fs3">Consequent Output</param> /// <param name="fs4">Consequent</param> /// <param name="ftemp">Rule Applicability Output Set</param> public static FuzzySet AND(double val1, FuzzySet fs1, double val2, FuzzySet fs2, ref FuzzySet fs3, FuzzySet fs4, FuzzySet ruleSet) { double lowRange = fs4.GetLowRange(); double highRange = fs4.GetHighRange(); //... and of the Consequent Output... string consName = fs3.Id; Brush consColour = fs3.LineColour; FuzzySet ftemp = new FuzzySet(ruleSet); ftemp.Clear(); ftemp.SetRangeWithPoints(lowRange, highRange); double fval1 = fs1.Fuzzify(val1); double fval2 = fs2.Fuzzify(val2); double membership = Math.Min(fval1, fval2); //MIN for AND if (membership > 0) { FuzzySet oldRule = new FuzzySet(ftemp); ftemp = new FuzzySet(Operations.ScaleFS(fs4, membership)); ftemp.LineColour = ruleSet.LineColour; ftemp.Id = ruleSet.Id; if (ftemp.GetNumPoints() < 2) ftemp = oldRule; fs3 = new FuzzySet(Operations.UnionFS(fs3, ftemp, consColour)); fs3.Id = consName; } return ftemp; }
/// <summary> /// FUZZY 'IS' RULE /// /// "IF /// val1 is a member of fs1, /// THEN /// fs3 IS fs4 /// </summary> /// <param name="val1">Antecedent 1</param> /// <param name="fs1">Antecedent Set 1</param> /// <param name="fs3">Consequent Output</param> /// <param name="fs4">Consequent</param> /// <param name="ftemp">Rule Applicability Output Set</param> public static FuzzySet IS(double val1, FuzzySet fs1, ref FuzzySet fs3, FuzzySet fs4, FuzzySet ruleSet) { double lowRange = fs4.GetLowRange(); double highRange = fs4.GetHighRange(); string consName = fs3.Id; Brush consColour = fs3.LineColour; FuzzySet ftemp = new FuzzySet(ruleSet); ftemp.Clear(); ftemp.SetRangeWithPoints(lowRange, highRange); double membership = fs1.Fuzzify(val1); if (membership > 0) { ftemp = Operations.ScaleFS(fs4, membership); ftemp.LineColour = ruleSet.LineColour; ftemp.Id = ruleSet.Id; fs3 = Operations.UnionFS(fs3, ftemp, ruleSet.LineColour); fs3.Id = consName; fs3.LineColour = consColour; } return ftemp; }
/// <summary> /// This is where the guts of it all goes down. /// /// Remember that because of the nature of C#, items within a collection /// CANNOT BE PASSED BY REFERENCE! Thus, if you are making an alteration to any /// set within a method where the set is passed by reference (ref), you will /// need to assign the FuzzySet to a variable, pass that variable, and then set /// the oiginal FuzzySet within the Collection to the altered variable. /// A little bit of frigging around, but it works. /// </summary> public override void CalculateFuzzyLogic() { //Get the vars for this Simulator - dont alter this! _lander = ((LanderSim)Globals.Simulator).SpaceShip; //Assign the sets to variables FuzzySet tResult = new FuzzySet(ThrottleOutputs["ThrottleResult"]); //Clear the ThrottleResult Set so that we can repopulate it with new data tResult.Clear(); tResult.SetRangeWithPoints(0, 100); //WRITE YOUR RULES LIKE THIS.... //(dont forget to pass the //accumulator variable by reference, and also pass the Rule itself //Hot Tip: COMMENT YOUR RULES SO YOU KNOW WHAT THEY DO! // Rule 0: IF Height is High THEN Throttle -> Soft //RuleSets["Rule0"] = Rule.IS(_lander.Y, HeightSets["high"], ref tResult, ThrottleSets["soft"],RuleSets["Rule0"]); /* * * Rules go here.... * * */ //reassign the variables to the sets ThrottleOutputs["ThrottleResult"] = new FuzzySet(tResult); if (!Manual) { //THIS IS THE THROTTLE VALUE SET BY PRESSING THE BUTTONS _lander.Throttle = throttle; //Limit Throttle (incase of ridiculous values) if (_lander.Throttle < 0) _lander.Throttle = 0; if (_lander.Throttle > 100) _lander.Throttle = 100; //IF YOU ARE WRITING RULES FOR THE SIDE-THRUST, // You will need to defuzzify into _lander.Left and _lander.Right // Otherwise, leave these here to control your lander with the function buttons _lander.Left = throttleL; _lander.Right = throttleR; } else { //THIS IS THE THROTTLE VALUE DEFUZZIFIED BY THE RULESETS _lander.Throttle = Operations.DeFuzzifyCOG(ThrottleOutputs["ThrottleResult"]); } //Save the state of the Lander - dont alter this ((LanderSim) (Globals.Simulator)).SpaceShip = _lander; }
public override void CalculateFuzzyLogic() { //START harrier = ((HarrierSim)Globals.Simulator).Harrier; double height; if ( Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Easy) || Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Medium) || Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Hard) ) height = harrier.Y - 23; else height = harrier.Y - 5; double speedY = harrier.YVel; double speedX = harrier.XVel; double safeX = harrier.X - harrier.MidSafeX - 40; //FuzzySet throttleOutput = ; //FuzzySet thrustVectorOutput = ; FuzzySet throttleOutput = new FuzzySet(ThrottleAccum["ThrottleOutput"]); FuzzySet thrustVectorOutput = new FuzzySet(ThrustVecAccum["ThrustVector"]); throttleOutput.Clear(); thrustVectorOutput.Clear(); throttleOutput.SetRangeWithPoints(0, 120); thrustVectorOutput.SetRangeWithPoints(-5, 5); //if height is high and speed is med, throttle soft :R1 //YourRuleSet["Rule0"] = Rule.AND(height, "Your Height Set[high]", speedY, "Your Y Speed Set[medium]", ref throttleOutput, "Your Throttle Set[soft]", YourRuleSet["Rule0"]); #region Throttle Rules if (Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Hard) || Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.VeryHard)) { #region Y Velocity Height Rules // if Y vel is up then throttle is no RuleSetThrottle["Rule0"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule0"]); // if height is high and Y vel is high then throttle is medium RuleSetThrottle["Rule1"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule1"]); // if height is high and Y vel is moderate then throttle is medium RuleSetThrottle["Rule2"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule2"]); // if height is high and Y vel is low then throttle is low RuleSetThrottle["Rule3"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule3"]); // if height is high and Y vel is safe then throttle is low RuleSetThrottle["Rule4"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule4"]); // if height is medium and Y vel is high then throttle is high RuleSetThrottle["Rule5"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule5"]); // if height is medium and Y vel is moderate then throttle is high RuleSetThrottle["Rule6"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule6"]); // if height is medium and Y vel is low then throttle is medium RuleSetThrottle["Rule7"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule7"]); // if height is medium and Y vel is safe then throttle is low RuleSetThrottle["Rule8"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule8"]); // if height is low and Y vel is high then throttle is high RuleSetThrottle["Rule9"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule9"]); // if height is low and Y vel is moderate then throttle is medium RuleSetThrottle["Rule10"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule10"]); // if height is low and Y vel is low then throttle is medium RuleSetThrottle["Rule11"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule11"]); // if height is low and Y vel is safe then throttle is low RuleSetThrottle["Rule12"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule12"]); // if height is landing and Y vel is high then throttle is high RuleSetThrottle["Rule13"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule13"]); // if height is landing and Y vel is moderate then throttle is high RuleSetThrottle["Rule14"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule14"]); // if height is landing and Y vel is low then throttle is medium RuleSetThrottle["Rule15"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule15"]); // if height is landing and Y vel is safe then throttle is low RuleSetThrottle["Rule16"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule16"]); RuleSetThrottle["Rule17"] = Rule.IS(height + 23, HeightSets["Below Deck Height"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule17"]); RuleSetThrottle["Rule18"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule18"]); RuleSetThrottle["Rule19"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule19"]); RuleSetThrottle["Rule20"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule20"]); #endregion } if (Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Easy) || Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Medium)) { #region Y Velocity Height Rules // if Y vel is up then throttle is no RuleSetThrottle["Rule0"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule0"]); // if height is high and Y vel is high then throttle is medium RuleSetThrottle["Rule1"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule1"]); // if height is high and Y vel is moderate then throttle is medium RuleSetThrottle["Rule2"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule2"]); // if height is high and Y vel is low then throttle is low RuleSetThrottle["Rule3"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule3"]); // if height is high and Y vel is safe then throttle is low RuleSetThrottle["Rule4"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule4"]); // if height is medium and Y vel is high then throttle is high RuleSetThrottle["Rule5"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule5"]); // if height is medium and Y vel is moderate then throttle is high RuleSetThrottle["Rule6"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule6"]); // if height is medium and Y vel is low then throttle is medium RuleSetThrottle["Rule7"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule7"]); // if height is medium and Y vel is safe then throttle is low RuleSetThrottle["Rule8"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule8"]); // if height is low and Y vel is high then throttle is high RuleSetThrottle["Rule9"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule9"]); // if height is low and Y vel is moderate then throttle is medium RuleSetThrottle["Rule10"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule10"]); // if height is low and Y vel is low then throttle is medium RuleSetThrottle["Rule11"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule11"]); // if height is low and Y vel is safe then throttle is low RuleSetThrottle["Rule12"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule12"]); // if height is landing and Y vel is high then throttle is high RuleSetThrottle["Rule13"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule13"]); // if height is landing and Y vel is moderate then throttle is high RuleSetThrottle["Rule14"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule14"]); // if height is landing and Y vel is low then throttle is medium RuleSetThrottle["Rule15"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule15"]); // if height is landing and Y vel is safe then throttle is low RuleSetThrottle["Rule16"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule16"]); RuleSetThrottle["Rule17"] = Rule.IS(height + 23, HeightSets["Below Deck Height"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule17"]); RuleSetThrottle["Rule18"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule18"]); RuleSetThrottle["Rule19"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule19"]); RuleSetThrottle["Rule20"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule20"]); #endregion } #endregion #region Thrust Vector Rules if (Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Hard) || Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.VeryHard)) { #region X Velocity Left Dangerzone Rules #region Rule 0: if distance is left high dangerzone then thrust vector is forward high thrust RuleSetThrustVec["Rule0"] = Rule.IS(safeX, DistanceSets["Left High Dangerzone"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule0"]); // if distance is left high dangerzone and X vel is high left then thrust vector is forward high thrust //RuleSetThrustVec["Rule0"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule0"]); // if distance is left high dangerzone and X vel is moderate left then thrust vector is forward high thrust //RuleSetThrustVec["Rule1"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule1"]); // if distance is left high dangerzone and X vel is Low left then thrust vector is forward high thrust //RuleSetThrustVec["Rule2"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule3"]); // if distance is left high dangerzone and X vel is Neutral then thrust vector is forward high thrust //RuleSetThrustVec["Rule3"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule3"]); #endregion // if distance is left moderate dangerzone and X vel is high left then thrust vector is forward high thrust RuleSetThrustVec["Rule1"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule1"]); // if distance is left moderate dangerzone and X vel is moderate left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule2"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule2"]); // if distance is left moderate dangerzone and X vel is low left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule3"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule3"]); // if distance is left moderate dangerzone and X vel is neutral then thrust vector is forward moderate thrust RuleSetThrustVec["Rule4"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule4"]); // if distance is left low dangerzone and X vel is high left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule5"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule5"]); // if distance is left low dangerzone and X vel is moderate left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule6"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule6"]); // if distance is left low dangerzone and X vel is low left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule7"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule7"]); // if distance is left low dangerzone and X vel is high left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule8"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Low Thrust"], RuleSetThrustVec["Rule8"]); #endregion #region X Velocity Safezone Rules // if distance is safe zone and X vel is high left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule9"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule9"]); // if distance is safe zone and X vel is moderate left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule10"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule10"]); // if distance is safe zone and X vel is low left then thrust vector is forward low thrust RuleSetThrustVec["Rule11"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Low Thrust"], RuleSetThrustVec["Rule11"]); // if distance is safe zone and X vel is neutral then thrust vector is neutral thrust RuleSetThrustVec["Rule12"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Neutral Thrust"], RuleSetThrustVec["Rule12"]); // if distance is safe zone and X vel is low right then thrust vector is backward low thrust RuleSetThrustVec["Rule13"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Low Thrust"], RuleSetThrustVec["Rule13"]); // if distance is safe zone and X vel is moderate right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule14"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule14"]); // if distance is safe zone and X vel is high right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule15"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule15"]); // if distance is safe zone and X vel is moderate right then thrust vector is backward moderate thrust //RuleSetThrustVec[""] = Rule.AND(safeX, DistanceSets[""], speedX, XVelocitySets[""], ref thrustVectorOutput, ThrustVecSets[""], RuleSetThrustVec[""]); #endregion #region X Velocity Right Dangerzone Rules #region Rule 16: if distance is right high dangerzone then thrust vector is backward high thrust RuleSetThrustVec["Rule16"] = Rule.IS(safeX, DistanceSets["Right High Dangerzone"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule16"]); /* // if distance is left high dangerzone and X vel is high left then thrust vector is forward high thrust RuleSetThrustVec["Rule0"] = Rule.AND(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule0"]); // if distance is left high dangerzone and X vel is moderate left then thrust vector is forward high thrust RuleSetThrustVec["Rule1"] = Rule.AND(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule1"]); // if distance is left high dangerzone and X vel is Low left then thrust vector is forward high thrust RuleSetThrustVec["Rule2"] = Rule.AND(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule3"]); // if distance is left high dangerzone and X vel is Neutral then thrust vector is forward high thrust RuleSetThrustVec["Rule3"] = Rule.AND(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule3"]); */ #endregion // if distance is right moderate dangerzone and X vel is high right then thrust vector is backward high thrust RuleSetThrustVec["Rule17"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule17"]); // if distance is right moderate dangerzone and X vel is moderate right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule18"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule18"]); // if distance is right moderate dangerzone and X vel is low right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule19"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule19"]); // if distance is right moderate dangerzone and X vel is neutral then thrust vector is backward moderate thrust RuleSetThrustVec["Rule20"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule20"]); // if distance is right low dangerzone and X vel is high right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule21"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule21"]); // if distance is right low dangerzone and X vel is moderate right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule22"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule22"]); // if distance is right low dangerzone and X vel is low right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule23"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule23"]); // if distance is right low dangerzone and X vel is high right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule24"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Low Thrust"], RuleSetThrustVec["Rule24"]); #endregion } if (Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Easy) || Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Medium)) { #region X Velocity Left Dangerzone Rules #region Rule 0: if distance is left high dangerzone then thrust vector is forward high thrust RuleSetThrustVec["Rule0"] = Rule.IS(safeX, DistanceSets["Left High Dangerzone"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule0"]); //// if distance is left high dangerzone and X vel is high left then thrust vector is forward high thrust //RuleSetThrustVec["Rule0"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule0"]); //// if distance is left high dangerzone and X vel is moderate left then thrust vector is forward high thrust //RuleSetThrustVec["Rule29"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule29"]); //// if distance is left high dangerzone and X vel is Low left then thrust vector is forward high thrust //RuleSetThrustVec["Rule30"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule30"]); //// if distance is left high dangerzone and X vel is Neutral then thrust vector is forward high thrust //RuleSetThrustVec["Rule31"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule31"]); #endregion // if distance is left moderate dangerzone and X vel is high left then thrust vector is forward high thrust RuleSetThrustVec["Rule1"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule1"]); // if distance is left moderate dangerzone and X vel is moderate left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule2"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule2"]); // if distance is left moderate dangerzone and X vel is low left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule3"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule3"]); // if distance is left moderate dangerzone and X vel is neutral then thrust vector is forward moderate thrust RuleSetThrustVec["Rule4"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Low Thrust"], RuleSetThrustVec["Rule4"]); // if distance is left low dangerzone and X vel is high left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule5"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule5"]); // if distance is left low dangerzone and X vel is moderate left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule6"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule6"]); // if distance is left low dangerzone and X vel is low left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule7"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Low Thrust"], RuleSetThrustVec["Rule7"]); // if distance is left low dangerzone and X vel is high left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule8"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Low Thrust"], RuleSetThrustVec["Rule8"]); #endregion #region X Velocity Safezone Rules if (Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Easy)) { // if distance is safe zone and X vel is high left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule9"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule9"]); // if distance is safe zone and X vel is moderate left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule10"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule10"]); // if distance is safe zone and X vel is low left then thrust vector is forward low thrust RuleSetThrustVec["Rule11"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule11"]); // if distance is safe zone and X vel is neutral then thrust vector is neutral thrust RuleSetThrustVec["Rule12"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Neutral Thrust"], RuleSetThrustVec["Rule12"]); // if distance is safe zone and X vel is low right then thrust vector is backward low thrust RuleSetThrustVec["Rule13"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule13"]); // if distance is safe zone and X vel is moderate right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule14"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule14"]); // if distance is safe zone and X vel is high right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule15"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule15"]); // if distance is safe zone and X vel is moderate right then thrust vector is backward moderate thrust //RuleSetThrustVec[""] = Rule.AND(safeX, DistanceSets[""], speedX, XVelocitySets[""], ref thrustVectorOutput, ThrustVecSets[""], RuleSetThrustVec[""]); } if (Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Medium)) { // if distance is safe zone and X vel is high left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule9"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule9"]); // if distance is safe zone and X vel is moderate left then thrust vector is forward moderate thrust RuleSetThrustVec["Rule10"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule10"]); // if distance is safe zone and X vel is low left then thrust vector is forward low thrust RuleSetThrustVec["Rule11"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Low Thrust"], RuleSetThrustVec["Rule11"]); // if distance is safe zone and X vel is neutral then thrust vector is neutral thrust RuleSetThrustVec["Rule12"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Neutral Thrust"], RuleSetThrustVec["Rule12"]); // if distance is safe zone and X vel is low right then thrust vector is backward low thrust RuleSetThrustVec["Rule13"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Low Thrust"], RuleSetThrustVec["Rule13"]); // if distance is safe zone and X vel is moderate right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule14"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule14"]); // if distance is safe zone and X vel is high right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule15"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule15"]); // if distance is safe zone and X vel is moderate right then thrust vector is backward moderate thrust //RuleSetThrustVec[""] = Rule.AND(safeX, DistanceSets[""], speedX, XVelocitySets[""], ref thrustVectorOutput, ThrustVecSets[""], RuleSetThrustVec[""]); } #endregion #region X Velocity Right Dangerzone Rules #region Rule 16: if distance is right high dangerzone then thrust vector is backward high thrust RuleSetThrustVec["Rule16"] = Rule.IS(safeX, DistanceSets["Right High Dangerzone"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule16"]); //// if distance is left high dangerzone and X vel is high left then thrust vector is forward high thrust //RuleSetThrustVec["Rule25"] = Rule.AND(safeX, DistanceSets["Right High Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule25"]); //// if distance is left high dangerzone and X vel is moderate left then thrust vector is forward high thrust //RuleSetThrustVec["Rule26"] = Rule.AND(safeX, DistanceSets["Right High Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule26"]); //// if distance is left high dangerzone and X vel is Low left then thrust vector is forward high thrust //RuleSetThrustVec["Rule27"] = Rule.AND(safeX, DistanceSets["Right High Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule27"]); //// if distance is left high dangerzone and X vel is Neutral then thrust vector is forward high thrust //RuleSetThrustVec["Rule28"] = Rule.AND(safeX, DistanceSets["Right High Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule28"]); #endregion // if distance is right moderate dangerzone and X vel is high right then thrust vector is backward high thrust RuleSetThrustVec["Rule17"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule17"]); // if distance is right moderate dangerzone and X vel is moderate right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule18"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule18"]); // if distance is right moderate dangerzone and X vel is low right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule19"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule19"]); // if distance is right moderate dangerzone and X vel is neutral then thrust vector is backward moderate thrust RuleSetThrustVec["Rule20"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Low Thrust"], RuleSetThrustVec["Rule20"]); // if distance is right low dangerzone and X vel is high right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule21"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule21"]); // if distance is right low dangerzone and X vel is moderate right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule22"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule22"]); // if distance is right low dangerzone and X vel is low right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule23"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Low Thrust"], RuleSetThrustVec["Rule23"]); // if distance is right low dangerzone and X vel is high right then thrust vector is backward moderate thrust RuleSetThrustVec["Rule24"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Low Thrust"], RuleSetThrustVec["Rule24"]); #endregion } #endregion ThrottleAccum["ThrottleOutput"] = new FuzzySet(throttleOutput); ThrustVecAccum["ThrustVector"] = new FuzzySet(thrustVectorOutput); //Switch for how to adjust throttle settings ('AutoPilot' Checkbox on form) if (!Manual) { harrier.Throttle = _throttle; harrier.ThrustVector = _tv; } else { harrier.Throttle = Operations.DeFuzzifyCOG(ThrottleAccum["ThrottleOutput"]); harrier.ThrustVector = Operations.DeFuzzifyCOG(ThrustVecAccum["ThrustVector"]); } //THESE ARE UP TO YOU TO TUNE!! harrier.Throttle += 20; harrier.ThrustVector += 90; //END ((HarrierSim) Globals.Simulator).Harrier = harrier; }