Beispiel #1
0
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        EnemyMovement enemy = hitInfo.GetComponent <EnemyMovement>();
        TableHP       table = hitInfo.GetComponent <TableHP>();

        if (enemy != null)
        {
            Debug.Log("Party Boi");
            hp = hp - 1;
            if (hp == 0)
            {
                health = health - 1;
            }
            StartCoroutine(ExampleCoroutine());
        }
        if (table != null)
        {
            Debug.Log("Table");
            hp = hp - 1;
            if (hp == 0)
            {
                health = health - 1;
            }
            StartCoroutine(ExampleCoroutine());
        }
        Moving1 spider = hitInfo.GetComponent <Moving1>();

        if (spider != null)
        {
            Debug.Log("Pinata");
            hp = hp - 1;
            if (hp == 0)
            {
                health = health - 1;
            }
            StartCoroutine(ExampleCoroutine());
        }
        if (health <= 0)
        {
            Destroy(gameObject);
            SceneManager.LoadScene("GameOver");
        }
    }
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        EnemyMovement enemy = hitInfo.GetComponent <EnemyMovement>();
        TableHP       table = hitInfo.GetComponent <TableHP>();

        if (enemy != null)
        {
            enemy.TakeDamage(damage);
        }
        if (table != null)
        {
            table.TakeDamage(damage);
        }
        Moving1 spider = hitInfo.GetComponent <Moving1>();

        if (spider != null)
        {
            spider.TakeDamage(damage);
        }
        Destroy(gameObject);
    }
Beispiel #3
0
    public IEnumerator State()
    {
        for (int m = 0; m < 4; m++)
        {
            Age = 1;
            currentPopulation = CreateInitialData();
            while (true)
            {
                Debug.Log("++++++++++++++++++" + Age + "世代++++++++++++++++++");
                //壁の作成///////////
                GameObject wall = GameObject.CreatePrimitive(PrimitiveType.Cube);
                wall.layer = 1;
                wall.transform.localScale    = new Vector3(37, 23, 1);
                wall.transform.localPosition = new Vector3(1, 14, 0);
                /////////////////////
                Moving1 moving = new Moving1();
                //適応度の計算
                for (int i = 0; i < 20; i++)
                {
                    Debug.Log("******************" + i + "個体******************");
                    yield return(StartCoroutine(moving.MovingArm()));

                    GameObject.Find("overlap").GetComponent <GetPic06>().evaluate02();
                    EvaluatePoint           = GameObject.Find("overlap").GetComponent <GetPic06>().count;
                    currentPopulation[i][8] = EvaluatePoint;
                    Debug.Log(EvaluatePoint + "第" + i + "個体の評価");
                }
                //適合率順にソート
                SortCurrentPopulation(currentPopulation);
                //エリート選択
                //NextPopulation.Add(currentPopulationSorted[0]);
                //次世代の個体を交叉と突然変異を用いて生成
                //int[] ellite = new int[GeneLength+1];
                List <int[]> ellite = new List <int[]>();
                ellite.Add(currentPopulationSorted[0]);
                Debug.Log(ellite[0][8]);
                currentPopulation.Add(ellite[0]);

                List <int[]> NextPopulation = new List <int[]>();
                for (int i = 0; i < kotainumber - 1; i++)
                {
                    if (Rnd.Next(0, 100) / 100 < 0.75)
                    {
                        if (i != kotainumber - 1)
                        {
                            //NextPopulation.Add(CrossOver(currentPopulationSorted[i], currentPopulationSorted[i + 1])[0]);
                            //temp = CrossOver(currentPopulationSorted[0], currentPopulationSorted[1]);
                            NextPopulation.Add(CrossOver(currentPopulationSorted[i], currentPopulationSorted[i + 1])[0]);
                        }
                        else
                        {
                            //NextPopulation.Add(CrossOver(currentPopulationSorted[i], currentPopulationSorted[0])[0]);
                            //temp = CrossOver(currentPopulationSorted[i], currentPopulationSorted[i])[0];
                            NextPopulation.Add(CrossOver(currentPopulationSorted[i], currentPopulationSorted[0])[0]);
                        }
                    }
                    else
                    {
                        NextPopulation.Add(MutaRate(currentPopulationSorted[i])[0]);
                    }
                }
                SubNextPopulation = NextPopulation;

                /*List<int[]> SubCurrentPopulation = new List<int[]>();
                 * for (int i=0; i<kotainumber;i++)
                 * {
                 *  int[] mmm = new int[GeneLength+1];
                 *  for (int j=0;j<=GeneLength;j++)
                 *  {
                 *      mmm[j] = 0;
                 *  }
                 *  SubCurrentPopulation.Add(mmm);
                 * }
                 * for (int i=0;i<18;i++)
                 * {
                 *  SubCurrentPopulation[i] = currentPopulationSorted[i];
                 * }
                 * for (int i = 0; i < 5; i++)
                 * {
                 *  Debug.Log(SubCurrentPopulation[i][8] + "いいいいいいいいいいいいいいいいいい");
                 * }*/
                for (int i = 0; i < 5; i++)
                {
                    //Debug.Log(NextPopulation[i][8] + "いいいいいいいいsadfasいいいいいいいいいい");
                    Debug.Log(currentPopulation[i][8] + "えええええええええええええええええええ");
                }
                //次世代の適応度の計算
                //List<int> pointpoint = new List<int>();
                for (int i = 0; i < 19; i++)
                {
                    Debug.Log("次世代の適応度計算******************" + i + "個体******************");
                    yield return(StartCoroutine(moving.MovingArm2()));

                    GameObject.Find("overlap").GetComponent <GetPic06>().evaluate02();
                    EvaluatePointNext = GameObject.Find("overlap").GetComponent <GetPic06>().count;
                    //pointpoint.Add(EvaluatePointNext);
                    NextPopulation[i][8] = EvaluatePointNext;
                    Debug.Log(EvaluatePointNext + "第" + i + "世代の評価");
                }
                //NextPopulationとcurrentPopulationSortedの合体をソートするcoun
                for (int i = 0; i < kotainumber - 1; i++)
                {
                    currentPopulationSorted.Add(NextPopulation[i]);
                }
                //SortLv2(currentPopulationSorted);
                Select(SortLv2(currentPopulationSorted));

                //壁の破壊//////
                yyy = true;
                if (yyy)
                {
                    Destroy(GameObject.Find("Cube"));
                }
                yyy = false;
                ////////////////

                //終了条件
                if (Age == 30)
                {
                    //20世代後に終了
                    break;
                }
                //ArmNumber--;
                Age++;
            }
            //ArmNumber--;
            //SwichCannel();
        }
        //return null;
    }
Beispiel #4
0
    public IEnumerator Amazon()
    {
        //for (int M = 0; M < 4; M++)
        //{
        Age = 1;
        currentPopulation = CreateInitialData();

        /*for (int i = 0; i < 20; i++)
         * {
         *  Debug.Log(i + "世代");
         *  for (int j = 0; j < 8; j++)
         *  {
         *      Debug.Log(currentPopulation[i][j]);
         *  }
         * }*/
        while (true)
        {
            Debug.Log(Age + "世代***************************************************************************");
            GameObject wall = GameObject.CreatePrimitive(PrimitiveType.Cube);
            wall.layer = 1;
            wall.transform.localScale    = new Vector3(37, 23, 1);
            wall.transform.localPosition = new Vector3(1, 14, 0);
            Moving1 moving = new Moving1();
            for (int i = 0; i < kotainumber; i++)
            {
                yield return(StartCoroutine(moving.MovingArm()));

                GameObject.Find("overlap").GetComponent <GetPic06>().evaluate02();
                EvaluatePoint           = GameObject.Find("overlap").GetComponent <GetPic06>().count;
                currentPopulation[i][8] = EvaluatePoint;
                Debug.Log(EvaluatePoint + "第" + i + "個体の評価");
            }
            SortVer1(currentPopulation);
            int[,] SubCurrentPopulation = new int[kotainumber, GeneLength];
            for (int i = 0; i < kotainumber; i++)
            {
                for (int j = 0; j < GeneLength; j++)
                {
                    SubCurrentPopulation[i, j] = currentPopulationSorted[i][j];
                }
            }

            /*for (int i = 0; i < 20; i++)
             * {
             *  Debug.Log(i + "個体");
             *  for (int j = 0; j < 9; j++)
             *  {
             *      Debug.Log(currentPopulationSorted[i][j] + "***************");
             *  }
             * }*/
            int[] ellite = new int[GeneLength];
            for (int i = 0; i < GeneLength; i++)
            {
                ellite[i] = 0;
            }
            for (int i = 0; i < GeneLength; i++)
            {
                if (ellite[8] < Master[8])
                {
                    ellite[i] = Master[i];
                }
            }
            //Debug.Log(ellite[8]+"LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL");

            /*for (int i = 0; i < GeneLength; i++)
             * {
             *  Debug.Log("ELLLLLLLLLLLLLLLLLLLLITE" + ellite[i]);
             *  Debug.Log("ELLLLLLLLLLLLLLLLLLLLITE" + SubCurrentPopulation[0, 8]);
             * }*/

            int[] point = new int[kotainumber];
            for (int i = 0; i < kotainumber; i++)
            {
                point[i] = 0;
                point[i] = currentPopulationSorted[i][8];
            }

            /*for (int i = 0; i < kotainumber; i++)
             * {
             *  Debug.Log(point[i]+"+++++++++++++++++++++++++");
             *  Debug.Log(rouletteChoice(point)+"L*+++++++++++++++++++++++++++++");
             * }*/

            //NextPopulation = CrossOver(currentPopulationSorted[rouletteChoice(point)], currentPopulationSorted[rouletteChoice(point) + 1]);

            /*for (int i=0;i<5;i++)
             * {
             *  Debug.Log(currentPopulationSorted[i][8]+ "L*+++++++++++++++++++++++++++++");
             * }*/
            List <int[]> NextPopulation = new List <int[]>();
            for (int i = 0; i < kotainumber - 1; i++)
            {
                int ff  = rouletteChoice(point);
                int ff2 = rouletteChoice(point);
                int ff3 = Rnd.Next(0, kotainumber - 15);
                if (Rnd.Next(0, 100) / 100 < 0.9)
                {
                    if (i != kotainumber - 1)
                    {
                        //NextPopulation.Add(CrossOver(currentPopulationSorted[i], currentPopulationSorted[i + 1])[0]);
                        NextPopulation.Add(CrossOver(currentPopulationSorted[ff], currentPopulationSorted[ff2]));    //ff,ff2
                        //NextPopulation.Add(NextArray);
                    }
                    else
                    {
                        //NextPopulation[i] = CrossOver(currentPopulationSorted[0], currentPopulationSorted[1])[0];
                        NextPopulation.Add(CrossOver(currentPopulationSorted[0], currentPopulationSorted[1]));
                    }
                }
                else
                {
                    NextPopulation[i] = MutaRate(currentPopulationSorted[i])[i];
                }
            }

            /*for (int i= 0;i<5;i++)
             * {
             *  Debug.Log(currentPopulationSorted[i][8]+"PPPPPPPPPPPPPPPPPPPPPPPPPP");
             *  //Debug.Log(currentPopulation[0]);
             *  //Debug.Log(currentPopulationSorted[0]);
             *  //Debug.Log(NextPopulation[0]);
             * }*/
            SubPopulation = new List <int[]>(NextPopulation);
            for (int i = 0; i < kotainumber - 2; i++)
            {
                Debug.Log("次世代の適応度計算******************" + i + "個体******************");
                yield return(StartCoroutine(moving.MovingArm2()));

                GameObject.Find("overlap").GetComponent <GetPic06>().evaluate02();
                EvaluatePointNext   = GameObject.Find("overlap").GetComponent <GetPic06>().count;
                SubPopulation[i][8] = EvaluatePointNext;
            }

            /*for (int i = 0; i < 19; i++)
             * {
             *  //Debug.Log("ELLLLLLLLLLLLLLLLLLLLITE" + ellite[i]);
             *  //Debug.Log(currentPopulationSorted[i][8] + "L*+++++++++++++++++++++++++++++");
             *  Debug.Log(SubPopulation[i][8] + "L*+++++++++++++++++++++++++++++");
             *  Debug.Log(SubCurrentPopulation[i,8]);
             * }*/
            int[,] SubSubPopulation = new int[kotainumber, GeneLength];
            for (int i = 0; i < kotainumber - 1; i++)
            {
                for (int j = 0; j < GeneLength; j++)
                {
                    SubSubPopulation[i, j] = SubPopulation[i][j];
                }
            }
            //配列の合成
            int[,] newPopulation = new int[SubCurrentPopulation.Length + SubSubPopulation.Length, GeneLength];
            Array.Copy(SubCurrentPopulation, newPopulation, SubCurrentPopulation.Length);
            Array.Copy(SubSubPopulation, 0, newPopulation, SubCurrentPopulation.Length, SubSubPopulation.Length);
            //SubCurrentPopulation.CopyTo(newPopulation, 0);
            //SubSubPopulation.CopyTo(newPopulation, SubCurrentPopulation.Length);

            //合成配列のソート
            //SortLv2(newPopulation);
            //上位20個体の選出
            //評価値渡すプロフラム
            int[] pointLv2 = new int[kotainumber];
            for (int i = 0; i < kotainumber - 1; i++)
            {
                pointLv2[i] = SortLv2(newPopulation)[i, 8];
            }
            int[,] newPopulationLv1_2 = new int[kotainumber * 2 - 1, GeneLength];
            for (int i = 0; i < kotainumber * 2 - 1; i++)
            {
                for (int j = 0; j < GeneLength; j++)
                {
                    newPopulationLv1_2[i, j] = SortLv2(newPopulation)[i, j];
                }
            }
            int[,] newPopulationLv2 = new int[kotainumber, GeneLength];
            for (int i = 1; i < kotainumber - 1; i++)
            {
                for (int j = 1; j < GeneLength; j++)
                {
                    newPopulationLv2[i, j] = newPopulationLv1_2[rouletteChoice(pointLv2), j];
                }
            }

            /*for (int i = 0; i < kotainumber - 1; i++)
             * {
             *  Debug.Log(newPopulationLv2[i,8]);
             * }*/
            /*newPopulationLv2 = new int[kotainumber,GeneLength];
             * for (int i = 0; i < GeneLength-1; i++)
             * {
             *  Debug.Log(ellite[i]);
             *  newPopulationLv2[kotainumber, i] = ellite[i];
             * }*/
            //newPopulationLv2[kotainumber,GeneLength-1] = ellite[];
            //int[] newPopulationLv3 = ellite.Concat(ellite).ToArray();

            List <int[]> GetBeautifull = new List <int[]>();
            for (int i = 0; i < kotainumber - 1; i++)
            {
                int[] aaa = new int[GeneLength];
                for (int j = 0; j < GeneLength; j++)
                {
                    aaa[j] = newPopulationLv2[i, j];
                    //Debug.Log(aaa[j] = newPopulationLv1_2[i, j]);
                }
                GetBeautifull.Add(aaa);
                //Debug.Log(aaa[8]+"GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG");
            }

            currentPopulation = new List <int[]>(GetBeautifull);
            currentPopulation.Add(ellite);

            /*for (int i = 0; i < kotainumber-1; i++)
             * {
             *  Debug.Log(GetBeautifull[i][8] + "************FFFFFFFFFFFFFFFFFFF*************************");
             * }*/
            //currentPopulation = newPopulationLv2;
            //GetBeautifull =

            /*int[] temp = new int[GeneLength];
             * for (int i =0;i<kotainumber;i++)
             * {
             *  for (int j =0;j<GeneLength;j++)
             *  {
             *      temp[j] = SubCurrentPopulation[i, j];
             *  }
             * }*/
            /*for (int i=0;i<39;i++)
             * {
             *  Debug.Log(SubPopulation[i]);
             * }*/
            //ortLv2(SubPopulation);

            /*for (int i = 0; i < kotainumber; i++)
             * {
             *  Debug.Log(pointLv2[i]+"*************************************");
             * }*/
            //壁の破壊//////
            yyy = true;
            if (yyy)
            {
                Destroy(GameObject.Find("Cube"));
            }
            yyy = false;
            ////////////////
            //終了条件
            if (Age == 20)
            {
                ArmNumber--;
                break;
                //20世代後に終了

                /*List<int[]> finish = new List<int[]>(SortVer1(currentPopulation));
                 * yield return StartCoroutine(moving.MovingArm3());
                 * Debug.Log(finish[0][8]+"結果+++++++++++++++++++++++++++++++++++");*/
            }
            Age++;
        }
        Moving1      moving2 = new Moving1();
        List <int[]> finish  = new List <int[]>(SortVer1(currentPopulation));

        yield return(StartCoroutine(moving2.MovingArm3()));

        Debug.Log(finish[0][8] + "結果+++++++++++++++++++++++++++++++++++");
        ArmNumber--;
        //}
    }