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));
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public void JustSampleUsage()
        {
            var actions       = LocomotionAction.EightDirections();
            var sequenceMaker = new EvolutionarySequenceMaker(epsilon: 0.3f, minimumCandidates: 30);
            var decisionMaker = new ReinforcementDecisionMaker();
            var brain         = new MotionGenerator.Brain(
                decisionMaker,
                sequenceMaker
                );

            brain.Init(
                new Dictionary <Guid, int> {
                { Guid.NewGuid(), (new ManipulatableMock()).GetManipulatableDimention() }
            },
                actions,
                new List <ISoul>()
            {
                new GluttonySoul()
            }
                );


            // Position, Rotation is required to update LocomotionAction
            // GluttonySoul.Key is required to update GluttonySoul
            // others are used to decide action
            brain.GenerateMotionSequence(new State(new Dictionary <string, Vector>()
            {
                { State.BasicKeys.RelativeFoodPosition, DenseVector.OfArray(new double[] { 0.5f, 0.5f, 0.5f }) },
                { State.BasicKeys.BirthPosition, DenseVector.OfArray(new double[] { 0f, 0f, 0f }) },
                { State.BasicKeys.Position, DenseVector.OfArray(new double[] { 0f, 0f, 0f }) },
                { State.BasicKeys.Rotation, DenseVector.OfArray(new double[] { 0f, 0f, 0f, 0f }) },
                { GluttonySoul.Key, DenseVector.OfArray(new double[] { 0f }) }
            }));

            brain.GenerateMotionSequence(new State(new Dictionary <string, Vector>()
            {
                { State.BasicKeys.RelativeFoodPosition, DenseVector.OfArray(new double[] { 0.5f, 0.5f, 0.5f }) },
                { State.BasicKeys.BirthPosition, DenseVector.OfArray(new double[] { 0f, 0f, 0f }) },
                { State.BasicKeys.Position, DenseVector.OfArray(new double[] { 0.1f, 0f, 0f }) },
                { State.BasicKeys.Rotation, DenseVector.OfArray(new double[] { 0f, 0f, 0f, 0f }) },
                { GluttonySoul.Key, DenseVector.OfArray(new double[] { 1f }) }
            }));
        }
Esempio n. 4
0
        private GameObject SpawnCreature()
        {
            var prefab = (GameObject)Resources.Load("Prefabs/Car");
            var car    = Instantiate(prefab, Vector3.zero, Quaternion.identity);

            CarControlManipulatable.CreateComponent(car);
            Sensor.CreateComponent(car, typeof(Food), State.BasicKeys.RelativeFoodPosition, range: 100f);
            Mouth.CreateComponent(car, 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(car, brain, new Body(car), actions);

            return(car);
        }
Esempio n. 5
0
        public static Car CreateComponent(Vector3 vector3, Camera main)
        {
            var prefab = (GameObject)Resources.Load("Prefabs/Car");
            var car    = Instantiate(prefab, vector3, Quaternion.identity);

            CarControlManipulatable.CreateComponent(car);
            SurroundSensor.CreateComponent(car);
            Sensor.CreateComponent(car, typeof(Food), State.BasicKeys.RelativeFoodPosition, range: 300f);
            Mouth.CreateComponent(car, typeof(Food));
            CrashSensor.CreateComponent(car);

            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,
                SurroundSensor.Key
            }, soulWeights: new[]
            {
                1f, 1f
            });

            decisionMaker = new LoggingDecisionMaker(decisionMaker);
            var brain = new Brain(
                decisionMaker,
                sequenceMaker
                );

            Agent.CreateComponent(car, brain, new Body(car), actions, souls: new List <ISoul>()
            {
                new SnufflingDifferencialSoul(),
                new AvoidCrashSoul()
            });

            return(car.AddComponent <Car>()._CreateComponent(main, vector3));
        }
Esempio n. 6
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);
        }
        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);
        }