Esempio n. 1
0
    public override void AddReward(BaseAgent agent, float[] vectorActions)
    {
        if (resetNextFrame)
        {
            agent.Done();
            myArea.ResetArea();
            resetNextFrame = false;
        }
        else
        {
            List <GameObject> objs = myArea.FindGameObjectsWithTagInChildren(Tag);
            foreach (GameObject obj in objs)
            {
                if ((obj.transform.position - agent.gameObject.transform.position).sqrMagnitude < Distance * Distance)
                {
                    if (ResetTime < 0)
                    {
                        ResetTime = Time.time;
                    }

                    ResetAreaAfter = AcademyParameters.Update(academy, ResetAreaAfterKeyVal, ResetAreaAfter);
                    if (Time.time - ResetTime >= ResetAreaAfter)
                    {
                        agent.AddReward(Reward);
                        resetNextFrame = true;
                    }
                }
                else
                {
                    ResetTime = -1;
                }
            }
        }
    }
Esempio n. 2
0
 public void FixedUpdate()
 {
     if (healthReference <= 0)
     {
         area.ResetAgents();
         area.ResetArea();
     }
 }
Esempio n. 3
0
    public IEnumerator HandleDead()
    {
        // Have to wait for action to register reward
        yield return(new WaitForFixedUpdate());

        yield return(new WaitForFixedUpdate());

        yield return(new WaitForFixedUpdate());

        yield return(new WaitForFixedUpdate());

        yield return(new WaitForFixedUpdate());

        yield return(new WaitForFixedUpdate());

        area.ResetAgents();
        area.ResetArea();
    }
    public override void AddReward(BaseAgent agent, float[] vectorActions)
    {
        List <ObservableFields> LabelObjects = new List <ObservableFields>();
        List <GameObject>       objs         = new List <GameObject>();

        foreach (string tag in Tags)
        {
            objs.AddRange(myArea.FindGameObjectsWithTagInChildren(tag));
        }

        foreach (GameObject obj in objs)
        {
            ObservableFields lobj = obj.GetComponent <ObservableFields>();
            if (lobj != null)
            {
                LabelObjects.Add(lobj);
            }
        }

        Reward = AcademyParameters.Update(academy, RewardKeyVal, Reward);

        if (AddedLastRound.Contains(agent.gameObject.GetInstanceID()))
        {
            AddedLastRound.Remove(agent.gameObject.GetInstanceID());

            if (AreaReset)
            {
                myArea.ResetArea();
            }

            return;
        }

        bool allHaveTag = true;

        foreach (ObservableFields labels in LabelObjects)
        {
            foreach (string label in Labels)
            {
                allHaveTag &= labels.LabelsHash.Contains(label);
            }
        }

        if (allHaveTag)
        {
            // TAG: MakeEvent myArea.Logger.Log(String.Concat("All ", String.Join(",", Tags), " have labels ", String.Join(",", Labels), " Adding reward: ", Reward));
            AddedLastRound.Add(agent.gameObject.GetInstanceID());
            agent.AddReward(Reward * (MultRewardByTagCount ? objs.Count : 1));

            if (Remove)
            {
                foreach (ObservableFields labels in LabelObjects)
                {
                    foreach (string label in Labels)
                    {
                        labels.LabelsHash.Remove(label);
                    }
                }
            }

            if (Reset)
            {
                agent.Done();
                agent.Reset();
            }
        }
    }