Пример #1
0
        public EventReaction EatFood(Food food)
        {
            Console.Write("Animal is eating {0} {1}... ", food.Type, food.Item);

            if (GetFoodReaction(food) == EventReaction.Dead)
            {
                if (InternalState.RemainingLifeTime.TotalSeconds/InternalState.RemainingLifeTimeLimit.TotalSeconds < 0.5)
                {
                    return EventReaction.Dead;
                }
                Console.Write("Food was refused");
            }

            int remainingLifeTime = (int) InternalState.RemainingLifeTime.TotalSeconds;

            InternalState.Change(FoodEvaluator.Evaluate(food));

            if (InternalState.RemainingLifeTime.TotalSeconds <= 0)
            {
                return EventReaction.Dead;
            }

            Console.Write("{0} to life",
                InternalState.RemainingLifeTime.TotalSeconds - remainingLifeTime);
            Console.WriteLine("\n\nAnimal's remaining life time: {0} sec.\n",
                InternalState.RemainingLifeTime.TotalSeconds);

            return EventReaction.Alive;
        }
Пример #2
0
 public StateDelta Evaluate(Food food)
 {
     int satiety = EvaluateSatiety(food);
     int happiness = EvaluateHappiness(food);
     int health = EvaluateHealth(food);
     return new StateDelta(happiness, health, satiety);
 }
Пример #3
0
 public int EvaluateSatiety(Food food)
 {
     switch (food.Type)
     {
         case FoodType.Valuable:
             return FoodReactions[food.Item].SatietyPlus*food.N*2 -
                    FoodReactions[food.Item].SatietyMinus*food.N;
         case FoodType.TastyButUseless:
             return FoodReactions[food.Item].SatietyPlus*food.N/2 - FoodReactions[food.Item].SatietyMinus*food.N;
         case FoodType.Neutral:
             return FoodReactions[food.Item].SatietyPlus*food.N - FoodReactions[food.Item].SatietyMinus*food.N;
         case FoodType.Harmful:
             return ((-1)*
                     Math.Abs(FoodReactions[food.Item].SatietyPlus*food.N/2 -
                              FoodReactions[food.Item].SatietyMinus*food.N*2));
         default:
             return 0;
     }
 }
Пример #4
0
 protected EventReaction GetFoodReaction(Food food)
 {
     if (food.Type == FoodType.Killing)
     {
         return EventReaction.Dead;
     }
     return EventReaction.Alive;
 }