Beispiel #1
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);
        }
        public static Agent CreateComponent(Vector3 vector3, Camera main)
        {
//            var prefab = (GameObject) Resources.Load("Prefabs/Car");
//            prefab.transform.localScale = prefab.transform.localScale * 5;
//            var creature = Instantiate(prefab, vector3, Quaternion.identity);
//            CarControlManipulatable.CreateComponent(creature);

            var prefab = (GameObject)Resources.Load("CreaturePrefabs/GymAnt");

            prefab.transform.localScale = prefab.transform.localScale * 1;
            var creature = Instantiate(prefab, vector3, Quaternion.identity);

            foreach (var rigid in creature.GetComponentsInChildren <Rigidbody>())
            {
                rigid.mass                  *= 300;
                rigid.solverIterations       = 1000;
                rigid.collisionDetectionMode = CollisionDetectionMode.Continuous;
            }

            foreach (var collider in creature.GetComponentsInChildren <Collider>())
            {
                collider.material = (Resources.Load <PhysicMaterial>("Ground"));
            }

            creature.transform.GetChild(0).GetComponent <Rigidbody>().mass        *= 5;
            creature.transform.GetChild(0).GetComponent <Rigidbody>().angularDrag *= 15;

            UnityEngine.Debug.Log(creature.name);
            foreach (Transform part in creature.transform)
            {
                var obj = part.gameObject;
                if (obj == null)
                {
                    continue;
                }
                obj.AddComponent <CrasherBehaviour>();
            }

            BuildingSensor.CreateComponent(creature.transform.GetChild(0).gameObject, 500);

            var actions       = LocomotionAction.EightDirections();
            var sequenceMaker = new EvolutionarySequenceMaker(epsilon: 0.3f, minimumCandidates: 30);
//            IDecisionMaker decisionMaker = new ReinforcementDecisionMaker(
//                keyOrder: new[]
//                {
//                    State.BasicKeys.Forward,
//                    State.BasicKeys.RelativeFoodPosition
//                }, soulWeights: new[]
//                {
//                    1f
//                });
//            decisionMaker = new LoggingDecisionMaker(decisionMaker);
            IDecisionMaker decisionMaker = new FollowPointDecisionMaker(State.BasicKeys.RelativeFoodPosition);
            var            brain         = new Brain(
                decisionMaker,
                sequenceMaker
                );
            var agent = Agent.CreateComponent(creature, brain, new Body(creature.transform.GetChild(0).gameObject),
                                              actions,
                                              souls: new List <ISoul>()
            {
                new SnufflingDifferencialSoul()
            });

            creature.AddComponent <CrasherCreature>()._CreateComponent(main, vector3);
            return(agent);
        }