public double EvaluateOnTold(Character perspectiveCharacter, Character evaluateCharacter, Game game) { //The perspectiveCharacter is the character performing the query. //The evaluateCharacter is the character whose opinion on the information we care about. EventContext observeContext = new EventContext(evaluateCharacter, parameters); return information.OnTold.Evaluate(game, observeContext, evaluateCharacter.GetWeights(perspectiveCharacter)); }
public BothButton(Character perspective, Character[] topButtons, bool[] topButtonEnables, string[] bottomButtons, bool[] bottomButtonEnables, Notificator notificator) { perspectiveCharacter = perspective; upperButtons = topButtons; upperButtonEnables = topButtonEnables; lowerButtons = bottomButtons; lowerButtonEnables = bottomButtonEnables; this.notificator = notificator; SelectedIndex = -1; }
public void EvaluatePrestigeModifiers(Character character, Game game) { foreach (var modifier in prestigeModifiers) { if (modifier.EvaluateRequirements(character, game)) { character.AddPrestigeModifier(modifier); character.PrestigeChange(modifier.DailyChange); } else { character.RemovePrestigeModifier(modifier); } } }
public DNA CreateChildDNA(Character character, DNA father, DNA mother, Game game) { int face = SelectRandomAllowed(faceImages, character, father.Face, mother.Face, game); int mouth = SelectRandomAllowed(mouthImages, character, father.Mouth, mother.Mouth, game); int nose = SelectRandomAllowed(noseImages, character, father.Nose, mother.Nose, game); int eyes = SelectRandomAllowed(eyeImages, character, father.Eyes, mother.Eyes, game); int eyebrows = SelectRandomAllowed(eyebrowImages, character, father.Eyebrows, mother.Eyebrows, game); int ears = SelectRandomAllowed(earImages, character, father.Ears, mother.Ears, game); int hair = SelectRandomAllowed(hairImages, character, father.Hair, mother.Hair, game); int skinColor = SelectRandomAllowedColor(skinColors, character, father.SkinColor, mother.SkinColor, game); int eyeColor = SelectRandomAllowedColor(eyeColors, character, father.EyeColor, mother.EyeColor, game); int hairColor = SelectRandomAllowedColor(hairColors, character, father.HairColor, mother.HairColor, game); int shirtColor = CharacterVisualizationManager.GetRandomShirtColor(game); return new DNA(face, mouth, nose, eyes, eyebrows, ears, hair, skinColor, eyebrows, hairColor, shirtColor); }
public JournalForm(Character[] characters, Game game, Character fixedPerspective) { InitializeComponent(); this.game = game; this.characters = characters; this.fixedPerspective = fixedPerspective; knownCharacters.Items.AddRange(characters); knownCharacters.SelectedIndex = 0; if(fixedPerspective != null) { debugPerspectiveBox.Visible = false; } else { debugPerspectiveBox.Items.AddRange(characters); debugPerspectiveBox.SelectedIndex = 0; } }
public void AssignInitialTraits(Game game, Character character, int maxInitialTraits) { ISet<string> banned = new HashSet<string>(); for (int i = 0; i < maxInitialTraits; ++i) { Trait nextTrait = traits.Values.ElementAt(game.GetRandom(traits.Values.Count)); if (banned.Contains(nextTrait.Identifier)) { continue; } foreach (var opposite in nextTrait.Opposites) { banned.Add(opposite); } banned.Add(nextTrait.Identifier); character.AddTrait(nextTrait); } }
private void UpdateCharacterInformation(Character character) { Character perspectiveChar = fixedPerspective == null ? debugPerspectiveBox.SelectedItem as Character : fixedPerspective; if (perspectiveChar == null || character == null) return; headshot.TargetCharacter = character; headshot.PerspectiveCharacter = perspectiveChar; goldLabel.Text = character.Money.ToString(); ageLabel.Text = character.Age.ToString(); willpowerLabel.Text = character.WillPower.ToString(); StringBuilder infoBuilder = new StringBuilder(); foreach (InformationInstance info in perspectiveChar.GetInformationAbout(character)) { infoBuilder.AppendLine(info.Description); } informationLabel.Text = infoBuilder.ToString(); traitLabel.Text = string.Join(", ", character.Traits.Select(t => t.Label)); StringBuilder opModBuilder = new StringBuilder(); opModBuilder.AppendLine("Prestige Modifiers:"); foreach (PrestigeModifier mod in character.CurrentPrestigeModifiers) { opModBuilder.AppendLine(string.Format("{0} {1}", mod.DailyChange, mod.Description)); } opModBuilder.AppendLine("Opinion Modifiers:"); foreach (OpinionModifierInstance mod in perspectiveChar.GetOpinionModifiersAbout(character)) { opModBuilder.AppendLine(string.Format("{0} {1}", mod.GetChange(game.CurrentDay), mod.Description)); } foreach (String variable in character.GetVariableNames()) { opModBuilder.AppendLine(string.Format("{0} = {1}", variable, character.GetVariable(variable))); } debugStatsBox.Text = opModBuilder.ToString(); }
private double EvaluateChangedModifiers(Character character, EventContext context, Game game) { context.PushScope(character); List<PrestigeModifier> addedModifiers = new List<PrestigeModifier>(); List<PrestigeModifier> removedModifiers = new List<PrestigeModifier>(); game.GetChangedModifiers(context, addedModifiers, removedModifiers); double result = 0.0; if (addedModifiers.Count > 0 || removedModifiers.Count > 0) { foreach (var added in addedModifiers) { result += added.DailyChange; } foreach (var removed in removedModifiers) { result -= removed.DailyChange; } } context.PopScope(); return result * 100.0 * 10.0; }
public double MeasurePrestige(Character currentCharacter, int change) { if (Perspective == currentCharacter) return change * 100.0; else return 0.0; }
public bool HasInformationAbout(Character about, InformationType type) { Weights weights = GetWeights(this); foreach(var info in KnownInformation) { if (info.IsAbout(about)) { double result = info.EvaluateOnTold(this, about, Game); if (type == InformationType.Positive && result > 0.0) return true; else if (type == InformationType.Negative && result < 0.0) return true; else if (type == InformationType.Neutral && result == 0.0) return true; } } return false; }
public int GetOpinionOf(Character character) { int opinion = 0; foreach (var trait in traits.Values) { if (character.traits.ContainsKey(trait.Identifier)) { opinion += trait.SameOpinion; } foreach (var oppositeId in trait.Opposites) { if (character.traits.ContainsKey(oppositeId)) { opinion += trait.OppositeOpinion; } } } ISet<OpinionModifierInstance> mods = null; if(opinionModifiers.TryGetValue(character, out mods)) { foreach(var mod in mods) { opinion += mod.GetChange(Game.CurrentDay); } } return opinion; }
public IEnumerable<InformationInstance> GetInformationAbout(Character character) { if(character == this) { foreach(var info in history) { yield return info; } } else { foreach (var info in KnownInformation) { if (info.IsAbout(character)) yield return info; } } }
public Character ChooseCharacter(Character[] characters, IExecute operation, EventContext context, string chosenName) { int index = OnChooseCharacter(characters, operation, context, chosenName); return characters[index]; }
public void AssignFamily(Character spouse, List<Character> children, Room home, DNA husbandDna, DNA wifeDna) { DNA = husbandDna; Home = home; Spouse = spouse; spouse.Spouse = this; spouse.DNA = wifeDna; Children = new List<Character>(children); spouse.Children = new List<Character>(children); CharacterLog("Created family for " + Name + " with spouse: " + spouse.Name + " and children: " + string.Join(", ", children.Select(c => c.Name + "(" + c.Gender.ToString() + ")"))); //Assign the home to the dependents as well. spouse.Home = home; foreach(var c in children) { c.Home = home; c.Father = this; c.Mother = spouse; c.DNA = Game.CreateChildDNA(c, husbandDna, wifeDna); } }
public Weights(Character perspective) { Perspective = perspective; }
public DNA CreateRandomDNA(Character character, Game game) { DNA dna = new DNA(SelectRandomAllowed(faceImages, character, game), SelectRandomAllowed(mouthImages, character, game), SelectRandomAllowed(noseImages, character, game), SelectRandomAllowed(eyeImages, character, game), SelectRandomAllowed(eyebrowImages, character, game), SelectRandomAllowed(earImages, character, game), SelectRandomAllowed(hairImages, character, game), game.GetRandom(skinColors.Length), game.GetRandom(eyeColors.Length), game.GetRandom(hairColors.Length), game.GetRandom(shirtColors.Length)); return dna; }
private int SelectRandomAllowed(List<PortraitRule> rules, Character character, int father, int mother, Game game) { EventContext context = new EventContext(character); List<PortraitRule> allowed = new List<PortraitRule>(); if(rules[father].Requirements.Evaluate(context, game)) { for (int i = 0; i < 45; ++i) { allowed.Add(rules[father]); } } if (rules[mother].Requirements.Evaluate(context, game)) { for (int i = 0; i < 45; ++i) { allowed.Add(rules[mother]); } } allowed.AddRange(rules.Where(r => r.Requirements.Evaluate(context, game))); return allowed[game.GetRandom(allowed.Count)].Index; }
private int SelectRandomAllowedColor(Color[] rules, Character character, int father, int mother, Game game) { return game.GetRandom(2) == 0 ? father : mother; }
// Returns true if the perspective is the current character. // This allows us to average other people's decisions and be smart // about what our own will be. public bool IsMyDecision(Character currentCharacter) { return Perspective == currentCharacter; }
public double MeasureAllowEventSelection(Character currentCharacter) { if (Perspective == currentCharacter) return 0.0; // Nobody cares about getting their turn back. else return 0.0; }
public void AssignParents(Character mother, Character father) { DNA = Game.CreateChildDNA(this, father.DNA, mother.DNA); Home = mother.Home; CurrentRoom = mother.Home; Mother = mother; Father = father; mother.Children.Add(this); father.Children.Add(this); }
public double MeasureGold(Character currentCharacter, int gold) { if (Perspective == currentCharacter) return gold * 1.0; else return 0.0; }
public InformationInstance ChooseInformationAbout(InformationType type, Character about) { InformationInstance[] information; if (type == InformationType.Positive) information = KnownInformation.Where(info => info.EvaluateOnTold(this, about, Game) > 0.0).ToArray(); else if (type == InformationType.Negative) information = KnownInformation.Where(info => info.EvaluateOnTold(this, about, Game) < 0.0).ToArray(); else information = KnownInformation.ToArray(); int index = OnChooseInformation(information); return information[index]; }
public double MeasureJob(Character currentCharacter, Job job) { if (Perspective == currentCharacter) return 1000.0; //Jobs are great. Really we should measure prestige modifiers since jobs can give you one. else return 0.0; }
public IEnumerable<OpinionModifierInstance> GetOpinionModifiersAbout(Character character) { ISet<OpinionModifierInstance> list; if (opinionModifiers.TryGetValue(character, out list)) { return list; } return Enumerable.Empty<OpinionModifierInstance>(); }
public double MeasureObserveChance(Character currentCharacter, double multiplier) { // Not caring about these right now because figuring out good weights is difficult // and having bad weights really messes with the AI (ie. Steward thinking Eavesdrop is // always better than getting taxes). return 0.0; }
public Weights GetWeights(Character perspective) { if (perspective == this) return privateWeights; return publicWeights; }
public double MeasureObserveInformation(InformationInstance info, Game game, Character observingCharacter) { // 1. Is info about the perspective character // then we like it as much as we like whatever the OnObserve of that information does. if (info.IsAbout(Perspective)) { return info.EvaluateOnObserve(Perspective, Perspective, game); } else if (observingCharacter == Perspective) { return 100.0; // It's good to know things about people. } else { return 0.0; // Don't care about other people learning random information } }
public virtual int OnChooseCharacter(Character[] characters, IExecute operation, EventContext context, string chosenName) { throw new NotImplementedException(); }
public double MeasureOpinion(Character charWithOpinion, Character opinionOf, OpinionModifier mod) { if (Perspective == opinionOf) return mod.Change * 1.0; else return 0.0; }