private void BruteForceInit() { // REFACTOR THIS!!!!!!!!!!!!!! //Debug.Log("BruteForceInit!" + currentTimeStep.ToString()); // Clear Everything: DeleteAllGameObjects(); currentTimeStep = 0; gameWonOrLost = false; // <-- 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++) { string assetURL = ""; if (i == 0) { assetURL = "PredatorPrey/PredatorPrefab"; } else { assetURL = "PredatorPrey/PreyPrefab"; } // Create Agent Base Body: //GameObject agentGO = Instantiate(Resources.Load(AgentBodyGenomeTemplate.GetAgentBodyTypeURL(currentEvalTicket.agentGenomesList[i].bodyGenome.bodyType))) as GameObject; //GameObject agentGO = new GameObject("Agent_" + currentEvalTicket.agentGenomesList[i].index.ToString()); //GameObject agentGO = GameObject.CreatePrimitive(PrimitiveType.Cube); GameObject agentGO = Instantiate(Resources.Load(assetURL)) as GameObject; agentGO.name = "Player[" + i.ToString() + "] Agent[" + currentEvalTicket.agentGenomesList[i].index.ToString() + "]"; agentGO.transform.parent = gameObject.transform; agentGO.transform.localPosition = currentEvalTicket.environmentGenome.agentStartPositionsList[i].agentStartPosition; agentGO.transform.localRotation = currentEvalTicket.environmentGenome.agentStartPositionsList[i].agentStartRotation; agentGO.GetComponent <CircleCollider2D>().enabled = false; Agent agentScript = agentGO.AddComponent <Agent>(); agentScript.isVisible = visible; agentScript.InitializeAgentFromTemplate(currentEvalTicket.agentGenomesList[i], currentEvalTicket.environmentGenome.agentStartPositionsList[i]); currentAgentsArray[i] = agentScript; } HookUpModules(); //SetInvisibleTraverse(gameObject); if (visible) { currentEnvironment.AddRenderableContent(currentEvalTicket.environmentGenome); 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: fitnessComponentEvaluationGroup.CreateFitnessComponentEvaluationGroup(fitnessManager, genomeIndex); //Debug.Log("currentEvalTicket.focusPopIndex: " + currentEvalTicket.focusPopIndex.ToString() + ", index: " + currentEvalTicket.genomeIndices[currentEvalTicket.focusPopIndex].ToString()); HookUpFitnessComponents(); } }
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(); } }