Example #1
0
    bool FixedUpdateFrisky()
    {
        GameObject target = closestVisibleMate();

        if (target == null)
        {
            return(false);
        }
        Omnivore mate = target.GetComponent <Omnivore>();

        if (Vector3.Distance(rb.position, target.transform.position) > size + 0.01)
        {
            Vector3 move = Vector3.MoveTowards(rb.position, target.transform.position, genome["walkspeed"].value());
            rb.MovePosition(move);
        }
        else
        {
            // Do the nasty
            if (mate.getMode() == "frisky" && this.getSex() == 0)
            {
                createOffspring(mate);
            }
        }
        return(true);
    }
Example #2
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 #3
0
    GameObject closestVisibleMate()
    {
        // find nearby things!
        Collider[] nearbyObjects = Physics.OverlapSphere(rb.position, genome["sightRange"].value());
        // find closest thing
        float      minDist      = 10000000000f;
        GameObject nearestThing = null;

        foreach (Collider c in nearbyObjects)
        {
            Omnivore mate = c.gameObject.GetComponent <Omnivore>();
            // Not all gameObjects are even Omnivores
            if (mate != null)
            {
                // Not all omnivores are the right sex, and not all of them are frisky
                if (mate.getSex() == -1 || mate.getSex() == this.getSex() || mate.getMode() != "frisky")
                {
                    mate = null;
                }
            }
            if (mate != null)
            {
                float dist = Vector3.Distance(rb.position, c.gameObject.transform.position);
                if (dist < minDist & c.gameObject != gameObject)
                {
                    minDist      = dist;
                    nearestThing = c.gameObject;
                }
            }
        }
        return(nearestThing);
    }
Example #4
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);
    }
Example #5
0
        public void GetFoodPrice_When_Omnivore_Returns_Price()
        {
            // Arrange

            var specie = new Omnivore(new Herbivore {
                Specie = AnimalSpecieNames.Wolf, Rate = 0.5
            })
            {
                Specie = AnimalSpecieNames.Wolf, Rate = 0.5, PricePerKg = 2, FruitPricePerKg = 1, MeatPercentage = 0.5
            };

            // Act
            var price = specie.GetFoodPrice(100);

            // Assert
            Assert.AreEqual(75, price);
        }
Example #6
0
 public CategoryResourceLoader(Omnivore io) : base(io)
 {
 }
Example #7
0
 public ResourceLoader(Omnivore io)
 {
     this.io = io;
 }
 public MenuResourceLoader(Omnivore io) : base(io)
 {
 }
Example #9
0
 public async Task <T> GetAsync(Omnivore io)
 {
     return(await io.GetAsyncWithException <T>(href, false));
 }
 public LocationResourceLoader(Omnivore io) : base(io)
 {
 }
Example #11
0
 public ResourceTester(Omnivore io)
 {
     this.io = io;
 }
 public ModifierResourceLoader(Omnivore io) : base(io)
 {
 }
Example #13
0
 public EmployeeResourceLoader(Omnivore io) : base(io)
 {
 }
 public PaymentResourceLoader(Omnivore io) : base(io)
 {
 }
Example #15
0
 public TableResourceLoader(Omnivore io) : base(io)
 {
 }
Example #16
0
 public OrderTypeResourceLoader(Omnivore io) : base(io)
 {
 }
 public TicketItemResourceLoader(Omnivore io) : base(io)
 {
 }
 public RevenueCenterResourceLoader(Omnivore io) : base(io)
 {
 }