コード例 #1
0
 public Plant(DNA dna, Ground parent)
     : base(dna, parent)
 {
     _status = kindstatus.Seed;
     //Get the generation from the DNA
     Generation = dna.Generation;
 }
コード例 #2
0
 public AbtractPlant(DNA dna, Ground parent)
 {
     Ramdom gui = new Ramdom();
     aliveID = gui.RandomString(32);
     _dna = new DNAPlant(dna, aliveID);
     _parent = parent;
 }
コード例 #3
0
        //Main factory where all the beings will be created
        public override IAlive CreateLive(string AliveBeing,DNA dna, Ground parent)
        {
            switch (AliveBeing) {
                case "plant":
                    Plant newplant = new Plant(dna, parent);
                    return newplant;
                default:
                    throw new ApplicationException(string.Format("Being '{0}' cannot be created", AliveBeing));

            }
        }
コード例 #4
0
 public abstract IAlive CreateLive(string AliveBeing, DNA dna , Ground parent);
コード例 #5
0
 public DNA(DNA dna, string parent)
 {
     _Parent_ID = parent;
        _dnachain = dna._dnachain;
        Generation = dna.Generation;
 }
コード例 #6
0
        private void spreadSeed( DNA[] Ldna)
        {
            Random numer = new Random();
            foreach (DNA p_dna in Ldna)
            {

                int randomnumer = numer.Next(1, 9);
                switch (randomnumer)
                {
                    //down left
                    case 1:
                        _parent.addPlantToGround(coordenate.positionx - 1, coordenate.positiony - 1, p_dna);
                        break;
                    case 2:
                        // down
                        _parent.addPlantToGround(coordenate.positionx, coordenate.positiony - 1, p_dna);
                        break;
                    case 3:
                        //down right
                        _parent.addPlantToGround(coordenate.positionx + 1, coordenate.positiony - 1, p_dna);
                        break;
                    case 4://right
                        _parent.addPlantToGround(coordenate.positionx + 1, coordenate.positiony, p_dna);
                        break;
                    case 5://right up
                        _parent.addPlantToGround(coordenate.positionx + 1, coordenate.positiony + 1, p_dna);
                        break;
                    case 6://up
                        _parent.addPlantToGround(coordenate.positionx, coordenate.positiony + 1, p_dna);
                        break;
                    case 7://left up

                            _parent.addPlantToGround(coordenate.positionx - 1, coordenate.positiony + 1, p_dna);
                        break;

                    case 8://left
                        _parent.addPlantToGround(coordenate.positionx - 1, coordenate.positiony, p_dna);
                        break;
                    case 9://center
                        _parent.addPlantToGround(coordenate.positionx, coordenate.positiony, p_dna);
                        break;

                }
            }
        }
コード例 #7
0
        private DNA[] mixDNA(DNA plant, DNA plant_2)
        {
            int generation = plant.Generation > plant_2.Generation ? plant.Generation : plant_2.Generation;
            generation += 1;
            DNA[] LDNA = new DNA[2];
            Random numer = new Random();
            int numberOfGens = plant.dnachain.Count;
            int randomnumer = numer.Next(1, numberOfGens);
            DNA DNA1= new DNAPlant();
            DNA DNA2 = new DNAPlant();
            DNA1.Generation = generation;
            DNA2.Generation = generation;
            foreach(gen g in plant.dnachain.GetRange(0,randomnumer)){
                gen g1 = new gen(g.name, mutation(g.valor));
                DNA1.dnachain.Add(g1);
            }
            foreach (gen g in plant_2.dnachain.GetRange(randomnumer, numberOfGens-randomnumer))
            {
                gen g1 = new gen(g.name, mutation(g.valor));
                DNA1.dnachain.Add(g1);
            }
            foreach (gen g in plant_2.dnachain.GetRange(0, randomnumer))
            {
                gen g1 = new gen(g.name, mutation(g.valor));
                DNA2.dnachain.Add(g1);
            }
            foreach (gen g in plant.dnachain.GetRange(randomnumer, numberOfGens - randomnumer))
            {
                gen g1 = new gen(g.name, mutation(g.valor));
                DNA2.dnachain.Add(g1);
            }

            LDNA[0] = DNA1;
            LDNA[1] = DNA2;

            return LDNA;
        }
コード例 #8
0
        public void addPlantToGround(int x, int y, DNA dna)
        {
            try
            {
                // Add a new plant to the ground place in the coordenates x, Y using de dna
                Ground targetGround = _mapM.Single(S => S.coordn.positionx == x && S.coordn.positiony == y);
                // No more thatn 21 seeds per ground
                if (targetGround.ListSeeds.Count < 21)
                {
                    IPlant plant = (IPlant)new BeingCreator().CreateLive("plant", dna, targetGround);

                    targetGround.ListSeeds.Add(plant);
                }

            }
            catch
            {
                Console.Write("out of map");
            }
        }
コード例 #9
0
 public DNAPlant(DNA dna,string parent)
     : base(dna,parent)
 {
 }