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 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() { 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); }
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)); }
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); }