Beispiel #1
0
    //public BrainParameters brain;
    //public AgentParameters agentParameters;


    void CreateAgents()
    {
        Debug.Log("CreateAgents called - CmvAgMan activating");
        var pp = new ParmProcessor();

#if UNITY_EDITOR
        pp.SetPreset("p1:par  p2:2.3  p3:3 p4:true p5:false p6");// for testing
#endif
        pp.Process();
        //pp.Dump();
        cmvSettings = GameObject.FindObjectOfType <CmvSettings>();
        area        = transform.parent.gameObject;
        ground      = area.transform.Find("Ground").gameObject;
        redGoal     = area.transform.Find("redGoal").gameObject;

        for (var i = 0; i < nagents; i++)
        {
            var agnum = i.ToString("D2");
            var aname = $"Agent-{agmanPrefix}-{agnum}";
            Debug.Log("Creating agent " + aname);
            var ago = new GameObject(aname);

            //dr.Awake();
            //ago.SetActive(false); // if we don't do this it gets enable events too soon (before we can init AgentParameters)
            ago.transform.parent = this.transform;
            var cmvag = ago.AddComponent <CmvAgent>();
            var dr    = ago.AddComponent <DecisionRequester>();
            dr.DecisionPeriod = 6;
            dr.TakeActionsBetweenDecisions = true;

            cmvag.rayPer = ago.AddComponent <RayPerceptionSensorComponent3D>();
            cmvag.rayPer.detectableTags = new List <string>()
            {
                "redGoal", "agent", "wall", "wall", "wall"
            };
            cmvag.rayPer.raysPerDirection = 2;// rays to the left or right
            cmvag.rayPer.CreateSensor();

            cmvag.LazyInitialize();
            cmvag.SetupAgent(this);
            //ago.SetActive(true);// causes agent's InitializeAgent() to be called
        }
        CrowdManInitAgents();

        Debug.Log("CreateAgents finished");
    }
Beispiel #2
0
    void CreateAgents()
    {
        Debug.Log("CreateAgents called - CmvAgMan activating");
        var pp = new ParmProcessor();

#if UNITY_EDITOR
        pp.SetPreset("p1:par  p2:2.3  p3:3 p4:true p5:false p6");// for testing
#endif
        pp.Process();
        //pp.Dump();
        area   = transform.parent.gameObject;
        ground = area.transform.Find("Ground").gameObject;
        //Debug.Log("Found ground");
        redGoal = area.transform.Find("redGoal").gameObject;
        //Debug.Log("Found redGoal");
        agentParameters                  = new AgentParameters();
        agentParameters.maxStep          = 3000;
        agentParameters.resetOnDone      = true;
        agentParameters.onDemandDecision = false;
        agentParameters.numberOfActionsBetweenDecisions = 6;
        var ap = agentParameters;

        var bp = brain;

        Debug.Log("AreaInit " + nagents + " agents " + name + " maxStep:" + ap.maxStep + " " +
                  bp.vectorActionSpaceType + " vos:" + bp.vectorObservationSize + " vas:" + bp.vectorActionSize.Length);
        for (var i = 0; i < nagents; i++)
        {
            var aname = "Agent" + i.ToString("D2");
            Debug.Log("Creating agent " + aname);
            var ago = new GameObject(aname);

            //ago.SetActive(false); // if we don't do this it gets enable events too soon (before we can init AgentParameters)
            ago.transform.parent = this.transform;
            var cmvag = ago.AddComponent <CmvAgent>();
            cmvag.SetupAgent(this);
            //ago.SetActive(true);// causes agent's InitializeAgent() to be called
        }
        CrowdManInitAgents();

        Debug.Log("CreateAgents finished");
    }