private void SpawnCreature(JointGenerator generator)
        {
            var pos = new Vector3(
                x: _size.xMin + Random.value * _size.width,
                y: 3,
                z: _size.yMin + Random.value * _size.height
                );
            var rootObject  = generator.Instantiate(pos);
            var centralBody = rootObject.transform.GetChild(0).gameObject;

            Sensor.CreateComponent(centralBody, typeof(Food), State.BasicKeys.RelativeFoodPosition, range: 100f);
            var mouth = Mouth.CreateComponent(centralBody, typeof(Food));

            var actions       = LocomotionAction.EightDirections();
            var sequenceMaker = new EvolutionarySequenceMaker(epsilon: 0.3f, minimumCandidates: 30);
            var brain         = new Brain(
                new FollowPointDecisionMaker(State.BasicKeys.RelativeFoodPosition),
                sequenceMaker
                );

            var agent = Agent.CreateComponent(rootObject, brain, new Body(rootObject), actions);

            agent.name = RandomName();
            var info = GameUI.AddAgent(agent);

            StartCoroutine(EntryPointUtility.Rename(info, agent, mouth));
        }
        private void Feed()
        {
            var foodObject  = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            var food        = foodObject.AddComponent <Food>();
            var heightRatio = Random.value;

            food.GetComponent <Renderer>().material.color = Color.green * (1 - heightRatio) + Color.red * heightRatio;
            food.GetComponent <Collider>().isTrigger      = true;
            food.transform.position = new Vector3(
                x: _size.xMin + Random.value * _size.width,
                y: heightRatio * 3,
                z: _size.yMin + Random.value * _size.height
                );
            StartCoroutine(EntryPointUtility.DeleteTimer(foodObject, 60 * 5));
        }
        private void Feed()
        {
            var foodObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            foodObject.transform.localScale = Vector3.one * 5;
            var food = foodObject.AddComponent <Food>();

            food.GetComponent <Renderer>().material  = Resources.Load("Materials/Food", typeof(Material)) as Material;
            food.GetComponent <Collider>().isTrigger = true;
            food.transform.position = new Vector3(
                x: _size.xMin + Random.value * _size.width,
                y: 0,
                z: _size.yMin + Random.value * _size.height
                );
            StartCoroutine(EntryPointUtility.DeleteTimer(foodObject, 60 * 10));
        }
예제 #4
0
        private Agent StartCreature(GameObject creatureRootGameObject, GameObject centralBody)
        {
            // Add Sensor and Mouth for food
            Sensor.CreateComponent(centralBody, typeof(Food), State.BasicKeys.RelativeFoodPosition, range: 100f);
            var mouth = Mouth.CreateComponent(centralBody, typeof(Food));

            // Initialize Brain
            var actions       = LocomotionAction.EightDirections();
            var sequenceMaker = new EvolutionarySequenceMaker(epsilon: 0.1f, minimumCandidates: 30);
            var decisionMaker = new FollowPointDecisionMaker(State.BasicKeys.RelativeFoodPosition);
            var souls         = new List <ISoul>()
            {
                new GluttonySoul()
            };

            var brain = new Brain(decisionMaker, sequenceMaker);
            var agent = Agent.CreateComponent(creatureRootGameObject, brain, new Body(centralBody), actions, souls);

            var info = GameUI.AddAgent(agent);

            StartCoroutine(EntryPointUtility.Rename(info, agent, mouth));
            return(agent);
        }
        private GameObject SpawnCreature(bool reinforcement = true)
        {
            var rootObject = new GameObject();
            var creature   = GameObject.CreatePrimitive(PrimitiveType.Cube);

            creature.transform.position = new Vector3(
                x: _size.xMin + Random.value * _size.width,
                y: 1,
                z: _size.yMin + Random.value * _size.height
                );
            creature.transform.parent = rootObject.transform;
            SuperFlexibleMove.CreateComponent(creature, speed: 1f);
            creature.AddComponent <Rigidbody>().freezeRotation = true;
            creature.GetComponent <Renderer>().material.color  = reinforcement ? Color.red : Color.yellow;
            Sensor.CreateComponent(creature, typeof(Food), State.BasicKeys.RelativeFoodPosition, range: 100f);
            var mouth         = Mouth.CreateComponent(creature, typeof(Food));
            var actions       = LocomotionAction.EightDirections();
            var sequenceMaker = new EvolutionarySequenceMaker(epsilon: 0.3f, minimumCandidates: 30);

            if (reinforcement)
            {
            }

            var decisonMaker = reinforcement
                ? (IDecisionMaker) new ReinforcementDecisionMaker()
                : (IDecisionMaker) new FollowPointDecisionMaker(State.BasicKeys.RelativeFoodPosition);
            var brain = new Brain(
                decisonMaker,
                sequenceMaker
                );
            var agent = Agent.CreateComponent(rootObject, brain, new Body(creature), actions);
            var info  = GameUI.AddAgent(agent);

            agent.name = reinforcement ? "Reinforce" : "Rule";
            StartCoroutine(EntryPointUtility.Rename(info, agent, mouth));
            return(creature);
        }