コード例 #1
0
 public void createoffspring(string agent, int energy)
 {
     if (agent == "Hawk")
     {
         Hawk hawk = spawnPrefab(hawkPrefab).GetComponent <Hawk>();
     }
     else if (agent == "Dove")
     {
         Dove dove = spawnPrefab(dovePrefab).GetComponent <Dove>();
     }
 }
コード例 #2
0
ファイル: GenericsTest.cs プロジェクト: MartinChavez/CSharp
        public void GenericsTypeSafety() //Generics types allow code reuse with type safety and Performance benefits
        {
            var dovesList = new List<Dove>(); //A List<T> is a Type that has one implementation but can work with any Object

            var firstDove = new Dove();
            var secondDove = new Dove();

            dovesList.Add(firstDove);
            dovesList.Add(secondDove);
            // dovesList.Add("StringDove");   This fails at compile time since the List<Dove> can only accept Doves

            Assert.AreEqual(true, dovesList.Any());
        }
コード例 #3
0
ファイル: GenericsTest.cs プロジェクト: MarcLongoria/CSharp
        public void GenericsTypeSafety()       //Generics types allow code reuse with type safety and Performance benefits
        {
            var dovesList = new List <Dove>(); //A List<T> is a Type that has one implementation but can work with any Object

            var firstDove  = new Dove();
            var secondDove = new Dove();

            dovesList.Add(firstDove);
            dovesList.Add(secondDove);
            // dovesList.Add("StringDove");   This fails at compile time since the List<Dove> can only accept Doves

            Assert.AreEqual(true, dovesList.Any());
        }
コード例 #4
0
    public void NextButtonClick()
    {
        List <GameObject> foods  = new List <GameObject>();
        List <GameObject> hawks  = new List <GameObject>();
        List <GameObject> doves  = new List <GameObject>();
        List <GameObject> agents = new List <GameObject>();

        for (int i = 0; i < System.Convert.ToInt32(foodNumber.text); i++)
        {
            spawnPrefab(foodPrefab);
        }
        foreach (GameObject fhd in GameObject.FindObjectsOfType(typeof(GameObject)))
        {
            if (fhd.name == "Food(Clone)")
            {
                foods.Add(fhd);
            }
            if (fhd.name == "Hawk(Clone)")
            {
                agents.Add(fhd);
                hawks.Add(fhd);
            }
            if (fhd.name == "Dove(Clone)")
            {
                agents.Add(fhd);
                doves.Add(fhd);
            }
        }
        while (agents != null)
        {
            if (foods.Count > 0)
            {
                if (agents.Count == 1)
                {
                    if (doves.Contains(agents[0]))
                    {
                        Dove dove = agents[0].transform.GetComponent <Dove>();
                        dove.energy = foodValueInt - baseReqInt + dove.energy;
                    }
                    if (hawks.Contains(agents[0]))
                    {
                        Hawk hawk = agents[0].transform.GetComponent <Hawk>();
                        hawk.energy = foodValueInt - baseReqInt + hawk.energy;
                    }

                    agents.RemoveAt(0);
                }
                else
                {
                    int        r1          = Random.Range(1, agents.Count) - 1;
                    int        r2          = Random.Range(1, agents.Count) - 1;
                    GameObject competitor1 = agents[r1];
                    GameObject competitor2 = agents[r2];
                    agents.RemoveAt(r1);
                    agents.RemoveAt(r2);
                    if (hawks.Contains(competitor1) && hawks.Contains(competitor2))
                    {
                        Hawk hawk1 = competitor1.transform.GetComponent <Hawk>();
                        Hawk hawk2 = competitor2.transform.GetComponent <Hawk>();
                        hawk1.energy = hawk1.energy + foodValueInt - baseReqInt;
                        hawk2.energy = hawk1.energy - injuryInt - baseReqInt;
                    }
                    if (doves.Contains(competitor1) && doves.Contains(competitor2))
                    {
                        Dove dove1 = competitor1.transform.GetComponent <Dove>();
                        Dove dove2 = competitor2.transform.GetComponent <Dove>();
                        dove1.energy = dove1.energy + foodValueInt - bluffingInt - baseReqInt;
                        dove2.energy = dove1.energy - bluffingInt - baseReqInt;
                    }
                    if (hawks.Contains(competitor1) && doves.Contains(competitor2))
                    {
                        Hawk hawk1 = competitor1.transform.GetComponent <Hawk>();
                        Dove dove1 = competitor2.transform.GetComponent <Dove>();
                        hawk1.energy = hawk1.energy + foodValueInt - baseReqInt;
                        dove1.energy = dove1.energy - baseReqInt;
                    }
                    if (doves.Contains(competitor1) && hawks.Contains(competitor2))
                    {
                        Dove dove1 = competitor1.transform.GetComponent <Dove>();
                        Hawk hawk1 = competitor2.transform.GetComponent <Hawk>();
                        dove1.energy = dove1.energy - baseReqInt;
                        hawk1.energy = hawk1.energy + foodValueInt - baseReqInt;
                    }
                }
                int r = Random.Range(1, foods.Count) - 1;
                GameObject.DestroyImmediate(foods[r]);
                foods.RemoveAt(r);
            }
            else
            {
                foreach (GameObject hd in agents)
                {
                    if (hawks.Contains(hd))
                    {
                        Hawk hawk = hd.transform.GetComponent <Hawk>();
                        hawk.energy = hawk.energy - baseReqInt;
                    }
                    else
                    {
                        Dove dove = hd.transform.GetComponent <Dove>();
                        dove.energy = dove.energy - baseReqInt;
                    }
                }
                break;
            }
        }

        int hnumber = 0;
        int dnumber = 0;
        int fnumber = 0;
        int item    = 0;

        foreach (GameObject hd in GameObject.FindObjectsOfType(typeof(GameObject)))
        {
            if (hd.name == "Hawk(Clone)")
            {
                hnumber++;
            }
            if (hd.name == "Dove(Clone)")
            {
                dnumber++;
            }
            if (hd.name == "Food(Clone)" || hd.name == "Food")
            {
                fnumber++;
            }
        }


        if (null == m_DataDiagram)
        {
            return;
        }

        foreach (GameObject line in lineList)
        {
            if (item == 0)
            {
                m_DataDiagram.InputPoint(line, new Vector2(1, (float)(hnumber / 10.0)));
            }
            else if (item == 1)
            {
                m_DataDiagram.InputPoint(line, new Vector2(1, (float)(dnumber / 10.0)));
            }
            else
            {
                m_DataDiagram.InputPoint(line, new Vector2(1, (float)(fnumber / 10.0)));
            }
            item++;
        }
    }
コード例 #5
0
ファイル: Evolution.cs プロジェクト: haraldq/hnd
        private static Agent CreateChild(Agent parent)
        {
            Agent child;

            if (parent is Hawk)
                child = new Hawk { HasMoved = true };
            else
                child = new Dove { HasMoved = true };

            DistributeFitness(parent, child);

            return child;
        }