Beispiel #1
0
    private void InitSheepDesireFM()
    {
        sheepDesireFM = new FuzzyModule();
        FuzzyVariable DistToTarget = sheepDesireFM.CreateFLV("DistToOgre");

        FzSet Dist_Close  = DistToTarget.AddLeftShoulderSet("Dist_Close", 0, 25, 150);
        FzSet Dist_Medium = DistToTarget.AddTriangleSet("Dist_Medium", 25, 50, 300);
        FzSet Dist_Far    = DistToTarget.AddRightShoulderSet("Dist_Far", 150, 300, 500);

        FuzzyVariable AmmoStatus = sheepDesireFM.CreateFLV("Hunger");

        FzSet Hunger_Low     = AmmoStatus.AddLeftShoulderSet("Hunger_Low", 0, 0, 10);
        FzSet Hunger_Okay    = AmmoStatus.AddTriangleSet("Hunger_Okay", 0, 10, 30);
        FzSet Hunger_Intense = AmmoStatus.AddRightShoulderSet("Hunger_Intense", 10, 30, 40);

        FuzzyVariable Desirability = sheepDesireFM.CreateFLV("Desirability");

        FzSet Undersirable  = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50);
        FzSet Desirable     = Desirability.AddTriangleSet("Desirable", 25, 50, 75);
        FzSet VeryDesirable = Desirability.AddRightShoulderSet("VeryDesirable", 50, 75, 100);

        sheepDesireFM.AddRule(new FzAND(Dist_Close, Hunger_Low), Undersirable);
        sheepDesireFM.AddRule(new FzAND(Dist_Close, Hunger_Okay), Undersirable);
        sheepDesireFM.AddRule(new FzAND(Dist_Close, Hunger_Intense), Undersirable);
        sheepDesireFM.AddRule(new FzAND(Dist_Medium, Hunger_Low), Desirable);
        sheepDesireFM.AddRule(new FzAND(Dist_Medium, Hunger_Okay), VeryDesirable);
        sheepDesireFM.AddRule(new FzAND(Dist_Medium, Hunger_Intense), VeryDesirable);
        sheepDesireFM.AddRule(new FzAND(Dist_Far, Hunger_Low), Undersirable);
        sheepDesireFM.AddRule(new FzAND(Dist_Far, Hunger_Okay), Desirable);
        sheepDesireFM.AddRule(new FzAND(Dist_Far, Hunger_Intense), Desirable);
    }
Beispiel #2
0
        public Thirst() : base()
        {
            _module = new FuzzyModule();

            // Antecedents
            FuzzyVariable Thirst      = _module.CreateFLV("Thirst");
            var           Thirst_Low  = Thirst.AddLeftShoulderSet("Thirst_Low", 0, 10, 20);
            var           Thirst_Med  = Thirst.AddTriangularSet("Thirst_Med", 10, 20, 30);
            var           Thirst_High = Thirst.AddRightShoulderSet("Thirst_High", 20, 30, _MAX_THIRST);

            FuzzyVariable Distance        = _module.CreateFLV("Distance");
            var           Distance_Close  = Distance.AddLeftShoulderSet("Distance_Close", 0, 40, 80);
            var           Distance_Medium = Distance.AddTriangularSet("Distance_Medium", 40, 80, 400);
            var           Distance_Far    = Distance.AddRightShoulderSet("Distance_Far", 80, 400, MAX_DISTANCE);

            // Consequence
            FuzzyVariable Desirability  = _module.CreateFLV("Desirability");
            var           Undesirable   = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50);
            var           Desirable     = Desirability.AddTriangularSet("Desirable", 25, 50, 75);
            var           VeryDesirable = Desirability.AddRightShoulderSet("VeryDesirable", 50, 75, 100);

            // Rules
            _module.AddRule(new FzAND(Thirst_Low, Distance_Close), Undesirable);
            _module.AddRule(new FzAND(Thirst_Low, Distance_Medium), Undesirable);
            _module.AddRule(new FzAND(Thirst_Low, Distance_Far), Undesirable);
            _module.AddRule(new FzAND(Thirst_Med, Distance_Close), Desirable);
            _module.AddRule(new FzAND(Thirst_Med, Distance_Medium), Undesirable);
            _module.AddRule(new FzAND(Thirst_Med, Distance_Far), Undesirable);
            _module.AddRule(new FzAND(Thirst_High, Distance_Close), VeryDesirable);
            _module.AddRule(new FzAND(Thirst_High, Distance_Medium), VeryDesirable);
            _module.AddRule(new FzAND(Thirst_High, Distance_Far), Desirable);
        }
Beispiel #3
0
        private void InitFuzzySets()
        {
            fm              = new FuzzyModule();
            DistToPlayer    = fm.CreateFLV("DistanceToPlayer");
            Distance_Close  = DistToPlayer.AddLeftShoulderSet("Close", 0, 40, 200);
            Distance_Medium = DistToPlayer.AddTriangularSet("Medium", 40, 200, 300);
            Distance_Far    = DistToPlayer.AddRightShoulderSet("Far", 200, 300, 400);

            RangeOfSeight = fm.CreateFLV("RangeOfSeight");
            Seight_Foggy  = RangeOfSeight.AddLeftShoulderSet("Foggy", 0, 1, 5);
            Seight_Dusty  = RangeOfSeight.AddTriangularSet("Dusty", 1, 5, 9);
            Seight_Clear  = RangeOfSeight.AddRightShoulderSet("Clear", 5, 9, 10);

            PlayerDistance         = fm.CreateFLV("PlayerDistance");
            Player_Is_ToClose      = PlayerDistance.AddLeftShoulderSet("ToClose", 0, 40, 200);
            Player_Is_PerfectRange = PlayerDistance.AddTriangularSet("Perfect", 40, 200, 360);
            Player_Is_FarAway      = PlayerDistance.AddRightShoulderSet("Far", 200, 360, 400);

            // Without Combs method, therefore: 3^2 = 9
            fm.AddRule(new FzAND(Distance_Close, Seight_Foggy), Player_Is_ToClose);
            fm.AddRule(new FzAND(Distance_Medium, Seight_Foggy), Player_Is_FarAway);
            fm.AddRule(new FzAND(Distance_Far, Seight_Foggy), Player_Is_FarAway);

            fm.AddRule(new FzAND(Distance_Close, Seight_Dusty), Player_Is_ToClose);
            fm.AddRule(new FzAND(Distance_Medium, Seight_Dusty), Player_Is_PerfectRange);
            fm.AddRule(new FzAND(Distance_Far, Seight_Dusty), Player_Is_FarAway);

            fm.AddRule(new FzAND(Distance_Close, Seight_Clear), Player_Is_ToClose);
            fm.AddRule(new FzAND(Distance_Medium, Seight_Clear), Player_Is_PerfectRange);
            fm.AddRule(new FzAND(Distance_Far, Seight_Clear), Player_Is_PerfectRange);
        }
Beispiel #4
0
        public void FuzzyTowerCalcSniper(FuzzyModule towerFuzzyModule)
        {
            // Retrieves the antecedents.
            FuzzyVariable health = towerFuzzyModule.GetVar("Health");
            FzSet         low    = new FzSet(health.GetSet("Low"));
            FzSet         middle = new FzSet(health.GetSet("Middle"));
            FzSet         high   = new FzSet(health.GetSet("High"));


            FuzzyVariable distanceToEnemy = towerFuzzyModule.GetVar("DistanceToEnemy");
            FzSet         close           = new FzSet(distanceToEnemy.GetSet("Close"));
            FzSet         medium          = new FzSet(distanceToEnemy.GetSet("Medium"));
            FzSet         far             = new FzSet(distanceToEnemy.GetSet("Far"));

            // Creates the consequent.
            FuzzyVariable shootDesirability = towerFuzzyModule.CreateFLV("ShootDesirability");

            FzSet undesirable   = shootDesirability.AddLeftShoulderSet("Undesirable", 0, 15, 30);
            FzSet desirable     = shootDesirability.AddTriangularSet("Desirable", 15, 30, 75);
            FzSet veryDesirable = shootDesirability.AddRightShoulderSet("VeryDesirable", 30, 75, 100);

            // Add rules to complete the FAM.
            towerFuzzyModule.AddRule(new FzAND(low, close), desirable);
            towerFuzzyModule.AddRule(new FzAND(low, medium), desirable);
            towerFuzzyModule.AddRule(new FzAND(low, far), veryDesirable);

            towerFuzzyModule.AddRule(new FzAND(middle, close), undesirable);
            towerFuzzyModule.AddRule(new FzAND(middle, medium), undesirable);
            towerFuzzyModule.AddRule(new FzAND(middle, far), desirable);

            towerFuzzyModule.AddRule(new FzAND(high, close), undesirable);
            towerFuzzyModule.AddRule(new FzAND(high, medium), undesirable);
            towerFuzzyModule.AddRule(new FzAND(high, far), desirable);
        }
Beispiel #5
0
    private void Awake()
    {
        fm = new FuzzyModule();
        FuzzyVariable DistToTarget = fm.CreateFLV("DistToTarget");

        FzSet Target_Close  = DistToTarget.AddLeftShoulderSet("Target_Close", 0, 25, 150);
        FzSet Target_Medium = DistToTarget.AddTriangleSet("Target_Medium", 25, 50, 300);
        FzSet Target_Far    = DistToTarget.AddRightShoulderSet("Target_Far", 150, 300, 500);

        FuzzyVariable AmmoStatus = fm.CreateFLV("AmmoStatus");

        FzSet Ammo_Low   = AmmoStatus.AddLeftShoulderSet("Ammo_Low", 0, 0, 10);
        FzSet Ammo_Okay  = AmmoStatus.AddTriangleSet("Ammo_Okay", 0, 10, 30);
        FzSet Ammo_Loads = AmmoStatus.AddRightShoulderSet("Ammo_Loads", 10, 30, 40);

        FuzzyVariable Desirability = fm.CreateFLV("Desirablility");

        FzSet Undersirable  = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50);
        FzSet Desirable     = Desirability.AddTriangleSet("Desirable", 25, 50, 75);
        FzSet VeryDesirable = Desirability.AddRightShoulderSet("VeryDesirable", 50, 75, 100);

        fm.AddRule(new FzAND(Target_Close, Ammo_Low), Undersirable);
        fm.AddRule(new FzAND(Target_Close, Ammo_Okay), Undersirable);
        fm.AddRule(new FzAND(Target_Close, Ammo_Loads), Undersirable);
        fm.AddRule(new FzAND(Target_Medium, Ammo_Low), Desirable);
        fm.AddRule(new FzAND(Target_Medium, Ammo_Okay), VeryDesirable);
        fm.AddRule(new FzAND(Target_Medium, Ammo_Loads), VeryDesirable);
        fm.AddRule(new FzAND(Target_Far, Ammo_Low), Undersirable);
        fm.AddRule(new FzAND(Target_Far, Ammo_Okay), Desirable);
        fm.AddRule(new FzAND(Target_Far, Ammo_Loads), Desirable);
    }
        public ThinkGoal(ConsciousGameEntity entity) : base(entity)
        {
            fuzzyModule = new FuzzyModule();

            FuzzyVariable hunger   = fuzzyModule.CreateFLV("Hunger");
            FzSet         starving = hunger.AddLeftShoulder("Starving", 0.0, 0.1, 0.3);
            FzSet         content  = hunger.AddTriangle("Content", 0.1, 0.5, 0.8);
            FzSet         full     = hunger.AddRightShoulder("Full", 0.5, 0.8, 1.0);

            FuzzyVariable sleep  = fuzzyModule.CreateFLV("Sleep");
            FzSet         tired  = sleep.AddLeftShoulder("Tired", 0.0, 0.1, 0.3);
            FzSet         sleepy = sleep.AddTriangle("Sleepy", 0.1, 0.3, 0.5);
            FzSet         awake  = sleep.AddRightShoulder("Awake", 0.3, 0.5, 1.0);

            FuzzyVariable desirability  = fuzzyModule.CreateFLV("Desirability");
            FzSet         undesirable   = desirability.AddLeftShoulder("Undesirable", 0, 0.25, 0.5);
            FzSet         desirable     = desirability.AddTriangle("Desirable", 0.25, 0.5, 0.75);
            FzSet         veryDesirable = desirability.AddRightShoulder("VeryDesirable", 0.5, 0.75, 1.0);

            fuzzyModule.AddRule(new FzOR(starving, tired), undesirable);
            fuzzyModule.AddRule(new FzAND(content, sleepy), undesirable);
            fuzzyModule.AddRule(new FzAND(full, sleepy), desirable);
            fuzzyModule.AddRule(new FzAND(content, awake), desirable);
            fuzzyModule.AddRule(new FzAND(full, awake), veryDesirable);
        }
Beispiel #7
0
        public MakeDecisionGoal(AwareEntity me) : base(me)
        {
            fuzzyModule = new FuzzyModule();

            FuzzyVariable hunger  = fuzzyModule.CreateFLV("Hunger");
            FzSet         hungry  = hunger.AddLeftShoulder("Hungry", 0.0, 0.1, 0.3);
            FzSet         content = hunger.AddTriangle("Content", 0.1, 0.5, 0.8);
            FzSet         full    = hunger.AddRightShoulder("Full", 0.5, 0.8, 1.0);

            FuzzyVariable fatique = fuzzyModule.CreateFLV("Fatique");
            FzSet         sleepy  = fatique.AddLeftShoulder("Sleepy", 0.0, 0.1, 0.3);
            FzSet         awake   = fatique.AddTriangle("Awake", 0.1, 0.3, 0.5);
            FzSet         alert   = fatique.AddRightShoulder("Alert", 0.3, 0.5, 1.0);

            FuzzyVariable desirability  = fuzzyModule.CreateFLV("Desirability");
            FzSet         unDesirable   = desirability.AddLeftShoulder("Undesirable", 0, 0.25, 0.5);
            FzSet         desirable     = desirability.AddTriangle("Desirable", 0.25, 0.5, 0.75);
            FzSet         veryDesirable = desirability.AddRightShoulder("VeryDesirable", 0.5, 0.75, 1.0);

            fuzzyModule.AddRule(new FzAND(hungry, sleepy), unDesirable);
            fuzzyModule.AddRule(new FzAND(hungry, awake), desirable);
            fuzzyModule.AddRule(new FzAND(hungry, alert), veryDesirable);
            fuzzyModule.AddRule(new FzAND(content, sleepy), unDesirable);
            fuzzyModule.AddRule(new FzAND(content, awake), desirable);
            fuzzyModule.AddRule(new FzAND(content, alert), veryDesirable);
            fuzzyModule.AddRule(new FzAND(full, sleepy), unDesirable);
            fuzzyModule.AddRule(new FzAND(full, awake), desirable);
            fuzzyModule.AddRule(new FzAND(full, alert), veryDesirable);
        }
Beispiel #8
0
    private void InitPromisingRegionFM()
    {
        // Promising Region FuzzyModule
        promisingRegionFM = new FuzzyModule();
        FuzzyVariable DistToRegion = promisingRegionFM.CreateFLV("DistToRegion");

        FzSet Dist_Close  = DistToRegion.AddLeftShoulderSet("Dist_Close", 0, 50, 150);
        FzSet Dist_Medium = DistToRegion.AddTriangleSet("Dist_Medium", 50, 150, 200);
        FzSet Dist_Far    = DistToRegion.AddRightShoulderSet("Dist_Far", 150, 250, 300);

        FuzzyVariable RegionWealth = promisingRegionFM.CreateFLV("RegionWealth");

        FzSet Region_Poor   = RegionWealth.AddLeftShoulderSet("Region_Poor", 0, 300, 750);
        FzSet Region_Decent = RegionWealth.AddTriangleSet("Region_Decent", 750, 1500, 2700);
        FzSet Region_Rich   = RegionWealth.AddRightShoulderSet("Region_Rich", 2250, 2700, Region.MAX_RESOURCE_COUNT);

        FuzzyVariable Desirability = promisingRegionFM.CreateFLV("Desirability");

        FzSet Undersirable   = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50);
        FzSet Desirable      = Desirability.AddTriangleSet("Desirable", 25, 50, 75);
        FzSet Very_Desirable = Desirability.AddRightShoulderSet("VeryDesirable", 50, 75, 100);

        promisingRegionFM.AddRule(new FzAND(Dist_Close, Region_Poor), Undersirable);
        promisingRegionFM.AddRule(new FzAND(Dist_Close, Region_Decent), Desirable);
        promisingRegionFM.AddRule(new FzAND(Dist_Close, Region_Rich), Very_Desirable);
        promisingRegionFM.AddRule(new FzAND(Dist_Medium, Region_Poor), Undersirable);
        promisingRegionFM.AddRule(new FzAND(Dist_Medium, Region_Decent), Undersirable);
        promisingRegionFM.AddRule(new FzAND(Dist_Medium, Region_Rich), Very_Desirable);
        promisingRegionFM.AddRule(new FzAND(Dist_Far, Region_Poor), Undersirable);
        promisingRegionFM.AddRule(new FzAND(Dist_Far, Region_Decent), Undersirable);
        promisingRegionFM.AddRule(new FzAND(Dist_Far, Region_Rich), Very_Desirable);
    }
Beispiel #9
0
 /* Right now the calculate function only relies on 2 input sets and 1 output set... */
 public static double calculate(FuzzyModule module, string xname, double xval, string yname, double yval, string outname)
 {
     module.Fuzzify(xname, ref xval);
     module.Fuzzify(yname, ref yval);
     Console.WriteLine(module.VarMap[xname]);
     Console.WriteLine(module.VarMap[yname]);
     return(module.Defuzzify(outname, FuzzyModule.DefuzzifyType.CENTROID));
 }
        public void CreateFuzzyFLV()
        {
            FuzzyModule fuzzyModule = new FuzzyModule();

            FuzzyVariable distanceToTarget = fuzzyModule.CreateFLV("DistanceToTarget");

            Assert.NotEqual(null, distanceToTarget);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        protected override void InitializeFuzzyModule()
        {
            InitializeDistanceToTarget(out var targetClose, out var targetMedium, out var targetFar);

            FzSet veryDesirable;

            InitializeDesirability(out var undesirable, out var desirable, out veryDesirable);

            FuzzyModule.AddRule(targetClose, desirable);
            FuzzyModule.AddRule(targetMedium, new FzVery(undesirable));
            FuzzyModule.AddRule(targetFar, new FzVery(undesirable));
        }
Beispiel #13
0
 /// FuzzyTower constructor.
 public FuzzyTower()
 {
     name                    = "Fuzzy Tower";
     description             = "The Fuzzy Tower carries 2 weapons: A long ranged sniper and a short ranged shotgun. It uses Fuzzy Logic to decide which weapon to use.";
     goldCost                = 35;
     sprite                  = new Bitmap(Properties.Resources.FuzzyTowerSprite);
     towerShotgunFuzzyModule = InitFuzzyTowerBaseModule();
     towerSniperFuzzyModule  = InitFuzzyTowerBaseModule();
     weapon                  = sniper;
     FuzzyTowerCalcShotgun(towerShotgunFuzzyModule);
     FuzzyTowerCalcSniper(towerSniperFuzzyModule);
 }
Beispiel #14
0
        public void Setup()
        {
            this.fuzzyModule = new FuzzyModule();

            const float range      = 1000; // max distance from one corner to another
            const float nearPeak   = .25f * range;
            const float mediumPeak = .5f * range;
            const float farPeak    = .75f * range;

            Variable ownDistanceVariable = this.fuzzyModule.CreateVariable(OWN_DISTANCE_VARIABLE_KEY);
            SetProxy selfNear            = ownDistanceVariable.AddLeftShoulder("near", 0, nearPeak, mediumPeak);
            SetProxy selfMedium          = ownDistanceVariable.AddTriangleSet("medium", nearPeak, mediumPeak, farPeak);
            SetProxy selfFar             = ownDistanceVariable.AddRightShoulder("far", mediumPeak, farPeak, range);

            Variable avgTeammatesDistanceVariable = this.fuzzyModule.CreateVariable(AVG_TEAMMATE_DISTANCE_VARIABLE_KEY);
            SetProxy teamNear   = avgTeammatesDistanceVariable.AddLeftShoulder("near", 0, nearPeak, mediumPeak);
            SetProxy teamMedium = avgTeammatesDistanceVariable.AddTriangleSet("medium", nearPeak, mediumPeak, farPeak);
            SetProxy teamFar    = avgTeammatesDistanceVariable.AddRightShoulder("far", mediumPeak, farPeak, range);

            Variable strategyVariable = this.fuzzyModule.CreateVariable(OWN_STRATEGY_VARIABLE_KEY);

            this.defensive = strategyVariable.AddLeftShoulder("defensive", 0, .4, .6);
            this.offensive = strategyVariable.AddRightShoulder("offensive", .4, .6, 1);

            /*
             * IF I am near AND teammates are near
             * THEN offensive
             *
             * IF I am near AND teammates are medium distance or far
             * THEN defensive
             *
             * IF I am medium distance AND teammates are (medium distance OR far)
             * THEN defensive
             *
             * IF teammates are near
             * THEN offensive
             *
             * IF I am far
             * THEN offensive
             */

            this.rule_nearAndNear          = new And(selfNear, teamNear);
            this.rule_nearAndMedium        = new And(selfNear, teamMedium);
            this.rule_mediumAndMediumOrFar = new And(selfMedium, new Or(teamMedium, teamFar));
            this.rule_near = teamNear;
            this.rule_far  = selfFar;

            this.fuzzyModule.AddRule(this.rule_nearAndNear, this.offensive);
            this.fuzzyModule.AddRule(this.rule_nearAndMedium, this.defensive);
            this.fuzzyModule.AddRule(this.rule_mediumAndMediumOrFar, this.defensive);
            this.fuzzyModule.AddRule(this.rule_near, this.offensive);
            this.fuzzyModule.AddRule(this.rule_far, this.offensive);
        }
Beispiel #15
0
        public Think(Ship owner, World world) : base(owner)
        {
            this.world  = world;
            this.random = new Random();

            this.fuzzyModule = new FuzzyModule();

            const float range      = 1000; // max distance from one corner to another
            const float nearPeak   = .25f * range;
            const float mediumPeak = .5f * range;
            const float farPeak    = .75f * range;

            Variable ownDistanceVariable = this.fuzzyModule.CreateVariable(OWN_DISTANCE_VARIABLE_KEY);
            SetProxy selfNear            = ownDistanceVariable.AddLeftShoulder("near", 0, nearPeak, mediumPeak);
            SetProxy selfMedium          = ownDistanceVariable.AddTriangleSet("medium", nearPeak, mediumPeak, farPeak);
            SetProxy selfFar             = ownDistanceVariable.AddRightShoulder("far", mediumPeak, farPeak, range);

            Variable avgTeammatesDistanceVariable = this.fuzzyModule.CreateVariable(AVG_TEAMMATE_DISTANCE_VARIABLE_KEY);
            SetProxy teamNear   = avgTeammatesDistanceVariable.AddLeftShoulder("near", 0, nearPeak, mediumPeak);
            SetProxy teamMedium = avgTeammatesDistanceVariable.AddTriangleSet("medium", nearPeak, mediumPeak, farPeak);
            SetProxy teamFar    = avgTeammatesDistanceVariable.AddRightShoulder("far", mediumPeak, farPeak, range);

            Variable strategyVariable = this.fuzzyModule.CreateVariable(OWN_STRATEGY_VARIABLE_KEY);

            this.defensive = strategyVariable.AddLeftShoulder("defensive", 0, .3, .5);
            this.offensive = strategyVariable.AddRightShoulder("offensive", .3, .5, 1);

            /*
             * IF I am near AND teammates are near
             * THEN offensive
             *
             * IF I am near AND teammates are medium distance or far
             * THEN defensive
             *
             * IF I am medium distance AND teammates are (medium distance OR far)
             * THEN defensive
             *
             * IF teammates are near
             * THEN offensive
             *
             * IF I am far
             * THEN offensive
             */

            this.fuzzyModule.AddRule(new And(
                                         new Or(selfNear, selfMedium),
                                         new Or(teamMedium, teamFar)
                                         ), this.defensive);
            this.fuzzyModule.AddRule(new Or(teamNear, selfFar), this.offensive);
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
 public Hunter(Vector2D pos, World world, float searchRadius) : base(pos, world)
 {
     stamina           = STAMINA_LIMIT;
     tinder            = 0;
     Scale             = 10;
     radius            = 10;
     MaxSpeed          = 100;
     Max_Force         = 25f;
     foundTorches      = new List <TorchObject>();
     this.searchRadius = searchRadius;
     brain             = new Brain(this);
     this.searchRadius = searchRadius;
     foundTorches      = new List <TorchObject>();
     fuzzyModule       = new FuzzyModule();
     level             = 0;
     FuzzyInitializer.InitializeRules(this);
 }
Beispiel #18
0
        public FuzzyModule InitFuzzyTowerBaseModule()
        {
            FuzzyModule towerFuzzyModule = new FuzzyModule();

            FuzzyVariable health = towerFuzzyModule.CreateFLV("Health");

            health.AddLeftShoulderSet("Low", 0, 20, 33);
            health.AddTriangularSet("Middle", 20, 33, 60);
            health.AddRightShoulderSet("High", 33, 60, 100);

            FuzzyVariable distanceToEnemy = towerFuzzyModule.CreateFLV("DistanceToEnemy");

            distanceToEnemy.AddLeftShoulderSet("Close", 0, 29, 30);
            distanceToEnemy.AddTriangularSet("Medium", 29, 30, 66);
            distanceToEnemy.AddRightShoulderSet("Far", 30, 66, 100);

            return(towerFuzzyModule);
        }
        public void Initialize()
        {
            _module = new FuzzyModule();

            FuzzyVariable ammo = _module.CreateFLV("ammo");
            IFuzzySet ammoLow = ammo.AddLeftShoulderSet("low", 0, 2, 8);
            IFuzzySet ammoDecent = ammo.AddTriangularSet("decent", 2, 8, 16);
            IFuzzySet ammoPlenty = ammo.AddRightShoulderSet("plenty", 8, 16, 32);

            FuzzyVariable desirability = _module.CreateFLV("desirability");
            IFuzzySet undesirable = desirability.AddLeftShoulderSet("undesirable", 0, 25, 50);
            IFuzzySet desirable = desirability.AddTriangularSet("desirable", 25, 50, 75);
            IFuzzySet veryDesirable = desirability.AddRightShoulderSet("very_desirable", 50, 75, 100);

            // Desirability for reloading.
            _module.AddRule(ammoLow, veryDesirable);
            _module.AddRule(ammoDecent, desirable);
            _module.AddRule(ammoPlenty, undesirable);
        }
        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);
        }
 protected Weapon(
     WeaponTypes weaponType,
     int roundsRemaining,
     int maximumRoundsCarried,
     float rateOfFire,
     float idealRange,
     float projectileSpeed,
     Agent agent)
 {
     FuzzyModule            = new FuzzyModule();
     WeaponType             = weaponType;
     RoundsRemaining        = roundsRemaining;
     Agent                  = agent;
     RateOfFire             = rateOfFire;
     MaximumRoundsCarried   = maximumRoundsCarried;
     LastDesirabilityScore  = 0;
     IdealRange             = idealRange;
     MaximumProjectileSpeed = projectileSpeed;
     TimeNextAvailable      = Time.time;
 }
Beispiel #22
0
        protected override void InitializeFuzzyModule()
        {
            InitializeDistanceToTarget(out var targetClose, out var targetMedium, out var targetFar);

            InitializeDesirability(out var undesirable, out var desirable, out var veryDesirable);

            var ammoStatus = FuzzyModule.CreateFlv("ammoStatus");
            var ammoLoads  = ammoStatus.AddRightShoulderSet("ammoLoads", 10, 12, 15);
            var ammoOkay   = ammoStatus.AddTriangularSet("ammoOkay", 5, 10, 12);
            var ammoLow    = ammoStatus.AddTriangularSet("ammoLow", 0, 2, 6);

            FuzzyModule.AddRule(new FzAnd(targetClose, ammoLoads), undesirable);
            FuzzyModule.AddRule(new FzAnd(targetClose, ammoOkay), undesirable);
            FuzzyModule.AddRule(new FzAnd(targetClose, ammoLow), undesirable);

            FuzzyModule.AddRule(new FzAnd(targetMedium, ammoLoads), veryDesirable);
            FuzzyModule.AddRule(new FzAnd(targetMedium, ammoOkay), veryDesirable);
            FuzzyModule.AddRule(new FzAnd(targetMedium, ammoLow), desirable);
            FuzzyModule.AddRule(new FzAnd(targetFar, ammoLoads), desirable);
            FuzzyModule.AddRule(new FzAnd(targetFar, ammoOkay), undesirable);
            FuzzyModule.AddRule(new FzAnd(targetFar, ammoLow), undesirable);
        }
    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);
    }
        // 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);
        }
Beispiel #25
0
 public Region(int resourceCount, AABB bounding, FuzzyModule fm)
 {
     this.resourceCount = resourceCount;
     this.bounding      = bounding;
     this.fm            = fm;
 }
Beispiel #26
0
        static void Main(string[] args)
        {
            Console.WriteLine("hello {0}", "John");

            FuzzyModule   fm           = new FuzzyModule();
            FuzzyVariable Dist2Target  = fm.CreateFLV("Dist2Target");
            FuzzyVariable Desirability = fm.CreateFLV("Desirability");
            FuzzyVariable AmmoStatus   = fm.CreateFLV("AmmoStatus");

            FzSet Target_Close = Dist2Target.AddLeftShoulderSet("Target_Close",
                                                                0, 25, 150);
            FzSet Target_Medium = Dist2Target.AddTrianglularSet("Target_Medium",
                                                                25, 150, 300);
            FzSet Target_Far = Dist2Target.AddRightShoulderSet("Target_Far",
                                                               150, 300, 400);

            FzSet Ammon_low = AmmoStatus.AddLeftShoulderSet("Ammon_low",
                                                            0, 0, 10);
            FzSet Ammon_Okay = AmmoStatus.AddTrianglularSet("Ammon_Okay",
                                                            0, 10, 30);
            FzSet Ammon_Loads = AmmoStatus.AddRightShoulderSet("Ammon_Loads",
                                                               10, 30, 40);

            FzSet Undesirable = Desirability.AddLeftShoulderSet("Undesirable",
                                                                0, 25, 50);
            FzSet Desirable = Desirability.AddTrianglularSet("Desirable",
                                                             25, 50, 75);
            FzSet VeryDesirable = Desirability.AddRightShoulderSet("VeryDesirable",
                                                                   50, 75, 100);

            bool Combos = true;

            if (Combos)
            {
                fm.AddRule((Target_Far), Undesirable);
                fm.AddRule((Target_Medium), VeryDesirable);
                fm.AddRule((Target_Close), Undesirable);
                fm.AddRule((Ammon_Loads), VeryDesirable);
                fm.AddRule((Ammon_Okay), Desirable);
                fm.AddRule((Ammon_low), Undesirable);

                //fm.AddRule(new FzFairly(Target_Far), Undesirable);
                //fm.AddRule(new FzFairly(Target_Medium), VeryDesirable);
                //fm.AddRule(new FzFairly(Target_Close), Undesirable);
                //fm.AddRule(new FzFairly(Ammon_Loads), VeryDesirable);
                //fm.AddRule(new FzFairly(Ammon_Okay), Desirable);
                //fm.AddRule(new FzFairly(Ammon_low), Undesirable);

                //fm.AddRule(new FzVery(Target_Far), Undesirable);
                //fm.AddRule(new FzVery(Target_Medium), VeryDesirable);
                //fm.AddRule(new FzVery(Target_Close), Undesirable);
                //fm.AddRule(new FzVery(Ammon_Loads), VeryDesirable);
                //fm.AddRule(new FzVery(Ammon_Okay), Desirable);
                //fm.AddRule(new FzVery(Ammon_low), Undesirable);
            }
            else
            {
                fm.AddRule(new FzAND(Target_Far, Ammon_Loads), Desirable);
                fm.AddRule(new FzAND(Target_Far, Ammon_Okay), Undesirable);
                fm.AddRule(new FzAND(Target_Far, Ammon_low), Undesirable);

                fm.AddRule(new FzAND(Target_Medium, Ammon_Loads), VeryDesirable);
                fm.AddRule(new FzAND(Target_Medium, Ammon_Okay), VeryDesirable);
                fm.AddRule(new FzAND(Target_Medium, Ammon_low), Desirable);

                fm.AddRule(new FzAND(Target_Close, Ammon_Loads), Undesirable);
                fm.AddRule(new FzAND(Target_Close, Ammon_Okay), Undesirable);
                fm.AddRule(new FzAND(Target_Close, Ammon_low), Undesirable);
            }

            fm.Fuzzify("Dist2Target", 200);
            fm.Fuzzify("AmmoStatus", 8);

            double result = fm.Defuzzify("Desirability", FuzzyModule.DefuzzifyMethod.max_av);

            Console.WriteLine("Dist2Target is {0}", fm.Defuzzify("Dist2Target", FuzzyModule.DefuzzifyMethod.max_av));
            Console.WriteLine("AmmoStatus is {0}", fm.Defuzzify("AmmoStatus", FuzzyModule.DefuzzifyMethod.max_av));
            Console.WriteLine("Desirability is {0}", result);
        }
        public void CreateFuzzyModule()
        {
            FuzzyModule fuzzyModule = new FuzzyModule();

            Assert.NotEqual(null, fuzzyModule);
        }
        /// <summary>
        /// static VALUE r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
        /// </summary>
        /// <param name="hasivp"></param>
        /// <param name="ivp"></param>
        /// <param name="extmod"></param>
        /// <returns></returns>
        public object ReadObject0(bool hasivp, ref bool ivp, List <FuzzyModule> extmod)
        {
            object v    = null;
            int    type = ReadByte();
            int    id;
            object link;

            switch (type)
            {
            case RubyMarshal.Types.Link:
                id = ReadLong();
                if (!this.m_objects.TryGetValue(id, out link))
                {
                    throw new InvalidDataException("dump format error (unlinked)");
                }
                v = link;
                if (this.m_proc != null)
                {
                    v = this.m_proc(v);
                }
                break;

            case RubyMarshal.Types.InstanceVariable:
            {
                bool ivar = true;
                v = ReadObject0(ref ivar, extmod);
                bool hasenc = false;
                if (ivar)
                {
                    ReadInstanceVariable(v, ref hasenc);
                }
            }
            break;

            case RubyMarshal.Types.Extended:
            {
                FuzzyModule m = FuzzyModule.GetModule(ReadUnique());
                if (extmod == null)
                {
                    extmod = new List <FuzzyModule>();
                }
                extmod.Add(m);
                v = ReadObject0(extmod);
                FuzzyObject fobj = v as FuzzyObject;
                if (fobj != null)
                {
                    fobj.ExtendModules.AddRange(extmod);
                }
            }
            break;

            case RubyMarshal.Types.UserClass:
            {
                FuzzyClass c = FuzzyClass.GetClass(ReadUnique());

                v = ReadObject0(extmod);
                if (v is FuzzyObject)
                {
                    (v as FuzzyObject).ClassName = c.Symbol;
                }
            }
            break;

            case RubyMarshal.Types.Nil:
                v = FuzzyNil.Instance;
                v = Leave(v);
                break;

            case RubyMarshal.Types.True:
                v = FuzzyBool.True;
                v = Leave(v);
                break;

            case RubyMarshal.Types.False:
                v = FuzzyBool.False;
                v = Leave(v);
                break;

            case RubyMarshal.Types.Fixnum:
                v = ReadLong();
                v = new FuzzyFixnum(Convert.ToInt64(v));
                v = Leave(v);
                break;

            case RubyMarshal.Types.Float:
            {
                double      d;
                FuzzyString fstr = ReadString();
                string      str  = fstr.Text;

                if (str == "inf")
                {
                    d = double.PositiveInfinity;
                }
                else if (str == "-inf")
                {
                    d = double.NegativeInfinity;
                }
                else if (str == "nan")
                {
                    d = double.NaN;
                }
                else
                {
                    if (str.Contains("\0"))
                    {
                        str = str.Remove(str.IndexOf("\0"));
                    }
                    d = Convert.ToDouble(str);
                }
                v = new FuzzyFloat(d);
                v = Entry(v);
                v = Leave(v);
            }
            break;

            case RubyMarshal.Types.Bignum:
            {
                int sign = 0;
                switch (ReadByte())
                {
                case 0x2b:
                    sign = 1;
                    break;

                case 0x2d:
                    sign = -1;
                    break;

                default:
                    sign = 0;
                    break;
                }
                int    num3  = ReadLong();
                int    index = num3 / 2;
                int    num5  = (num3 + 1) / 2;
                uint[] data  = new uint[num5];
                for (int i = 0; i < index; i++)
                {
                    data[i] = m_reader.ReadUInt32();
                }
                if (index != num5)
                {
                    data[index] = m_reader.ReadUInt16();
                }
                v = new FuzzyBignum(sign, data);
                v = new FuzzyBignumAdapter(v as FuzzyBignum);
                v = Entry(v);
                v = Leave(v);
            }
            break;

            case RubyMarshal.Types.String:
                v = Entry(ReadString());
                v = Leave(v);
                break;

            case RubyMarshal.Types.Regexp:
            {
                FuzzyString str          = ReadString();
                int         options      = ReadByte();
                bool        has_encoding = false;
                int         idx          = Prepare();
                if (hasivp)
                {
                    ReadInstanceVariable(str, ref has_encoding);
                    ivp = false;
                }
                if (!has_encoding)
                {
                    // TODO: 1.8 compatibility; remove escapes undefined in 1.8

                    /*
                     * char *ptr = RSTRING_PTR(str), *dst = ptr, *src = ptr;
                     * long len = RSTRING_LEN(str);
                     * long bs = 0;
                     * for (; len-- > 0; *dst++ = *src++) {
                     *  switch (*src) {
                     *      case '\\': bs++; break;
                     *      case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
                     *      case 'm': case 'o': case 'p': case 'q': case 'u': case 'y':
                     *      case 'E': case 'F': case 'H': case 'I': case 'J': case 'K':
                     *      case 'L': case 'N': case 'O': case 'P': case 'Q': case 'R':
                     *      case 'S': case 'T': case 'U': case 'V': case 'X': case 'Y':
                     *      if (bs & 1) --dst;
                     *      default: bs = 0; break;
                     *  }
                     * }
                     * rb_str_set_len(str, dst - ptr);
                     */
                }
                v = Entry0(new FuzzyRegexp(str, (FuzzyRegexpOptions)options), idx);
                v = Leave(v);
            }
            break;

            case RubyMarshal.Types.Array:
            {
                int        len = ReadLong();
                FuzzyArray ary = new FuzzyArray();
                v = ary;
                v = Entry(v);
                while (len-- > 0)
                {
                    ary.Push(ReadObject());
                }
                v = Leave(v);
            }
            break;

            case RubyMarshal.Types.Hash:
            case RubyMarshal.Types.HashWithDefault:
            {
                int       len  = ReadLong();
                FuzzyHash hash = new FuzzyHash();
                v = hash;
                v = Entry(v);
                while (len-- > 0)
                {
                    object key   = ReadObject();
                    object value = ReadObject();
                    hash.Add(key, value);
                }
                if (type == RubyMarshal.Types.HashWithDefault)
                {
                    hash.DefaultValue = ReadObject();
                }
                v = Leave(v);
            }
            break;

            case RubyMarshal.Types.Struct:
            {
                int         idx   = Prepare();
                FuzzyStruct obj   = new FuzzyStruct();
                FuzzySymbol klass = ReadUnique();
                obj.ClassName = klass;
                int len = ReadLong();
                v = obj;
                v = Entry0(v, idx);
                while (len-- > 0)
                {
                    FuzzySymbol key   = ReadSymbol();
                    object      value = ReadObject();
                    obj.InstanceVariable[key] = value;
                }
                v = Leave(v);
            }
            break;

            case RubyMarshal.Types.UserDefined:
            {
                FuzzySymbol klass  = ReadUnique();
                var         factor = Factory <byte[]> .Factor(klass.Name);

                if (factor == null)
                {
                    FuzzyString data = ReadString();
                    if (hasivp)
                    {
                        ReadInstanceVariable(data);
                        ivp = false;
                    }

                    FuzzyUserdefinedDumpObject obj = new FuzzyUserdefinedDumpObject();
                    obj.ClassName    = klass;
                    obj.DumpedObject = data.Raw;
                    v = obj;
                    v = Entry(v);
                    v = Leave(v);
                }
                else
                {
                    object obj = factor._dump(m_stream, null);
                    v = obj;
                    v = Entry(v);
                    v = Leave(v);
                }
            }
            break;

            case RubyMarshal.Types.UserMarshal:
            {
                FuzzySymbol klass = ReadUnique();
                FuzzyUserdefinedMarshalDumpObject obj = new FuzzyUserdefinedMarshalDumpObject();
                v = obj;
                if (extmod != null)
                {
                    AppendExtendedModule(obj, extmod);
                }
                v = Entry(v);
                object data = ReadObject();
                obj.ClassName    = klass;
                obj.DumpedObject = data;
                v = Leave(v);
                if (extmod != null)
                {
                    extmod.Clear();
                }
            }
            break;

            case RubyMarshal.Types.Object:
            {
                int         idx   = Prepare();
                FuzzyObject obj   = new FuzzyObject();
                FuzzySymbol klass = ReadUnique();
                obj.ClassName = klass;
                v             = obj;
                v             = Entry0(v, idx);
                ReadInstanceVariable(v);
                v = Leave(v);
            }
            break;

            case RubyMarshal.Types.Class:
            {
                FuzzyString str = ReadString();
                v = FuzzyClass.GetClass(FuzzySymbol.GetSymbol(str));
                v = Entry(v);
                v = Leave(v);
            }
            break;

            case RubyMarshal.Types.Module:
            {
                FuzzyString str = ReadString();
                v = FuzzyModule.GetModule(FuzzySymbol.GetSymbol(str));
                v = Entry(v);
                v = Leave(v);
            }
            break;

            case RubyMarshal.Types.Symbol:
                if (hasivp)
                {
                    v   = ReadSymbolReal(ivp);
                    ivp = false;
                }
                else
                {
                    v = ReadSymbolReal(false);
                }
                v = Leave(v);
                break;

            case RubyMarshal.Types.SymbolLink:
                v = ReadSymbolLink();
                break;

            case RubyMarshal.Types.Data:
            /*  TODO: Data Support
             *  {
             *      VALUE klass = path2class(r_unique(arg));
             *      VALUE oldclass = 0;
             *
             *      v = obj_alloc_by_klass(klass, arg, &oldclass);
             *      if (!RB_TYPE_P(v, T_DATA)) {
             *          rb_raise(rb_eArgError, "dump format error");
             *      }
             *      v = r_entry(v, arg);
             *      if (!rb_respond_to(v, s_load_data)) {
             *          rb_raise(rb_eTypeError, "class %s needs to have instance method `_load_data'", rb_class2name(klass));
             *      }
             *      rb_funcall(v, s_load_data, 1, r_object0(arg, 0, extmod));
             *      check_load_arg(arg, s_load_data);
             *      v = r_leave(v, arg);
             *  }
             */
            case RubyMarshal.Types.ModuleOld:
            /*
             *  TODO: ModuleOld Support
             *  {
             *      volatile VALUE str = r_bytes(arg);
             *      v = rb_path_to_class(str);
             *      v = r_entry(v, arg);
             *      v = r_leave(v, arg);
             *  }
             */
            default:
                throw new InvalidDataException(string.Format("dump format error(0x{0:X2})", type));
            }
            return(v);
        }
Beispiel #29
0
        public override Status Process()
        {
            var enemy = Owner.IsScaredOf();

            ActivateIfInactive();


            double distanceBetweenAnimals = Owner.DistanceToClosestEnemy() / (6000 / 150); // Could be 0 - 150
            double gazelleHunger          = Owner.Hunger;                                  // Could be 0 - 150


            FuzzyModule gazelle = FuzzyManager.CreateBaseGazelleModule();

            FuzzyManager.GazelleWannaRun(gazelle);
            double dWannaRun =
                FuzzyManager.CalculateDesirability(gazelle, distanceBetweenAnimals, gazelleHunger, "RunDesirability");

            FuzzyManager.GazelleWannaEat(gazelle);
            double dWannaEat =
                FuzzyManager.CalculateDesirability(gazelle, distanceBetweenAnimals, gazelleHunger, "EatDesirability");

            FuzzyManager.GazelleWannaWander(gazelle);
            double dWannaWander =
                FuzzyManager.CalculateDesirability(gazelle, distanceBetweenAnimals, gazelleHunger, "WanderDesirability");

            if (!_running)
            {
                if (dWannaRun > dWannaEat && dWannaRun > dWannaWander)
                {
                    _running   = true;
                    _eating    = false;
                    _wandering = false;
                    RemoveAllSubgoals();
                    AddSubgoal(new GoalEscapeLion(Owner, enemy));
                }
            }

            if (!_eating)
            {
                if (dWannaEat > dWannaRun && dWannaEat > dWannaWander)
                {
                    _eating    = true;
                    _running   = false;
                    _wandering = false;
                    RemoveAllSubgoals();
                    AddSubgoal(new GoalGatherFood(Owner));
                }
            }

            if (!_wandering)
            {
                if (dWannaWander > dWannaRun && dWannaWander > dWannaEat)
                {
                    _eating    = false;
                    _running   = false;
                    _wandering = true;
                    RemoveAllSubgoals();
                    AddSubgoal(new GoalWander(Owner));
                }
            }

            var status = ProcessSubgoals();

            return(status);
        }
Beispiel #30
0
 public static void add_rule(FuzzyModule module, FuzzyTermSet IF, FuzzyTermSet AND, FuzzyTermSet THEN) => module.AddRule(new FuzzyAND(IF, AND), THEN);
Beispiel #31
0
 public static FuzzyVariable create_flv(FuzzyModule module, string name) => module.CreateFLV(name);