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 void Initialize(AtmosphereGenome genome) { 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); //gameObject.transform.localPosition = new Vector3(x, 0.5f, z); //gameObject.transform.localScale = new Vector3(genome.targetRadius, 10f, genome.targetRadius); }
public static AtmosphereGenome BirthNewGenome(AtmosphereGenome parentGenome, float mutationRate, float mutationDriftAmount) { // OBSTACLES: // NEED TO COPY ALL ATTRIBUTES HERE unless I switch mutation process to go: full-copy, then re-traverse and mutate on a second sweep... AtmosphereGenome newGenome = new AtmosphereGenome(); newGenome.windForce = parentGenome.windForce; newGenome.maxWindSpeed = parentGenome.maxWindSpeed; float rand = UnityEngine.Random.Range(0f, 1f); if (rand < mutationRate) { Vector3 randDir = UnityEngine.Random.onUnitSphere; Vector3 randForce = randDir * UnityEngine.Random.Range(0f, newGenome.maxWindSpeed); newGenome.windForce = Vector3.Lerp(newGenome.windForce, randForce, mutationDriftAmount); } return(newGenome); }
public AtmosphereGenome(AtmosphereGenome templateGenome) { windForce = templateGenome.windForce; maxWindSpeed = templateGenome.maxWindSpeed; }