Beispiel #1
0
    public override void AddReward(BaseAgent agent, float[] vectorAction)
    {
        bool isOut = false;

        foreach (GameObject TargetObject in TargetObjects)
        {
            if (TargetObject == agent.gameObject)
            {
                continue;
            }

            if ((new Vector2(TargetObject.transform.position.x, TargetObject.transform.position.z)).sqrMagnitude
                > Radius * Radius)
            {
                agent.AddReward(Amount);
                isOut = true;
            }

            if (Mathf.Abs(TargetObject.transform.localPosition.y - PositionY) > LimitY)
            {
                agent.AddReward(Amount);
                isOut = true;
            }
        }

        if (isOut && Reset)
        {
            agent.Done();
            agent.Reset();
        }
    }
    public override void AddReward(BaseAgent agent, float[] vectorActions)
    {
        Rigidbody rb = agent.gameObject.GetComponent <Rigidbody>();

        if (rb == null)
        {
            return;
        }

        agent.AddReward(Mathf.Abs(rb.velocity.x) * Multiplier / (float)agent.agentParameters.maxStep);
        agent.AddReward(Mathf.Abs(rb.velocity.z) * Multiplier / (float)agent.agentParameters.maxStep);
    }
Beispiel #3
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;
                }
            }
        }
    }
 public override void AddReward(BaseAgent agent, float[] vectorActions)
 {
     if (agent.GetComponent <ObservableFields>().FieldsHash.ContainsKey(Label))
     {
         agent.AddReward(Reward / (float)agent.agentParameters.maxStep);
     }
 }
Beispiel #5
0
    public override void AddReward(BaseAgent agent, float[] vectorActions)
    {
        bool isOut = false;

        if (Mathf.Abs(agent.gameObject.transform.position.x) > LimitX)
        {
            agent.AddReward(Amount);
            isOut = true;
        }

        if (Mathf.Abs(agent.gameObject.transform.localPosition.y - PositionY) > LimitY)
        {
            agent.AddReward(AmountY);
            isOut = true;
        }

        if (Mathf.Abs(agent.gameObject.transform.position.z) > LimitZ)
        {
//TAG: MakeEvent             myArea.Logger.Log(String.Concat("LeavePlayArea Reward", Amount));
            //TAG: MakeEvent  myArea.Logger.Log(Logger.CreateMessage(LogMessageType.Agent, AgentLeaveMessage), agent);
            agent.AddReward(Amount);
            isOut = true;
        }

        if (isOut && Wrap)
        {
            agent.gameObject.transform.position = new Vector3(
                FuckCSharpModulo(agent.gameObject.transform.position.x + LimitX, LimitX * 2) - LimitX,
                FuckCSharpModulo(agent.gameObject.transform.position.y + LimitY, LimitY * 2) - LimitY,
                FuckCSharpModulo(agent.gameObject.transform.position.z + LimitZ, LimitZ * 2) - LimitZ
                );
        }

        if (isOut && Done)
        {
            agent.Done();
        }

        if (isOut && Reset)
        {
            agent.Reset();
        }
    }
Beispiel #6
0
    public override void AddReward(BaseAgent agent, float[] vectorActions)
    {
        bool isOut = false;

        if ((new Vector2(agent.transform.position.x, agent.transform.position
                         .z)).sqrMagnitude > LimitRadius * LimitRadius)
        {
            agent.AddReward(Amount);
            isOut = true;
        }

        if (Mathf.Abs(agent.gameObject.transform.localPosition.y - PositionY) > LimitY)
        {
            agent.AddReward(Amount);
            isOut = true;
        }

        if (isOut && Reset)
        {
            agent.Done();
            agent.Reset();
        }
    }
    public override void AddReward(BaseAgent agent, float[] vectorActions)
    {
        if (TagAGameObject == null || TagBGameObject == null)
        {
            FindTags(agent);
        }
        else
        {
            float sqrmag       = (TagAGameObject.transform.position - TagBGameObject.transform.position).sqrMagnitude;
            float byMaxDist    = sqrmag / (MaxDistance * MaxDistance);
            float scaledReward = Mathf.Max((1 - byMaxDist) * Reward, 0) / Mathf.Max((float)agent.agentParameters.maxStep, 1);
            agent.AddReward(scaledReward);

            if (agent.area.EventSystem != null)
            {
                agent.area.EventSystem.RaiseEvent(DistanceEvent.Create(agent.gameObject, sqrmag));
            }
        }
    }
Beispiel #8
0
    public override void AddReward(BaseAgent agent, float[] vectorActions)
    {
        Mult = AcademyParameters.Update(academy, MultKeyVal, Mult);
        agent.TriggerCollider
        .Filter(tc => tc != null)
        .Filter(tc => tc.gameObject.tag == "consumable")
        .MatchSome(tc => {
            GameObject go         = tc.gameObject;
            Consumable consumable = go.GetComponent <Consumable>();
            agent.AddReward(consumable.value * Mult);

            SpawnDistance         = AcademyParameters.Update(academy, SpawnDistanceKeyVal, SpawnDistance);
            Vector2 pos           = new Vector2(Random.Range(-SpawnDistance, SpawnDistance), Random.Range(-SpawnDistance, SpawnDistance));
            go.transform.position = new Vector3(pos.x, go.transform.position.y, pos.y);

            if (agent.area.EventSystem != null)
            {
                agent.area.EventSystem.RaiseEvent(ConsumableEvent.Create(agent.gameObject, consumable.value, tc.transform.position));
            }
        });
    }
    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();
            }
        }
    }
Beispiel #10
0
 public override void AddReward(BaseAgent agent, float[] vectorActions)
 {
     agent.AddReward(Mathf.Abs(vectorActions[ForwardIdx]) * MultiplierForward / (float)agent.agentParameters.maxStep);
     agent.AddReward(Mathf.Abs(vectorActions[RightIdx]) * MultiplierRight / (float)agent.agentParameters.maxStep);
     agent.AddReward(Mathf.Abs(vectorActions[TurnIdx]) * MultiplierTurn / (float)agent.agentParameters.maxStep);
 }
 public override void AddReward(BaseAgent agent, float[] vectorAction)
 {
     Amount = AcademyParameters.Update(academy, AmountKeyVal, Amount);
     agent.AddReward(Amount / (float)agent.agentParameters.maxStep);
 }
    public override void AddReward(BaseAgent agent, float[] vectorActions)
    {
        Reward           = AcademyParameters.Update(academy, RewardKeyVal, Reward);
        ContinuousReward = AcademyParameters.Update(academy, ContinuousRewardKeyVal, ContinuousReward);
        Penalty          = AcademyParameters.Update(academy, PenaltyKeyVal, Penalty);

        float labelValue;

        switch (LabelValue)
        {
        case LabelValueType.Boolean: labelValue = 1; break;

        case LabelValueType.Time: labelValue = Time.time; break;

        default: labelValue = 0; break;
        }


        Option <GameObject> triggerColCont =
            agent.TriggerCollider
            .Filter(tc => tc != null)
            .Map(tc => tc.gameObject)
            .Filter(gob => gob.tag == Tag);

        Option <Collider> prevFrame = PreviousFrame.Filter(p => p != null);

        Option <GameObject> triggerCol =
            triggerColCont
            .Filter(tc => !tc.SomeNotNull().Equals(prevFrame.Map(p => p.gameObject)));

        triggerCol
        .MatchSome(_ => {
            if (AgentCollisionMessage != "")
            {
                //TAG: MakeEvent myArea.Logger.Log(Logger.CreateMessage(LogMessageType.Agent, AgentCollisionMessage), agent);
            }

            //TAG: MakeEvent myArea.Logger.Log(String.Concat("Tagged ", agent.transform.position.y));
        });

        triggerColCont.MatchSome(_ => {
            agent.AddReward(ContinuousReward);
        });

        prevFrame
        .Filter(pc => triggerColCont.HasValue)
        .FlatMap(pc => pc.GetComponent <ObservableFields>().SomeNotNull())
        .MatchSome(lc => {
            if (RemoveOnLeave)
            {
                //TAG: MakeEvent myArea.Logger.Log(String.Concat("Removing label on leave ", Label));
                lc.FieldsHash.Remove(Label);
            }
        });

        triggerCol
        .Map(tc => tc.gameObject)
        .MatchSome(go => {
            ObservableFields lc = go.GetComponent <ObservableFields>();
            if ((lc == null || !lc.FieldsHash.ContainsKey(LabelPrevents)) && NewTag != "")
            {
                //TAG: MakeEvent myArea.Logger.Log(String.Concat("Adding tag ", NewTag));
                go.tag = NewTag;
                agent.area.EventSystem.RaiseEvent(TagEvent.Create(go));
                agent.area.EventSystem.RaiseEvent(TaggingEvent.Create(agent.gameObject, NewTag));
            }
        });

        ObservableFields selfFields = agent.gameObject.GetComponent <ObservableFields>();

        triggerCol
        .FlatMap(tc => tc.GetComponent <ObservableFields>().SomeNotNull())
        .MatchSome(lc => {
            if (lc.FieldsHash.ContainsKey(Label) && Time.time - lc.FieldsHash[Label] < Cooldown
                )
            {
                //TAG: MakeEvent myArea.Logger.Log(String.Concat("already there ", Label));
                if (Toggle)
                {
                    //TAG: MakeEvent myArea.Logger.Log(String.Concat("Removing label ", Label));
                    lc.FieldsHash.Remove(Label);
                }

                //TAG: MakeEvent myArea.Logger.Log(String.Concat("Penalizing already there ", Penalty));
                agent.AddReward(Penalty);

                if (DoneIfAlreadyThere)
                {
                    //TAG: MakeEvent myArea.Logger.Log(String.Concat("Done already there ", agent.gameObject.tag));
                    agent.Done();
                }

                if (ResetAreaIfAlreadyThere)
                {
                    //TAG: MakeEvent myArea.Logger.Log(String.Concat("Resetting already there ", agent.gameObject.tag));
                    myArea.ResetArea();
                }
            }
            else if (!lc.FieldsHash.ContainsKey(LabelPrevents) && !lc.FieldsHash.ContainsKey(Label) &&
                     (CooldownSelfTag == "" || selfFields == null || !selfFields.FieldsHash.ContainsKey(CooldownSelfTag) ||
                      Time.time - selfFields.FieldsHash[CooldownSelfTag] < Cooldown))
            {
                //TAG: MakeEvent myArea.Logger.Log(String.Concat("Adding reward ", Reward));
                agent.AddReward(Reward);
                if (Label != "")
                {
                    //TAG: MakeEvent myArea.Logger.Log(String.Concat("Adding label ", Label));
                    lc.FieldsHash.Add(Label, labelValue);
                }
            }
        });

        triggerCol
        .Filter((GameObject go) => Remove)
        .MatchSome(tc => GameObject.Destroy(tc));

        triggerCol
        .Filter((GameObject go) => Done)
        .MatchSome(_ => agent.Done());

        triggerCol
        .Filter((GameObject go) => Reset)
        .MatchSome(_ => {
            //TAG: MakeEvent myArea.Logger.Log(String.Concat("Reset on collide ", Tag));
            agent.Reset();
        });

        triggerCol
        .Filter((GameObject go) => ResetArea)
        .MatchSome(_ => myArea.ResetArea());

        PreviousFrame = agent.TriggerCollider;

        PreviousFrameTag = agent.gameObject.tag;
    }