protected void GetAllowedEnergyAndPleasantness(ref Pleasantness p, ref EnergyLevel e, bool isFinalEvent) { if (isFinalEvent) { //Final event has opposite energy of the one before it if (fromPriorRound.TheTone.IsHighEnergy()) { e = EnergyLevel.AlwaysLowEnergy; } else { e = EnergyLevel.AlwaysHighEnergy; } } else if (consecutive_HighEnergy >= MAX_CONSECUTIVE_HIGH_ENERGY) { e = EnergyLevel.AlwaysLowEnergy; } else if (consecutive_LowEnergy >= MAX_CONSECUTIVE_LOW_ENERGY) { e = EnergyLevel.AlwaysHighEnergy; } if (consecutive_Pleasant >= MAX_CONSECUTIVE_PLEASANT) { p = Pleasantness.NeverPleasant; } else if (consecutive_Unpleasant >= MAX_CONSECUTIVE_UNPLEASANT) { p = Pleasantness.AlwaysPleasant; } //Future: // Toggle to allow hook for follow-up story. If true, // allow high energy unpleasant as final event. If false, // 50% chance to have happy ending vs 50% chance to cut final event short and have tragedy }
protected IIncident GetNextEvent(Random rng, bool isJustBeforeEnding, bool isFinalEvent) { var chosenCollection = this.possibleIncidents.ChooseRandomCollection(rng); Pleasantness allowedPleasantness = Pleasantness.EitherPleasantOrNot; EnergyLevel allowedEnergy = EnergyLevel.EitherLowOrHigh; GetAllowedEnergyAndPleasantness(ref allowedPleasantness, ref allowedEnergy, isFinalEvent); Frequency minFrequency = GetMinFrequency(isJustBeforeEnding); var chosenIncident = chosenCollection.GetRandomIncident(rng, allowedPleasantness, allowedEnergy, minFrequency); var popluatedSucessfully = chosenIncident?.TryToPopulateIncident(this.currentCast, rng) ?? false; if (popluatedSucessfully == false) { return(null); } else { UpdatePatternTracking(chosenIncident); return(chosenIncident); } }
public SetEnergyEffect(EnergyLevel energyLevel, EffectType type) { Name = $"SetEnergy({energyLevel})"; Type = type; EnergyLevel = energyLevel; }
public void EvaluateTraits(CreatureManager hManager, string speciesName) { List <Gene> genes = new List <Gene>(); if (!GlobalGEPSettings.RANDOMIZED_TRAITS || traitIndices.Count == 0) { traitIndices = GlobalGEPSettings.speciesTraitLayouts[speciesName]; } foreach (KeyValuePair <string, int[][]> thisTrait in traitIndices) { string key = thisTrait.Key; //For every chromosome a trait is linked to... //i = chromosome index (when a trait is on multiple chromosomes) for (int i = 0; i < thisTrait.Value.Length; i++) { //Index [i][0] will ALWAYS be the chromosome index int chromosomeIndex = thisTrait.Value[i][0]; //For every gene this trait is linked to (on this chromosome)... //j = gene index for this chromosome for (int j = 1; j < thisTrait.Value[i].Length; j++) { //Get the gene index int geneIndex = thisTrait.Value[i][j]; //Add the gene at the chromosomeIndex and geneIndex to a list to be evaluated //Accesses the genome rather than making a copy ensuring the genes accessed later on match exactly the current genome genes.Add(genome[chromosomeIndex].genes[geneIndex]); } } List <Trait> thisTraitList = AccessTraits(genes); //For each trait (keyValuePair) evaluate the genes //Could put the results into a dictionary - this way would be more polymorphic as would search for (or add) a row for each trait and search by name // instead of individual variables, or an array which requires the developer to remember which index is which switch (key.ToLower()) { case "eye left colour": eyeColours[0] = new GeneColour(thisTraitList); if (eyeColours[1] == null && eyeStyle != null) { if (eyeStyle.eyeMatching) { eyeColours[1] = eyeColours[0]; UnityEngine.Debug.Log("Eye Matching, Assigned 1 = 0"); } } break; case "eye right colour": eyeColours[1] = new GeneColour(thisTraitList); if (eyeColours[0] == null && eyeStyle != null) { if (eyeStyle.eyeMatching) { eyeColours[0] = eyeColours[1]; UnityEngine.Debug.Log("Eye Matching, Assigned 0 = 1"); } } break; case "eye style": eyeStyle = new EyeStyle(thisTraitList); if (eyeStyle.eyeMatching) { if (eyeColours[0] != null) { eyeColours[1] = eyeColours[0]; } else if (eyeColours[1] != null) { eyeColours[0] = eyeColours[1]; } else { UnityEngine.Debug.Log("Error: Both eye colours are currently NULL"); } } break; case "hair colour": hairColour = new GeneColour(thisTraitList); break; case "skin colour": skinColour = new GeneColour(thisTraitList); break; case "growth rate": growthRate = new GrowthRate(thisTraitList); break; case "life expectancy": lifeExpectancy = new LifeExpectancy(thisTraitList); break; case "reproductive age": reproductiveAge = new ReproductiveAge(thisTraitList); break; case "gestation period": gestationPeriod = new GestationPeriod(thisTraitList); break; case "energy level": energyLevel = new EnergyLevel(thisTraitList); break; case "energy consumption": energyConsumption = new EnergyConsumption(thisTraitList); break; case "food level": foodLevel = new FoodLevel(thisTraitList); break; case "food consumption": foodConsumption = new FoodConsumption(thisTraitList); break; case "water level": waterLevel = new WaterLevel(thisTraitList); break; case "water consumption": waterConsumption = new WaterConsumption(thisTraitList); break; case "strength": case "intellect": case "constitution": case "wisdom": case "charisma": case "vanity": attributesList.Add(new AttributeTrait(thisTraitList)); break; } genes.Clear(); } }
public void Initialize() { _sampleEnergyLevel1 = EnergyLevelGenerator.GenerateEnergyLevel1(); _sampleEnergyLevel2 = EnergyLevelGenerator.GenerateEnergyLevel2(); _manyEnergyLevels = EnergyLevelGenerator.GenerateManyEnergyLevels(); }
// Start is called before the first frame update void Awake() { anim = GetComponent <Animator>(); currentEnergyLevel = EnergyLevel.Poor; energyAmount = 0; }
private static Bundle GetBestMallBundle(BlueprintUtilityBuilding building, GameLayer layer) { var state = layer.GetState(); Position pos = GetBestUtilityPosition(layer, building); if (pos == null) { return(null); } int turnsLeft = state.MaxTurns - state.Turn - 8; if (state.UtilityBuildings.Any(t => t.BuildingName == "Mall")) { return(null); } var arr = Helper.GetUtilitiyGrid(state); int popAffected = 0; int popOne = 0; int avalibleSpace = 0; int avSpaceOne = 0; for (int k = -3; k < 4; k++) { for (int c = -3; c < 4; c++) { int i = pos.x; int j = pos.y; if (Math.Abs(k) + Math.Abs(c) > 3 || !Helper.InGrid(i + k, j + c, state) || state.Map[i + k][j + c] == 1 || (k == 0 && c == 0)) { continue; } if (state.ResidenceBuildings.Any(x => x.Position.x == i + k && x.Position.y == j + c && !x.Effects.Any(t => t.StartsWith(building.BuildingName)))) { popAffected += layer.GetResidenceBlueprint(state.ResidenceBuildings.Find(x => x.Position.x == i + k && x.Position.y == j + c).BuildingName).MaxPop; if ((Math.Abs(k) + Math.Abs(c) == 1)) { popOne += layer.GetResidenceBlueprint(state.ResidenceBuildings.Find(x => x.Position.x == i + k && x.Position.y == j + c).BuildingName).MaxPop; } } else if (!state.ResidenceBuildings.Any(x => x.Position.x == i + k && x.Position.y == j + c) && !state.UtilityBuildings.Any(x => x.Position.x == i + k && x.Position.y == j + c) && (arr[i + k, j + c] & Helper.UtilityToInt[building.BuildingName]) != Helper.UtilityToInt[building.BuildingName]) { avalibleSpace++; if ((Math.Abs(k) + Math.Abs(c) == 1)) { avSpaceOne++; } } else if (state.UtilityBuildings.Any(x => x.Position.x == i + k && x.Position.y == j + c)) { avalibleSpace--; } } } EnergyLevel el = Helper.GetEnergyLevel(layer, Helper.GetEnergyConsumation(layer)); EnergyLevel elAfter = Helper.GetEnergyLevel(layer, Helper.GetEnergyConsumation(layer) + 8 - (state.UtilityBuildings.Any(t => t.BuildingName == "WindTurbine" && Math.Abs(pos.x - t.Position.x) + Math.Abs(pos.y - t.Position.y) <= 2) ? 3.4 : 0)); double potentialScore = -200 - (popAffected - popOne) * 0.009 / 2 * turnsLeft - (Math.Max(0, (avalibleSpace - avSpaceOne)) * 15.0 / 10.0) * 0.009 / 2 * turnsLeft + 0.12 * (popAffected + avalibleSpace * 25.0 / 3.0) * turnsLeft / 10; //potentialScore -= 25 * Constants.AVG_POP_HAPPINESS * turnsLeft / 20.0; if (!state.UtilityBuildings.Any(t => t.BuildingName == building.BuildingName)) { potentialScore += 15 * 0.15 * turnsLeft / 2; } if (el.CostPerMwh != elAfter.CostPerMwh) { potentialScore -= (elAfter.TonCo2PerMwh - el.TonCo2PerMwh) * Helper.GetEnergyConsumation(layer) * turnsLeft; } potentialScore -= turnsLeft * elAfter.TonCo2PerMwh * (8 - (state.UtilityBuildings.Any(t => t.BuildingName == "WindTurbine" && Math.Abs(pos.x - t.Position.x) + Math.Abs(pos.y - t.Position.y) <= 2) ? 3.4 : 0)); if (Helper.GetPossibleMorePop(layer, 1) + Helper.GetCurrentMaxPop(layer) < Constants.TARGET_END_POP_COUNT) { return(null); } Bundle bundle = new Bundle { UpfrontCost = building.Cost, TotalIncome = Math.Pow(0.5, state.UtilityBuildings.Where(t => t.BuildingName == building.BuildingName).Count()) * 240 * turnsLeft, ExtraCost = elAfter.CostPerMwh * (8 - (state.UtilityBuildings.Any(t => t.BuildingName == "WindTurbine" && Math.Abs(pos.x - t.Position.x) + Math.Abs(pos.y - t.Position.y) <= 2) ? 3.4 : 0)) * turnsLeft, Turn = new PlaceUtilityTurn(pos.x, pos.y, building, layer.GetState().GameId), PotentialScore = potentialScore, EnergyNeed = 8 - (state.UtilityBuildings.Any(t => t.BuildingName == "WindTurbine" && Math.Abs(pos.x - t.Position.x) + Math.Abs(pos.y - t.Position.y) <= 2) ? 3.4 : 0) }; return(bundle); }
private static Bundle GetBestWindTurbineBundle(BlueprintUtilityBuilding building, GameLayer layer) { var state = layer.GetState(); Position pos = GetBestUtilityPosition(layer, building); if (pos == null) { return(null); } int turnsLeft = state.MaxTurns - state.Turn - 5; double energySaved = 0; int avalibleSpace = 0; for (int k = -2; k < 3; k++) { for (int c = -2; c < 3; c++) { int i = pos.x; int j = pos.y; if (Math.Abs(k) + Math.Abs(c) > 2 || !Helper.InGrid(i + k, j + c, state) || state.Map[i + k][j + c] == 1 || (k == 0 && c == 0)) { continue; } if (state.ResidenceBuildings.Any(x => x.Position.x == i + k && x.Position.y == j + c && !x.Effects.Contains(building.BuildingName))) { BuiltBuilding b = state.ResidenceBuildings.First(x => x.Position.x == i + k && x.Position.y == j + c); energySaved += Math.Min(3.4, Math.Max(b.EffectiveEnergyIn - (b.Effects.Contains("SolarPanel") ? 3.4 : 0), 0)); } if (state.UtilityBuildings.Any(x => x.Position.x == i + k && x.Position.y == j + c && x.BuildingName != "WindTurbine" && !x.Effects.Contains(building.BuildingName))) { BuiltBuilding b = state.UtilityBuildings.First(x => x.Position.x == i + k && x.Position.y == j + c); energySaved += Math.Min(3.4, Math.Max(b.EffectiveEnergyIn - (b.Effects.Contains("SolarPanel") ? 3.4 : 0), 0)); } else if (!state.ResidenceBuildings.Any(x => x.Position.x == i + k && x.Position.y == j + c) && !state.UtilityBuildings.Any(x => x.Position.x == i + k && x.Position.y == j + c)) { avalibleSpace++; } else if (state.UtilityBuildings.Any(x => x.Position.x == i + k && x.Position.y == j + c)) { avalibleSpace--; } } } EnergyLevel el = Helper.GetEnergyLevel(layer, Helper.GetEnergyConsumation(layer)); EnergyLevel elAfter = Helper.GetEnergyLevel(layer, Helper.GetEnergyConsumation(layer) - energySaved); double potentialScore = -25; potentialScore -= 25 * Constants.AVG_POP_HAPPINESS * turnsLeft / 20.0; if (!state.UtilityBuildings.Any(t => t.BuildingName == building.BuildingName)) { potentialScore += 15 * 0.15 * turnsLeft / 2; } potentialScore += el.TonCo2PerMwh * Helper.GetEnergyConsumation(layer) * turnsLeft - (elAfter.TonCo2PerMwh * (Helper.GetEnergyConsumation(layer) - energySaved)) * turnsLeft; if (Helper.GetPossibleMorePop(layer, 1) + Helper.GetCurrentMaxPop(layer) < Constants.TARGET_END_POP_COUNT) { return(null); } Bundle bundle = new Bundle { UpfrontCost = building.Cost, TotalIncome = turnsLeft * elAfter.CostPerMwh * energySaved,//saved on electicity ExtraCost = 0, Turn = new PlaceUtilityTurn(pos.x, pos.y, building, layer.GetState().GameId), PotentialScore = potentialScore, EnergyNeed = -energySaved }; return(bundle); }
private static Bundle GetBestParkBundle(BlueprintUtilityBuilding building, GameLayer layer) { var state = layer.GetState(); Position pos = GetBestUtilityPosition(layer, building); if (pos == null) { return(null); } int turnsLeft = state.MaxTurns - state.Turn - 5; var arr = Helper.GetUtilitiyGrid(layer.GetState()); int popAffected = 0; int avalibleSpace = 0; for (int k = -3; k < 4; k++) { for (int c = -3; c < 4; c++) { int i = pos.x; int j = pos.y; if (Math.Abs(k) + Math.Abs(c) > 2 || !Helper.InGrid(i + k, j + c, state) || state.Map[i + k][j + c] == 1 || (k == 0 && j == 0)) { continue; } if (state.ResidenceBuildings.Any(x => x.Position.x == i + k && x.Position.y == j + c && !x.Effects.Contains(building.BuildingName))) { popAffected += layer.GetResidenceBlueprint(state.ResidenceBuildings.First(x => x.Position.x == i + k && x.Position.y == j + c).BuildingName).MaxPop; } else if (!state.ResidenceBuildings.Any(x => x.Position.x == i + k && x.Position.y == j + c) && !state.UtilityBuildings.Any(x => x.Position.x == i + k && x.Position.y == j + c) && (arr[i + k, j + c] & Helper.UtilityToInt[building.BuildingName]) != Helper.UtilityToInt[building.BuildingName]) { avalibleSpace++; } else if (state.UtilityBuildings.Any(x => x.Position.x == i + k && x.Position.y == j + c)) { avalibleSpace--; } } } EnergyLevel el = Helper.GetEnergyLevel(layer); EnergyLevel elAfter = Helper.GetEnergyLevel(layer, Helper.GetEnergyConsumation(layer) + Math.Max(0, 2.4 - (state.UtilityBuildings.Any(t => t.BuildingName == "WindTurbine" && Math.Abs(pos.x - t.Position.x) + Math.Abs(pos.y - t.Position.y) <= 2) ? 2.4 : 0))); double potentialScore = -10 + (popAffected + avalibleSpace * 30.0 / 6.0) * 0.007 * turnsLeft + 0.11 * (popAffected + avalibleSpace * 30.0 / 6.0) * turnsLeft / 10; if (!state.UtilityBuildings.Any(t => t.BuildingName == building.BuildingName)) { potentialScore += 15 * 0.15 * turnsLeft / 2; } else { potentialScore -= 20 * Constants.AVG_POP_HAPPINESS * turnsLeft / 20.0; } if (el.CostPerMwh != elAfter.CostPerMwh) { potentialScore -= (elAfter.TonCo2PerMwh - el.TonCo2PerMwh) * Helper.GetEnergyConsumation(layer); } potentialScore -= turnsLeft * elAfter.TonCo2PerMwh * Math.Max(0, 2.4 - (state.UtilityBuildings.Any(t => t.BuildingName == "WindTurbine" && Math.Abs(pos.x - t.Position.x) + Math.Abs(pos.y - t.Position.y) <= 2) ? 2.4 : 0)); if (Helper.GetPossibleMorePop(layer, 1) + Helper.GetCurrentMaxPop(layer) < Constants.TARGET_END_POP_COUNT) { return(null); } Bundle bundle = new Bundle { UpfrontCost = building.Cost, TotalIncome = 0, ExtraCost = el.CostPerMwh * (2.4 - (state.UtilityBuildings.Any(t => t.BuildingName == "WindTurbine" && Math.Abs(pos.x - t.Position.x) + Math.Abs(pos.y - t.Position.y) <= 2) ? 2.4 : 0)) * turnsLeft, Turn = new PlaceUtilityTurn(pos.x, pos.y, building, layer.GetState().GameId), PotentialScore = potentialScore, EnergyNeed = Math.Max(0, 2.4 - (state.UtilityBuildings.Any(t => t.BuildingName == "WindTurbine" && Math.Abs(pos.x - t.Position.x) + Math.Abs(pos.y - t.Position.y) <= 2) ? 2.4 : 0)) }; return(bundle); }
public AIDomainBuilder HasEnergy(EnergyLevel value) { return(HasState(AIWorldState.Energy, (byte)value)); }
public void SetState(AIWorldState state, EnergyLevel value, EffectType type) { SetState(state, (byte)value, type); }
public static KeyValuePair <byte, byte> CreateEnergyGoal(EnergyLevel energyLevel) { return(CreateGoal(AIWorldState.Energy, (byte)energyLevel)); }
public EnergyLevel CreateEnergyLevel(EnergyLevel l) { db.EnergyLevels.Add(l); return(l); }