Exemplo n.º 1
0
    public Loup randomLoupSeen()
    {
        List <Living> percepts = perceptView.getLiving();
        int           nbLoups  = 0;

        for (int i = 0; i < percepts.Count; ++i)
        {
            if (percepts[i] as Loup != null)
            {
                nbLoups++;
            }
        }
        int  indiceLoup = Random.Range(1, nbLoups);
        Loup result     = null;

        if (nbLoups > 0)
        {
            for (int i = 0; i < percepts.Count; ++i)
            {
                result = percepts[i] as Loup;
                if (result != null)
                {
                    indiceLoup--;
                    if (indiceLoup == 0)
                    {
                        break;
                    }
                }
            }
        }
        return(result);
    }
Exemplo n.º 2
0
        public void TrierPlatTest()
        {
            List <Plat> listPlat = new List <Plat>()
            {
                new Plat {
                    TypePlat = "Sucrerie", PlatId = 1001, NbrBouchee = 3
                },
                new Plat {
                    TypePlat = "Carnivore", PlatId = 1002, NbrBouchee = 5
                },
                new Plat {
                    TypePlat = "Végéterien", PlatId = 1003, NbrBouchee = 4
                }
            };

            Loup CrocBlanc = new Loup();
            Plat p         = CrocBlanc.TrierPlat(listPlat);

            Assert.AreEqual(listPlat[0], p);                // Plat Sucrerie
            //Assert.AreEqual(listPlat[1],p);   // Plat Carnivore
        }
Exemplo n.º 3
0
 public A_TaquinerAlpha()
     : base("A_TaquinerAlpha")
 {
     this.cible = LoupInferieur.alpha;
 }
Exemplo n.º 4
0
 public MindLoup(Loup agent) : base(agent)
 {
 }
Exemplo n.º 5
0
    public override void vivre()
    {
        base.vivre();

        Loup loup = ((Loup)agent);

        if (Loup.GESTION_FAIM)
        {
            if (loup.faim <= loup.FAIM_MAX / 2)
            {
                List <MemoryBloc> memoryBlocs       = new List <MemoryBloc>(loup.GetComponent <Memory>().getMemoyBlocs());
                Animal            plusProcheCadavre = null;
                for (int i = 0; i < memoryBlocs.Count; ++i)
                {
                    Animal animal = memoryBlocs[i].getEntity() as Animal;
                    if (animal != null)
                    {
                        if (animal.estMort())
                        {
                            if (animal.quantiteDeViande > 0)
                            {
                                if (plusProcheCadavre == null)
                                {
                                    plusProcheCadavre = animal;
                                }
                                else if (Vector2.Distance(plusProcheCadavre.transform.position, agent.transform.position) > Vector2.Distance(animal.transform.position, agent.transform.position))
                                {
                                    plusProcheCadavre = animal;
                                }
                            }
                        }
                    }
                }

                if (plusProcheCadavre != null)
                {
                    A_SeNourrir newAction = new A_SeNourrir(plusProcheCadavre);
                    A_SeNourrir actionNourrirPrecedente = actionList.getFirstActionWithSameType <A_SeNourrir>();
                    if (actionNourrirPrecedente == null)
                    {
                        actionList.addAction(newAction);
                    }
                    else if (actionNourrirPrecedente.getDistanceFrom(agent.transform.position) > newAction.getDistanceFrom(agent.transform.position))
                    {
                        actionList.removeAction(actionNourrirPrecedente);
                        actionList.addAction(newAction);
                    }
                }
            }
            loup.faim -= Time.deltaTime;
            if (loup.faim <= loup.FAIM_MAX / 2)
            {
                loup.displayStaticEmoticon(loup.hungryEmoticonSprite);
            }
            if (loup.faim <= 0)
            {
                loup.blesse(-loup.faim);
                loup.faim = 0;
            }
        }

        actionList.addAction(new A_Promenade(((Animal)agent).vitesse));
        if (actionList.size() == 1)  //Si l'agent ne fait que se promener et qu'il s'embête ... ajout d'une action d'occupation aléatoire spécifiée par randomAction()
        {
            compteurActiviteAleatoire -= Time.deltaTime;
            if (compteurActiviteAleatoire <= 0)
            {
                randomAction();
                compteurActiviteAleatoire = Random.Range(10, 50);
            }
        }
    }