Пример #1
0
 public static FGUIRule createFGUIRule(FuzzyRule r)
 {
     GameObject go = (GameObject)Instantiate(prefabFGUIRule);
     FGUIRule gui = go.GetComponent<FGUIRule>();
     gui.setRule(r);
     return gui;
 }
Пример #2
0
    private void testFuzzy()
    {
        // Creates a working Fuzzy system via code

        // Inference engine
        this.system.setEngine(new FuzzyInferenceEngine());

        // Variables
        FuzzyVariable vHealth = new FuzzyVariable("Health",0.0f,10.0f);
        vHealth.addMf("Low");	// Should also be able to specify slope and origin
        vHealth.addMf("Mid");
        vHealth.addMf("High");

        FuzzyVariable vDistance = new FuzzyVariable("Distance",0.0f,10.0f);
        vDistance.addMf("Low");
        vDistance.addMf("Mid");
        vDistance.addMf("High");

        FuzzyVariable vFear = new FuzzyVariable("Fear",0.0f,10.0f);
        vFear.addMf("Low");
        vFear.addMf("Mid");
        vFear.addMf("High");

        // Rules
        FuzzyRule rule = new FuzzyRule("Test1");
        rule.addAntecedent(vHealth,"Low");
        rule.addAntecedent(vDistance,"Low");
        rule.addConsequent(vFear,"High");
        this.system.addRule(rule);

        // Inferral
        this.system.infer();
    }
Пример #3
0
    public void Awake()
    {
        contentH = 1-titleH;
        ruleBuildH = 1-ruleTextH;
        ruleBuild2H = 1- ruleReposH;

        // TEST
        rule = new FuzzyRule("AA",Random.Range(1,10));

        GameObject repoGo = new GameObject("Repository");
        repoGo.transform.parent = transform;
        repoGo.transform.position = transform.position;

        repository = (FuzzyGUIRepoMenu)repoGo.AddComponent("FuzzyGUIRepoMenu");
    }
Пример #4
0
 public void setRule(FuzzyRule rule)
 {
     setRule(rule,FGUICompression.COMPRESSED);
 }
Пример #5
0
 public void setRule(FuzzyRule rule, FGUICompression compression)
 {
     this.rule = rule;
     this.name = rule.name;
     this.setCompression(compression);
 }
Пример #6
0
        public PlayerFeeling CalculateCurrentFeeling(PlayerScript player, PlayerFeeling curFeeling)
        {
            int quadsTouched = 0;
            for(int i = 0; i < QuadrantDensity; ++i)
            {
                for(int j = 0; j < QuadrantDensity; ++j)
                {
                    QuadrantsTouched[i,j].timer -= 1;
                    if(QuadrantsTouched[i,j].timer < 0)
                        QuadrantsTouched[i,j].timer = 0;

                    if(QuadrantsTouched[i,j].timer > 0)
                        ++quadsTouched;
                }
            }

            float dt = Time.deltaTime;
            float quadrantsPerSecond = quadsTouched / TimeSinceLastTouchDown;
            float anglesPerSecond = TotalAngleChanges / TimeSinceLastTouchDown;
            float distancePerSecond = DistanceTraveled / TimeSinceLastTouchDown;

            TotalAngleChanges -= 1000.0f * dt;
            //DistanceTraveled -= 1.0f*dt;
            if(TotalAngleChanges < 0)
                TotalAngleChanges = 0;
            if(DistanceTraveled < 0)
                DistanceTraveled= 0;

            FuzzyRule isSadQuadrants = new FuzzyRule(0, 2, 5, 15, quadsTouched);
            float amountOfSadQuads = isSadQuadrants.Fuzzify();
            FuzzyRule isHappyQuadrants = new FuzzyRule(5, 20, 35, 50, quadsTouched);
            float amountOfHappyQuads = isHappyQuadrants.Fuzzify();
            FuzzyRule isAngryQuadrants = new FuzzyRule(25, 40, 60, 255, quadsTouched);
            float amountOfAngryQuads = isAngryQuadrants.Fuzzify();

            float aps = anglesPerSecond * 0.1f;
            FuzzyRule isSadAngles = new FuzzyRule(0, 15, 45, 110, aps);
            float amountOfSadAngles = isSadAngles.Fuzzify();
            FuzzyRule isHappyAngles = new FuzzyRule(15, 50, 250, 360, aps);
            float amountOfHappyAngles = isHappyAngles.Fuzzify();
            FuzzyRule isAngryAngles = new FuzzyRule(200, 320, 400, 1500, aps);
            float amountOfAngryAngles = isAngryAngles.Fuzzify();

            FuzzyRule isSadDistance = new FuzzyRule(0, 0.25f, 0.85f, 1.25f, distancePerSecond);
            float amountOfSadDistance = isSadDistance.Fuzzify();
            FuzzyRule isHappyDistance = new FuzzyRule(0.5f, 1.15f, 2.0f, 4.0f, distancePerSecond);
            float amountOfHappyDistance = isHappyDistance.Fuzzify();
            FuzzyRule isAngryDistance = new FuzzyRule(1.75f, 3.0f, 5.0f, 10.0f, distancePerSecond);
            float amountOfAngryDistance = isAngryDistance.Fuzzify();

            player.totalSadness = (amountOfSadQuads +  amountOfSadDistance)/2.0f;
            player.totalHappiness = (amountOfHappyQuads +  amountOfHappyDistance)/2.0f;
            player.totalAngriness = (amountOfAngryQuads +  amountOfAngryDistance)/2.0f;

            string debugMsg = "\ntotalSadness: " + player.totalSadness.ToString("f2");
            debugMsg += "\ntotalHappiness: " + player.totalHappiness.ToString("f2");
            debugMsg += "\ntotalAngriness: " + player.totalAngriness.ToString("f2");

            //string debugMsg = "LineIntersects: " + LineIntersects.ToString();

            //string debugMsg = "quadsTouched: " + quadsTouched.ToString("f2");
            //debugMsg += "\naps: " + aps.ToString("f2");
            //debugMsg += "\ndistancePerSecond: " + distancePerSecond.ToString("f2");
            debugMsg += "\ncurrent feeling: " + curFeeling.ToString();
            //DebugStreamer.message = debugMsg;

            if(TimeSinceLastFeelingChange < 3.50f)
                return curFeeling;

            if(player.totalSadness > player.totalHappiness && player.totalSadness > player.totalAngriness)
                return PlayerFeeling.Sad;
            else if(player.totalHappiness > player.totalSadness && player.totalHappiness > player.totalAngriness)
                return PlayerFeeling.Happy;
            else if(player.totalAngriness > player.totalSadness && player.totalAngriness > player.totalHappiness)
                return PlayerFeeling.Angry;

            return curFeeling;
        }
Пример #7
0
 public void addRule(FuzzyRule rule)
 {
     this.rules.Add(rule);
 }
Пример #8
0
 public void addRule(FuzzyRule rule)
 {
     rules.Add(rule);
         //rules.Sort();// TODO sort according to priority
 }
Пример #9
0
    private void testRead()
    {
        // Read a fuzzy system from Fuzzy Tactics Data files
        Dictionary<string,object> dictVariables =  Json.loadJsonFromFolder("Assets/Scripts/Fuzzy/json/variables");
        Dictionary<string,object> dictRules = Json.loadJsonFromFolder("Assets/Scripts/Fuzzy/json/rules");

        // Inference engine
        this.system.setEngine(new FuzzyInferenceEngine());

        // Variables
         	//((List<object>) dict["array"])[0]);
        List<object> listVariables = ((List<object>) dictVariables["variables"]);

        foreach (Dictionary<string,object> variable in listVariables){
            float min = (float)((double)variable["min"]);
            float max = (float)((double)variable["max"]);

            FuzzyVariable newVar = new FuzzyVariable((string)variable["name"],min,max);

            List<object> mfs = ((List<object>) variable["mfs"]);
            foreach (Dictionary<string,object> mf in mfs){
                float origin = (float) ((double)mf["origin"]);
                float slope = (float) ((double)mf["slope"]);
                float width = (float) ((double)mf["width"]);
                newVar.addMf((string)mf["label"],slope,origin,width);
            }

            this.variables[newVar.name] = newVar;

            print("Added new variable " + newVar);

        }

        // Rules
        List<object> listRules = ((List<object>) dictRules["rules"]);

        foreach (Dictionary<string,object> rule in listRules){
            float weight = (float)((double)rule["weight"]);

            FuzzyRule newRule = new FuzzyRule((string)rule["name"], weight);

            List<object> antecedents = ((List<object>) rule["antecedents"]);
            foreach (Dictionary<string,object> antecedent in antecedents){
                newRule.addAntecedent(this.variables[(string)antecedent["variable"]], (string)antecedent["label"]);
            }

            List<object> consequents = ((List<object>) rule["consequents"]);
            foreach (Dictionary<string,object> consequent in consequents){
                newRule.addConsequent(this.variables[(string)consequent["variable"]], (string)consequent["label"]);
            }

            this.system.addRule(newRule);

            Debug.Log("Added new rule: " + newRule);
        }

        // Inferral
        //this.system.infer();
    }