コード例 #1
0
ファイル: Lifeform.cs プロジェクト: azcion/ComplexLifeforms
 /// <summary>
 /// Constructor for making a new child based on two parents.
 /// </summary>
 private Lifeform(World world, Species species, MoodManager mood, int parentIdA, int parentIdB)
     : this(world, species)
 {
     ParentIdA = parentIdA;
     ParentIdB = parentIdB;
     MM        = mood;
 }
コード例 #2
0
ファイル: Lifeform.cs プロジェクト: azcion/ComplexLifeforms
        public override string ToString()
        {
            char   s    = Separator;
            string data = $"{Species,-7}{s}{_age,5}{s}{_hp,5}{s}{_energy,5}{s}{_food,5}{s}{_water,5}";

            if (!Extended)
            {
                return(data);
            }

            if (TruncateTo == 0)
            {
                data += $"{s}{MM.Urge,-9}{s}{MoodManager.EmotionName(MM),-12}{s}{MM.Mood,-8}"
                        + $"{s}{_deathBy,-13}{s}{(MM.Asleep ? "yes" : "no"),-6}";
            }
            else
            {
                object[] elements =
                {
                    MM.Urge, MoodManager.EmotionName(MM), MM.Mood, _deathBy, MM.Asleep ? "yes" : "no"
                };

                foreach (object element in elements)
                {
                    data += s + Truncate(element.ToString(), TruncateTo, 1);
                }
            }

            return(data);
        }
コード例 #3
0
ファイル: Lifeform.cs プロジェクト: azcion/ComplexLifeforms
        public object[] ToObjectArray()
        {
            if (!Extended)
            {
                return(new object[] { Species, _age, _hp, _energy, _food, _water });
            }

            return(new object[] {
                Species, _age, _hp, _energy, _food, _water,
                MM.Urge, MoodManager.EmotionName(MM), MM.Mood, _deathBy, MM.Asleep ? "Yes" : "No"
            });
        }
コード例 #4
0
ファイル: Lifeform.cs プロジェクト: azcion/ComplexLifeforms
        public Lifeform(World world, Species species)
        {
            Id        = _id++;
            ParentIdA = -1;
            ParentIdB = -1;
            Species   = species;
            Log       = Logging ? new HashSet <string>() : null;
            World     = world;
            MM        = new MoodManager(this);

            Init     = SpeciesContainer.INIT[species];
            _alive   = true;
            _deathBy = DeathBy.None;

            _hp     = Init.Hp;
            _energy = Init.Energy;
            _food   = Init.Food;
            _water  = Init.Water;
        }
コード例 #5
0
ファイル: Lifeform.cs プロジェクト: azcion/ComplexLifeforms
        public static Lifeform Breed(Lifeform parentA, Lifeform parentB)
        {
            if (!IsQualified(parentA) || !IsQualified(parentB))
            {
                return(null);
            }

            int[] dna = MixDNA();

            Tier[] urgeBias    = new Tier[URGE_COUNT];
            Tier[] emotionBias = new Tier[EMOTION_COUNT];

            for (int i = 0; i < URGE_COUNT; ++i)
            {
                Lifeform parent = dna[i] == 0 ? parentA : parentB;
                urgeBias[i] = parent.MM.UrgeBias[i];
            }

            for (int i = 0; i < EMOTION_COUNT; ++i)
            {
                Lifeform parent = dna[i + URGE_COUNT] == 0 ? parentA : parentB;
                emotionBias[i] = parent.MM.EmotionBias[i];
            }

            MoodManager mood  = new MoodManager(urgeBias, emotionBias);
            Lifeform    child = new Lifeform(parentA.World, parentA.Species, mood, parentA.Id, parentB.Id)
            {
                _food  = parentA.Init.FoodDrain + parentB.Init.FoodDrain,
                _water = parentA.Init.WaterDrain + parentB.Init.WaterDrain
            };

            BreedAction(parentA);
            BreedAction(parentB);

            return(child);
        }
コード例 #6
0
        private static List <object[]> TopAndBottom(int best, int worst, bool data)
        {
            List <object[]> itemsSource = new List <object[]>();

            if (LIFEFORMS.Count == 0)
            {
                return(itemsSource);
            }

            Lifeform[] lifeforms = LIFEFORMS
                                   .OrderByDescending(c => c.BreedCount)
                                   .ThenByDescending(c => c.Age)
                                   .ToArray();

            if (lifeforms.Length < best + worst)
            {
                foreach (Lifeform lifeform in lifeforms)
                {
                    itemsSource.Add(lifeform.ToObjectArray());
                }

                if (!data)
                {
                    return(itemsSource);
                }

                Console.WriteLine();
                Console.WriteLine(MoodManager.ToStringHeader());

                foreach (Lifeform lifeform in lifeforms)
                {
                    Console.WriteLine(lifeform.MM.ToString());
                }

                return(itemsSource);
            }

            for (int i = 0; i < best; ++i)
            {
                itemsSource.Add(lifeforms[i].ToObjectArray());
            }

            for (int i = worst + 1; i > 1; --i)
            {
                itemsSource.Add(lifeforms[lifeforms.Length - i].ToObjectArray());
            }

            if (!data)
            {
                return(itemsSource);
            }

            Console.WriteLine($"\n{"Urges",-29}||{"Emotions",-39}");
            Console.WriteLine(MoodManager.ToStringHeader());

            for (int i = 0; i < best; ++i)
            {
                Console.WriteLine(lifeforms[i].MM.ToString());
            }

            for (int i = worst + 1; i > 1; --i)
            {
                Console.WriteLine(lifeforms[lifeforms.Length - i].MM.ToString());
            }

            return(itemsSource);
        }
コード例 #7
0
 public static string EmotionName(MoodManager mood)
 {
     int[] result = EmotionIntensity(mood._emotionValues);
     return(EMOTION_NAMES[result[0], result[1]]);
 }