Exemplo n.º 1
0
 void Start()
 {
     // Get the ground's bounds
     areaBounds = ground.GetComponent <Collider>().bounds;
     // Get the ground renderer so we can change the material when a goal is scored
     m_GroundRenderer = ground.GetComponent <Renderer>();
     // Starting material
     m_GroundMaterial    = m_GroundRenderer.material;
     m_PushBlockSettings = FindObjectOfType <PushBlockSettings>();
     // Initialize Blocks
     foreach (var item in BlocksList)
     {
         item.StartingPos = item.T.transform.position;
         item.StartingRot = item.T.transform.rotation;
         item.Rb          = item.T.GetComponent <Rigidbody>();
     }
     // Initialize TeamManager
     m_AgentGroup = new SimpleMultiAgentGroup();
     foreach (var item in AgentsList)
     {
         item.StartingPos = item.Agent.transform.position;
         item.StartingRot = item.Agent.transform.rotation;
         item.Rb          = item.Agent.GetComponent <Rigidbody>();
         m_AgentGroup.RegisterAgent(item.Agent);
     }
     ResetScene();
 }
        public void TestRegisteredAgentGroupId()
        {
            var agentGo = new GameObject("TestAgent");

            agentGo.AddComponent <TestAgent>();
            var agent = agentGo.GetComponent <TestAgent>();

            // test register
            SimpleMultiAgentGroup agentGroup1 = new SimpleMultiAgentGroup();

            agentGroup1.RegisterAgent(agent);
            Assert.AreEqual(agentGroup1.GetId(), agent._GroupId);
            Assert.IsNotNull(agent._OnAgentDisabledActions);

            // should not be able to registered to multiple groups
            SimpleMultiAgentGroup agentGroup2 = new SimpleMultiAgentGroup();

            Assert.Throws <UnityAgentsException>(
                () => agentGroup2.RegisterAgent(agent));
            Assert.AreEqual(agentGroup1.GetId(), agent._GroupId);

            // test unregister
            agentGroup1.UnregisterAgent(agent);
            Assert.AreEqual(0, agent._GroupId);
            Assert.IsNull(agent._OnAgentDisabledActions);

            // test register to another group after unregister
            agentGroup2.RegisterAgent(agent);
            Assert.AreEqual(agentGroup2.GetId(), agent._GroupId);
            Assert.IsNotNull(agent._OnAgentDisabledActions);
        }
Exemplo n.º 3
0
    void Start()
    {
        TeamRed  = new SimpleMultiAgentGroup();
        TeamBlue = new SimpleMultiAgentGroup();

        ballRb       = ball.GetComponent <Rigidbody>();
        oriPosofBall = new Vector3(ball.transform.position.x, ball.transform.position.y, ball.transform.position.z);


        foreach (var item in AgentsList)
        {
            item.originPos = item.Agent.transform.position;
            item.originRot = item.Agent.transform.rotation;
            item.Rb        = item.Agent.GetComponent <Rigidbody>();

            if (item.Agent.team == Team.Red)
            {
                TeamRed.registerAgent(item.Agent);
            }
            else
            {
                TeamBlue.RegisterAgent(item.Agent);
            }
        }
        ResetScene();
    }
    void ResetScene()
    {
        m_ResetTimer = 0;

        carLst       = new List <MLCar>();
        m_AgentGroup = new SimpleMultiAgentGroup();

        Extension.Shuffle(goals);

        for (int i = 0; i < count; i++)
        {
            // Random target
            int target = 0;
            do
            {
                target = Random.Range(0, goals.Count);
            } while (target == i);

            //item.selfTransfrom.SetPositionAndRotation(goals[index].position, goals[index].rotation);

            //a.target = goals[target];
            Debug.Log("Player" + i + " - " + goals[i].name + ", " + goals[target].name);

            var t = Instantiate(car);
            t.parent = transform.parent;
            var a = t.GetComponent <MLCar>();
            carLst.Add(a);
            a.Setup(this, i, goals[target]);
            m_AgentGroup.RegisterAgent(a);
            a.SetPosition(goals[i].position, goals[i].rotation);
        }
        //Debug.Log(m_AgentGroup.GetRegisteredAgents().Count);

        activeCars = count;
    }
        public void TestGroupIdCounter()
        {
            SimpleMultiAgentGroup group1 = new SimpleMultiAgentGroup();
            SimpleMultiAgentGroup group2 = new SimpleMultiAgentGroup();

            // id should be unique
            Assert.AreNotEqual(group1.GetId(), group2.GetId());
        }
Exemplo n.º 6
0
 private void Start()
 {
     foreach (var a in _agents)
     {
         if (!_teams.ContainsKey(a.TeamID))
         {
             var smag = new SimpleMultiAgentGroup();
             smag.RegisterAgent(a);
             _teams.Add(a.TeamID, smag);
         }
         else
         {
             _teams[a.TeamID].RegisterAgent(a);
         }
         a.Manager = this;
     }
     BeginGroupEpisode();
 }
        public void TestRegisterMultipleAgent()
        {
            var agentGo1 = new GameObject("TestAgent");

            agentGo1.AddComponent <TestAgent>();
            var agent1   = agentGo1.GetComponent <TestAgent>();
            var agentGo2 = new GameObject("TestAgent");

            agentGo2.AddComponent <TestAgent>();
            var agent2 = agentGo2.GetComponent <TestAgent>();

            SimpleMultiAgentGroup agentGroup = new SimpleMultiAgentGroup();

            agentGroup.RegisterAgent(agent1);   // register
            Assert.AreEqual(agentGroup.GetRegisteredAgents().Count, 1);
            agentGroup.UnregisterAgent(agent2); // unregister non-member agent
            Assert.AreEqual(agentGroup.GetRegisteredAgents().Count, 1);
            agentGroup.UnregisterAgent(agent1); // unregister
            Assert.AreEqual(agentGroup.GetRegisteredAgents().Count, 0);
            agentGroup.RegisterAgent(agent1);
            agentGroup.RegisterAgent(agent1); // duplicated register
            Assert.AreEqual(agentGroup.GetRegisteredAgents().Count, 1);
            agentGroup.RegisterAgent(agent2); // register another
            Assert.AreEqual(agentGroup.GetRegisteredAgents().Count, 2);

            // test add/set group rewards
            agentGroup.AddGroupReward(0.1f);
            Assert.AreEqual(0.1f, agent1._GroupReward);
            agentGroup.AddGroupReward(0.5f);
            Assert.AreEqual(0.6f, agent1._GroupReward);
            agentGroup.SetGroupReward(0.3f);
            Assert.AreEqual(0.3f, agent1._GroupReward);
            // unregistered agent should not receive group reward
            agentGroup.UnregisterAgent(agent1);
            agentGroup.AddGroupReward(0.2f);
            Assert.AreEqual(0.3f, agent1._GroupReward);
            Assert.AreEqual(0.5f, agent2._GroupReward);

            // dispose group should automatically unregister all
            agentGroup.Dispose();
            Assert.AreEqual(0, agent1._GroupId);
            Assert.AreEqual(0, agent2._GroupId);
        }
    void Start()
    {
        // Get the ground's bounds
        areaBounds = ground.GetComponent <Collider>().bounds;
        // Get the ground renderer so we can change the material when a goal is scored
        m_GroundRenderer = ground.GetComponent <Renderer>();
        // Starting material
        m_GroundMaterial    = m_GroundRenderer.material;
        m_PushBlockSettings = FindObjectOfType <PushBlockSettings>();

        //Reset Players Remaining
        m_NumberOfRemainingPlayers = AgentsList.Count;

        //Hide The Key
        Key.SetActive(false);

        // Initialize TeamManager
        m_AgentGroup = new SimpleMultiAgentGroup();
        foreach (var item in AgentsList)
        {
            item.StartingPos = item.Agent.transform.position;
            item.StartingRot = item.Agent.transform.rotation;
            item.Rb          = item.Agent.GetComponent <Rigidbody>();
            item.Col         = item.Agent.GetComponent <Collider>();
            // Add to team manager
            m_AgentGroup.RegisterAgent(item.Agent);
        }
        foreach (var item in DragonsList)
        {
            item.StartingPos = item.Agent.transform.position;
            item.StartingRot = item.Agent.transform.rotation;
            item.T           = item.Agent.transform;
            item.Col         = item.Agent.GetComponent <Collider>();
        }

        ResetScene();
    }
Exemplo n.º 9
0
 void Start()
 {
     m_SoccerSettings = FindObjectOfType <SoccerSettings>();
     // Initialize TeamManager
     m_BlueAgentGroup   = new SimpleMultiAgentGroup();
     m_PurpleAgentGroup = new SimpleMultiAgentGroup();
     ballRb             = ball.GetComponent <Rigidbody>();
     m_BallStartingPos  = new Vector3(ball.transform.position.x, ball.transform.position.y, ball.transform.position.z);
     foreach (var item in AgentsList)
     {
         item.StartingPos = item.Agent.transform.position;
         item.StartingRot = item.Agent.transform.rotation;
         item.Rb          = item.Agent.GetComponent <Rigidbody>();
         if (item.Agent.team == Team.Blue)
         {
             m_BlueAgentGroup.RegisterAgent(item.Agent);
         }
         else
         {
             m_PurpleAgentGroup.RegisterAgent(item.Agent);
         }
     }
     ResetScene();
 }