public void AgentAddRewardDirectly(float reward)
 {
     if (this.isScriptValid() && this.getScriptType() == "AgentScript")
     {
         AgentScript.AddReward(reward);
     }
 }
    public void Apply(AgentScript Agent)
    {
        float allReward = 0;

        foreach (float i in bag.ToArray())
        {
            allReward += i;
        }
        Agent.AddReward(allReward);
        BagReset();
    }
    // Update is called once per frame
    public void shoot()
    {
        areaScript  = transform.parent.parent.GetComponentInParent <AreaScript>();
        agentScript = transform.parent.parent.GetComponent <AgentScript>();
        if (Physics.Raycast(transform.position, transform.forward, out RaycastHit hit, 15))
        {
            GameObject shot = hit.transform.gameObject;
            if (shot.CompareTag("enemy"))
            {
                areaScript.DestroyEnemy(shot);
                Debug.Log("Hit Enemy");
            }

            else
            {
                agentScript.AddReward(-0.0002f);
            }
        }
Example #4
0
    public void DestroyEnemy(GameObject enemy)
    {
        GameObject  agent       = transform.Find("Agent").gameObject;
        AgentScript agentScript = agent.GetComponent <AgentScript>();

        for (int i = 0; i < enemylist.Count; i++)
        {
            if (GameObject.ReferenceEquals(enemylist[i], enemy))
            {
                Destroy(enemylist[i]);
                enemylist.Remove(enemylist[i]);
                agentScript.AddReward(1f);
            }
        }

        if (enemylist.Count == 0)
        {
            //agentScript.AddReward(5f);
            agentScript.EndEpisode();
        }
    }