コード例 #1
0
ファイル: Creature.cs プロジェクト: OCox1991/Genome
 /// <summary>
 /// Checks if a piece of food is of the type the creature prefers
 /// </summary>
 /// <param name="f">The piece of food to check</param>
 /// <returns>If the piece of food is of the type the creature prefer</returns>
 private bool foodIsPreferred(FoodSource f)
 {
     bool b = false;
     if (f.isPlant() && diet * 2 <= 1)
     {
         b = true;
     }
     else if (!f.isPlant() && diet * 2 >= 1) //Both use >= / <= since omnivores shouldn't really have any preference
     {
         b = true;
     }
     else
     {
         b = false;
     }
     return b;
 }
コード例 #2
0
ファイル: Creature.cs プロジェクト: OCox1991/Genome
 /// <summary>
 /// Eats a piece of food only if it is of the type the creature prefers
 /// </summary>
 /// <param name="f"></param>
 private void eatPreferred(FoodSource f)
 {
     if (foodIsPreferred(f))
     {
         eat(f);
     }
     else
     {
         randomAction();
     }
 }
コード例 #3
0
ファイル: Creature.cs プロジェクト: OCox1991/Genome
 /// <summary>
 /// A public way to access getNourishmentAmt, used in debugging and testing
 /// </summary>
 public int pubGetNourishmentAmt(FoodSource f)
 {
     return getNourishmentAmt(f);
 }
コード例 #4
0
ファイル: Creature.cs プロジェクト: OCox1991/Genome
 /// <summary>
 /// Eats a piece of food and adjusts stamina, energy and the food itself as needed
 /// </summary>
 /// <param name="f">The foodsource to eat from</param>
 public void eat(FoodSource f)
 {
     if (f == null)
     {
         randomAction();
     }
     else
     {
         if (isAdjacent(f))
         {
             if (stamina == maxStamina)
             {
                 f.beEaten();
                 energy += getNourishmentAmt(f);
                 float ts = (float)stamina; //convert to float here to avoid minimise rounding errors
                 ts /= (100 / 50); //div 50 could be settable by Simulation (100 / x) where x == %age of stamina to drain
                 stamina = (int)ts;
             }
             else
             {
                 //wait for stamina to increase
             }
         }
         else
         {
             moveTowards(f);
         }
     }
 }
コード例 #5
0
ファイル: Creature.cs プロジェクト: OCox1991/Genome
 /// <summary>
 /// Gets how nourishing a given FoodSource is, by applying the multiplication that will
 /// be applied to the food based on diet when it is eaten
 /// </summary>
 /// <param name="f">The foodsource to look</param>
 /// <returns>The energy the creature would get if it ate the foodsource</returns>
 private int getNourishmentAmt(FoodSource f)
 {
     double ret = 0;
     if (f.isPlant())
     {
         double inverseDiet = 1 - diet;
         ret = f.getFoodValue() * inverseDiet;
     }
     else
     {
         ret = f.getFoodValue() * diet;
     }
     return (int)ret;
 }