Example #1
0
    List <GameObject> CreateNOmnivores(int n)
    {
        List <GameObject> result = new List <GameObject>();

        for (int i = 0; i < n; i++)
        {
            GameObject c = (GameObject)Instantiate(
                omnivore,
                new Vector3(Random.value * 100 - 50, 1, Random.value * 100 - 50),
                Quaternion.identity
                );
            Omnivore omni = c.GetComponent <Omnivore>();
            // gene dictionary initialize!
            Dictionary <string, Gene> genome = new Dictionary <string, Gene>()
            {
                { "h", new Gene(i % 2 == 0 ? 0: 0.8f) },
                { "s", new Gene(1) },
                { "v", new Gene(1) },
                { "walkspeed", new Gene(0.03f) },
                { "size", new Gene(0.05f, 10) },
                { "ageToReproduce", new Gene(0.1f, 100) },
                { "sex", new Gene(i % 2 == 0 ? 0: 1, 1, "binary") },
                { "id", new Gene(i / 65000.0f) },
                { "sightRange", new Gene(1.0f, 100f) }
            };
            omni.SetGenome(omnivore, genome);
            result.Add(c);
        }
        return(result);
    }
Example #2
0
    public void createOffspring(Omnivore mate)
    {
        recoveryTime = 10;

        Vector3 offset = new Vector3(0, size, 0);
        Vector3 pos    = gameObject.transform.position + offset;

        // Unity doesn't let you use meaningful constructors.
        // The way to pass down the genome is explicitely with a setter:
        GameObject go   = (GameObject)Instantiate(prefab, pos, Quaternion.identity);
        Omnivore   omni = go.GetComponent <Omnivore>();
        Dictionary <string, Gene> newGenome = Genome.cross(this.genome, mate.genome);

        omni.SetGenome(prefab, newGenome);
    }