public void Remove(PlayerPopulationData other) { populationSize = Mathf.Max(0, populationSize - other.populationSize); energy = Mathf.Max(0, energy - other.energy); waste = Mathf.Max(0, waste - other.waste); damage = Mathf.Max(0, damage - other.damage); }
public void SetFrom(PlayerPopulationData other) { data.damage = other.waste; data.populationSize = other.populationSize; data.waste = other.waste; data.energy = other.energy; }
public void SetPopulationFromData(int playerId, PlayerPopulationData data) { PlayerPopulation pop = GetPlayerPopulation(playerId); pop.Clear(); pop.SetFrom(data); }
public void Add(PlayerPopulationData other) { if (other == null) { return; } populationSize += other.populationSize; energy += other.energy; waste += other.waste; damage += other.damage; }
public PlayerPopulationData SubSample(int sample, out int realizedSample) { realizedSample = Mathf.Min(sample, populationSize); float fraction = sample / (float)populationSize; PlayerPopulationData sampleData = new PlayerPopulationData(); sampleData.populationSize = sample; sampleData.energy = Mathf.FloorToInt(fraction * energy); sampleData.waste = Mathf.FloorToInt(fraction * waste); sampleData.damage = Mathf.FloorToInt(fraction * damage); return(sampleData); }
public void InitiateBatch(int nPlayers) { int totalSize; int[] totalSizes = TotalPlayerPopulations(out totalSize, nPlayers); int[] samples = GetSampleSizes(totalSizes, totalSize); PlayerPopulationData[] pops = new PlayerPopulationData[samples.Length]; for (int i = 0; i < nPlayers; i++) { pops[i] = GetReplatePopulation(i, samples[i]); } RemovePopulations(); for (int i = 0; i < nPlayers; i++) { startTiles[i].SetPopulationFromData(i, pops[i]); } }
PlayerPopulationData GetReplatePopulation(int player, int sampleSize) { PlayerPopulationData pop = new PlayerPopulationData(); float perTile = sampleSize / 16f; int soFar = 0; Tile[] tiles = GetComponentsInChildren <Tile>(); while (soFar < sampleSize) { for (int i = 0; i < tiles.Length; i++) { int sample = Mathf.Min(Mathf.FloorToInt(perTile), sampleSize - soFar); int resultingSample; pop.Add(tiles[i].GetSubSample(player, sample, out resultingSample)); soFar += resultingSample; if (soFar >= sampleSize) { break; } } } return(pop); }
public void RemoveMigrants(PlayerPopulationData migrants) { data.Remove(migrants); }
public void AddMigrants(PlayerPopulationData migrants) { data.Add(migrants); }