void Start()
    {
        GenePool.Initialize(Managers.Entity.numberOfVillagers, Managers.Entity.numberOfWerewolves);
        GenePool.CreatePopulation();
        mayorStartPos = Managers.Entity.MainObjs["Mayor"].transform.position;

        firstRound = true;
        StartNewRound();
    }
Example #2
0
 public void AddRange_AddsRangeOfGenes()
 {
     GenePool<int> pool = new GenePool<int>();
     pool.AddRange(new int[] { 10, 20, 30 });
     
     Assert.AreEqual(3, pool.Count);
     Assert.AreEqual(10, pool[0]);
     Assert.AreEqual(20, pool[1]);
     Assert.AreEqual(30, pool[2]);
 }
Example #3
0
        public void AddRange_AddsRangeOfGeneswithDuplicates_DuplicatesShouldBeSkipped()
        {
            GenePool<int> pool = new GenePool<int>();
            pool.AddRange(new int[] { 10, 10, 20, 20, 10, 20, 30, 30, 10, 20, 30, 10 });

            Assert.AreEqual(3, pool.Count);
            Assert.AreEqual(10, pool[0]);
            Assert.AreEqual(20, pool[1]);
            Assert.AreEqual(30, pool[2]);
        }
Example #4
0
    public void SetGenes()
    {
        for (int i = 0; i < numberOfVillagers; i++)
        {
            villagers[i].SetGenes(GenePool.PopVillagerGene());
        }

        for (int i = 0; i < numberOfWerewolves; i++)
        {
            werewolves[i].SetGenes(GenePool.PopWerewolfGene());
        }
    }
Example #5
0
        public void Add_AddingGeneAlreadyInPool_GeneShouldntBeDuplicated()
        {
            GenePool<int> pool = new GenePool<int>();
            pool.Add(10);

            Assert.AreEqual(1, pool.Count);
            Assert.AreEqual(10, pool[0]);

            pool.Add(10);

            Assert.AreEqual(1, pool.Count);
            Assert.AreEqual(10, pool[0]);
        }
Example #6
0
        // INTERFACE
        public void Evolve()
        {
            IGenePool newGenePool = new GenePool(_genePool);

            // Generate a new population of the same size
            // Each child's genotype is a pair of random alleles from random parent genotypes
            for (ulong i = 0; i < _genePool.GenotypeCount; ++i) {

            }

            // Overwrite the old genotype counts with the newly generated ones
            _genePool = newGenePool;
        }
Example #7
0
        public void Add_AddsNewGene()
        {
            GenePool<int> pool = new GenePool<int>();
            pool.Add(10);

            Assert.AreEqual(1, pool.Count);
            Assert.AreEqual(10, pool[0]);

            pool.Add(5);

            Assert.AreEqual(2, pool.Count);
            Assert.AreEqual(10, pool[0]);
            Assert.AreEqual(5, pool[1]);
        }
Example #8
0
        public bool PlantPlant(GenePool seedling, int box)
        {
            bool canPlant = false;

            if (plants[box] == null && (box == 1 || box == 0))
            {
                canPlant    = true;
                plants[box] = Instantiate(plantPrefab, planterBoxes[box].transform).GetComponent <Plant>();
                foreach (Gene entity in seedling.GetAllGenes())
                {
                    plants[box].GetGenes().ModifyGenes(entity, plants[box].GetMainRender(), plants[box].GetSubRender());
                }
                plants[box].PlantGrewUp(RandomGrowthSpread);
            }
            return(canPlant);
        }
    /// <summary>
    /// Call this at the start of a new round, hides the results screen.
    /// </summary>
    public void StartNewRound()
    {
        ui.HideResults();

        Managers.Entity.MainObjs["Mayor"].transform.position = mayorStartPos;
        if (!firstRound)
        {
            GenePool.Breed();
        }
        Managers.Entity.CreateNPCs();
        Managers.Entity.SetGenes();
        Managers.Weather.RandomCondition();
        Managers.Entity.UpdateDecisionTrees();

        startTime = Time.time;
        timing    = true;
    }
Example #10
0
        public bool SameGenes(GenePool genes)
        {
            bool same = false;

            if (this.genes.GetAllGenes().Count == genes.GetAllGenes().Count)
            {
                same = true;
                for (int i = 0; i < this.genes.GetAllGenes().Count; i++)
                {
                    if (this.genes.GetAllGenes()[i] != genes.GetAllGenes()[i])
                    {
                        same = false;
                    }
                }
            }
            return(same);
        }
    // Use this for initialization
    void Start()
    {
        Cars          = new List <VehicleDriver>();
        pool          = new GenePool();
        pool.PoolSize = NumIndividuals;
        pool.Initialize(new int[] { 17, 10, 10, 2 });

        for (int i = 0; i < pool.PoolSize; i++)
        {
            VehicleDriver car = (Instantiate(CarPrototype) as GameObject).GetComponent <VehicleDriver>();
            car.network = pool.Individuals[i];
            Cars.Add(car);
        }

        GetComponent <TrackGenerator>().GenerateTrack();
        Cars[0].FollowedCar = true;
    }
Example #12
0
        static void Main(string[] args)
        {
            animals = new List <Animal>();
            Gene   _g;
            Animal _a;
            Races  _r;

            _r  = Races.Human;
            dna = new GenePool();

            switch (_r)
            {
            case Races.Human:
                _g = new Gene(typeof(HairColor), HairColor.Blonde, HairColor.Blonde);
                dna.Add(_g);
                _g = new Gene(typeof(SkinColor), SkinColor.Caucasian, SkinColor.Caucasian);
                dna.Add(_g);
                _g = new Gene(typeof(EyeColor), EyeColor.Green, EyeColor.Green);
                dna.Add(_g);
                break;

            case Races.Dog:
                /*_g = new Gene(typeof(Enums.Dog.HairColor), Enums.Dog.HairColor.Blonde.ToString(), Enums.Dog.HairColor.Blonde.ToString());
                 * dna.Add(_g);
                 * _g = new Gene(typeof(Enums.Dog.SkinColor), Enums.Dog.SkinColor.Axil.ToString(), Enums.Dog.SkinColor.Axil.ToString());
                 * dna.Add(_g);
                 * _g = new Gene(typeof(Enums.Dog.EyeColor), Enums.Dog.EyeColor.Axil.ToString(), Enums.Dog.EyeColor.Axil.ToString());
                 * dna.Add(_g);*/
                break;
            }

            _a = new Animal(1, _r, dna);
            animals.Add(_a);

            dna = new GenePool();

            switch (_r)
            {
            case Races.Human:
                _g = new Gene(typeof(HairColor), HairColor.Black, HairColor.Black);
                dna.Add(_g);
                _g = new Gene(typeof(SkinColor), SkinColor.Asian, SkinColor.Asian);
                dna.Add(_g);
                _g = new Gene(typeof(EyeColor), EyeColor.Brown, EyeColor.Brown);
                dna.Add(_g);
                break;

            case Races.Dog:
                /*_g = new Gene(typeof(Enums.Dog.HairColor), Enums.Dog.HairColor.Brunette, Enums.Dog.HairColor.Brunette);
                 * dna.Add(_g);
                 * _g = new Gene(typeof(Enums.Dog.SkinColor), Enums.Dog.SkinColor.Terminal.ToString(), Enums.Dog.SkinColor.Terminal.ToString());
                 * dna.Add(_g);
                 * _g = new Gene(typeof(Enums.Dog.EyeColor), Enums.Dog.EyeColor.Terminal.ToString(), Enums.Dog.EyeColor.Terminal.ToString());
                 * dna.Add(_g);*/
                break;
            }

            _a = new Animal(2, _r, dna);
            animals.Add(_a);

            animals.Add(new Animal(3, animals[0].Race, animals[0], animals[1]));


            #region Table info
            GenePool father = animals[0].GetGenes;
            GenePool mother = animals[1].GetGenes;
            GenePool child  = animals[2].GetGenes;

            Console.WriteLine(String.Format("\n|{0,5}\t\t|{1,5}\t|{2,5}\t|{3,5}\n", "Trait", animals[0].Race.ToString() + " 1", animals[1].Race.ToString() + " 2", animals[2].Race.ToString() + " Child"));

            foreach (Type trait in Trait.AllTraits)
            {
                bool raceFound = false;
                foreach (RaceAttribute r in Enums.GetAttributes <RaceAttribute>(trait))
                {
                    if (r.Race.Equals(animals[0].Race))
                    {
                        raceFound = true;
                        break;
                    }
                }

                if (raceFound)
                {
                    Gene gf = father.FindByTrait(trait);
                    Gene gm = mother.FindByTrait(trait);
                    Gene gc = child.FindByTrait(trait);

                    string traitAsString = Enums.GetAttribute <DescriptionAttribute>(trait).Description;

                    if (gf.Dominant.ToString().Length <= 6)
                    {
                        Console.WriteLine(String.Format("|{0,5}\t|{1,5}\t\t|{2,5}\t\t|{3,5}", traitAsString, gf.Dominant.ToString(), gm.Dominant.ToString(), gc.Dominant.ToString()));
                    }
                    else
                    {
                        Console.WriteLine(String.Format("|{0,5}\t|{1,5}\t|{2,5}\t\t|{3,5}", traitAsString, gf.Dominant.ToString(), gm.Dominant.ToString(), gc.Dominant.ToString()));
                    }

                    if (gf.Dominant.ToString().Length <= 6)
                    {
                        Console.WriteLine(String.Format("|{0,5}\t|{1,5}\t\t|{2,5}\t\t|{3,5}", traitAsString, gf.Recessive.ToString(), gm.Recessive.ToString(), gc.Recessive.ToString()));
                    }
                    else
                    {
                        Console.WriteLine(String.Format("|{0,5}\t|{1,5}\t|{2,5}\t\t|{3,5}", traitAsString, gf.Recessive.ToString(), gm.Recessive.ToString(), gc.Recessive.ToString()));
                    }
                }
            }
            #endregion

            Console.WriteLine("Press enter key to continue . . .");
            Console.ReadLine();
        }
Example #13
0
 public void AddRange_ArgumentIsNull_ThrowsAnException()
 {
     GenePool < int > pool = new GenePool<int>();
     pool.AddRange(null);
     Assert.Fail();
 }
Example #14
0
 public Animal(int id, Races race, GenePool genes) : base(id, genes)
 {
     Race = race;
 }
Example #15
0
 public void Constructor_CreatesInstance()
 {
     GenePool<int> pool = new GenePool<int>();
     Assert.IsNotNull(pool);
     Assert.AreEqual(0, pool.Count);
 }
Example #16
0
 // CONSTRUCTORS
 public Population(GenePool genepool)
 {
     // Define private variables
     _genePool = genepool;
     _rand = new Random();
 }
Example #17
0
 public Flower(int id, GenePool genes) : base(id, genes)
 {
 }