Exemple #1
0
        private GameObject SpawnCreature()
        {
            var rootObject = GameObject.CreatePrimitive(PrimitiveType.Cube);

            SuperFlexibleMove.CreateComponent(rootObject, speed: 1f);
            rootObject.AddComponent <Rigidbody>().freezeRotation = true;
            rootObject.GetComponent <Renderer>().material.color  = Color.red;
            Sensor.CreateComponent(rootObject, typeof(Food), State.BasicKeys.RelativeFoodPosition, range: 100f);
            Mouth.CreateComponent(rootObject, 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
                );

            Agent.CreateComponent(rootObject, brain, new Body(rootObject), actions);
            return(rootObject);
        }
        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);
        }