private void SetUpDefaultFitnessComponents(Challenge.Type challengeType, FitnessManager fitnessManager) { switch (challengeType) { case Challenge.Type.Test: FitnessComponentDefinition newComponent = new FitnessComponentDefinition(FitnessComponentType.Random, FitnessComponentMeasure.Avg, 1f, true); fitnessManager.fitnessComponentDefinitions.Add(newComponent); break; case Challenge.Type.Racing: FitnessComponentDefinition newComponentRacing = new FitnessComponentDefinition(FitnessComponentType.Random, FitnessComponentMeasure.Avg, 1f, true); fitnessManager.fitnessComponentDefinitions.Add(newComponentRacing); break; case Challenge.Type.Combat: FitnessComponentDefinition newComponentCombat = new FitnessComponentDefinition(FitnessComponentType.Random, FitnessComponentMeasure.Avg, 1f, true); fitnessManager.fitnessComponentDefinitions.Add(newComponentCombat); break; default: Debug.LogError("ChallengeType Not Found! " + challengeType.ToString()); break; } fitnessManager.SetPendingFitnessListFromMaster(); // make pending list a copy of the primary }
private AgentBodyGenomeTemplate GetDefaultTemplateAgentGenome(Challenge.Type challengeType) { AgentBodyGenomeTemplate templateGenome; switch (challengeType) { case Challenge.Type.Test: templateGenome = Resources.Load("Templates/Agents/TemplateSnakeA") as AgentBodyGenomeTemplate; //templateGenome = ((AgentGenomeTemplate)AssetDatabase.LoadAssetAtPath("Assets/Templates/Agents/TemplateTelevisionWalker.asset", typeof(AgentGenomeTemplate))); break; case Challenge.Type.Racing: //Debug.Log("Loaded DogCar!"); templateGenome = Resources.Load("Templates/Agents/TemplateDogCar") as AgentBodyGenomeTemplate; //templateGenome = ((AgentGenomeTemplate)AssetDatabase.LoadAssetAtPath("Assets/Templates/Agents/TemplateDogCar.asset", typeof(AgentGenomeTemplate))); break; case Challenge.Type.Combat: templateGenome = Resources.Load("Templates/Agents/TemplateCombat2") as AgentBodyGenomeTemplate; //templateGenome = ((AgentGenomeTemplate)AssetDatabase.LoadAssetAtPath("Assets/Templates/Agents/TemplateCombatBot.asset", typeof(AgentGenomeTemplate))); break; default: Debug.LogError("ChallengeType Not Found! " + challengeType.ToString()); templateGenome = null; break; } return(templateGenome); }
/*public void ReloadAgentTemplates() { * // Players: * for (int i = 0; i < playersList.Count; i++) { * // Might have to revisit how to pass agent templates per population... * AgentGenomeTemplate templateAgentGenome = GetDefaultTemplateAgentGenome(challengeType); * playersList[i].templateGenome = templateAgentGenome.templateGenome; * } * }*/ private EnvironmentGenome GetDefaultTemplateEnvironmentGenome(Challenge.Type challengeType) { EnvironmentGenome templateGenome; switch (challengeType) { case Challenge.Type.Test: templateGenome = (Resources.Load("Templates/Environments/TemplateTestDefault2") as EnvironmentGenomeTemplate).templateGenome; //templateGenome = ((EnvironmentGenomeTemplate)AssetDatabase.LoadAssetAtPath("Assets/Templates/Environments/TemplateTestDefault.asset", typeof(EnvironmentGenomeTemplate))).templateGenome; break; case Challenge.Type.Racing: templateGenome = (Resources.Load("Templates/Environments/TemplateRacingDefault") as EnvironmentGenomeTemplate).templateGenome; //templateGenome = ((EnvironmentGenomeTemplate)AssetDatabase.LoadAssetAtPath("Assets/Templates/Environments/TemplateRacingDefault.asset", typeof(EnvironmentGenomeTemplate))).templateGenome; break; case Challenge.Type.Combat: templateGenome = (Resources.Load("Templates/Environments/TemplateCombatDefault") as EnvironmentGenomeTemplate).templateGenome; //templateGenome = ((EnvironmentGenomeTemplate)AssetDatabase.LoadAssetAtPath("Assets/Templates/Environments/TemplateCombatDefault.asset", typeof(EnvironmentGenomeTemplate))).templateGenome; break; default: Debug.LogError("ChallengeType Not Found! " + challengeType.ToString()); templateGenome = null; break; } return(templateGenome); }
private void SetUpDefaultFitnessComponents(Challenge.Type challengeType, FitnessManager fitnessManager) { switch (challengeType) { case Challenge.Type.Test: //FitnessComponentDefinition fitTest1 = new FitnessComponentDefinition(FitnessComponentType.WinLoss, FitnessComponentMeasure.Last, 1f, true); //fitnessManager.fitnessComponentDefinitions.Add(fitTest1); //FitnessComponentDefinition fitTest2 = new FitnessComponentDefinition(FitnessComponentType.DistanceToTargetSquared, FitnessComponentMeasure.Avg, 1f, false); //fitnessManager.fitnessComponentDefinitions.Add(fitTest2); FitnessComponentDefinition fitTest1 = new FitnessComponentDefinition(FitnessComponentType.ContactHazard, FitnessComponentMeasure.Avg, 1f, false); fitnessManager.fitnessComponentDefinitions.Add(fitTest1); FitnessComponentDefinition fitTest2 = new FitnessComponentDefinition(FitnessComponentType.DistToOrigin, FitnessComponentMeasure.Avg, 1f, true); fitnessManager.fitnessComponentDefinitions.Add(fitTest2); FitnessComponentDefinition fitTest3 = new FitnessComponentDefinition(FitnessComponentType.Velocity, FitnessComponentMeasure.Avg, 1f, true); fitnessManager.fitnessComponentDefinitions.Add(fitTest3); break; case Challenge.Type.Racing: FitnessComponentDefinition fitCompRacing1 = new FitnessComponentDefinition(FitnessComponentType.ContactHazard, FitnessComponentMeasure.Avg, 1f, false); fitnessManager.fitnessComponentDefinitions.Add(fitCompRacing1); FitnessComponentDefinition fitCompRacing2 = new FitnessComponentDefinition(FitnessComponentType.Velocity, FitnessComponentMeasure.Avg, 1f, true); fitnessManager.fitnessComponentDefinitions.Add(fitCompRacing2); break; case Challenge.Type.Combat: FitnessComponentDefinition fitCompCombat1 = new FitnessComponentDefinition(FitnessComponentType.Random, FitnessComponentMeasure.Avg, 0.1f, true); fitnessManager.fitnessComponentDefinitions.Add(fitCompCombat1); FitnessComponentDefinition fitCompCombat2 = new FitnessComponentDefinition(FitnessComponentType.Health, FitnessComponentMeasure.Avg, 0.5f, true); fitnessManager.fitnessComponentDefinitions.Add(fitCompCombat2); FitnessComponentDefinition fitCompCombat3 = new FitnessComponentDefinition(FitnessComponentType.DamageInflicted, FitnessComponentMeasure.Avg, 1f, true); fitnessManager.fitnessComponentDefinitions.Add(fitCompCombat3); FitnessComponentDefinition fitCompCombat4 = new FitnessComponentDefinition(FitnessComponentType.WinLoss, FitnessComponentMeasure.Avg, 1f, true); fitnessManager.fitnessComponentDefinitions.Add(fitCompCombat4); break; default: Debug.LogError("ChallengeType Not Found! " + challengeType.ToString()); break; } fitnessManager.SetPendingFitnessListFromMaster(); // make pending list a copy of the primary }
public void GoToChallengeSetup() { switch (challengeType) { case Challenge.Type.Test: // do something break; case Challenge.Type.Racing: // do something break; case Challenge.Type.Combat: // do something break; default: //do nothing Debug.LogError("[ERROR!] NO SUCH CHALLENGETYPE FOUND! (" + challengeType.ToString() + ")"); break; } ChangeState(GameState.ChallengeSetup); }
private void BruteForceInit() { // REFACTOR THIS!!!!!!!!!!!!!! // Clear Everything: DeleteAllGameObjects(); currentTimeStep = 0; gameWonOrLost = false; // <-- revisit this shit //winnerPopIndex = -1; // <-- revisit this shit currentAgentsArray = new Agent[currentEvalTicket.agentGenomesList.Count]; agentGameScoresArray = new float[currentEvalTicket.agentGenomesList.Count][]; for (int i = 0; i < agentGameScoresArray.Length; i++) { agentGameScoresArray[i] = new float[1]; } // Create Environment: CreateEnvironment(); // Create Agents: for (int i = 0; i < currentAgentsArray.Length; i++) { // Create Agent Base Body: GameObject agentGO = Instantiate(Resources.Load(AgentBodyGenomeTemplate.GetAgentBodyTypeURL(currentEvalTicket.agentGenomesList[i].bodyGenome.bodyType))) as GameObject; agentGO.transform.parent = gameObject.transform; //Debug.Log("null check: " + currentEvalTicket.environmentGenome.agentStartPositionsList.Count.ToString()); agentGO.transform.localPosition = currentEvalTicket.environmentGenome.agentStartPositionsList[i].agentStartPosition; agentGO.transform.localRotation = currentEvalTicket.environmentGenome.agentStartPositionsList[i].agentStartRotation; Agent agentScript = agentGO.GetComponent <Agent>(); agentScript.rootObject.GetComponent <Rigidbody>().centerOfMass = agentScript.rootCOM; agentScript.isVisible = visible; agentScript.InitializeAgentFromTemplate(currentEvalTicket.agentGenomesList[i]); currentAgentsArray[i] = agentScript; } // Create Challenge Instance: GameObject challengeGO = new GameObject("challenge" + challengeType.ToString()); switch (challengeType) { case Challenge.Type.Test: ChallengeTest challengeTest = challengeGO.AddComponent <ChallengeTest>(); currentChallenge = challengeTest; break; case Challenge.Type.Racing: ChallengeRacing challengeRacing = challengeGO.AddComponent <ChallengeRacing>(); currentChallenge = challengeRacing; break; case Challenge.Type.Combat: ChallengeCombat challengeCombat = challengeGO.AddComponent <ChallengeCombat>(); currentChallenge = challengeCombat; break; default: break; } challengeGO.transform.parent = gameObject.transform; challengeGO.transform.localPosition = new Vector3(0f, 0f, 0f); // !!! RETHINK ROLE OF CHALLENGE CLASS!!! currentChallenge.agent = currentAgentsArray[0]; // hacky to prevent error, hardcoded for Test challengeType currentChallenge.environment = currentEnvironment; //currentChallenge.HookUpModules(); // maybe do this through the modules themselves -- by passing relevant agent/environment info through function? /*if (isExhibition) { * if(currentEvalTicket.environmentGenome.useAtmosphere) { * Debug.Log("Wind: " + currentEvalTicket.environmentGenome.atmosphereGenome.windForce.ToString()); * } * }*/ HookUpModules(); //SetInvisibleTraverse(gameObject); if (visible) { currentEnvironment.AddRenderableContent(currentEvalTicket.environmentGenome); SetVisibleTraverse(gameObject); //Debug.Log("IS VISIBLE" + gameObject.name); //currentEnvironment.AddRenderableContent(teamsConfig.environmentPopulation.environmentGenomeList[currentEvalTicket.genomeIndices[0]]); //SetVisibleTraverse(gameObject); } else { SetInvisibleTraverse(gameObject); } if (isExhibition) { } else { // Fitness Crap only if NON-exhibition!: FitnessManager fitnessManager; int genomeIndex; if (currentEvalTicket.focusPopIndex == 0) // environment { fitnessManager = teamsConfig.environmentPopulation.fitnessManager; genomeIndex = currentEvalTicket.environmentGenome.index; } else // a player { fitnessManager = teamsConfig.playersList[currentEvalTicket.focusPopIndex - 1].fitnessManager; genomeIndex = currentEvalTicket.agentGenomesList[currentEvalTicket.focusPopIndex - 1].index; } fitnessComponentEvaluationGroup = new FitnessComponentEvaluationGroup(); // Creates a copy inside this, and also a copy in the FitnessManager, but they share refs to the FitComps themselves: //Debug.Log("focusPop: " + currentEvalTicket.focusPopIndex.ToString() + ", index: " + genomeIndex.ToString()); fitnessComponentEvaluationGroup.CreateFitnessComponentEvaluationGroup(fitnessManager, genomeIndex); //Debug.Log("currentEvalTicket.focusPopIndex: " + currentEvalTicket.focusPopIndex.ToString() + ", index: " + currentEvalTicket.genomeIndices[currentEvalTicket.focusPopIndex].ToString()); HookUpFitnessComponents(); } }