private void EnvironmentCrossover() { List <EnvironmentGenome> newGenGenomeList = new List <EnvironmentGenome>(); // new population! FitnessManager fitnessManager = teamsConfig.environmentPopulation.fitnessManager; TrainingSettingsManager trainingSettingsManager = teamsConfig.environmentPopulation.trainingSettingsManager; float mutationChance = trainingSettingsManager.mutationChance; float mutationStepSize = trainingSettingsManager.mutationStepSize; // Keep top-half peformers + mutations: for (int x = 0; x < teamsConfig.environmentPopulation.environmentGenomeList.Count; x++) { if (false) //x == 0) { // Top performer stays { EnvironmentGenome parentGenome = teamsConfig.environmentPopulation.environmentGenomeList[fitnessManager.rankedIndicesList[x]]; parentGenome.index = 0; newGenGenomeList.Add(parentGenome); } else { int parentIndex = fitnessManager.GetAgentIndexByLottery(); EnvironmentGenome parentGenome = teamsConfig.environmentPopulation.environmentGenomeList[parentIndex]; EnvironmentGenome newGenome = parentGenome.BirthNewGenome(parentGenome, newGenGenomeList.Count, teamsConfig.challengeType, mutationChance, mutationStepSize); newGenGenomeList.Add(newGenome); } } for (int i = 0; i < teamsConfig.environmentPopulation.environmentGenomeList.Count; i++) { teamsConfig.environmentPopulation.environmentGenomeList[i] = newGenGenomeList[i]; } }
public BasicObstaclesGenome(BasicObstaclesGenome templateGenome, EnvironmentGenome envGenomeRef) { numObstacles = templateGenome.numObstacles; minObstacleSize = templateGenome.minObstacleSize; maxObstacleSize = templateGenome.maxObstacleSize; obstaclePositions = new Vector2[numObstacles]; obstacleScales = new float[numObstacles]; for (int i = 0; i < obstaclePositions.Length; i++) { if (i < templateGenome.obstaclePositions.Length) // when changing numOctaves, doesn't immediately change parentgenome terrainWaves array //terrainWaves[i] = new Vector3(templateGenome.terrainWaves[i].x, templateGenome.terrainWaves[i].y, templateGenome.terrainWaves[i].z); //Debug.Log("Copy Terrain Genome: " + terrainWaves[i].ToString()); { obstaclePositions[i] = new Vector2(templateGenome.obstaclePositions[i].x, templateGenome.obstaclePositions[i].y); obstacleScales[i] = templateGenome.obstacleScales[i]; // = size; } else { obstaclePositions[i] = new Vector2(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)); // Revisit this for prepping agentStartPositions!!!! Vector2 startCoords = new Vector2(envGenomeRef.agentStartPositionsList[0].agentStartPosition.x / 40f + 0.5f, envGenomeRef.agentStartPositionsList[0].agentStartPosition.z / 40f + 0.5f); if ((obstaclePositions[i] - startCoords).magnitude < 0.15f) { obstaclePositions[i] = startCoords + (obstaclePositions[i] - startCoords) * 0.15f / (obstaclePositions[i] - startCoords).magnitude; } obstacleScales[i] = UnityEngine.Random.Range(1f, 1f); } } }
public TeamsConfig(int numPlayers, int numEnvironmentReps, int numPlayerReps) { //EnvironmentGenome templateEnvironmentGenome = GetDefaultTemplateEnvironmentGenome(challengeType); EnvironmentGenome templateEnvironmentGenome = new EnvironmentGenome(-1); templateEnvironmentGenome.InitializeAsDefaultGenome(); // Temporary hacky solution environmentPopulation = new EnvironmentPopulation(templateEnvironmentGenome, numEnvironmentGenomes, numEnvironmentReps); // Players: playersList = new List <PlayerPopulation>(); for (int i = 0; i < numPlayers; i++) { // Might have to revisit how to pass agent templates per population... //AgentBodyGenomeTemplate templateAgentGenome = GetDefaultTemplateAgentGenome(challengeType); // Temporary hack solution: BodyGenome templateBodyGenome = new BodyGenome(); templateBodyGenome.InitializeGenomeAsDefault(); if (i == 0f) { templateBodyGenome.testModuleGenome.maxSpeed = 0.25f; templateBodyGenome.testModuleGenome.accel = 0.025f; } else { templateBodyGenome.testModuleGenome.maxSpeed = 1f; templateBodyGenome.testModuleGenome.accel = 0.35f; } // List of Agent Genomes PlayerPopulation player = new PlayerPopulation(i, templateBodyGenome, numAgentGenomesPerPlayer, numPlayerReps); playersList.Add(player); } }
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 TeamsConfig(int numPlayers, Challenge.Type challengeType, int numEnvironmentReps, int numPlayerReps) { this.challengeType = challengeType; // Challenges might have required modules for environment (& agent?) genomes: // for example, go-to-target would REQUIRE having a target object in the environment Debug.Log("TeamsConfig() " + this.challengeType.ToString()); // Teams: // Environment EnvironmentGenome templateEnvironmentGenome = GetDefaultTemplateEnvironmentGenome(challengeType); environmentPopulation = new EnvironmentPopulation(challengeType, templateEnvironmentGenome, numEnvironmentGenomes, numBaselineGenomes, numEnvironmentReps); // Players: playersList = new List <PlayerPopulation>(); for (int i = 0; i < numPlayers; i++) { // Might have to revisit how to pass agent templates per population... AgentBodyGenomeTemplate templateAgentGenome = GetDefaultTemplateAgentGenome(challengeType); Debug.Log("TEMPLATE: " + templateAgentGenome.bodyGenome.ToString()); // List of Agent Genomes PlayerPopulation player = new PlayerPopulation(challengeType, templateAgentGenome.bodyGenome, numAgentGenomesPerPlayer, numBaselineGenomes, numPlayerReps); playersList.Add(player); } }
public EvaluationTicket(EnvironmentGenome environmentGenome, List <AgentGenome> agentGenomesList, int focusPopIndex, int maxTimeSteps) { status = EvaluationStatus.Pending; this.environmentGenome = environmentGenome; this.agentGenomesList = agentGenomesList; this.focusPopIndex = focusPopIndex; this.maxTimeSteps = maxTimeSteps; }
// public Vector3 ArenaBounds? //public ChallengeSettingsGenome challengeSettings; /*public EvaluationTicket(int[] genomeIndices, int focusIndex, int maxTimeSteps) { * status = EvaluationStatus.Pending; * //environmentRepIndex = environmentIndex; * this.genomeIndices = genomeIndices; * this.focusPopIndex = focusIndex; * this.maxTimeSteps = maxTimeSteps; * //challengeSettings = settings; * }*/ public EvaluationTicket(EnvironmentGenome environmentGenome, List <AgentGenome> agentGenomesList, int focusIndex, int maxTimeSteps) { status = EvaluationStatus.Pending; //environmentRepIndex = environmentIndex; //this.genomeIndices = genomeIndices; this.environmentGenome = environmentGenome; this.agentGenomesList = agentGenomesList; this.focusPopIndex = focusIndex; this.maxTimeSteps = maxTimeSteps; //challengeSettings = settings; }
public void CopyGenomeFromTemplate(EnvironmentGenome templateGenome) { 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++) { StartPositionGenome genomeCopy = new StartPositionGenome(templateGenome.agentStartPositionsList[i]); agentStartPositionsList.Add(genomeCopy); } }
private static void ArenaAdjustments(EnvironmentGenome genome) { //Debug.Log("ArenaAdjustments: startPos: " + genome.agentStartPositionsList[0].agentStartPosition.ToString()); Material modifyHeightMat = new Material(Shader.Find("TerrainBlit/TerrainBlitArenaAdjustments")); modifyHeightMat.SetVector("_GridBounds", new Vector4(-1f / Mathf.Pow(2f, 3), 1f / Mathf.Pow(2f, 3), -1f / Mathf.Pow(2f, 3), 1f / Mathf.Pow(2f, 3))); modifyHeightMat.SetVector("_StartPosition", new Vector4(genome.agentStartPositionsList[0].agentStartPosition.x, genome.agentStartPositionsList[0].agentStartPosition.y, genome.agentStartPositionsList[0].agentStartPosition.z, 0f)); modifyHeightMat.SetPass(0); Graphics.Blit(heightMapCascadeTextures[3], temporaryRT, modifyHeightMat); // perform calculations on texture Graphics.Blit(temporaryRT, heightMapCascadeTextures[3]); // copy results back into main texture }
public EnvironmentGenome BirthNewGenome(EnvironmentGenome parentGenome, int index, float mutationRate, float mutationDriftAmount) { EnvironmentGenome newGenome = new EnvironmentGenome(index); newGenome.arenaBounds = new Vector3(parentGenome.arenaBounds.x, parentGenome.arenaBounds.y, parentGenome.arenaBounds.z); // StartPositions: // HACKY! DOES NOT SUPPORT EVOLVING START POSITIONS! ALL THE SAME!!!! newGenome.agentStartPositionsList = parentGenome.agentStartPositionsList; return(newGenome); }
public static float GetAltitude(EnvironmentGenome genome, float x, float z) { if (!genome.terrainGenome.useAltitude) { return(0f); } float altitude = 0f; float distMultiplier = 0.02f; float dist = new Vector2(x, z).magnitude *distMultiplier; float amplitude = 60f; float total = 0f; for (int i = 0; i < genome.terrainGenome.terrainWaves.Length; i++) { float height = NoisePrime.Simplex3D(new Vector3(x, genome.terrainGenome.terrainWaves[i].z, z), genome.terrainGenome.terrainWaves[i].x * Mathf.Pow(2f, i)).value *(amplitude * genome.terrainGenome.terrainWaves[i].y / Mathf.Pow(2f, i) * dist); total += height; } altitude = total / genome.terrainGenome.terrainWaves.Length; // StartPositions!!! for (int j = 0; j < genome.agentStartPositionsList.Count; j++) { float distToSpawn = (new Vector2(x, z) - new Vector2(genome.agentStartPositionsList[j].agentStartPosition.x, genome.agentStartPositionsList[j].agentStartPosition.z)).magnitude; if (distToSpawn < 12f) { altitude = Mathf.Lerp(0f, altitude, Mathf.Max(distToSpawn - 4f, 0f) / 8f); } } return(altitude); // OLD!!!! /* * * float total = 0f; * for (int i = 0; i < genome.terrainGenome.terrainWaves.Length; i++) { * if (i % 2 == 0) { * total += Mathf.Sin(x * genome.terrainGenome.terrainWaves[i].x + genome.terrainGenome.terrainWaves[i].z) * genome.terrainGenome.terrainWaves[i].y / genome.terrainGenome.terrainWaves[i].x; // divide by frequency * } * else { * total += Mathf.Sin(z * genome.terrainGenome.terrainWaves[i].x + genome.terrainGenome.terrainWaves[i].z) * genome.terrainGenome.terrainWaves[i].y / genome.terrainGenome.terrainWaves[i].x; * } * } * float height = total / genome.terrainGenome.terrainWaves.Length; * float distToSpawn = new Vector2(x, z).magnitude; * if (distToSpawn < 12f) { * height = Mathf.Lerp(0f, height, Mathf.Max(distToSpawn - 4f, 0f) / 8f); * } * return height;*/ }
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 void UpdateActorModules(int focusPop, EnvironmentGenome pendingEnvGenome, BodyGenome pendingBodyGenome) { if (focusPop == 0) // Environment: //Debug.Log("UpdateActorModules startPosCount: " + pendingEnvGenome.agentStartPositionsList.Count.ToString()); { teamsConfig.environmentPopulation.ChangeGenomeTemplate(pendingEnvGenome); //Debug.Log("") } else // Agent: { teamsConfig.playersList[focusPop - 1].ChangeBodyTemplate(pendingBodyGenome); } ResetGeneration(); }
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 Mesh GetTerrainMesh(EnvironmentGenome genome, int xResolution, int zResolution, float xCenter, float zCenter, float xSize, float zSize) { float xQuadSize = xSize / (float)xResolution; float zQuadSize = zSize / (float)zResolution; Vector3 offset = new Vector3(xSize * 0.5f, 0f, zSize * 0.5f); Vector3[] vertices; Mesh mesh = new Mesh(); mesh.name = "Procedural Grid"; vertices = new Vector3[(xResolution + 1) * (zResolution + 1)]; Vector2[] uv = new Vector2[vertices.Length]; Vector4[] tangents = new Vector4[vertices.Length]; Vector4 tangent = new Vector4(1f, 0f, 0f, -1f); for (int i = 0, z = 0; z <= zResolution; z++) { for (int x = 0; x <= xResolution; x++, i++) { float altitude = GetAltitude(genome, x * xQuadSize - offset.x + xCenter, z * zQuadSize - offset.z + zCenter); vertices[i] = new Vector3(x * xQuadSize, altitude, z * zQuadSize) - offset; uv[i] = new Vector2((float)x / xResolution, (float)z / zResolution); tangents[i] = tangent; } } mesh.vertices = vertices; mesh.uv = uv; mesh.tangents = tangents; int[] triangles = new int[xResolution * zResolution * 6]; for (int ti = 0, vi = 0, z = 0; z < zResolution; z++, vi++) { for (int x = 0; x < xResolution; x++, ti += 6, vi++) { triangles[ti] = vi; triangles[ti + 3] = triangles[ti + 2] = vi + 1; triangles[ti + 4] = triangles[ti + 1] = vi + xResolution + 1; triangles[ti + 5] = vi + xResolution + 2; } } mesh.triangles = triangles; mesh.RecalculateNormals(); return(mesh); }
private static void CenterHeightTextures(EnvironmentGenome genome) { Material modifyHeightMat = new Material(Shader.Find("TerrainBlit/TerrainBlitCenterHeightTextures")); modifyHeightMat.SetPass(0); modifyHeightMat.SetVector("_StartPosition", new Vector4(genome.agentStartPositionsList[0].agentStartPosition.x, genome.agentStartPositionsList[0].agentStartPosition.y, genome.agentStartPositionsList[0].agentStartPosition.z, 0f)); modifyHeightMat.SetTexture("_CenterTex", heightMapCascadeTextures[3]); for (int i = 0; i < heightMapCascadeTextures.Length; i++) { modifyHeightMat.SetVector("_GridBounds", new Vector4(-1f / Mathf.Pow(2f, i), 1f / Mathf.Pow(2f, i), -1f / Mathf.Pow(2f, i), 1f / Mathf.Pow(2f, i))); Graphics.Blit(heightMapCascadeTextures[i], temporaryRT, modifyHeightMat); // perform calculations on texture Graphics.Blit(temporaryRT, heightMapCascadeTextures[i]); // copy results back into main texture } }
public void ChangeGenomeTemplate(EnvironmentGenome pendingGenome) { //Debug.Log("ChangeGenomeTemplate PENDING startPosCount: " + pendingGenome.agentStartPositionsList.Count.ToString()); // Apply to Population Template: templateGenome.CopyGenomeFromTemplate(pendingGenome); // sets contents of genome to a copy of the sourceGenome // Apply to each Environment Genome: for (int i = 0; i < environmentGenomeList.Count; i++) { environmentGenomeList[i].CopyGenomeFromTemplate(pendingGenome); } //Debug.Log("ChangeGenomeTemplate TEMPLATE startPosCount: " + templateGenome.agentStartPositionsList.Count.ToString()); //Debug.Log("ChangeGenomeTemplate ACTIVE startPosCount: " + environmentGenomeList[0].agentStartPositionsList.Count.ToString()); }
public void BuildChunk(EnvironmentGenome genome, Vector2 position, Vector2 scale, Material mat) { GameObject chunkGO = new GameObject("chunkMesh"); /*Debug.Log("BuildChunk position: " + position.ToString() + ", scale: " + scale.ToString() + ", west: " + thisWest.ToString() + ", north: " + thisNorth.ToString() + ", east: " + thisEast.ToString() + ", south: " + thisSouth.ToString());*/ //TerrainConstructorGPU constructor = new TerrainConstructorGPU(); Mesh groundMesh = TerrainConstructorGPU.GetTerrainMesh(this.resolutionX, this.resolutionZ, position.x, position.y, scale.x * 2f, scale.y * 2); chunkGO.AddComponent <MeshFilter>().sharedMesh = groundMesh; this.mesh = groundMesh; chunkGO.AddComponent <MeshRenderer>().material = mat; chunkGO.transform.parent = gameObject.transform; chunkGO.transform.localPosition = new Vector3(0f, 0f, 0f); }
public void CreateCollisionAndGameplayContent(EnvironmentGenome genome) { //GameObject environmentGameplayGO = new GameObject("environmentGameplay"); //environmentGameplay = environmentGameplayGO.AddComponent<EnvironmentGameplay>(); //environmentGameplay.transform.parent = gameObject.transform; //environmentGameplay.transform.localPosition = new Vector3(0f, 0f, 0f); // Construct Ground Physics Material: //=============WALLS=========== // Game-Required Modules: // Target !!! // Obstacles: // Atmosphere (WIND) !!! // Set Genome's prefab environment: //genome.gameplayPrefab = environmentGameplay; }
public void Initialize(GameObject parentGO, EnvironmentGenome genome, Material mat, Vector2 position, Vector2 scale, int maxLOD) { this.maxLOD = maxLOD; this.groundMaterial = mat; this.position = position; this.scale = scale; gameObject.transform.parent = parentGO.transform; GameObject rootChunkGO = new GameObject("rootChunk"); rootChunkGO.transform.parent = parentGO.transform; rootChunk = rootChunkGO.AddComponent <TerrainChunk>(); rootChunk.maxLOD = this.maxLOD; //position = new Vector2(0f, 0f); //scale = new Vector2(320f, 320f); rootChunk.maxLOD = this.maxLOD; rootChunk.Initialize(gameObject, genome, 0, 0, 61, 61, new Vector2(40f, 40f), position, scale, groundMaterial); }
public void PrepareTournament(AgentGenome playerGenome) { List <EnvironmentGenome> environmentGenomeList = new List <EnvironmentGenome>(); List <AgentGenome> competitorGenomeList = new List <AgentGenome>(); // Load environments and competitors? for (int e = 0; e < environmentsFileList.Count; e++) { string path = Application.dataPath + "/IndividualSaves/Environments/" + environmentsFileList[e] + ".json"; string dataAsJson = File.ReadAllText(path); EnvironmentGenome genome = JsonUtility.FromJson <EnvironmentGenome>(dataAsJson); environmentGenomeList.Add(genome); } // might need to check for null! if (competitorsFileList != null) { // Load competitor Agent Genomes! for (int a = 0; a < competitorsFileList.Count; a++) { string path = Application.dataPath + "/IndividualSaves/Agents/" + competitorsFileList[a] + ".json"; string dataAsJson = File.ReadAllText(path); AgentGenome genome = JsonUtility.FromJson <AgentGenome>(dataAsJson); competitorGenomeList.Add(genome); } } // Fill in Rounds & Matchups! this.winnerID = -1; this.tournamentFinished = false; for (int i = 0; i < tournamentRoundList.Count; i++) { tournamentRoundList[i].winnerID = -1; tournamentRoundList[i].roundFinished = false; for (int j = 0; j < tournamentRoundList[i].matchupList.Count; j++) { // Creates and fills in EvaluationTicket for this matchup with actual Genomes (before it was just coded with IDs) tournamentRoundList[i].matchupList[j].PrepareMatchup(environmentGenomeList, competitorGenomeList, playerGenome, (numOpponents + 1), tournamentRoundList[i].maxTimeSteps); } } }
//public int numBaselineReps = 0; public EnvironmentPopulation(EnvironmentGenome templateGenome, int numGenomes, int numReps) { this.templateGenome = templateGenome; popSize = numGenomes; //this.numBaseline = numBaseline; environmentGenomeList = new List <EnvironmentGenome>(); historicGenomePool = new List <EnvironmentGenome>(); //baselineGenomePool = new List<EnvironmentGenome>(); for (int e = 0; e < numGenomes; e++) { // Create new environmentGenome EnvironmentGenome envGenome = new EnvironmentGenome(e); envGenome.InitializeRandomGenomeFromTemplate(templateGenome); // Add to envGenomesList: environmentGenomeList.Add(envGenome); // Create parallel initial batch of genomes to be used as baseline comparison //EnvironmentGenome baseGenome = new EnvironmentGenome(e); //baseGenome.InitializeRandomGenomeFromTemplate(templateGenome); //baselineGenomePool.Add(baseGenome); } //AppendBaselineGenomes(); // Representatives: numPerformanceReps = numReps; ResetRepresentativesList(); historicGenomePool.Add(environmentGenomeList[0]); // init fitnessManager = new FitnessManager(); SetUpDefaultFitnessComponents(fitnessManager); //fitnessManager.ResetHistoricalData(); fitnessManager.InitializeForNewGeneration(environmentGenomeList.Count); trainingSettingsManager = new TrainingSettingsManager(0.25f, 0.05f, 0f, 0f); }
public void InitializeRandomGenomeFromTemplate(EnvironmentGenome templateGenome) { CopyGenomeFromTemplate(templateGenome); if (useTerrain) { terrainGenome.InitializeRandomGenome(); } if (useBasicObstacles) { basicObstaclesGenome.InitializeRandomGenome(); } if (useTargetColumn) { targetColumnGenome.InitializeRandomGenome(); } if (useAtmosphere) { atmosphereGenome.InitializeRandomGenome(); } if (useMeteorites) { meteoritesGenome.InitializeRandomGenome(); } }
// Use this for initialization void Start() { envGenome = (Resources.Load("Templates/Environments/TemplateTestDefault") as EnvironmentGenomeTemplate).templateGenome; // Set Noise Textures: presetNoiseTextures = new Texture2D[8]; presetNoiseTextures[0] = this.presetNoiseTex0; presetNoiseTextures[1] = this.presetNoiseTex1; presetNoiseTextures[2] = this.presetNoiseTex2; presetNoiseTextures[3] = this.presetNoiseTex3; presetNoiseTextures[4] = this.presetNoiseTex4; presetNoiseTextures[5] = this.presetNoiseTex5; presetNoiseTextures[6] = this.presetNoiseTex6; presetNoiseTextures[7] = this.presetNoiseTex7; // PROCESS GENOME DATA FOR COMPUTE SHADER!!!!!! if (terrainGenomeCBuffer != null) { terrainGenomeCBuffer.Release(); } //generatedPaletteNoiseTextures = new RenderTexture[4]; // Create palette noise textures: //GeneratePaletteNoise(); //TerrainConstructorGPU.presetNoiseTextures = this.presetNoiseTextures; // &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // &&&&&&&&&&&&&&&&&&&&&&&&&&&& CONSTRUCT HEIGHT MAP CASCADE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& heightMapCascadeTextures = new RenderTexture[4]; // Initialize Cascade Textures for (int i = 0; i < heightMapCascadeTextures.Length; i++) { RenderTexture renderTexture = new RenderTexture(xResolution, yResolution, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Default); renderTexture.wrapMode = TextureWrapMode.Clamp; renderTexture.filterMode = FilterMode.Bilinear; renderTexture.enableRandomWrite = true; renderTexture.useMipMap = true; renderTexture.Create(); heightMapCascadeTextures[i] = renderTexture; } temporaryRT = new RenderTexture(xResolution, yResolution, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear); temporaryRT.wrapMode = TextureWrapMode.Clamp; temporaryRT.filterMode = FilterMode.Bilinear; temporaryRT.enableRandomWrite = true; temporaryRT.useMipMap = true; temporaryRT.Create(); // STRATA INIT::::: rockStrataRemapRT = new RenderTexture(numRockStrataLayers, 1, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear); rockStrataRemapRT.wrapMode = TextureWrapMode.Clamp; rockStrataRemapRT.filterMode = FilterMode.Bilinear; rockStrataRemapRT.enableRandomWrite = true; //rockStrataRemapRT.useMipMap = true; rockStrataRemapRT.Create(); // Creates Actual Mesh data by reading from existing main Height Texture!!!!:::::: //int FillStrataRemapTexKernelID = terrainConstructorGPUCompute.FindKernel("CSFillStrataRemapTexture"); //terrainConstructorGPUCompute.SetInt("_NumStrata", numRockStrataLayers); //terrainConstructorGPUCompute.SetTexture(FillStrataRemapTexKernelID, "strataRemapTexture", rockStrataRemapRT); // Write-Only //terrainConstructorGPUCompute.Dispatch(FillStrataRemapTexKernelID, numRockStrataLayers, 1, 1); // rockStrataDataCBuffer = new ComputeBuffer(numRockStrataLayers, sizeof(float) * 4); RockStrataData[] rockStrataDataArray = new RockStrataData[rockStrataDataCBuffer.count]; for (int i = 0; i < rockStrataDataArray.Length; i++) { RockStrataData data = new RockStrataData(); data.color = UnityEngine.Random.insideUnitSphere; // set random color data.hardness = UnityEngine.Random.Range(0f, 0.65f); rockStrataDataArray[i] = data; } rockStrataDataCBuffer.SetData(rockStrataDataArray); // PASSES: FirstPass(); // populated height texture with solid rocks height SecondPass(); RockPass(); // STRATA ADJUST: for (int i = numRockStrataLayers - 2; i > 0; i -= 2) { StrataAdjustments(i); } ThirdPass(); // Debris 1 FourthPass(); // SNOW //StrataAdjustments(3); //for (int i = 0; i < 2; i++) { // SmoothHeights(); //} // Arena Adjustments: ArenaAdjustments(); for (int i = 0; i < 8; i++) { SmoothHeights(); } // &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TextureDisplayQuadGO1.GetComponent <MeshRenderer>().material.SetTexture("_MainTex", rockStrataRemapRT); if (heightMapCascadeTextures.Length > 1) { TextureDisplayQuadGO2.GetComponent <MeshRenderer>().material.SetTexture("_MainTex", heightMapCascadeTextures[1]); } if (heightMapCascadeTextures.Length > 2) { TextureDisplayQuadGO3.GetComponent <MeshRenderer>().material.SetTexture("_MainTex", heightMapCascadeTextures[2]); } // Set Data on Constructor: TerrainConstructorGPU.terrainConstructorGPUCompute = this.terrainConstructorGPUCompute; // Set Cascade Height Textures: TerrainConstructorGPU.heightMapCascadeTextures = heightMapCascadeTextures; // BUILD MESH FROM TEXTURE STACK!!!! terrainManagerRef.Initialize(this.gameObject, envGenome, groundMat, new Vector2(0f, 0f), new Vector2(680f, 680f), 7); }
public void InitializeRandomGenomeFromTemplate(EnvironmentGenome templateGenome) { CopyGenomeFromTemplate(templateGenome); }
private string GetTextAgentModules() { string txt = ""; if (gameManager.trainerRef.evaluationManager.exhibitionTicketList[gameManager.trainerRef.evaluationManager.exhibitionTicketCurrentIndex].focusPopIndex < 1) { // ENVIRONMENT: //EnvironmentGenome currentEnvironmentGenome = trainerRef.teamsConfig.environmentPopulation.environmentGenomeList[trainerRef.evaluationManager.exhibitionTicketList[trainerRef.evaluationManager.exhibitionTicketCurrentIndex].genomeIndices[0]]; EnvironmentGenome currentEnvironmentGenome = gameManager.trainerRef.evaluationManager.exhibitionTicketList[gameManager.trainerRef.evaluationManager.exhibitionTicketCurrentIndex].environmentGenome; txt += "Environment Genome: " + currentEnvironmentGenome.index + "\n\n"; if (currentEnvironmentGenome.useAtmosphere) { txt += "ATMOSPHERE\nWind: " + currentEnvironmentGenome.atmosphereGenome.windForce.ToString(); //txt += "\n"; } if (currentEnvironmentGenome.useBasicObstacles) { txt += "\nOBSTACLES ON\n"; } if (currentEnvironmentGenome.useMeteorites) { txt += "\nMETEORITES ON\n"; } if (currentEnvironmentGenome.useTargetColumn) { txt += "\nTARGET LOCATION ON\n"; } if (currentEnvironmentGenome.terrainGenome.useAltitude) { txt += "\nALTITUDE ON\n"; } } else { // AGENT: //AgentGenome currentAgentGenome = trainerRef.teamsConfig.playersList[trainerRef.evaluationManager.exhibitionTicketList[trainerRef.evaluationManager.exhibitionTicketCurrentIndex].focusPopIndex - 1].agentGenomeList[trainerRef.evaluationManager.exhibitionTicketList[trainerRef.evaluationManager.exhibitionTicketCurrentIndex].genomeIndices[trainerRef.evaluationManager.exhibitionTicketList[trainerRef.evaluationManager.exhibitionTicketCurrentIndex].focusPopIndex]]; AgentGenome currentAgentGenome = gameManager.trainerRef.evaluationManager.exhibitionTicketList[gameManager.trainerRef.evaluationManager.exhibitionTicketCurrentIndex].agentGenomesList[gameManager.trainerRef.evaluationManager.exhibitionTicketList[gameManager.trainerRef.evaluationManager.exhibitionTicketCurrentIndex].focusPopIndex - 1]; // Index: txt += "Player: " + gameManager.trainerRef.evaluationManager.exhibitionTicketList[gameManager.trainerRef.evaluationManager.exhibitionTicketCurrentIndex].focusPopIndex.ToString(); txt += ", Genome: " + currentAgentGenome.index.ToString() + "\n"; txt += "BodyNeurons: " + currentAgentGenome.brainGenome.bodyNeuronList.Count.ToString() + "\n"; txt += "HiddenNeurons: " + currentAgentGenome.brainGenome.hiddenNeuronList.Count.ToString() + "\n"; txt += "Links: " + currentAgentGenome.brainGenome.linkList.Count.ToString() + "\n"; // Modules: Agent curAgent = gameManager.trainerRef.evaluationManager.exhibitionInstance.currentAgentsArray[gameManager.trainerRef.evaluationManager.exhibitionTicketList[gameManager.trainerRef.evaluationManager.exhibitionTicketCurrentIndex].focusPopIndex - 1]; if (curAgent.healthModuleList.Count > 0) { txt += "HEALTH: " + curAgent.healthModuleList[0].health.ToString() + " / " + curAgent.healthModuleList[0].maxHealth.ToString() + "\n"; } if (curAgent.oscillatorList.Count > 0) { txt += "\nOSCILLATOR INPUTS: "; for (int i = 0; i < curAgent.oscillatorList.Count; i++) { txt += "\n" + i.ToString() + ": current value= " + curAgent.oscillatorList[i].value[0].ToString(); } txt += "\n"; } if (curAgent.targetSensorList.Count > 0) { txt += "\nTARGET SENSOR: "; if (curAgent.targetSensorList[0].targetPosition != null) { txt += curAgent.targetSensorList[0].targetPosition.position.ToString() + "\n"; if (currentAgentGenome.bodyGenome.targetSensorList[0].useX) { txt += "DotX = " + curAgent.targetSensorList[0].dotX[0].ToString() + "\n"; } if (currentAgentGenome.bodyGenome.targetSensorList[0].useY) { txt += "DotY = " + curAgent.targetSensorList[0].dotY[0].ToString() + "\n"; } if (currentAgentGenome.bodyGenome.targetSensorList[0].useZ) { txt += "DotZ = " + curAgent.targetSensorList[0].dotZ[0].ToString() + "\n"; } if (currentAgentGenome.bodyGenome.targetSensorList[0].useX && currentAgentGenome.bodyGenome.targetSensorList[0].useVel) { txt += "DotVelX = " + curAgent.targetSensorList[0].dotVelX[0].ToString() + "\n"; } if (currentAgentGenome.bodyGenome.targetSensorList[0].useY && currentAgentGenome.bodyGenome.targetSensorList[0].useVel) { txt += "DotVelY = " + curAgent.targetSensorList[0].dotVelY[0].ToString() + "\n"; } if (currentAgentGenome.bodyGenome.targetSensorList[0].useZ && currentAgentGenome.bodyGenome.targetSensorList[0].useVel) { txt += "DotVelZ = " + curAgent.targetSensorList[0].dotVelZ[0].ToString() + "\n"; } if (currentAgentGenome.bodyGenome.targetSensorList[0].useDist) { txt += "Dist = " + curAgent.targetSensorList[0].dist[0].ToString() + "\n"; } if (currentAgentGenome.bodyGenome.targetSensorList[0].useInvDist) { txt += "InvDist = " + curAgent.targetSensorList[0].invDist[0].ToString() + "\n"; } } } if (curAgent.raycastSensorList.Count > 0) { txt += "\nRAYCAST SENSOR:\n"; txt += "Left = " + curAgent.raycastSensorList[0].distanceLeft[0].ToString() + "\n"; txt += "LeftCenter = " + curAgent.raycastSensorList[0].distanceLeftCenter[0].ToString() + "\n"; txt += "CenterShort = " + curAgent.raycastSensorList[0].distanceCenterShort[0].ToString() + "\n"; txt += "RightCenter = " + curAgent.raycastSensorList[0].distanceRightCenter[0].ToString() + "\n"; txt += "Right = " + curAgent.raycastSensorList[0].distanceRight[0].ToString() + "\n"; txt += "CenterLong = " + curAgent.raycastSensorList[0].distanceCenter[0].ToString() + "\n"; txt += "Back = " + curAgent.raycastSensorList[0].distanceBack[0].ToString() + "\n"; } if (curAgent.thrusterEffectorList.Count > 0) { txt += "\nTHRUSTER: "; for (int i = 0; i < curAgent.thrusterEffectorList.Count; i++) { //txt += "\n" + i.ToString() + ": current value= " + curAgent.thrusterEffectorList[i].throttleY[0].ToString(); if (currentAgentGenome.bodyGenome.thrusterList[0].useX) { txt += "X = " + curAgent.torqueEffectorList[0].throttleX[0].ToString() + ", "; } if (currentAgentGenome.bodyGenome.thrusterList[0].useY) { txt += "Y = " + curAgent.torqueEffectorList[0].throttleY[0].ToString() + ", "; } if (currentAgentGenome.bodyGenome.thrusterList[0].useZ) { txt += "Z = " + curAgent.torqueEffectorList[0].throttleZ[0].ToString() + "\n"; } } //txt += "\n"; //txt += curAgent.thrusterEffectorList[0].throttleZ[0].ToString() + "\n"; } if (curAgent.torqueEffectorList.Count > 0) { //txt += "TORQUE: "; txt += "\nTORQUE: "; if (currentAgentGenome.bodyGenome.torqueList[0].useX) { txt += "X = " + curAgent.torqueEffectorList[0].throttleX[0].ToString() + ", "; } if (currentAgentGenome.bodyGenome.torqueList[0].useY) { txt += "Y = " + curAgent.torqueEffectorList[0].throttleY[0].ToString() + ", "; } if (currentAgentGenome.bodyGenome.torqueList[0].useZ) { txt += "Z = " + curAgent.torqueEffectorList[0].throttleZ[0].ToString() + "\n"; } //txt += curAgent.torqueEffectorList[0].throttleY[0].ToString() + "\n"; } if (curAgent.weaponProjectileList.Count > 0) { txt += "\nWEAPON-PROJECTILE:\n"; txt += "Throttle = " + curAgent.weaponProjectileList[0].throttle[0].ToString() + "\n"; txt += "Damage Inflicted = " + curAgent.weaponProjectileList[0].damageInflicted[0].ToString() + "\n"; txt += "Energy = " + curAgent.weaponProjectileList[0].energy[0].ToString() + "\n"; } if (curAgent.weaponTazerList.Count > 0) { txt += "\nWEAPON-TAZER:\n"; txt += "Throttle = " + curAgent.weaponTazerList[0].throttle[0].ToString() + "\n"; txt += "Damage Inflicted = " + curAgent.weaponTazerList[0].damageInflicted[0].ToString() + "\n"; txt += "Energy = " + curAgent.weaponTazerList[0].energy[0].ToString() + "\n"; } if (curAgent.contactSensorList.Count > 0) { txt += "\nCONTACT:\n"; txt += "Contact = " + curAgent.contactSensorList[0].contactSensor[0].ToString() + "\n"; } if (curAgent.gravitySensorList.Count > 0) { txt += "\nGRAVITY SENSOR:\n"; if (currentAgentGenome.bodyGenome.gravitySensorList[0].useGravityDir) { txt += "DotX = " + curAgent.gravitySensorList[0].dotX[0].ToString() + "\n"; txt += "DotY = " + curAgent.gravitySensorList[0].dotY[0].ToString() + "\n"; txt += "DotZ = " + curAgent.gravitySensorList[0].dotZ[0].ToString() + "\n"; } if (currentAgentGenome.bodyGenome.gravitySensorList[0].useVel) { txt += "VelX = " + curAgent.gravitySensorList[0].velX[0].ToString() + "\n"; txt += "VelY = " + curAgent.gravitySensorList[0].velY[0].ToString() + "\n"; txt += "VelZ = " + curAgent.gravitySensorList[0].velZ[0].ToString() + "\n"; } if (currentAgentGenome.bodyGenome.gravitySensorList[0].useAltitude) { txt += "Altitude = " + curAgent.gravitySensorList[0].altitude[0].ToString() + "\n"; } } if (curAgent.healthModuleList.Count > 0) { txt += "\nHEALTH:\n"; txt += "Health = " + curAgent.healthModuleList[0].healthSensor[0].ToString() + "\n"; txt += "Damage = " + curAgent.healthModuleList[0].takingDamage[0].ToString() + "\n"; } if (curAgent.basicWheelList.Count > 0) { txt += "\nBASIC AXLE:\n"; for (int i = 0; i < curAgent.basicWheelList.Count; i++) { txt += "Throttle = " + curAgent.basicWheelList[i].throttle[0].ToString() + "\n"; txt += "SteerAngle = " + curAgent.basicWheelList[i].steerAngle[0].ToString() + "\n"; txt += "Brake = " + curAgent.basicWheelList[i].brake[0].ToString() + "\n"; txt += "Speed = " + curAgent.basicWheelList[i].speed[0].ToString() + "\n\n"; } //txt += "Throttle = " + curAgent.basicWheelList[0].throttle[0].ToString() + "\n"; //txt += "SteerAngle = " + curAgent.basicWheelList[0].steerAngle[0].ToString() + "\n"; //txt += "Brake = " + curAgent.basicWheelList[0].brake[0].ToString() + "\n"; //txt += "Speed = " + curAgent.basicWheelList[0].speed[0].ToString() + "\n"; } if (curAgent.atmosphereSensorList.Count > 0) { txt += "\nATMOSPHERE SENSOR:\n"; txt += "WindX = " + curAgent.atmosphereSensorList[0].windDotX[0].ToString() + "\n"; txt += "WindY = " + curAgent.atmosphereSensorList[0].windDotY[0].ToString() + "\n"; txt += "WindZ = " + curAgent.atmosphereSensorList[0].windDotZ[0].ToString() + "\n"; } } return(txt); }
public void InitializeInstancedGeometry(EnvironmentGenome genome, Mesh instancePebbleMesh, Material instancePebbleMaterial, Mesh instanceRockMesh, Material instanceRockMaterial, Mesh instanceRockReliefArenaMesh, Material instanceRockReliefArenaMaterial, Mesh instanceRockCliffsMesh, Material instanceRockCliffsMaterial, Mesh vistaRockClusterMesh, Material vistaRockClusterMaterial, Mesh obstacleRockMesh, Material obstacleRockMaterial, ComputeShader instanceComputeShader) { this.instancePebbleMaterial = instancePebbleMaterial; this.instancePebbleMesh = instancePebbleMesh; this.instanceRockMaterial = instanceRockMaterial; this.instanceRockMesh = instanceRockMesh; this.instanceRockReliefArenaMaterial = instanceRockReliefArenaMaterial; this.instanceRockReliefArenaMesh = instanceRockReliefArenaMesh; this.instanceRockCliffsMaterial = instanceRockCliffsMaterial; this.instanceRockCliffsMesh = instanceRockCliffsMesh; this.vistaRockClusterMaterial = vistaRockClusterMaterial; this.vistaRockClusterMesh = vistaRockClusterMesh; this.obstacleRockMaterial = obstacleRockMaterial; this.obstacleRockMesh = obstacleRockMesh; // PEBBLES: #region Pebbles if (instancedPebblesCBuffer != null) { instancedPebblesCBuffer.Release(); } instancedPebblesCBuffer = new ComputeBuffer(numPebblesSide * numPebblesSide, sizeof(float) * 11); this.instancePebbleMaterial.SetPass(0); this.instancePebbleMaterial.SetBuffer("instancedPebblesCBuffer", instancedPebblesCBuffer); instanceComputeShader.SetVector("_QuadBounds", new Vector4(-85f, 85f, -85f, 85f)); // worldspace size of smallest heightTexture Region instanceComputeShader.SetVector("_GlobalBounds", new Vector4(-680f, 680f, -680f, 680f)); instanceComputeShader.SetInt("_NumPebblesSide", numPebblesSide); int initializeInstancePebblesKernelID = instanceComputeShader.FindKernel("CSInitializeInstancePebblesData"); instanceComputeShader.SetBuffer(initializeInstancePebblesKernelID, "instancedPebblesCBuffer", instancedPebblesCBuffer); instanceComputeShader.SetTexture(initializeInstancePebblesKernelID, "heightTexture3", TerrainConstructorGPU.heightMapCascadeTexturesRender[3]); instanceComputeShader.Dispatch(initializeInstancePebblesKernelID, numPebblesSide / 32, numPebblesSide / 32, 1); //Debug.Log("numPebbles: " + instancedPebblesCBuffer.count.ToString()); // Initialize positions and orientations and shit: // all zeros for now // indirect args indirectArgsPebblesCBuffer = new ComputeBuffer(1, indirectArgsPebbles.Length * sizeof(uint), ComputeBufferType.IndirectArguments); uint numIndices = (instancePebbleMesh != null) ? (uint)instancePebbleMesh.GetIndexCount(0) : 0; indirectArgsPebbles[0] = numIndices; indirectArgsPebbles[1] = (uint)numPebblesSide * (uint)numPebblesSide; indirectArgsPebblesCBuffer.SetData(indirectArgsPebbles); #endregion // ROCKS: #region Rocks if (instancedRocksCBuffer != null) { instancedRocksCBuffer.Release(); } instancedRocksCBuffer = new ComputeBuffer(numRocksSide * numRocksSide, sizeof(float) * 16); if (instancedRocksInvMatrixCBuffer != null) { instancedRocksInvMatrixCBuffer.Release(); } instancedRocksInvMatrixCBuffer = new ComputeBuffer(numRocksSide * numRocksSide, sizeof(float) * 16); this.instanceRockMaterial.SetPass(0); this.instanceRockMaterial.SetBuffer("matricesCBuffer", instancedRocksCBuffer); this.instanceRockMaterial.SetBuffer("invMatricesCBuffer", instancedRocksInvMatrixCBuffer); instanceComputeShader.SetVector("_QuadBounds", new Vector4(-85f, 85f, -85f, 85f)); // worldspace size of smallest heightTexture Region instanceComputeShader.SetVector("_GlobalBounds", new Vector4(-680f, 680f, -680f, 680f)); instanceComputeShader.SetInt("_NumRocksSide", numRocksSide); int initializeInstanceRocksKernelID = instanceComputeShader.FindKernel("CSInitializeInstanceRocksData"); instanceComputeShader.SetBuffer(initializeInstanceRocksKernelID, "instancedRocksMatricesCBuffer", instancedRocksCBuffer); instanceComputeShader.SetBuffer(initializeInstanceRocksKernelID, "instancedRocksInvMatrixCBuffer", instancedRocksInvMatrixCBuffer); instanceComputeShader.SetTexture(initializeInstanceRocksKernelID, "heightTexture0", TerrainConstructorGPU.heightMapCascadeTexturesRender[0]); instanceComputeShader.SetTexture(initializeInstanceRocksKernelID, "heightTexture1", TerrainConstructorGPU.heightMapCascadeTexturesRender[1]); instanceComputeShader.SetTexture(initializeInstanceRocksKernelID, "heightTexture2", TerrainConstructorGPU.heightMapCascadeTexturesRender[2]); instanceComputeShader.SetTexture(initializeInstanceRocksKernelID, "heightTexture3", TerrainConstructorGPU.heightMapCascadeTexturesRender[3]); instanceComputeShader.Dispatch(initializeInstanceRocksKernelID, numRocksSide / 32, numRocksSide / 32, 1); //Debug.Log("numRocks: " + instancedRocksCBuffer.count.ToString()); // Initialize positions and orientations and shit: // all zeros for now // indirect args indirectArgsRocksCBuffer = new ComputeBuffer(1, indirectArgsRocks.Length * sizeof(uint), ComputeBufferType.IndirectArguments); uint numIndicesRock = (instanceRockMesh != null) ? (uint)instanceRockMesh.GetIndexCount(0) : 0; indirectArgsRocks[0] = numIndicesRock; indirectArgsRocks[1] = (uint)numRocksSide * (uint)numRocksSide; indirectArgsRocksCBuffer.SetData(indirectArgsRocks); #endregion #region ReliefArenaRocks // RELIEF ARENA ROCKS: (hug Terrain) if (instancedRocksReliefArenaCBuffer != null) { instancedRocksReliefArenaCBuffer.Release(); } instancedRocksReliefArenaCBuffer = new ComputeBuffer(numRocksReliefArenaSide * numRocksReliefArenaSide, sizeof(float) * 16); if (instancedRocksReliefArenaInvMatrixCBuffer != null) { instancedRocksReliefArenaInvMatrixCBuffer.Release(); } instancedRocksReliefArenaInvMatrixCBuffer = new ComputeBuffer(numRocksReliefArenaSide * numRocksReliefArenaSide, sizeof(float) * 16); this.instanceRockReliefArenaMaterial.SetPass(0); this.instanceRockReliefArenaMaterial.SetBuffer("matricesCBuffer", instancedRocksReliefArenaCBuffer); this.instanceRockReliefArenaMaterial.SetBuffer("invMatricesCBuffer", instancedRocksReliefArenaInvMatrixCBuffer); instanceComputeShader.SetVector("_QuadBounds", new Vector4(-85f, 85f, -85f, 85f)); // worldspace size of smallest heightTexture Region instanceComputeShader.SetVector("_GlobalBounds", new Vector4(-680f, 680f, -680f, 680f)); instanceComputeShader.SetInt("_NumRocksReliefArenaSide", numRocksReliefArenaSide); int initializeInstanceRocksReliefArenaKernelID = instanceComputeShader.FindKernel("CSInitializeInstanceRocksReliefArenaData"); instanceComputeShader.SetBuffer(initializeInstanceRocksReliefArenaKernelID, "instancedRocksReliefArenaMatricesCBuffer", instancedRocksReliefArenaCBuffer); instanceComputeShader.SetBuffer(initializeInstanceRocksReliefArenaKernelID, "instancedRocksReliefArenaInvMatrixCBuffer", instancedRocksReliefArenaInvMatrixCBuffer); instanceComputeShader.SetTexture(initializeInstanceRocksReliefArenaKernelID, "heightTexture0", TerrainConstructorGPU.heightMapCascadeTexturesRender[0]); instanceComputeShader.SetTexture(initializeInstanceRocksReliefArenaKernelID, "heightTexture1", TerrainConstructorGPU.heightMapCascadeTexturesRender[1]); instanceComputeShader.SetTexture(initializeInstanceRocksReliefArenaKernelID, "heightTexture2", TerrainConstructorGPU.heightMapCascadeTexturesRender[2]); instanceComputeShader.SetTexture(initializeInstanceRocksReliefArenaKernelID, "heightTexture3", TerrainConstructorGPU.heightMapCascadeTexturesRender[3]); instanceComputeShader.Dispatch(initializeInstanceRocksReliefArenaKernelID, numRocksReliefArenaSide / 32, numRocksReliefArenaSide / 32, 1); //Debug.Log("numRocks: " + instancedRocksCBuffer.count.ToString()); //Matrix4x4[] matrixArray = new Matrix4x4[instancedRocksReliefArenaInvMatrixCBuffer.count]; //instancedRocksReliefArenaInvMatrixCBuffer.GetData(matrixArray); //Debug.Log("instancedRocksCBuffer[0] " + matrixArray[0].ToString()); // Initialize positions and orientations and shit: // all zeros for now // indirect args indirectArgsRocksReliefArenaCBuffer = new ComputeBuffer(1, indirectArgsRocksReliefArena.Length * sizeof(uint), ComputeBufferType.IndirectArguments); uint numIndicesRockReliefArena = (instanceRockReliefArenaMesh != null) ? (uint)instanceRockReliefArenaMesh.GetIndexCount(0) : 0; indirectArgsRocksReliefArena[0] = numIndicesRockReliefArena; indirectArgsRocksReliefArena[1] = (uint)numRocksReliefArenaSide * (uint)numRocksReliefArenaSide; indirectArgsRocksReliefArenaCBuffer.SetData(indirectArgsRocksReliefArena); #endregion #region Cliffs Rocks // CLIFFS ROCKS: (hug Terrain) if (instancedRocksCliffsMatrixCBuffer != null) { instancedRocksCliffsMatrixCBuffer.Release(); } instancedRocksCliffsMatrixCBuffer = new ComputeBuffer(numRocksCliffsSide * numRocksCliffsSide, sizeof(float) * 16); if (instancedRocksCliffsInvMatrixCBuffer != null) { instancedRocksCliffsInvMatrixCBuffer.Release(); } instancedRocksCliffsInvMatrixCBuffer = new ComputeBuffer(numRocksCliffsSide * numRocksCliffsSide, sizeof(float) * 16); this.instanceRockCliffsMaterial.SetPass(0); this.instanceRockCliffsMaterial.SetBuffer("matricesCBuffer", instancedRocksCliffsMatrixCBuffer); this.instanceRockCliffsMaterial.SetBuffer("invMatricesCBuffer", instancedRocksCliffsInvMatrixCBuffer); instanceComputeShader.SetVector("_QuadBounds", new Vector4(-85f, 85f, -85f, 85f)); // worldspace size of smallest heightTexture Region instanceComputeShader.SetVector("_GlobalBounds", new Vector4(-680f, 680f, -680f, 680f)); instanceComputeShader.SetInt("_NumRocksCliffsSide", numRocksCliffsSide); int initializeInstanceRocksCliffsKernelID = instanceComputeShader.FindKernel("CSInitializeInstanceRocksCliffsData"); instanceComputeShader.SetBuffer(initializeInstanceRocksCliffsKernelID, "instancedRocksCliffsMatrixCBuffer", instancedRocksCliffsMatrixCBuffer); instanceComputeShader.SetBuffer(initializeInstanceRocksCliffsKernelID, "instancedRocksCliffsInvMatrixCBuffer", instancedRocksCliffsInvMatrixCBuffer); instanceComputeShader.SetTexture(initializeInstanceRocksCliffsKernelID, "heightTexture0", TerrainConstructorGPU.heightMapCascadeTexturesRender[0]); instanceComputeShader.SetTexture(initializeInstanceRocksCliffsKernelID, "heightTexture1", TerrainConstructorGPU.heightMapCascadeTexturesRender[1]); instanceComputeShader.SetTexture(initializeInstanceRocksCliffsKernelID, "heightTexture2", TerrainConstructorGPU.heightMapCascadeTexturesRender[2]); instanceComputeShader.SetTexture(initializeInstanceRocksCliffsKernelID, "heightTexture3", TerrainConstructorGPU.heightMapCascadeTexturesRender[3]); instanceComputeShader.Dispatch(initializeInstanceRocksCliffsKernelID, numRocksCliffsSide / 32, numRocksCliffsSide / 32, 1); // indirect args indirectArgsRocksCliffsCBuffer = new ComputeBuffer(1, indirectArgsRocksCliffs.Length * sizeof(uint), ComputeBufferType.IndirectArguments); uint numIndicesRockCliffs = (instanceRockCliffsMesh != null) ? (uint)instanceRockCliffsMesh.GetIndexCount(0) : 0; indirectArgsRocksCliffs[0] = numIndicesRockCliffs; indirectArgsRocksCliffs[1] = (uint)numRocksCliffsSide * (uint)numRocksCliffsSide; indirectArgsRocksCliffsCBuffer.SetData(indirectArgsRocksCliffs); #endregion #region VISTA ROCK CLUSTERS!!!! WOOOOOOOO // ROCKS CLUSTERS!!!!!!: if (appendRocksClusterCoreCBuffer != null) { appendRocksClusterCoreCBuffer.Release(); } indirectArgsRocksClusterCoreCBuffer = new ComputeBuffer(1, indirectArgsRocksClusterCore.Length * sizeof(uint), ComputeBufferType.IndirectArguments); appendRocksClusterCoreCBuffer = new ComputeBuffer(maxClustersPerSide * maxClustersPerSide, sizeof(float) * 3, ComputeBufferType.Append); appendRocksClusterCoreCBuffer.SetCounterValue(0); // Set Shader Params: instanceComputeShader.SetInt("_MaxClustersPerSide", maxClustersPerSide); instanceComputeShader.SetVector("_QuadBounds", new Vector4(-85f, 85f, -85f, 85f)); // worldspace size of smallest heightTexture Region instanceComputeShader.SetVector("_GlobalBounds", new Vector4(-680f, 680f, -680f, 680f)); int generateRockClustersKernelID = instanceComputeShader.FindKernel("CSGenerateRockClusters"); instanceComputeShader.SetTexture(generateRockClustersKernelID, "heightTexture0", TerrainConstructorGPU.heightMapCascadeTexturesRender[0]); instanceComputeShader.SetTexture(generateRockClustersKernelID, "heightTexture1", TerrainConstructorGPU.heightMapCascadeTexturesRender[1]); instanceComputeShader.SetTexture(generateRockClustersKernelID, "heightTexture2", TerrainConstructorGPU.heightMapCascadeTexturesRender[2]); instanceComputeShader.SetTexture(generateRockClustersKernelID, "heightTexture3", TerrainConstructorGPU.heightMapCascadeTexturesRender[3]); instanceComputeShader.SetBuffer(generateRockClustersKernelID, "appendRocksClusterCoreCBuffer", appendRocksClusterCoreCBuffer); // Search through height-map texture for suitable rock cluster locations: // DISPATCH HERE: instanceComputeShader.Dispatch(generateRockClustersKernelID, maxClustersPerSide / 32, maxClustersPerSide / 32, 1); // create all triangles from Neurons indirectArgsRocksClusterCore[0] = 0; // set later by counter;// 3; // 3 vertices to start indirectArgsRocksClusterCore[1] = 1; // 1 instance/copy indirectArgsRocksClusterCoreCBuffer.SetData(indirectArgsRocksClusterCore); ComputeBuffer.CopyCount(appendRocksClusterCoreCBuffer, indirectArgsRocksClusterCoreCBuffer, 0); indirectArgsRocksClusterCoreCBuffer.GetData(indirectArgsRocksClusterCore); int numRockClusters = (int)indirectArgsRocksClusterCore[0]; Debug.Log("Rock Cluster Count: " + numRockClusters.ToString()); // OK! now that we have cluster locations and data inside appendRocksClusterCoreCBuffer, create individual rock insatnce data based on those: if (numRockClusters > 0) { if (vistaRocksClusterMatrixCBuffer != null) { vistaRocksClusterMatrixCBuffer.Release(); } vistaRocksClusterMatrixCBuffer = new ComputeBuffer(numRockClusters * numRockInstancesPerCluster, sizeof(float) * 16); if (vistaRocksClusterInvMatrixCBuffer != null) { vistaRocksClusterInvMatrixCBuffer.Release(); } vistaRocksClusterInvMatrixCBuffer = new ComputeBuffer(numRockClusters * numRockInstancesPerCluster, sizeof(float) * 16); //CSGenerateVistaClusterRocks //_NumRockInstancesPerCluster instanceComputeShader.SetInt("_NumRockClusters", numRockClusters); instanceComputeShader.SetInt("_NumRockInstancesPerCluster", numRockInstancesPerCluster); this.vistaRockClusterMaterial.SetPass(0); this.vistaRockClusterMaterial.SetBuffer("matricesCBuffer", vistaRocksClusterMatrixCBuffer); this.vistaRockClusterMaterial.SetBuffer("invMatricesCBuffer", vistaRocksClusterInvMatrixCBuffer); instanceComputeShader.SetVector("_QuadBounds", new Vector4(-85f, 85f, -85f, 85f)); // worldspace size of smallest heightTexture Region instanceComputeShader.SetVector("_GlobalBounds", new Vector4(-680f, 680f, -680f, 680f)); int generateVistaClusterRocksKernelID = instanceComputeShader.FindKernel("CSGenerateVistaClusterRocks"); instanceComputeShader.SetTexture(generateVistaClusterRocksKernelID, "heightTexture0", TerrainConstructorGPU.heightMapCascadeTexturesRender[0]); instanceComputeShader.SetTexture(generateVistaClusterRocksKernelID, "heightTexture1", TerrainConstructorGPU.heightMapCascadeTexturesRender[1]); instanceComputeShader.SetTexture(generateVistaClusterRocksKernelID, "heightTexture2", TerrainConstructorGPU.heightMapCascadeTexturesRender[2]); instanceComputeShader.SetTexture(generateVistaClusterRocksKernelID, "heightTexture3", TerrainConstructorGPU.heightMapCascadeTexturesRender[3]); instanceComputeShader.SetBuffer(generateVistaClusterRocksKernelID, "rocksClusterCoreCBuffer", appendRocksClusterCoreCBuffer); instanceComputeShader.SetBuffer(generateVistaClusterRocksKernelID, "vistaRocksClusterMatrixCBuffer", vistaRocksClusterMatrixCBuffer); instanceComputeShader.SetBuffer(generateVistaClusterRocksKernelID, "vistaRocksClusterInvMatrixCBuffer", vistaRocksClusterInvMatrixCBuffer); // Search through height-map texture for suitable rock cluster locations: // DISPATCH HERE: instanceComputeShader.Dispatch(generateVistaClusterRocksKernelID, numRockClusters, numRockInstancesPerCluster, 1); // create all triangles from Neurons // indirect args argsVistaRocksClusterCBuffer = new ComputeBuffer(1, argsVistaRocksCluster.Length * sizeof(uint), ComputeBufferType.IndirectArguments); uint numIndicesVistaRockCluster = (vistaRockClusterMesh != null) ? (uint)vistaRockClusterMesh.GetIndexCount(0) : 0; argsVistaRocksCluster[0] = numIndicesVistaRockCluster; argsVistaRocksCluster[1] = (uint)numRockClusters * (uint)numRockInstancesPerCluster; argsVistaRocksClusterCBuffer.SetData(argsVistaRocksCluster); } #endregion #region OBSTACLE ROCKS if (genome.useBasicObstacles) { // Process data from Obstacles Genome into GPU-friendly structure: if (obstacleDataCBuffer != null) { obstacleDataCBuffer.Release(); } int numObstacles = genome.basicObstaclesGenome.numObstacles; obstacleDataCBuffer = new ComputeBuffer(numObstacles, sizeof(float) * 9); ObstacleData[] obstacleDataArray = new ObstacleData[numObstacles]; for (int i = 0; i < numObstacles; i++) { /* * obstacle.transform.parent = environmentGameplay.gameObject.transform; * //float x = genome.basicObstaclesGenome.obstaclePositions[i].x * genome.arenaBounds.x - genome.arenaBounds.x * 0.5f; * //float z = genome.basicObstaclesGenome.obstaclePositions[i].y * genome.arenaBounds.z - genome.arenaBounds.z * 0.5f; * float x = genome.basicObstaclesGenome.obstaclePositions[i].x * genome.arenaBounds.x - genome.arenaBounds.x * 0.5f; * float z = genome.basicObstaclesGenome.obstaclePositions[i].y * genome.arenaBounds.z - genome.arenaBounds.z * 0.5f; * if (genome.useTargetColumn) { * float distToTarget = (new Vector2(environmentGameplay.targetColumn.transform.localPosition.x, environmentGameplay.targetColumn.transform.localPosition.z) - new Vector2(x, z)).magnitude; * if(distToTarget < genome.basicObstaclesGenome.obstacleScales[i] * 0.6f) { * obstacle.SetActive(false); * } * } * float y = TerrainConstructor.GetAltitude(genome, x, z) + 0.5f; * obstacle.transform.localScale = new Vector3(genome.basicObstaclesGenome.obstacleScales[i], 1f, genome.basicObstaclesGenome.obstacleScales[i]); * obstacle.transform.localPosition = new Vector3(x, y, z); */ ObstacleData data = new ObstacleData(); Vector3 obstaclePos = new Vector3(genome.basicObstaclesGenome.obstaclePositions[i].x * genome.arenaBounds.x - genome.arenaBounds.x * 0.5f, 0f, genome.basicObstaclesGenome.obstaclePositions[i].y * genome.arenaBounds.z - genome.arenaBounds.z * 0.5f); data.worldPos = obstaclePos; data.scale = Vector3.one * genome.basicObstaclesGenome.obstacleScales[i]; data.eulerRotation = Vector3.zero; obstacleDataArray[i] = data; } obstacleDataCBuffer.SetData(obstacleDataArray); // Create and initialize Transform Matrices CBuffers: if (obstacleRockMatrixCBuffer != null) { obstacleRockMatrixCBuffer.Release(); } obstacleRockMatrixCBuffer = new ComputeBuffer(numObstacles * numRockInstancesPerObstacle, sizeof(float) * 16); if (obstacleRockInvMatrixCBuffer != null) { obstacleRockInvMatrixCBuffer.Release(); } obstacleRockInvMatrixCBuffer = new ComputeBuffer(numObstacles * numRockInstancesPerObstacle, sizeof(float) * 16); // Pass XForm Matrix data to display shader so it can draw rock instances! this.obstacleRockMaterial.SetPass(0); this.obstacleRockMaterial.SetBuffer("matricesCBuffer", obstacleRockMatrixCBuffer); this.obstacleRockMaterial.SetBuffer("invMatricesCBuffer", obstacleRockInvMatrixCBuffer); // Initialize ComputeShader with all the data it needs to generate individual instanced rock xForm Matrices: // Set Shader Params: instanceComputeShader.SetInt("_NumRockInstancesPerObstacle", numRockInstancesPerObstacle); instanceComputeShader.SetVector("_QuadBounds", new Vector4(-85f, 85f, -85f, 85f)); // worldspace size of smallest heightTexture Region instanceComputeShader.SetVector("_GlobalBounds", new Vector4(-680f, 680f, -680f, 680f)); int generateObstacleRocksKernelID = instanceComputeShader.FindKernel("CSGenerateObstacleRocks"); // Only needs closest LOD level since obstacles are inside the Arena (or barely outside - sans collision) instanceComputeShader.SetTexture(generateObstacleRocksKernelID, "heightTexture3", TerrainConstructorGPU.heightMapCascadeTexturesRender[3]); instanceComputeShader.SetBuffer(generateObstacleRocksKernelID, "obstacleDataCBuffer", obstacleDataCBuffer); instanceComputeShader.SetBuffer(generateObstacleRocksKernelID, "obstacleRockMatrixCBuffer", obstacleRockMatrixCBuffer); instanceComputeShader.SetBuffer(generateObstacleRocksKernelID, "obstacleRockInvMatrixCBuffer", obstacleRockInvMatrixCBuffer); // Generate Transform Matrices for all obstalce rock instances: instanceComputeShader.Dispatch(generateObstacleRocksKernelID, numObstacles * numRockInstancesPerObstacle, 1, 1); // create all triangles from Neurons // indirect args argsObstacleRockCBuffer = new ComputeBuffer(1, argsObstacleRock.Length * sizeof(uint), ComputeBufferType.IndirectArguments); uint numIndicesObstacleRock = (obstacleRockMesh != null) ? (uint)obstacleRockMesh.GetIndexCount(0) : 0; argsObstacleRock[0] = numIndicesObstacleRock; argsObstacleRock[1] = (uint)numObstacles * (uint)numRockInstancesPerObstacle; argsObstacleRockCBuffer.SetData(argsObstacleRock); } #endregion }
public static BasicObstaclesGenome BirthNewGenome(BasicObstaclesGenome parentGenome, float mutationRate, float mutationDriftAmount, EnvironmentGenome envGenomeRef) { // 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... BasicObstaclesGenome newGenome = new BasicObstaclesGenome(); newGenome.numObstacles = parentGenome.numObstacles; newGenome.minObstacleSize = parentGenome.minObstacleSize; newGenome.maxObstacleSize = parentGenome.maxObstacleSize; newGenome.randomSeed = parentGenome.randomSeed; float rand = UnityEngine.Random.Range(0f, 1f); if (rand < mutationRate) { int newVal = UnityEngine.Random.Range(0, 99999); newGenome.randomSeed = newVal; } newGenome.obstaclePositions = new Vector2[newGenome.numObstacles]; newGenome.obstacleScales = new float[newGenome.numObstacles]; for (int i = 0; i < parentGenome.obstaclePositions.Length; i++) { newGenome.obstaclePositions[i] = new Vector2(parentGenome.obstaclePositions[i].x, parentGenome.obstaclePositions[i].y); newGenome.obstacleScales[i] = parentGenome.obstacleScales[i]; rand = UnityEngine.Random.Range(0f, 1f); if (rand < mutationRate) { float newPosX = UnityEngine.Random.Range(0f, 1f); newGenome.obstaclePositions[i].x = Mathf.Lerp(newGenome.obstaclePositions[i].x, newPosX, mutationDriftAmount); } if (rand < mutationRate) { float newPosZ = UnityEngine.Random.Range(0f, 1f); newGenome.obstaclePositions[i].y = Mathf.Lerp(newGenome.obstaclePositions[i].y, newPosZ, mutationDriftAmount); } // Check for intersection with Agent Start Position: Vector2 startCoords = new Vector2(envGenomeRef.agentStartPositionsList[0].agentStartPosition.x / 40f + 0.5f, envGenomeRef.agentStartPositionsList[0].agentStartPosition.z / 40f + 0.5f); if ((newGenome.obstaclePositions[i] - startCoords).magnitude < 0.15f) { newGenome.obstaclePositions[i] = startCoords + (newGenome.obstaclePositions[i] - startCoords) * 0.15f / (newGenome.obstaclePositions[i] - startCoords).magnitude; } // Check for intersection with Target Position: // will need to do this as env is being created since target pos is random /*if(envGenomeRef.useTargetColumn) { * Vector2 targetCoords = new Vector2(envGenomeRef.targetColumnGenome..agentStartPosition.x / 40f + 0.5f, envGenomeRef.agentStartPositionsList[0].agentStartPosition.z / 40f + 0.5f); * if ((newGenome.obstaclePositions[i] - startCoords).magnitude < 0.15f) { * newGenome.obstaclePositions[i] = startCoords + (newGenome.obstaclePositions[i] - startCoords) * 0.15f / (newGenome.obstaclePositions[i] - startCoords).magnitude; * } * // * }*/ if (rand < mutationRate) { float newScale = UnityEngine.Random.Range(newGenome.minObstacleSize, newGenome.maxObstacleSize); newGenome.obstacleScales[i] = Mathf.Lerp(newGenome.obstacleScales[i], newScale, mutationDriftAmount); } } return(newGenome); }
public void AddRenderableContent(EnvironmentGenome genome) { }
public void Init1(TeamsConfig teamsConfig) { challengeType = teamsConfig.challengeType; // Temp hardcoded!!!!! competitionType = CompetitionType.Independent; competitionFormat = CompetitionFormat.HighScore; numOpponents = 1; tournamentRoundList = new List <TournamentRound>(); TournamentRound round1 = new TournamentRound(0); // MOCKUP: int[] competitorIDs = new int[1]; competitorIDs[0] = -1; // Match1 string savename = "env1"; string path = Application.dataPath + "/IndividualSaves/Environments/" + savename + ".json"; // Read the json from the file into a string string dataAsJson = File.ReadAllText(path); EnvironmentGenome loadedGenome1 = JsonUtility.FromJson <EnvironmentGenome>(dataAsJson); List <AgentGenome> agentGenomesList1 = new List <AgentGenome>(); agentGenomesList1.Add(teamsConfig.playersList[0].agentGenomeList[0]); EvaluationTicket ticket1 = new EvaluationTicket(loadedGenome1, agentGenomesList1, 1, 1000); TournamentMatchup matchup1 = new TournamentMatchup(0, ticket1, 0, competitorIDs); round1.matchupList.Add(matchup1); // Match2 savename = "env2"; path = Application.dataPath + "/IndividualSaves/Environments/" + savename + ".json"; // Read the json from the file into a string dataAsJson = File.ReadAllText(path); EnvironmentGenome loadedGenome2 = JsonUtility.FromJson <EnvironmentGenome>(dataAsJson); List <AgentGenome> agentGenomesList2 = new List <AgentGenome>(); agentGenomesList2.Add(teamsConfig.playersList[0].agentGenomeList[0]); EvaluationTicket ticket2 = new EvaluationTicket(loadedGenome2, agentGenomesList2, 1, 1000); TournamentMatchup matchup2 = new TournamentMatchup(1, ticket2, 1, competitorIDs); round1.matchupList.Add(matchup2); // Matchup3: savename = "env3"; path = Application.dataPath + "/IndividualSaves/Environments/" + savename + ".json"; // Read the json from the file into a string dataAsJson = File.ReadAllText(path); EnvironmentGenome loadedGenome3 = JsonUtility.FromJson <EnvironmentGenome>(dataAsJson); List <AgentGenome> agentGenomesList3 = new List <AgentGenome>(); agentGenomesList3.Add(teamsConfig.playersList[0].agentGenomeList[0]); EvaluationTicket ticket3 = new EvaluationTicket(loadedGenome3, agentGenomesList3, 1, 1000); TournamentMatchup matchup3 = new TournamentMatchup(2, ticket3, 2, competitorIDs); round1.matchupList.Add(matchup3); tournamentRoundList.Add(round1); }