public Plant(DNA dna, Ground parent) : base(dna, parent) { _status = kindstatus.Seed; //Get the generation from the DNA Generation = dna.Generation; }
public AbtractPlant(DNA dna, Ground parent) { Ramdom gui = new Ramdom(); aliveID = gui.RandomString(32); _dna = new DNAPlant(dna, aliveID); _parent = parent; }
//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)); } }
public abstract IAlive CreateLive(string AliveBeing, DNA dna , Ground parent);
public DNA(DNA dna, string parent) { _Parent_ID = parent; _dnachain = dna._dnachain; Generation = dna.Generation; }
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; } } }
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; }
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"); } }
public DNAPlant(DNA dna,string parent) : base(dna,parent) { }