Exemple #1
0
    public Dictionary <string, FuzzyVariable> getUpdatedFuzzyVariables(FuzzyMachine fm)
    {
        Dictionary <string, FuzzyVariable> dictionary = new Dictionary <string, FuzzyVariable>();

        float NearPlayer = Mathf.Clamp(1 / (Vector3.Distance(fm.player.transform.position, gameObject.transform.position) + 1), 0, 1);

        PlayerController movement = fm.player.GetComponent <PlayerController>();
        float            Nuggets  = movement.getCollectibles() / movement.maxCollectibles;

        EnemyHealth HealthScript = gameObject.GetComponent <EnemyHealth>();
        float       health       = HealthScript.currentHealth / HealthScript.health;

        float pHealth = movement.getHealth() / movement.maxHealth;

        float NearFriends = Mathf.Clamp(1 / (Vector3.Distance(fm.getAveragePosition(), gameObject.transform.position)) + 1, 0, 1);
        float Crowded     = Mathf.Clamp(1 / ((float)fm.getAverageDistance() + 1), 0, 1);

        dictionary.Add("NearPlayer", new FuzzyVariable(NearPlayer));
        dictionary.Add("Nuggets", new FuzzyVariable(Nuggets));
        dictionary.Add("NearFriends", new FuzzyVariable(1 - NearFriends));
        dictionary.Add("LowHealth", new FuzzyVariable(1 - health));
        dictionary.Add("PlayerLowHealth", new FuzzyVariable(1 - pHealth));
        dictionary.Add("FriendsAttacking", new FuzzyVariable(fm.getAverageAttack()));
        dictionary.Add("Crowded", new FuzzyVariable(Crowded));


        return(dictionary);
    }
    // Update is called once per frame
    void Update()
    {
        int     children = container.transform.childCount;
        Vector3 position = new Vector3();
        float   x        = Random.Range(-20, 20);
        float   z        = Random.Range(-20, 20);

        position.x = x;
        position.z = z;
        position.y = 20.0f;
        if (children < maxEnemies)
        {
            var enemy = (GameObject)Instantiate(
                enemyPrefab,
                position,
                transform.rotation);
            enemy.transform.parent = container.transform;
            FuzzyMachine   fm    = enemy.GetComponent <FuzzyMachine>();
            Defuzzyficator defuz = enemy.GetComponent <Defuzzyficator>();
            fm.player  = player;
            fm.friends = container;

            float Homicidal      = Random.Range(0.5f, 2);
            float Fearful        = Random.Range(0.5f, 2);
            float Social         = Random.Range(0.5f, 2);
            float LoneWolf       = Random.Range(0.5f, 2);
            float Aggressiveness = Random.Range(0.5f, 1.5f);

            defuz.homicidal      = Homicidal;
            defuz.fearful        = Fearful;
            defuz.social         = Social;
            defuz.loneWolf       = LoneWolf;
            defuz.aggressiveness = Aggressiveness;
        }
    }
Exemple #3
0
        private void PostInitialize()
        {
            Settings.LoadSettings();
            ImageManager.Delete();
            PathManager.Delete();

            TickDelay = Settings.Instance.GameTickTime;

            Width  = Settings.Instance.Width;
            Height = Settings.Instance.Height;

            FuzzyMachine.Initialize();
            StateMachine.Initialize();

            if (Settings.Instance.RandomSeed != 0)
            {
                Random = new Random(Settings.Instance.RandomSeed);
            }
            else
            {
                Random = new Random();
            }

            Obstacles = new List <BaseObstacle>();
            for (int i = 0; i < Settings.Instance.RockCount; i++)
            {
                Obstacles.Add(new Rock(new Location(Random.Next((int)Width), Random.Next((int)Height)), 30));
            }
            for (int i = 0; i < Settings.Instance.TreeCount; i++)
            {
                Obstacles.Add(new Tree(new Location(Random.Next((int)Width), Random.Next((int)Height)), 30));
            }

            SteeringForceCalculationType = SteeringForceCalculationType.WeightedTruncatedSum;

            StoneEdge();

            Entities = new List <BaseEntity>();
            for (int i = 0; i < Settings.Instance.HerbivoreCount; i++)
            {
                Entities.Add(new Herbivore {
                    State = Settings.Instance.HerbivoreStartState, Direction = Math.PI * 2 * Random.NextDouble(), Location = new Location(Random.Next(40, (int)Width - 40), Random.Next(40, (int)Height - 40))
                });
            }

            for (int i = 0; i < Settings.Instance.OmnivoreCount; i++)
            {
                Entities.Add(new Omnivore {
                    State = Settings.Instance.OmnivoreStartState, Direction = Math.PI * 2 * Random.NextDouble(), Location = new Location(Random.Next(40, (int)Width - 40), Random.Next(40, (int)Height - 40))
                });
            }

            InitGrids();
            NavGraph = new Graph();

            watch = new Stopwatch();
            watch.Start();

            timer          = new Timer();
            timer.Interval = TickDelay;
            timer.Tick    += new EventHandler(GameTick);
            timer.Start();
        }