示例#1
0
    // Use this for initialization
    void Start()
    {
        area    = areaObject.GetComponent <TennisArea>();
        agentA1 = area.agentA1.GetComponent <TennisAgent>();
        agentB1 = area.agentB1.GetComponent <TennisAgent>();
        agentA2 = area.agentA2.GetComponent <TennisAgent>();
        agentB2 = area.agentB2.GetComponent <TennisAgent>();

        agentA1.setTeammate(agentA2);
        agentA2.setTeammate(agentA1);
        agentB1.setTeammate(agentB2);
        agentB2.setTeammate(agentB1);
    }
示例#2
0
    private void OnTriggerExit(Collider other)
    {
        TennisArea  area   = areaObject.GetComponent <TennisArea>();
        TennisAgent agentA = area.agentA.GetComponent <TennisAgent>();
        TennisAgent agentB = area.agentB.GetComponent <TennisAgent>();

        if (other.name == "over")
        {
            if (lastAgentHit == 0)
            {
                agentA.AddReward(0.1f);
            }
            else
            {
                agentB.AddReward(0.1f);
            }
            lastAgentHit = 0;
        }
    }
示例#3
0
 //  Use this for initialization
 void Start()
 {
     m_Area   = areaObject.GetComponent <TennisArea>();
     m_AgentA = m_Area.agentA.GetComponent <TennisAgent>();
     m_AgentB = m_Area.agentB.GetComponent <TennisAgent>();
 }
示例#4
0
    private void OnCollisionEnter(Collision collision)
    {
        TennisArea  area   = areaObject.GetComponent <TennisArea>();
        TennisAgent agentA = area.agentA.GetComponent <TennisAgent>();
        TennisAgent agentB = area.agentB.GetComponent <TennisAgent>();

        if (collision.gameObject.tag == "iWall")
        {
            if (collision.gameObject.name == "wallA")
            {
                if (lastAgentHit == 0)
                {
                    agentA.AddReward(-0.01f);
                    agentB.SetReward(0);
                    agentB.score += 1;
                }
                else
                {
                    agentA.SetReward(0);
                    agentB.AddReward(-0.01f);
                    agentA.score += 1;
                }
            }
            else if (collision.gameObject.name == "wallB")
            {
                if (lastAgentHit == 0)
                {
                    agentA.AddReward(-0.01f);
                    agentB.SetReward(0);
                    agentB.score += 1;
                }
                else
                {
                    agentA.SetReward(0);
                    agentB.AddReward(-0.01f);
                    agentA.score += 1;
                }
            }
            else if (collision.gameObject.name == "floorA")
            {
                if (lastAgentHit == 0 || lastAgentHit == -1)
                {
                    agentA.AddReward(-0.01f);
                    agentB.SetReward(0);
                    agentB.score += 1;
                }
                else
                {
                    agentA.AddReward(-0.01f);
                    agentB.SetReward(0);
                    agentB.score += 1;
                }
            }
            else if (collision.gameObject.name == "floorB")
            {
                if (lastAgentHit == 1 || lastAgentHit == -1)
                {
                    agentA.SetReward(0);
                    agentB.AddReward(-0.01f);
                    agentA.score += 1;
                }
                else
                {
                    agentA.SetReward(0);
                    agentB.AddReward(-0.01f);
                    agentA.score += 1;
                }
            }
            else if (collision.gameObject.name == "net")
            {
                if (lastAgentHit == 0)
                {
                    agentA.AddReward(-0.01f);
                    agentB.SetReward(0);
                    agentB.score += 1;
                }
                else
                {
                    agentA.SetReward(0);
                    agentB.AddReward(-0.01f);
                    agentA.score += 1;
                }
            }
            agentA.Done();
            agentB.Done();
            area.MatchReset();
        }

        if (collision.gameObject.tag == "agent")
        {
            if (collision.gameObject.name == "AgentA")
            {
                lastAgentHit = 0;
            }
            else
            {
                lastAgentHit = 1;
            }
        }
    }
    private void OnCollisionEnter(Collision collision)
    {
        TennisArea  area   = areaObject.GetComponent <TennisArea>();
        TennisAgent agentA = area.agentA.GetComponent <TennisAgent>();
        TennisAgent agentB = area.agentB.GetComponent <TennisAgent>();

        if (collision.gameObject.tag == "iWall")
        {
            if (collision.gameObject.name == "wallA")
            {
                if (lastAgentHit == 0)
                {
                    agentA.reward = -0.1f;
                    agentB.reward = 0;
                    agentB.score += 1;
                }
                else
                {
                    agentA.reward = 0;
                    agentB.reward = -0.1f;
                    agentA.score += 1;
                }
            }
            else if (collision.gameObject.name == "wallB")
            {
                if (lastAgentHit == 0)
                {
                    agentA.reward = -0.1f;
                    agentB.reward = 0;
                    agentB.score += 1;
                }
                else
                {
                    agentA.reward = 0;
                    agentB.reward = -0.1f;
                    agentA.score += 1;
                }
            }
            else if (collision.gameObject.name == "floorA")
            {
                if (lastAgentHit != 1)
                {
                    agentA.reward = -0.1f;
                    agentB.reward = 0;
                    agentB.score += 1;
                }
                else
                {
                    agentA.reward = -0.1f;
                    agentB.reward = 0.1f;
                    agentB.score += 1;
                }
            }
            else if (collision.gameObject.name == "floorB")
            {
                if (lastAgentHit == 0)
                {
                    agentA.reward = 0.1f;
                    agentB.reward = -0.1f;
                    agentA.score += 1;
                }
                else
                {
                    agentA.reward = 0;
                    agentB.reward = -0.1f;
                    agentA.score += 1;
                }
            }
            else if (collision.gameObject.name == "net")
            {
                if (lastAgentHit == 0)
                {
                    agentA.reward = -0.1f;
                    agentB.reward = 0.0f;
                    agentB.score += 1;
                }
                else
                {
                    agentA.reward = 0.0f;
                    agentB.reward = -0.1f;
                    agentA.score += 1;
                }
            }
            area.MatchReset();
            agentA.done = true;
            agentB.done = true;
        }

        if (collision.gameObject.tag == "agent")
        {
            if (collision.gameObject.name == "AgentA")
            {
                if (lastAgentHit != 0)
                {
                    agentA.reward += 0.1f;
                    agentB.reward += 0.05f;
                }
                else
                {
                    agentA.reward += 0.01f;
                }
                lastAgentHit = 0;
            }
            else
            {
                if (lastAgentHit != 1)
                {
                    agentB.reward += 0.1f;
                    agentA.reward += 0.05f;
                }
                else
                {
                    agentB.reward += 0.01f;
                }
                lastAgentHit = 1;
            }
        }
    }