Exemple #1
0
        void Reset()
        {
            if (playground.agentA.score > playground.levelOne && playground.agentB.score > playground.levelOne)
            {
            }

            var px = 8f; // Random.Range(-playground.HalfSize.x, playground.HalfSize.x) > 0 ? 8f : -8f;
            var py = 2f; //Random.Range(4f, playground.HalfSize.y);//
            var pz = 0f; // Random.Range(-playground.HalfSize.z, playground.HalfSize.z);

            transform.localPosition = new Vector3(px, py, pz);

            var vx = -12.6f; // (px > 0f ? -1f:1f) * Random.Range(velocityMinInit.x, velocityMax.x); // * 14f; //
            var vy = 3.5f;   // Random.Range(velocityMinInit.y, velocityMax.y); // 3.5f;//
            var vz = -3f;    // Random.Range(velocityMinInit.z, velocityMax.z);

            rb.velocity = new Vector3(vx, vy, vz);

            playground.agentA.EndEpisode();
            playground.agentB.EndEpisode();
            playground.agentA2.EndEpisode();
            playground.agentB2.EndEpisode();
            lastFloorHit = FloorHit.Service;
            lastHitAgent = null;
            net          = false;
        }
 void Reset()
 {
     m_AgentA.Done();
     m_AgentB.Done();
     m_Area.MatchReset();
     lastFloorHit = FloorHit.Service;
     net          = false;
 }
Exemple #3
0
 void Reset()
 {
     m_AgentA.EndEpisode();
     m_AgentB.EndEpisode();
     m_Area.MatchReset();
     lastFloorHit = FloorHit.Service;
     net          = false;
 }
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.CompareTag("Brick"))
     {
         BrickHit?.Invoke(collision.gameObject);
     }
     else if (collision.gameObject.CompareTag("Floor"))
     {
         FloorHit?.Invoke();
     }
 }
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("iWall"))
        {
            if (collision.gameObject.name == "wallA")
            {
                // Agent A hits into wall or agent B hit a winner
                if (lastAgentHit == 0 || lastFloorHit == FloorHit.FloorAHit)
                {
                    AgentBWins();
                }
                // Agent B hits long
                else
                {
                    AgentAWins();
                }
            }
            else if (collision.gameObject.name == "wallB")
            {
                // Agent B hits into wall or agent A hit a winner
                if (lastAgentHit == 1 || lastFloorHit == FloorHit.FloorBHit)
                {
                    AgentAWins();
                }
                // Agent A hits long
                else
                {
                    AgentBWins();
                }
            }
            else if (collision.gameObject.name == "floorA")
            {
                // Agent A hits into floor, double bounce or service
                if (lastAgentHit == 0 || lastFloorHit == FloorHit.FloorAHit || lastFloorHit == FloorHit.Service)
                {
                    AgentBWins();
                }
                else
                {
                    lastFloorHit = FloorHit.FloorAHit;
                    //successful serve
                    if (!net)
                    {
                        net = true;
                    }
                }
            }
            else if (collision.gameObject.name == "floorB")
            {
                // Agent B hits into floor, double bounce or service
                if (lastAgentHit == 1 || lastFloorHit == FloorHit.FloorBHit || lastFloorHit == FloorHit.Service)
                {
                    AgentAWins();
                }
                else
                {
                    lastFloorHit = FloorHit.FloorBHit;
                    //successful serve
                    if (!net)
                    {
                        net = true;
                    }
                }
            }
            else if (collision.gameObject.name == "net" && !net)
            {
                if (lastAgentHit == 0)
                {
                    AgentBWins();
                }
                else if (lastAgentHit == 1)
                {
                    AgentAWins();
                }
            }
        }
        else if (collision.gameObject.name == "AgentA")
        {
            // Agent A double hit
            if (lastAgentHit == 0)
            {
                AgentBWins();
            }
            else
            {
                //agent can return serve in the air
                if (lastFloorHit != FloorHit.Service && !net)
                {
                    net = true;
                }

                lastAgentHit = 0;
                lastFloorHit = FloorHit.FloorHitUnset;
            }
        }
        else if (collision.gameObject.name == "AgentB")
        {
            // Agent B double hit
            if (lastAgentHit == 1)
            {
                AgentAWins();
            }
            else
            {
                if (lastFloorHit != FloorHit.Service && !net)
                {
                    net = true;
                }

                lastAgentHit = 1;
                lastFloorHit = FloorHit.FloorHitUnset;
            }
        }
    }
Exemple #6
0
        void OnCollisionEnter(Collision collision)
        {
            currentCollision = collision;
            if (CollisionEnter != null)
            {
                CollisionEnter(collision, "Enter");
            }

            if (collision.gameObject.CompareTag("iWall"))
            {
                if (collision.gameObject.name == "wallA")
                {
                    // Agent A hits into wall or agent B hit a winner
                    if ((lastHitAgent && !lastHitAgent.invertX) ||
                        lastFloorHit == FloorHit.FloorAHit)
                    {
                        if (lastHitAgent && lastHitAgent.invertX) // agent B hit a winner
                        {
                            lastHitAgent.Wins();
                        }
                        else                      // Agent A hits into wall
                        {
                            AgentBWins();
                        }
                    }
                    // Agent B hits long
                    else // if (lastAgentHit == AgentRole.B)
                    {
                        AgentAWins();
                    }
                    Reset();
                }
                else if (collision.gameObject.name == "wallB")
                {
                    // Agent B hits into wall or agent A hit a winner
                    if ((lastHitAgent && lastHitAgent.invertX) ||
                        lastFloorHit == FloorHit.FloorBHit)
                    {
                        if (lastHitAgent && !lastHitAgent.invertX) // agent A hit a winner
                        {
                            lastHitAgent.Wins();
                        }
                        else                      // Agent B hits into wall
                        {
                            AgentAWins();
                        }
                    }
                    // Agent A hits long
                    else // if (lastAgentHit == AgentRole.A)
                    {
                        AgentBWins();
                    }
                    Reset();
                }
                else if (collision.gameObject.name == "floorA")
                {
                    // Agent A hits into floor, double bounce or service
                    if (lastFloorHit == FloorHit.FloorAHit    // double bounce
                        // || lastFloorHit == FloorHit.Service
                        )
                    {
                        if (lastHitAgent && lastHitAgent.invertX) // agent B hit a winner
                        {
                            lastHitAgent.Wins();
                        }
                        else                      // Agent A hits into floor
                        {
                            AgentBWins();
                        }
                        Reset();
                    }
                    else
                    {
                        lastFloorHit = FloorHit.FloorAHit;
                    }
                }
                else if (collision.gameObject.name == "floorB")
                {
                    // Agent B hits into floor, double bounce or service
                    if (lastFloorHit == FloorHit.FloorBHit
                        // || lastFloorHit == FloorHit.Service
                        )
                    {
                        if (lastHitAgent && !lastHitAgent.invertX) // agent A hit a winner
                        {
                            lastHitAgent.Wins();
                        }
                        else                      // Agent B hits into floor
                        {
                            AgentAWins();
                        }
                        Reset();
                    }
                    else
                    {
                        lastFloorHit = FloorHit.FloorBHit;
                    }
                }
                else if (collision.gameObject.name == "net")
                {
                    if (lastHitAgent && !lastHitAgent.invertX)
                    {
                        AgentBWins();
                    }
                    else // if (lastAgentHit == AgentRole.B)
                    {
                        AgentAWins();
                    }
                }
            }
            else if (collision.gameObject.CompareTag("agent"))
            {
                var agent = collision.gameObject.GetComponent <TennisAgentA>();
                agent.AddReward(0.6f);
                ++agent.hitCount;
                if (!agent.invertX) // A
                {
                    // Agent A double hit
                    if (lastHitAgent && !lastHitAgent.invertX)
                    {
                        AgentBWins();
                    }
                    else
                    {
                        lastFloorHit = FloorHit.FloorHitUnset;
                    }
                }
                else // if (collision.gameObject.name == "AgentB")
                {
                    // Agent B double hit
                    if (lastHitAgent && lastHitAgent.invertX)
                    {
                        AgentAWins();
                    }
                    else
                    {
                        lastFloorHit = FloorHit.FloorHitUnset;
                    }
                }
                lastHitAgent = agent;
            }
        }