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 void Migrate(int playerId) { Tile migrationTarget = GetMigrationTarget(playerId); if (!HasNeighbour(migrationTarget) || migrationTarget == null) { throw new System.ArgumentException(string.Format("Destination {0} is not a neighbour for player {1}", migrationTarget, playerId)); } for (int pId = 0, l = playerPopulations.Count; pId < l; pId++) { if (pId != playerId) { continue; } PlayerPopulation sourcePop = GetPlayerPopulation(pId); PlayerPopulation targetPop = migrationTarget.GetPlayerPopulation(pId); int migration = (sourcePop.Size - targetPop.Size) / migrationFraction; if (migration > 0) { int realizedSample; var subPop = sourcePop.GetDataSample(migration, out realizedSample); sourcePop.RemoveMigrants(subPop); targetPop.AddMigrants(subPop); targetPop.SetSize(targetPop.Size); //Debug.Log("Migrated " + subPop.populationSize + " (" + migration + "/" + realizedSample + ") units for Player " + pId + " from " + name + " to " + migrationTarget.name); } } }
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 SetPopulationFromData(int playerId, PlayerPopulationData data) { PlayerPopulation pop = GetPlayerPopulation(playerId); pop.Clear(); pop.SetFrom(data); }
public void ClearEvents() { //loop through every event and unsubscribe the events if (LevelGeneration != null) { foreach (var eventDelegate in LevelGeneration.GetInvocationList()) { LevelGeneration -= (eventDelegate as EventHandler); } } if (LevelBaking != null) { foreach (var eventDelegate in LevelBaking.GetInvocationList()) { LevelBaking -= (eventDelegate as EventHandler); } } if (LevelPopulation != null) { foreach (var eventDelegate in LevelPopulation.GetInvocationList()) { LevelPopulation -= (eventDelegate as EventHandler); } } if (PlayerPopulation != null) { foreach (var eventDelegate in PlayerPopulation.GetInvocationList()) { PlayerPopulation -= (eventDelegate as EventHandler); } } if (PostPlayer != null) { foreach (var eventDelegate in PostPlayer.GetInvocationList()) { PostPlayer -= (eventDelegate as EventHandler); } } if (FinalizeObjectPools != null) { foreach (var eventDelegate in FinalizeObjectPools.GetInvocationList()) { FinalizeObjectPools -= (eventDelegate as EventHandler); } } if (FinalStep != null) { foreach (var eventDelegate in FinalStep.GetInvocationList()) { FinalStep -= (eventDelegate as EventHandler); } } }
public PlayerPopulationData GetSubSample(int playerId, int sample, out int realizedSample) { PlayerPopulation pop = GetPlayerPopulation(playerId); if (pop && pop.Size > 0) { return(pop.GetDataSample(sample, out realizedSample)); } realizedSample = 0; return(null); }
public static void ShowPop(PlayerPopulation pop) { var v = viewer; v.popSize.text = pop.Size.ToString(); v.aaNutr.text = pop.GetNutrientState(Nutrients.AA).ToString(); v.cNutr.text = pop.GetNutrientState(Nutrients.C).ToString(); v.nNutr.text = pop.GetNutrientState(Nutrients.N).ToString(); //v.waste.text = pop.GetWasteState().ToString(); v.damage.text = pop.GetDamageState().ToString(); v.energy.text = pop.GetEnergyState().ToString(); }
public void SetPopulationSizeAndEnergy(int playerId, int size, int energy) { PlayerPopulation pop = GetPlayerPopulation(playerId); if (pop == null) { pop = gameObject.AddComponent <PlayerPopulation>(); playerPopulations.Add(pop); } pop.SetSize(size); pop.SetEnergy(energy); }
public void EnactProcreation() { foreach (Tile tile in GetComponentsInChildren <Tile>()) { foreach (int playerId in tile.GetPlayerIndexBySize()) { if (tile.GetPlayerAction(playerId) == PlayerAction.Population || !Tile.allowProcreationAsAction) { PlayerPopulation pop = tile.GetPlayerPopulation(playerId); if (pop.activeAction == ActionMode.Procreation || !Tile.allowProcreationAsAction) { //Debug.Log("Procreate " + playerId + " on tile " + tile.name); pop.Procreate(); } } } } }
public void EnactMetabolism() { foreach (Tile tile in GetComponentsInChildren <Tile>()) { foreach (int playerId in tile.GetPlayerIndexBySize()) { if (tile.GetPlayerAction(playerId) == PlayerAction.Population) { PlayerPopulation pop = tile.GetPlayerPopulation(playerId); if (pop.activeAction == ActionMode.Metabolism) { Debug.Log("Metabolize " + playerId + " on tile " + tile.name); pop.Metabolize(); } } } } }
public PlayerPopulation GetPlayerPopulation(int playerId) { for (int i = 0, l = playerPopulations.Count; i < l; i++) { if (playerPopulations[i].playerId == playerId) { return(playerPopulations[i]); } } playerPopulations.AddRange( GetComponents <PlayerPopulation>() .Where(e => !playerPopulations.Contains(e))); PlayerPopulation pop = playerPopulations.FirstOrDefault(e => e.playerId == playerId); if (pop == null) { pop = gameObject.AddComponent <PlayerPopulation>(); pop.playerId = playerId; playerPopulations.Add(pop); } return(pop); }
public bool HasPopulation(int playerId) { PlayerPopulation pop = GetPlayerPopulation(playerId); return(pop ? pop.Size > 0 : false); }
public int GetPopulationSize(int playerId) { PlayerPopulation pop = GetPlayerPopulation(playerId); return(pop ? pop.Size : 0); }