Beispiel #1
0
    void OnCollisionEnter2D(Collision2D other)
    {
        if (firstOnce)
        {
            if (!isGround)
            {
                if (other.gameObject.tag == "Terrain")
                {
                    if (!other.gameObject.GetComponent <FrogGameTerrain>().isSafeTerrain)
                    {
                        FrogGameMaster.isGameOver = true;
                        FrogGameQLearning.AddMemory((bool[])FrogGameMaster.latestIndex.Clone(), FrogGameMaster.latestJumpType, false);
                    }
                    else
                    {
                        FrogGameQLearning.AddMemory((bool[])FrogGameMaster.latestIndex.Clone(), FrogGameMaster.latestJumpType, true);
                    }

                    other.gameObject.GetComponent <FrogGameTerrain>().Greened();

                    gameMaster.GetLatestIndex();
                }
                isGround = true;
            }
        }
        else
        {
            firstOnce = true;
            isGround  = true;
        }
    }
    void Spawn(bool skip = false)
    {
        int isSafe = Random.Range(0, 2);

        if (skip)
        {
            isSafe = 1;
        }
        else
        {
            if (isSafe == 0)
            {
                int count = 0;
                for (int i = 1; i < FrogGameQLearning.GetInputCount(); i++)
                {
                    if (indexList[indexList.Count - i] == false)
                    {
                        count++;
                    }
                }

                if (count >= FrogGameQLearning.GetInputCount() - 1)
                {
                    isSafe = 1;
                }
            }
        }

        //isSafe = 1;

        GameObject ne = Instantiate(terrainPrefab, spawner.position, Quaternion.identity, spawner);

        if (isSafe == 1)
        {
            ne.GetComponent <FrogGameTerrain>().Initialize(true, indexList.Count);
            indexList.Add(true);
        }
        else
        {
            ne.GetComponent <FrogGameTerrain>().Initialize(false, indexList.Count);
            indexList.Add(false);
        }

        RefreshTerrain();
    }
    void RandomMove()
    {
        randomTime -= Time.deltaTime;
        if (randomTime < 0)
        {
            /*
             * if (FrogQLearning.memoryFragments.Count > 0)
             * {
             *  randomTime = Random.Range(0.0f, randomTimeMax / (FrogQLearning.memoryFragments.Count * 2));
             * } else
             * {
             *  randomTime = Random.Range(0.0f, randomTimeMax);
             * }
             */

            Jump(FrogGameQLearning.CheckMemory(latestIndex));
        }
    }
    void Start()
    {
        latestIndexTerrain = new int[FrogGameQLearning.GetInputCount()];
        latestIndex        = new bool[FrogGameQLearning.GetInputCount()];

        latestIndexOffset = FrogGameQLearning.GetInputCount();
        //latestIndexOffset = 8;
        //latestIndexOffset = FrogGameQLearning.NUMBER_OF_ACTIONS;

        latestJumpType = 0;
        scoreValue     = 0;
        isGameOver     = false;
        isGameOverPrev = false;
        //

        uiRetry.text = "Retry : " + retryValue.ToString() + " (s)";

        for (int i = 0; i < FrogGameQLearning.GetInputCount() + 10; i++)
        {
            Spawn(true);
        }

        GetLatestIndex();
    }