Example #1
0
    private void ReplicateAgent(GameObject original)
    {
        if (original == null)
        {
            return;
        }

        DestroyAllChildren();
        original.SetActive(true);
        for (int i = 0; i < base_net.AgentsPerGeneration; ++i)
        {
            GameObject agentObject = GameObject.Instantiate <GameObject>(original);
            childrenGOs.Add(agentObject);
        }
        for (int i = 0; i < childrenGOs.Count; ++i)
        {
            ANNAgent agent = childrenGOs[i].GetComponent <ANNAgent>();
            agent.network = base_net.Instanciate();
            if (i == 0 || i == 1)
            {
                agent.network.loadFromBest = true;
            }
            StartAgent(agent);
        }
        original.SetActive(false);
    }
Example #2
0
    public override void OnInspectorGUI()
    {
        if (target.GetType() != typeof(ANNAgent))
        {
            GUILayout.Label("       ------ Script ------", EditorStyles.boldLabel);
            DrawDefaultInspector();
        }

        GUILayout.Label("       ------ Agent ------", EditorStyles.boldLabel);

        ANNAgent   comp   = (ANNAgent)target;
        ANNNetwork auxNet = null;

        auxNet = (ANNNetwork)EditorGUILayout.ObjectField("Network:", comp.network, typeof(ANNNetwork), true);
        if (auxNet != comp.network)
        {
            comp.network = auxNet;
            if (auxNet != null)
            {
                comp.network.agent = comp;
            }
        }

        GUILayout.Label("       ------ Network ------", EditorStyles.boldLabel);
        showNetInspector = EditorGUILayout.Toggle("Show Network Inpector:", showNetInspector);
        if (showNetInspector)
        {
            if (comp.network != null)
            {
                ANNNetworkInspector.DrawInspector(comp.network);
            }
        }
    }
Example #3
0
    /// !_USER METHODS /// ------------------------------------------------------------------------------------------------

    public ANNNetwork CreateChild(ANNAgent agent)
    {
        ANNNetwork child = this.Instanciate();

        child.LoadNetwork(false, true);
        child.agent = agent;
        children.Add(child);
        return(child);
    }
Example #4
0
    // Use this for initialization
    void Start()
    {
        if (Application.isPlaying)
        {
            base_agent = AgentPrefab.GetComponent <ANNAgent>();
            if (base_agent == null)
            {
                Debug.LogError("ANNAcademy => Trying to use an AgentPrefab without an ANNAgent Component.");
                return;
            }
            base_net         = base_agent.network;
            base_net.topBest = 0;

            switch (base_net.TrainingType)
            {
            case ANNNetwork.ANNNetworkTrainingType.MultiAgent:              // MULTI
                ReplicateAgent(AgentPrefab);
                break;

            case ANNNetwork.ANNNetworkTrainingType.SingleAgent:             // SINGLE
                AgentPrefab.SetActive(true);
                StartAgent(base_agent);
                break;
            }
        }
        else if (Application.isEditor)
        {
            if (AgentPrefab != null)
            {
                base_agent = AgentPrefab.GetComponent <ANNAgent>();
                if (base_agent != null)
                {
                    base_net = base_agent.network;
                    base_net.LoadNetwork(true, true);
                }
            }
        }
    }
Example #5
0
 private void StartAgent(ANNAgent agent)
 {
     agent.StartAgent();
     agent.Start();
 }