Beispiel #1
0
        public Character(string name, int birthdate, Dynasty dynasty, int money, Game game, Gender gender)
        {
            Name = name;
            BirthDate = birthdate;
            Dynasty = dynasty;
            Money = money;
            WillPower = Game.MAX_WILLPOWER;
            Game = game;
            Gender = gender;
            KnownInformation = new List<InformationInstance>();
            traits = new Dictionary<string, Trait>();
            jobs = new Dictionary<string, Job>();
            prestigeModifiers = new HashSet<PrestigeModifier>();
            Children = new List<Character>();

            //TODO: have actual personality in the weights.
            //TODO: public and private weights should be different
            publicWeights = new Weights(this);
            privateWeights = new Weights(this);
        }
Beispiel #2
0
        public double Evaluate(Game game, EventContext context, Weights weights)
        {
            //TODO: Start with random index.
            // TODO: Should we be doing some average here instead of just stopping
            // at the first one that works?
            for (int i = 0; i < context.CurrentCharacter.Children.Count; ++i)
            {
                Character character = context.CurrentCharacter.Children[i];
                context.PushScope(character);
                if (requirements.Evaluate(context, game))
                {
                    double result = operation.Evaluate(game, context, weights);

                    //AnyChild stops after a single interation.
                    context.PopScope();
                    return result;
                }
                context.PopScope();
            }
            return 0.0;
        }
Beispiel #3
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     double result = 0.0;
     for (int i = 0; i < instructions.Length; ++i)
     {
         result += instructions[i].Evaluate(game, context, weights);
     }
     return result;
 }
Beispiel #4
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     double result = 0.0;
     for (int i = 0; i < outcomes.Length; ++i)
     {
         result += outcomes[i].Evaluate(game, context, weights) * chances[i];
     }
     return result;
 }
Beispiel #5
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     return weights.MeasurePrestige(context.CurrentCharacter, change);
 }
Beispiel #6
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     return weights.MeasureOpinion(context.CurrentCharacter, context.GetScopedObjectByName(character) as Character, game.GetOpinionModifier(identifier));
 }
Beispiel #7
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     Dictionary<string, object> computedParameters = new Dictionary<string, object>();
     foreach (var pair in parameters)
     {
         computedParameters.Add(pair.Key, context.GetScopedObjectByName(pair.Value));
     }
     EventContext newContext = new EventContext(context.CurrentCharacter, computedParameters);
     return game.GetEventById(eventid).Evaluate(game, newContext, weights);
 }
Beispiel #8
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     return weights.MeasureGold(context.CurrentCharacter, -gold);
 }
Beispiel #9
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     if (requirements.Evaluate(context, game))
     {
         return thenExecute.Evaluate(game, context, weights);
     }
     else
     {
         return elseExecute.Evaluate(game, context, weights);
     }
 }
Beispiel #10
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     return weights.MeasureJob(context.CurrentCharacter, game.GetJobById(jobId));
 }
Beispiel #11
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     double result = 0.0;
     foreach (var character in context.CurrentCharacter.CurrentRoom.GetCharacters(context.CurrentCharacter))
     {
         context.PushScope(character);
         if (requirements.Evaluate(context, game))
         {
             result += operation.Evaluate(game, context, weights);
         }
         context.PopScope();
     }
     return result;
 }
Beispiel #12
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     return weights.MeasureAllowEventSelection(context.CurrentCharacter);
 }
Beispiel #13
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     //The AI needs to understand that it'll get to go again.
     return 0.0;
 }
Beispiel #14
0
        public double Evaluate(Game game, EventContext context, Weights weights)
        {
            //Get the weights for the character that will be choosing the character.
            Weights charWeights = context.CurrentCharacter.GetWeights(weights.Perspective);

            Character[] availableCharacters = game.FilterCharacters(requirements, context).ToArray();
            bool[] allowed = new bool[availableCharacters.Length];
            if (context.CurrentCharacter is AICharacter)
            {
                //AICharacter will only select characters from his important character's list.
                var important = (context.CurrentCharacter as AICharacter).GetImportantCharacters().Select(pair => pair.Key).ToList();
                for (int i = 0; i < availableCharacters.Length; ++i)
                {
                    allowed[i] = important.Contains(availableCharacters[i]);
                }
            }
            else
            {
                //The player could select anything.  We don't know anything about his preferences.
                for (int i = 0; i < availableCharacters.Length; ++i)
                {
                    allowed[i] = true;
                }
            }

            //Figure out which ones we think he will choose.
            int[] bestIndices = AIHelper.GetBest(availableCharacters, allowed, charWeights, (character, localWeights) =>
            {
                //We are only considering things theoretically: Don't make any changes to the context
                //we are given.  We want a new local context for each character so variable changes for
                //one character don't influence the others.
                EventContext localContext = new EventContext(context);
                localContext.PushScope(character, scopeName);
                double directResult = operation.Evaluate(game, localContext, localWeights);
                //We need to take into account any prestige modifiers because we are throwing away
                //the local context now.
                return directResult + localWeights.MeasureAfter(localContext, game);
            });
            //Evaluate each of those character using our weights
            double result = 0.0;
            foreach(var bestIndex in bestIndices)
            {
                Character best = availableCharacters[bestIndex];
                //We are only considering things theoretically: Don't make any changes to the context
                //we are given.  We want a new local context for each character so variable changes for
                //one character don't influence the others.
                EventContext localContext = new EventContext(context);
                localContext.PushScope(best, scopeName);
                result += operation.Evaluate(game, localContext, weights);
                //We need to take into account any prestige modifiers because we are throwing away
                //the local context now.
                result += weights.MeasureAfter(localContext, game);
            }
            return result / bestIndices.Length;
        }
Beispiel #15
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     context.PushScope(context.GetScopedObjectByName(scopeName));
     double result = operation.Evaluate(game, context, weights);
     context.PopScope();
     return result;
 }
Beispiel #16
0
        public double Evaluate(Game game, EventContext context, Weights weights)
        {
            if (XmlHelper.IsSpecialName(varName))
                throw new InvalidOperationException("Cannot assign to special properties: " + varName);

            context.SetVariable(context.CurrentCharacter, varName, newValue.Calculate(context, game));
            return 0.0;
        }
Beispiel #17
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     return weights.MeasureObserveChance(context.CurrentCharacter, multiplier);
 }
Beispiel #18
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     // TODO: We need some way to be intelligent in ChooseInformationAbout for AI character before implementing this.
     return 0.0;
 }
Beispiel #19
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     return 0.0;
 }
Beispiel #20
0
 public double Evaluate(Game game, EventContext context, Weights weights)
 {
     Dictionary<string, object> computedParameters = new Dictionary<string, object>();
     foreach (var pair in parameters)
     {
         computedParameters.Add(pair.Key, context.GetScopedObjectByName(pair.Value));
     }
     InformationInstance info = new InformationInstance(game.GetInformationById(informationId), computedParameters, game.CurrentTime);
     return weights.MeasureObserveInformation(info, game, context.CurrentCharacter);
 }
Beispiel #21
0
        public double Evaluate(Game game, EventContext context, Weights weights)
        {
            double result = 0.0;

            //DirectExecute always happens if it is present.
            if (DirectExecute != null)
                result += DirectExecute.Evaluate(game, context, weights);

            EventOption[] options = GetAvailableOptions(context, game);
            if(options.Length == 1)
            {
                //This is an optimization.  We don't need to evaluate another character's perspective
                //if they only have a single option.

                //We are only considering things theoretically: Don't make any changes to the context
                //we are given.  We want a new local context for each option so variable changes for
                //one option don't influence the others.
                EventContext localContext = new EventContext(context);
                result += options[0].DirectExecute.Evaluate(game, localContext, weights);
                //We need to take into account any prestige modifiers because we are throwing away
                //the local context now.
                result += weights.MeasureAfter(localContext, game);
            }
            else if (options.Length > 0)
            {
                //Get the weights that will be used to decide the best option.
                Weights optionWeights = context.CurrentCharacter.GetWeights(weights.Perspective);

                //Evaluate each option from the perpsective of the character choosing.
                EventOption[] bestOptions = AIHelper.GetBest(options, optionWeights, (option, w) =>
                {
                    //We are only considering things theoretically: Don't make any changes to the context
                    //we are given.  We want a new local context for each option so variable changes for
                    //one option don't influence the others.
                    EventContext localContext = new EventContext(context);
                    double localResult = option.DirectExecute.Evaluate(game, localContext, w);
                    //We need to take into account any prestige modifiers because we are throwing away
                    //the local context now.
                    return localResult + w.MeasureAfter(localContext, game);
                });

                //The current character will choose one of the best (or so we think)
                //We need to evaluate the options from our perspective and average those values.
                foreach(var best in bestOptions)
                {
                    //We are only considering things theoretically: Don't make any changes to the context
                    //we are given.  We want a new local context for each option so variable changes for
                    //one option don't influence the others.
                    EventContext localContext = new EventContext(context);
                    result += best.DirectExecute.Evaluate(game, localContext, weights);
                    //We need to take into account any prestige modifiers because we are throwing away
                    //the local context now.
                    result += weights.MeasureAfter(localContext, game);
                }
                result /= bestOptions.Length;
            }
            return result;
        }