コード例 #1
0
 void Reset()
 {
     m_AgentA.Done();
     m_AgentB.Done();
     m_Area.MatchReset();
     lastFloorHit = FloorHit.Service;
     net          = false;
 }
コード例 #2
0
    private void OnCollisionEnter(Collision collision)
    {
        debugAward("Start - Collision");
        if (collision.gameObject.CompareTag("iWall"))
        {
            if (collision.gameObject.name == "wallA")
            {
                agentA1.AddReward(-0.01f);
                agentA2.AddReward(-0.01f);
                agentB1.SetReward(0);
                agentB2.SetReward(0);
                agentB1.score += 1;
                agentB2.score  = agentB1.score;
                debugAward("Hit Wall A");
            }
            else if (collision.gameObject.name == "wallB")
            {
                agentA1.SetReward(0);
                agentA2.SetReward(0);
                agentB1.AddReward(-0.01f);
                agentB2.AddReward(-0.01f);
                agentA1.score += 1;
                agentA2.score  = agentA1.score;
                debugAward("Hit Wall B");
            }
            else if (collision.gameObject.name == "floorA")
            {
                agentA1.AddReward(-0.01f);
                agentA2.AddReward(-0.01f);
                agentB1.SetReward(0);
                agentB2.SetReward(0);
                agentB1.score += 1;
                agentB2.score  = agentB1.score;
                debugAward("Hit Floor A");
            }
            else if (collision.gameObject.name == "floorB")
            {
                agentA1.SetReward(0);
                agentA2.SetReward(0);
                agentB1.AddReward(-0.01f);
                agentB2.AddReward(-0.01f);
                agentA1.score += 1;
                agentA2.score  = agentA1.score;
                debugAward("Hit Floor B");
            }
            else if (collision.gameObject.name == "net")
            {
                switch (lastAgentHit)
                {
                case 0:
                    agentA1.AddReward(-0.01f);
                    agentA2.AddReward(-0.01f);
                    agentB1.SetReward(0);
                    agentB2.SetReward(0);
                    agentB1.score += 1;
                    agentB2.score  = agentB1.score;
                    break;

                case 1:
                    agentA1.AddReward(-0.01f);
                    agentA2.AddReward(-0.01f);
                    agentB1.SetReward(0);
                    agentB2.SetReward(0);
                    agentB1.score += 1;
                    agentB2.score  = agentB1.score;
                    break;

                case 2:
                    agentA1.SetReward(0);
                    agentA2.SetReward(0);
                    agentB1.AddReward(-0.01f);
                    agentB2.AddReward(-0.01f);
                    agentA1.score += 1;
                    agentA2.score  = agentA1.score;
                    break;

                case 3:
                    agentA1.SetReward(0);
                    agentA2.SetReward(0);
                    agentB1.AddReward(-0.01f);
                    agentB2.AddReward(-0.01f);
                    agentA1.score += 1;
                    agentA2.score  = agentA1.score;
                    break;

                default: break;
                }
                debugAward("Hit Net");
            }
            debugScore();
            agentA1.Done();
            agentA2.Done();
            agentB1.Done();
            agentB2.Done();
            area.MatchReset();
        }

        if (collision.gameObject.CompareTag("agent"))
        {
            //lastAgentHit = collision.gameObject.name == "AgentA" ? 0 : 1;
            switch (collision.gameObject.name)
            {
            case "AgentA1": lastAgentHit = 0; break;

            case "AgentA2": lastAgentHit = 1; break;

            case "AgentB1": lastAgentHit = 2; break;

            case "AgentB2": lastAgentHit = 3; break;
            }
            debugAward("Hit Agent");
        }
        debugAward("End - Collision");
    }
コード例 #3
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;
            }
        }
    }
コード例 #4
0
ファイル: HitWall.cs プロジェクト: Dushess0/Solar-Simulation
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("iWall"))
        {
            if (collision.gameObject.name == "wallA")
            {
                if (lastAgentHit == 0)
                {
                    m_AgentA.AddReward(-0.01f);
                    m_AgentB.SetReward(0);
                    m_AgentB.score += 1;
                }
                else
                {
                    m_AgentA.SetReward(0);
                    m_AgentB.AddReward(-0.01f);
                    m_AgentA.score += 1;
                }
            }
            else if (collision.gameObject.name == "wallB")
            {
                if (lastAgentHit == 0)
                {
                    m_AgentA.AddReward(-0.01f);
                    m_AgentB.SetReward(0);
                    m_AgentB.score += 1;
                }
                else
                {
                    m_AgentA.SetReward(0);
                    m_AgentB.AddReward(-0.01f);
                    m_AgentA.score += 1;
                }
            }
            else if (collision.gameObject.name == "floorA")
            {
                if (lastAgentHit == 0 || lastAgentHit == -1)
                {
                    m_AgentA.AddReward(-0.01f);
                    m_AgentB.SetReward(0);
                    m_AgentB.score += 1;
                }
                else
                {
                    m_AgentA.AddReward(-0.01f);
                    m_AgentB.SetReward(0);
                    m_AgentB.score += 1;
                }
            }
            else if (collision.gameObject.name == "floorB")
            {
                if (lastAgentHit == 1 || lastAgentHit == -1)
                {
                    m_AgentA.SetReward(0);
                    m_AgentB.AddReward(-0.01f);
                    m_AgentA.score += 1;
                }
                else
                {
                    m_AgentA.SetReward(0);
                    m_AgentB.AddReward(-0.01f);
                    m_AgentA.score += 1;
                }
            }
            else if (collision.gameObject.name == "net")
            {
                if (lastAgentHit == 0)
                {
                    m_AgentA.AddReward(-0.01f);
                    m_AgentB.SetReward(0);
                    m_AgentB.score += 1;
                }
                else
                {
                    m_AgentA.SetReward(0);
                    m_AgentB.AddReward(-0.01f);
                    m_AgentA.score += 1;
                }
            }
            m_AgentA.Done();
            m_AgentB.Done();
            m_Area.MatchReset();
        }

        if (collision.gameObject.CompareTag("agent"))
        {
            lastAgentHit = collision.gameObject.name == "AgentA" ? 0 : 1;
        }
    }