Пример #1
0
    private async static void WarikomiAI()
    {
        await Task.Delay(500);

        if (DangerForAI.overDanger)
        {
            Debug.Log("case 1");
            DangerForAI.DangerReset();
            ReadAI(true);
            return;
        }
        else if (DangerForAI.HP == 1)
        {
            Debug.Log("case 2");
            DangerForAI.DangerReset();
            ReadAI(true);
            return;
        }
        else if (DangerForAI.danger)
        {
            Debug.Log("case 3");
            var(x1, y1) = DangerForAI.dangerList[0];
            if (DataBase.BoardInfo(x1, y1) == 1)
            {
                DangerForAI.DangerReset();
                ReadAI(true);
                return;
            }
            else
            {
                Debug.Log("case 4");
                List <GameObject> res = DataBase.MyKoma(gameManage.turn, true);
                foreach (GameObject obj in res)
                {
                    foreach ((int, int)T in obj.GetComponent <interFace>().Movable())
                    {
                        if (T == DangerForAI.dangerList[0])
                        {
                            var(x, y) = T;
                            GameObject obj1 = DataBase.objs[x, y];

                            await Task.Delay(100);

                            gameManage.requestEnqueue(obj);
                            await Task.Delay(600);

                            gameManage.requestEnqueue(obj1);
                            await Task.Delay(100);

                            if (gameManage.receiveMode != gameManage.situation.attackselect)
                            {
                                DangerForAI.DangerReset();
                                return;
                            }
                            else
                            {
                                List <GameObject> res1 = DataBase.MyKoma(gameManage.turn, false);

                                (GameObject, GameObject)Act = (null, null);
                                int ActionPoint = -1000;
                                for (int k = 0; k < res1.Count(); k++)
                                {
                                    GameObject        obj2        = res1[k];
                                    List <(int, int)> attackRange = obj2.GetComponent <interFace>().Attackable();
                                    for (int l = 0; l < attackRange.Count(); l++)
                                    {
                                        var(x3, y3) = attackRange[l];
                                        GameObject obj3 = DataBase.objs[x3, y3];
                                        int        evaAtc;
                                        evaAtc = obj3 == DangerForAI.dangerEnemyG ? 10000000 : obj3.GetComponent <interFace>().AtcEvaluation();

                                        int actPt = evaAtc;
                                        if (actPt > ActionPoint)
                                        {
                                            ActionPoint = actPt;
                                            Act         = (obj2, obj3);
                                        }
                                    }
                                }
                                var(Robj3, Robj4) = Act;

                                gameManage.requestEnqueue(Robj3);
                                await Task.Delay(600);

                                gameManage.requestEnqueue(Robj4);
                                await Task.Delay(100);

                                DangerForAI.DangerReset();
                                return;
                            }
                        }
                    }
                }
                ReadAI(true);
                DangerForAI.DangerReset();
                return;
            }
        }
        else
        {
            ReadAI(false);
            DangerForAI.DangerReset();
            return;
        }
    }
Пример #2
0
    private async static void ReadAI(bool mode)
    {
        List <GameObject> res = DataBase.MyKoma(gameManage.turn, true);

        if (!res.Any())
        {
            Debug.Log("case 5");
            aiPlaying = false;
            gameManage.Skip();
            aiPlaying = true;
            await Task.Delay(100);

            if (gameManage.receiveMode != gameManage.situation.attackselect)
            {
                return;
            }
            else
            {
                (GameObject, GameObject)Act = (null, null);
                int ActionPoint        = -1000;
                List <GameObject> res1 = DataBase.MyKoma(gameManage.turn, false);
                for (int k = 0; k < res1.Count(); k++)
                {
                    GameObject        obj2        = res1[k];
                    List <(int, int)> attackRange = obj2.GetComponent <interFace>().Attackable();
                    for (int l = 0; l < attackRange.Count(); l++)
                    {
                        var(x3, y3) = attackRange[l];
                        GameObject obj3   = DataBase.objs[k, l];
                        int        evaAtc = obj3.GetComponent <interFace>().AtcEvaluation();
                        int        actPt  = evaAtc;
                        if (actPt > ActionPoint)
                        {
                            ActionPoint = actPt;
                            Act         = (obj2, obj3);
                        }
                    }
                }
                var(Robj, Robj1) = Act;
                Debug.Log("評価値は" + ActionPoint.ToString());
                gameManage.requestEnqueue(Robj);
                await Task.Delay(1000);

                gameManage.requestEnqueue(Robj1);
                await Task.Delay(100);
            }
        }
        else
        {
            Debug.Log("case 7");
            (GameObject, GameObject, GameObject, GameObject)Act = (null, null, null, null);
            int  ActionPoint = -1000;
            bool afterSkip   = false;
            for (int i = 0; i < res.Count(); i++)
            {
                GameObject obj = res[i];
                var(x0, y0) = DataBase.objSearch(obj);
                List <(int, int)> moveRange = obj.GetComponent <interFace>().Movable();
                for (int j = 0; j < moveRange.Count(); j++)
                {
                    var(x1, y1) = moveRange[j];
                    GameObject obj1 = DataBase.objs[x1, y1];
                    obj.GetComponent <interFace>().Move(x1, y1);
                    DataBase.Set(x0, y0, 0);
                    DataBase.Set(x1, y1, 2);
                    DataBase.objs[x0, y0] = obj1;
                    DataBase.objs[x1, y1] = obj;
                    List <GameObject> res1 = DataBase.MyKoma(gameManage.turn, false);
                    int eva0   = obj.GetComponent <interFace>().Evaluation(x0, y0);
                    int eva1   = obj.GetComponent <interFace>().Evaluation(x1, y1);
                    int movePt = eva1 - eva0;
                    if (x0 == 0 & DangerForAI.dangers[y0])
                    {
                        movePt = -100000000;
                    }
                    if (!res1.Any())
                    {
                        if (movePt > ActionPoint)
                        {
                            ActionPoint = movePt;
                            Act         = (obj, obj1, null, null);
                            afterSkip   = true;
                        }
                    }
                    else
                    {
                        for (int k = 0; k < res1.Count(); k++)
                        {
                            GameObject        obj2        = res1[k];
                            List <(int, int)> attackRange = obj2.GetComponent <interFace>().Attackable();
                            for (int l = 0; l < attackRange.Count(); l++)
                            {
                                var(x3, y3) = attackRange[l];
                                GameObject obj3 = DataBase.objs[x3, y3];
                                int        evaAtc;
                                if (mode)
                                {
                                    evaAtc = obj3 == DangerForAI.dangerEnemyG ? 10000000 : obj3.GetComponent <interFace>().AtcEvaluation();
                                }
                                else
                                {
                                    evaAtc = obj3.GetComponent <interFace>().AtcEvaluation();
                                }
                                int actPt = movePt * 10 + evaAtc;
                                if (actPt > ActionPoint)
                                {
                                    ActionPoint = actPt;
                                    Act         = (obj, obj1, obj2, obj3);
                                    afterSkip   = false;
                                }
                            }
                        }
                    }
                    DataBase.Set(x0, y0, 2);
                    DataBase.Set(x1, y1, 0);
                    obj.GetComponent <interFace>().Move(x0, y0);
                    DataBase.objs[x0, y0] = obj;
                    DataBase.objs[x1, y1] = obj1;
                }
            }
            var(Robj1, Robj2, Robj3, Robj4) = Act;
            if (afterSkip)
            {
                Debug.Log("評価値は" + ActionPoint.ToString());
                await Task.Delay(100);

                gameManage.requestEnqueue(Robj1);
                await Task.Delay(600);

                gameManage.requestEnqueue(Robj2);
                await Task.Delay(100);

                if (gameManage.receiveMode != gameManage.situation.attackselect)
                {
                    return;
                }
                else
                {
                    gameManage.Skip();//何か問題が生じた時に止まらないための処置.正しく動けばこれは起きない
                }
            }
            else
            {
                Debug.Log("評価値は" + ActionPoint.ToString());
                await Task.Delay(100);

                gameManage.requestEnqueue(Robj1);
                await Task.Delay(600);

                gameManage.requestEnqueue(Robj2);
                await Task.Delay(600);

                gameManage.requestEnqueue(Robj3);
                await Task.Delay(600);

                gameManage.requestEnqueue(Robj4);
                await Task.Delay(100);

                DangerForAI.DangerReset();
            }
        }
    }
Пример #3
0
    private async static void RandomAI2()
    {
        await Task.Delay(500);

        List <GameObject> res = DataBase.MyKoma(gameManage.turn, true);
        int power1            = 7;

        if (!res.Any())
        {
            aiPlaying = false;
            gameManage.Skip();
            aiPlaying = true;
            await Task.Delay(100);

            if (gameManage.receiveMode != gameManage.situation.attackselect)
            {
                Debug.Log("a");
                return;
            }
            else
            {
                (GameObject, GameObject)Act = (null, null);
                int ActionPoint        = -1000;
                List <GameObject> res1 = DataBase.MyKoma(gameManage.turn, false);
                for (int k = 0; k < res1.Count(); k++)
                {
                    GameObject        obj2        = res1[k];
                    List <(int, int)> attackRange = obj2.GetComponent <interFace>().Attackable();
                    for (int l = 0; l < attackRange.Count(); l++)
                    {
                        var(x3, y3) = attackRange[l];
                        GameObject obj3   = DataBase.objs[k, l];
                        int        evaAtc = obj3.GetComponent <interFace>().AtcEvaluation();
                        int        actPt  = evaAtc;
                        if (actPt > ActionPoint)
                        {
                            ActionPoint = actPt;
                            Act         = (obj2, obj3);
                        }
                    }
                }
                var(Robj, Robj1) = Act;
                Debug.Log("評価値は" + ActionPoint.ToString());
                gameManage.requestEnqueue(Robj);
                await Task.Delay(600);

                gameManage.requestEnqueue(Robj1);
                await Task.Delay(200);
            }
        }
        else
        {
            (GameObject, GameObject, GameObject, GameObject)Act = (null, null, null, null);
            int  ActionPoint = -1000;
            bool afterSkip   = false;
            for (int t = 0; t < power1; t++)
            {
                GameObject        myobj     = res[Random.Range(0, res.Count() - 1)];
                List <(int, int)> moveRange = myobj.GetComponent <interFace>().Movable();
                var(i0, j0) = DataBase.objSearch(myobj);
                var(i, j)   = moveRange[Random.Range(0, moveRange.Count() - 1)];
                GameObject myobj1 = DataBase.objs[i, j];
                myobj.GetComponent <interFace>().Move(i, j);
                DataBase.Set(i0, j0, 0);
                DataBase.Set(i, j, 2);
                DataBase.objs[i0, j0] = myobj1;
                DataBase.objs[i, j]   = myobj;
                int eva0               = myobj.GetComponent <interFace>().Evaluation(i0, j0);
                int eva1               = myobj.GetComponent <interFace>().Evaluation(i, j);
                int movePt             = eva1 - eva0;
                List <GameObject> res1 = DataBase.MyKoma(gameManage.turn, false);
                if (!res1.Any())
                {
                    if (movePt > ActionPoint)
                    {
                        ActionPoint = movePt;
                        Act         = (myobj, myobj1, null, null);
                        afterSkip   = true;
                    }
                }
                else
                {
                    for (int k = 0; k < res1.Count(); k++)
                    {
                        GameObject        obj2        = res1[k];
                        List <(int, int)> attackRange = obj2.GetComponent <interFace>().Attackable();
                        for (int l = 0; l < attackRange.Count(); l++)
                        {
                            var(x3, y3) = attackRange[l];
                            GameObject obj3   = DataBase.objs[x3, y3];
                            int        evaAtc = obj3.GetComponent <interFace>().AtcEvaluation();
                            int        actPt  = movePt * 10 + evaAtc;
                            if (actPt > ActionPoint)
                            {
                                ActionPoint = actPt;
                                Act         = (myobj, myobj1, obj2, obj3);
                                afterSkip   = false;
                            }
                        }
                    }
                }
                myobj.GetComponent <interFace>().Move(i0, j0);
                DataBase.Set(i0, j0, 2);
                DataBase.Set(i, j, 0);
                DataBase.objs[i, j]   = myobj1;
                DataBase.objs[i0, j0] = myobj;
            }
            var(Robj1, Robj2, Robj3, Robj4) = Act;
            if (afterSkip)
            {
                Debug.Log("評価値は" + ActionPoint.ToString());
                await Task.Delay(100);

                gameManage.requestEnqueue(Robj1);
                await Task.Delay(600);

                gameManage.requestEnqueue(Robj2);
                await Task.Delay(200);

                if (gameManage.receiveMode != gameManage.situation.attackselect)
                {
                    return;
                }
                else
                {
                    gameManage.Skip();//何か問題が生じた時に止まらないための処置.正しく動けばこれは起きない
                }
            }
            else
            {
                Debug.Log("評価値は" + ActionPoint.ToString());
                await Task.Delay(100);

                gameManage.requestEnqueue(Robj1);
                await Task.Delay(600);

                gameManage.requestEnqueue(Robj2);
                await Task.Delay(600);

                gameManage.requestEnqueue(Robj3);
                await Task.Delay(600);

                gameManage.requestEnqueue(Robj4);
                await Task.Delay(100);
            }
            DangerForAI.DangerReset();
        }
    }