public void Initialize(TargetColumnGenome genome, EnvironmentGenome envGenomeRef) { this.genome = genome; gameObject.GetComponent <Collider>().enabled = false; //Vector2 randDir = UnityEngine.Random.insideUnitCircle; //float radius = 20f; //float x = UnityEngine.Random.Range(genome.minX, genome.maxX) * Challenge.GetChallengeArenaBounds(Challenge.Type.Test).x - (Challenge.GetChallengeArenaBounds(Challenge.Type.Test).x * 0.5f); //float z = UnityEngine.Random.Range(genome.minZ, genome.maxZ) * Challenge.GetChallengeArenaBounds(Challenge.Type.Test).z - (Challenge.GetChallengeArenaBounds(Challenge.Type.Test).z * 0.5f); float x = genome.minX * Challenge.GetChallengeArenaBounds(Challenge.Type.Test).x - (Challenge.GetChallengeArenaBounds(Challenge.Type.Test).x * 0.5f); float z = genome.minZ * Challenge.GetChallengeArenaBounds(Challenge.Type.Test).z - (Challenge.GetChallengeArenaBounds(Challenge.Type.Test).z * 0.5f); Vector3 targetPos = new Vector3(x, 0.5f, z); Vector3 startToTarget = targetPos - envGenomeRef.agentStartPositionsList[0].agentStartPosition; if (startToTarget.magnitude <= 3f) { targetPos = new Vector3(envGenomeRef.agentStartPositionsList[0].agentStartPosition.x, 0.5f, envGenomeRef.agentStartPositionsList[0].agentStartPosition.z + 6f); //Debug.Log("Moved TargetPos to avoid collision!!!"); } gameObject.transform.localPosition = targetPos; gameObject.transform.localScale = new Vector3(genome.targetRadius, 10f, genome.targetRadius); }
public TargetColumnGenome(TargetColumnGenome templateGenome) { targetRadius = templateGenome.targetRadius; minX = templateGenome.minX; maxX = templateGenome.maxX; minZ = templateGenome.minZ; maxZ = templateGenome.maxZ; minDistanceFromAgent = templateGenome.minDistanceFromAgent; }
public void CopyGenomeFromTemplate(EnvironmentGenome templateGenome) { //Debug.Log("CopyGenomeFromTemplate BEFORE startPosCount: " + templateGenome.agentStartPositionsList.Count.ToString()); // This method creates a clone of the provided ScriptableObject Genome - should have no shared references!!! this.challengeType = templateGenome.challengeType; arenaBounds = new Vector3(templateGenome.arenaBounds.x, templateGenome.arenaBounds.y, templateGenome.arenaBounds.z); agentStartPositionsList = new List <StartPositionGenome>(); for (int i = 0; i < templateGenome.agentStartPositionsList.Count; i++) { //Debug.Log("CopyGenomeFromTemplate DURING i: " + i.ToString()); StartPositionGenome genomeCopy = new StartPositionGenome(templateGenome.agentStartPositionsList[i]); agentStartPositionsList.Add(genomeCopy); } //Debug.Log("CopyGenomeFromTemplate AFTER startPosCount: " + agentStartPositionsList.Count.ToString()); useTerrain = templateGenome.useTerrain; if (useTerrain) { terrainGenome = new TerrainGenome(templateGenome.terrainGenome); //terrainGenome.InitializeRandomGenome(); } useBasicObstacles = templateGenome.useBasicObstacles; if (useBasicObstacles) { basicObstaclesGenome = new BasicObstaclesGenome(templateGenome.basicObstaclesGenome, this); //basicObstaclesGenome.InitializeRandomGenome(); } useTargetColumn = templateGenome.useTargetColumn; if (useTargetColumn) { targetColumnGenome = new TargetColumnGenome(); //targetColumnGenome.InitializeRandomGenome(); } useAtmosphere = templateGenome.useAtmosphere; if (useAtmosphere) { atmosphereGenome = new AtmosphereGenome(templateGenome.atmosphereGenome); //basicObstaclesGenome.InitializeRandomGenome(); } useMeteorites = templateGenome.useMeteorites; if (useMeteorites) { meteoritesGenome = new MeteoritesGenome(templateGenome.meteoritesGenome); //basicObstaclesGenome.InitializeRandomGenome(); } // For now this is fine -- but eventually might want to copy brainGenome from saved asset! //brainGenome = new BrainGenome(); // creates neuron and axonLists //InitializeRandomBrainGenome(); }
public EnvironmentGenome BirthNewGenome(EnvironmentGenome parentGenome, int index, Challenge.Type challengeType, float mutationRate, float mutationDriftAmount) { EnvironmentGenome newGenome = new EnvironmentGenome(index); newGenome.challengeType = parentGenome.challengeType; newGenome.arenaBounds = new Vector3(parentGenome.arenaBounds.x, parentGenome.arenaBounds.y, parentGenome.arenaBounds.z); newGenome.useTerrain = parentGenome.useTerrain; if (parentGenome.useTerrain) { newGenome.terrainGenome = TerrainGenome.BirthNewGenome(parentGenome.terrainGenome, mutationRate, mutationDriftAmount); } newGenome.useBasicObstacles = parentGenome.useBasicObstacles; if (parentGenome.useBasicObstacles) { newGenome.basicObstaclesGenome = BasicObstaclesGenome.BirthNewGenome(parentGenome.basicObstaclesGenome, mutationRate, mutationDriftAmount, this); } newGenome.useTargetColumn = parentGenome.useTargetColumn; if (parentGenome.useTargetColumn) { newGenome.targetColumnGenome = TargetColumnGenome.BirthNewGenome(parentGenome.targetColumnGenome, mutationRate, mutationDriftAmount); } newGenome.useAtmosphere = parentGenome.useAtmosphere; if (parentGenome.useAtmosphere) { newGenome.atmosphereGenome = AtmosphereGenome.BirthNewGenome(parentGenome.atmosphereGenome, mutationRate, mutationDriftAmount); } newGenome.useMeteorites = parentGenome.useMeteorites; if (parentGenome.useMeteorites) { newGenome.meteoritesGenome = MeteoritesGenome.BirthNewGenome(parentGenome.meteoritesGenome, mutationRate, mutationDriftAmount); } // StartPositions: // HACKY! DOES NOT SUPPORT EVOLVING START POSITIONS! ALL THE SAME!!!! newGenome.agentStartPositionsList = parentGenome.agentStartPositionsList; /*newGenome.agentStartPositionsList = new List<Vector3>(); * //Debug.Log("(parentGenome.agentStartPositionsList.Count" + parentGenome.agentStartPositionsList.Count.ToString()); * for (int i = 0; i < parentGenome.agentStartPositionsList.Count; i++) { * newGenome.agentStartPositionsList.Add(new Vector3(parentGenome.agentStartPositionsList[i].x, parentGenome.agentStartPositionsList[i].y, parentGenome.agentStartPositionsList[i].z)); * } * newGenome.agentStartRotationsList = new List<Quaternion>(); * for (int i = 0; i < parentGenome.agentStartRotationsList.Count; i++) { * newGenome.agentStartRotationsList.Add(new Quaternion(parentGenome.agentStartRotationsList[i].x, parentGenome.agentStartRotationsList[i].y, parentGenome.agentStartRotationsList[i].z, parentGenome.agentStartRotationsList[i].w)); * }*/ return(newGenome); }
public static TargetColumnGenome BirthNewGenome(TargetColumnGenome parentGenome, float mutationRate, float mutationDriftAmount) { // TARGET: TargetColumnGenome newGenome = new TargetColumnGenome(); newGenome.targetRadius = parentGenome.targetRadius; newGenome.minX = parentGenome.minX; newGenome.maxX = parentGenome.maxX; newGenome.minZ = parentGenome.minZ; newGenome.maxZ = parentGenome.maxZ; float rand = UnityEngine.Random.Range(0f, 1f); if (rand < mutationRate) { float newX = Mathf.Lerp(newGenome.minX, UnityEngine.Random.Range(0f, 1f), mutationDriftAmount); newGenome.minX = Mathf.Min(newX, parentGenome.maxX); // prevent min being bigger than max } rand = UnityEngine.Random.Range(0f, 1f); if (rand < mutationRate) { float newX = Mathf.Lerp(newGenome.maxX, UnityEngine.Random.Range(0f, 1f), mutationDriftAmount); newGenome.maxX = Mathf.Max(newX, parentGenome.minX); } rand = UnityEngine.Random.Range(0f, 1f); if (rand < mutationRate) { float newZ = Mathf.Lerp(newGenome.minZ, UnityEngine.Random.Range(0f, 1f), mutationDriftAmount); newGenome.minZ = Mathf.Min(newZ, parentGenome.maxZ); // prevent min being bigger than max } rand = UnityEngine.Random.Range(0f, 1f); if (rand < mutationRate) { float newZ = Mathf.Lerp(newGenome.maxZ, UnityEngine.Random.Range(0f, 1f), mutationDriftAmount); newGenome.maxZ = Mathf.Max(newZ, parentGenome.minZ); } return(newGenome); }