Example #1
0
    /// <summary>
    /// 意思決定
    /// </summary>
    public int DecideIntention()
    {
        NumYArray xData = new NumYArray();

        xData.Add(situation);
        //ニューラルネットワークによる結果表示
        NumYArray            resultArray = new NumYArray(nn.Predict(xData));
        List <List <float> > resultList  = resultArray.Get();

        //ランダムによる意思決定
        float n      = Random.Range(0.0f, NumY.Sum(resultArray).Get()[0][0]);
        float offset = 0.0f;

        for (int i = 0; i < resultList[0].Count; i++)
        {
            offset += resultList[0][i];
            if (n <= offset)
            {
                intention = i;
                break;
            }
        }

        return(this.intention);
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < 2; i++)
        {
            List <float> a = new List <float>();
            for (int j = 0; j < 3; j++)
            {
                a.Add(0);
            }
            arrayA.Add(a);
        }

        //float[][] b = { new float[] { 1, 2 }, new float[] { 3, 4 }, new float[] { 5, 6 } };
        //NumYArray arrayB = NumY.NumYArray(b);

        //float[][] c = { new float[] { 6, 5, 4, }, new float[] { 3, 2, 1 } };
        //NumYArray arrayC = NumY.NumYArray(c);

        //行列内の表示
        //arrayA.DisplayNum();
        //arrayB.DisplayNum();
        //arrayC.DisplayNum();
        //行列の四則演算
        //Array arrayD = NumY.Array(arrayC + arrayB);
        //arrayD = -arrayD;
        //arrayD.DisplayNum();
        //Array arrayE = NumY.Array(arrayC - arrayB);
        //arrayE.DisplayNum();
        //Array arrayF = NumY.Array(arrayC * arrayB);
        //arrayF.DisplayNum();
        //Array arrayG = NumY.Array(arrayC / arrayB);
        //arrayG.DisplayNum();

        //行列の内積計算
        //Array arrayH = NumY.Dot(arrayB, arrayC);
        //arrayH.DisplayNum();

        //行列の和を求めるテスト
        //float[][] o = { new float[] { 1, 2, 3, 4 }, new float[] { 1, 2, 3, 4 }, new float[] { 1, 2, 3, 4 } };
        //Array arrayO = NumY.Array(o);
        //arrayO.DisplayNum();
        //Array arrayO1 = new Array(NumY.Sum(arrayO));
        //arrayO1.DisplayNum();
        //Array arrayO2 = new Array(NumY.Sum(arrayO,0));
        //arrayO2.DisplayNum();
        //Array arrayO3 = new Array(NumY.Sum(arrayO,1));
        //arrayO3.DisplayNum();

        //転置行列を求めるテスト
        //float[][] p = { new float[] { 1, 2, 3, 4 }, new float[] { 1, 2, 3, 4 }, new float[] { 1, 2, 3, 4 } };
        //Array arrayP = NumY.Array(p);
        //arrayP = arrayP.T;
        //arrayP.DisplayNum();
    }
Example #3
0
    /// <summary>
    /// 意思と結果を基に教師値を算出
    /// </summary>
    public void CalcTeachData(string result, string state, float dis)
    {
        if (intention == -1)
        {
            return;
        }

        //教師値の算出
        switch (result)
        {
        case "Guard":
            teachValue[intention] = 1.0f;
            break;

        case "WasGuarded":
            if (state == "StandGuard")
            {
                teachValue[(int)EnemyAI.BEHAVE.swATTACK] = 1.0f;
                teachValue[(int)EnemyAI.BEHAVE.ssATTACK] = 1.0f;
            }
            else
            {
                teachValue[intention] = 1.0f;
            }
            break;

        case "Damage":
            switch (state)
            {
            case "StandGuard":
                teachValue[(int)EnemyAI.BEHAVE.sGUARD] = 1.0f;
                break;

            case "SitGuard":
                teachValue[(int)EnemyAI.BEHAVE.GUARD] = 1.0f;
                break;

            case "Kick":
                teachValue[(int)EnemyAI.BEHAVE.wATTACK] = 1.0f;
                break;

            case "SitKick":
                teachValue[(int)EnemyAI.BEHAVE.swATTACK] = 1.0f;
                break;

            default:
                teachValue[(int)EnemyAI.BEHAVE.sGUARD] = 1.0f;
                teachValue[(int)EnemyAI.BEHAVE.GUARD]  = 1.0f;
                break;
            }
            break;

        case "Damaged":
            teachValue[intention] = 1.0f;
            break;

        default:
            nowSkip++;
            if (nowSkip < learningSkipNum)
            {
                situation = new List <float>();
                return;
            }
            for (int i = 0; i < teachValue.Count; i++)
            {
                if (dis <= 0.1f)
                {
                    teachValue[(int)EnemyAI.BEHAVE.wATTACK] = 1.0f;
                    teachValue[(int)EnemyAI.BEHAVE.sATTACK] = 1.0f;
                    if (dis <= 0.3f)
                    {
                        teachValue[(int)EnemyAI.BEHAVE.swATTACK] = 1.0f;
                        teachValue[(int)EnemyAI.BEHAVE.ssATTACK] = 1.0f;
                    }
                    break;
                }
                if (i != (int)EnemyAI.BEHAVE.wATTACK &&
                    i != (int)EnemyAI.BEHAVE.sATTACK &&
                    i != (int)EnemyAI.BEHAVE.swATTACK &&
                    i != (int)EnemyAI.BEHAVE.ssATTACK)
                {
                    if (i != (int)EnemyAI.BEHAVE.JUMP &&
                        i != (int)EnemyAI.BEHAVE.fJUMP &&
                        i != (int)EnemyAI.BEHAVE.bJUMP)
                    {
                        teachValue[i] = 1.0f;
                    }
                    else
                    {
                        teachValue[i] = 0.3f;
                    }
                }
            }
            nowSkip = 0;
            break;
        }

        if (situation.Count == 0)
        {
            JudgSituation(dis);
        }

        //状況データと教師データを学習データに追加
        situationDatas.Add(situation);
        teachDatas.Add(teachValue);

        //入っているデータを削除
        situation  = new List <float>();
        teachValue = new List <float> {
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        };
    }