Пример #1
0
        public Food(ConstsUniverse ctUn, FoodType foodType) : base(ctUn)
        {
            switch (foodType)
            {
            case FoodType.deadCell:
                descriptor  = -2;
                energyLevel = ConstsUniverse.EnergyLevel_DeadCell;
                break;

            case FoodType.defaultFood:
                descriptor  = -1;
                energyLevel = ConstsUniverse.EnergyLevel_DefFood;
                break;

            case FoodType.poison:
                descriptor  = -3;
                energyLevel = ConstsUniverse.EnergyLevel_Poison;
                break;

            default:
                descriptor  = -1;
                energyLevel = 1;
                break;
            }

            this.foodType = foodType;
        }
Пример #2
0
        public Cell(ConstsUniverse ctUn, Dictionary <string, object> dictionary) : base(ctUn)
        {
            Initialize(
                new Genome(
                    ConstsUniverse,
                    Convert.ToInt32(dictionary["hunger"]),
                    Convert.ToInt32(dictionary["aggression"]),
                    Convert.ToInt32(dictionary["reproduction"]),
                    Convert.ToInt32(dictionary["friendly"]),
                    Convert.ToInt32(dictionary["poisonAddiction"])
                    ),
                1000, 1000);
            foreach (var atr in GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public))
            {
                if (atr == null)
                {
                    continue;
                }
                string name = atr.Name;

                if (typeof(IFormattable).IsAssignableFrom(atr.FieldType))
                {
                    atr.SetValue(this, dictionary[name]);
                }
            }
        }
Пример #3
0
        void Initialize(int width, int height, ConstsUniverse ctUniverse)
        {
            if (width <= 0 || height <= 0)
            {
                throw new Exception(@"Can`t create so small Universe!");
            }
            ConstsUniverse = ctUniverse;
            this.width     = width;
            this.height    = height;
            universeMatrix = new UniverseObject[width, height];

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    AddUniverseObject(i, j, new EmptySpace(ConstsUniverse), true);
                }
            }

            disposed        = false;
            foodForTick     = 0;
            poisonForTick   = 0;
            ticksCount      = 0;
            blockCellDesc   = 0;
            MaxCellsPersent = 1;
            SetFoodPlace(0, 0, width, height);
            SetPoisonPlace(0, 0, width, height);
        }
Пример #4
0
 public Food(ConstsUniverse constsUniverse, FoodType foodType) : base(constsUniverse)
 {
     //I use delegate to always return value from ConstsUniverse, if it updated.
     if (foodType == FoodType.defaultFood)
     {
         descriptor             = -1;
         GetEnergyLevelDelegate = delegate
         {
             return(ConstsUniverseProperty.EnergyLevel_DefFood);
         };
     }
     else if (foodType == FoodType.deadCell)
     {
         descriptor             = -2;
         GetEnergyLevelDelegate = delegate
         {
             return(ConstsUniverseProperty.EnergyLevel_DeadCell);
         };
     }
     else if (foodType == FoodType.poison)
     {
         descriptor             = -3;
         GetEnergyLevelDelegate = delegate
         {
             return(ConstsUniverseProperty.EnergyLevel_PoisonedFood);
         };
     }
 }
Пример #5
0
 public Genome(ConstsUniverse ctUn)
 {
     ConstsUniverse  = ctUn;
     Hunger          = ConstsUniverse.CellGenome_Hunger;
     Aggression      = ConstsUniverse.CellGenome_Aggression;
     Reproduction    = ConstsUniverse.CellGenome_Reproduction;
     Friendly        = ConstsUniverse.CellGenome_Friendly;
     PoisonAddiction = ConstsUniverse.CellGenome_PoisonAddiction;
 }
Пример #6
0
 public Genome(ConstsUniverse ctUn, int hunger, int aggression, int reproduction, int friendly, int poisonAddiction)
 {
     ConstsUniverse  = ctUn;
     Hunger          = hunger;
     Aggression      = aggression;
     Reproduction    = reproduction;
     Friendly        = friendly;
     PoisonAddiction = poisonAddiction;
 }
Пример #7
0
 public Universe(int width, int height)
 {
     this.width  = width;
     this.height = height;
     foodPlace   = new bool[width, height];
     poisonPlace = new bool[width, height];
     SetDefaultObjectsAccessiblePlace();
     ConstsUniverseProperty = new ConstsUniverse();
     universeMatrix         = new UniverseObject[width, height];
     ticksCount             = 0;
 }
Пример #8
0
 public Genome(ConstsUniverse constsUniverse) :
     this(
         constsUniverse.CellGenome_Hunger,
         constsUniverse.CellGenome_Aggression,
         constsUniverse.CellGenome_Reproduction,
         constsUniverse.CellGenome_Friendly,
         constsUniverse.CellGenome_PoisonAddiction,
         constsUniverse.CellGenome_CorpseAddiction
         )
 {
 }
Пример #9
0
        public EmptySpace(ConstsUniverse ctUn, Dictionary <string, object> dictionary) : base(ctUn, dictionary)
        {
            //foreach (var atr in GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public))
            //{
            //    if (atr == null)
            //        continue;
            //    string name = atr.Name;

            //    if (typeof(IFormattable).IsAssignableFrom(atr.FieldType))
            //        atr.SetValue(this, dictionary[name]);
            //}
        }
Пример #10
0
 public Cell(ConstsUniverse constsUniverse, Genome genome, float energyLevel, int descriptor) : base(constsUniverse)
 {
     this.genome      = genome;
     age              = 0;
     this.energyLevel = energyLevel;
     if (descriptor < 100)
     {
         int desc = StableRandom.rd.Next(100, int.MaxValue);
         this.descriptor = desc;
     }
     else
     {
         this.descriptor = descriptor;
     }
     parentDescriptor = StableRandom.rd.Next(100, int.MaxValue);
 }
Пример #11
0
 public void Dispose()
 {
     disposed = true;
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             GetMatrixElement(i, j).Dispose();
         }
     }
     universeMatrix        = null;
     poisonPlace           = null;
     foodPlace             = null;
     cellList              = null;
     MostFitGenome_OneCell = null;
     constsUniverse        = null;
     invokedActions        = null;
 }
Пример #12
0
 public Cell(ConstsUniverse constsUniverse) : this(constsUniverse, new Genome(constsUniverse), constsUniverse.EnergyLevel_CreatingCell, 1)
 {
 }
Пример #13
0
 public Food(ConstsUniverse ctUn) : this(ctUn, FoodType.defaultFood)
 {
 }
Пример #14
0
 public Cell(ConstsUniverse ctUn, Genome genome, float energyLevel, int descriptor) : base(ctUn)
 {
     Initialize(genome, descriptor, energyLevel);
 }
Пример #15
0
 public Cell(ConstsUniverse ctUn, Genome genome, float energyLevel) : base(ctUn)
 {
     Initialize(genome, 1, energyLevel);
 }
Пример #16
0
 public Cell(ConstsUniverse ctUn, Genome genome) : base(ctUn)
 {
     Initialize(genome, 1, ConstsUniverse.EnergyLevel_CreatingCell);
 }
Пример #17
0
 public Cell(ConstsUniverse ctUn) : base(ctUn)
 {
     Initialize(new Genome(ConstsUniverse), 1, ConstsUniverse.EnergyLevel_CreatingCell);
 }
Пример #18
0
 public EmptySpace(ConstsUniverse ctUn) : base(ctUn)
 {
 }
Пример #19
0
 public UniverseObject(ConstsUniverse constsUniverse)
 {
     ConstsUniverseProperty = constsUniverse;
 }
Пример #20
0
 protected UniverseObject(ConstsUniverse ctUn)
 {
     ConstsUniverse = ctUn;
 }