Example #1
0
    // Use this for initialization
    void Start()
    {
        rb   = GetComponent <Rigidbody>();
        nnai = GetComponent <NNAI>();
        //Direction = new Vector3(UnityEngine.Random.Range(-1, 2) * Step, 0.0f, UnityEngine.Random.Range(-1,2) * Step);
        tree     = new TreeOfDecisions(this);
        decision = nnai.GetDecision();
        tree.WalkWith(decision);
        Direction           = nnai.GetDirection();
        deadEndAgentCounter = DeadEndAgentCounterValue;


        //Vector3 j = new Vector3(-0.5f, 0, 0.5f);
        //j = j.normalized;
        //proc(j.x, j.z);
        //j = new Vector3(-0.5f, 0, -0.5f);
        //j = j.normalized;
        //proc(j.x, j.z);
        //j = new Vector3(0.5f, 0, 0.5f);
        //j = j.normalized;
        //proc(j.x, j.z);
        //j = new Vector3(0.5f, 0, -0.5f);
        //j = j.normalized;
        //proc(j.x, j.z);
    }
Example #2
0
 void Awake()
 {
     nnAIInstance = this;
 }
Example #3
0
    public void StartNewSimulation()
    {
        //simulation preparation
        //remove resources
        foreach (ResourceController res in resources)
        {
            if (res != null)
            {
                RemoveResourceUnit(res.gameObject);
            }
        }
        //renew parameters

        WorldAge          = 0;
        AgentIdCounter    = 0;
        ResourceIdCounter = 0;

        //renew agentSample parameters
        AgentSample.SpreadBorder   = 20;
        AgentSample.ResourceAmount = 15;
        NNAI nnai = AgentSample.GetComponent <NNAI>();

        //HiddenLayerLength;
        //DecisionLearningRate = 1.0f;
        //DirectionLearningRate = 1.0f;
        //MutationRate = 0.1f;
        nnai.HiddenLayerLength     = (uint)Random.Range(2, 20);
        nnai.DecisionLearningRate  = Random.Range(0.01f, 10f);
        nnai.DirectionLearningRate = Random.Range(0.01f, 10f);
        nnai.MutationRate          = Random.Range(0.1f, 0.9f);
        foreach (SafeArea area in safeAreas)
        {
            area.Owner = null;
        }


        Path = @"c:\USBoNNA\" + SimulationNumber + @"\";
        if (Directory.Exists(Path))
        {
            SimulationNumber++;
            Start();
            //throw new MissingComponentException("There is such simulation cathalog. Choose another simulation number.");
        }
        else
        {
            Directory.CreateDirectory(Path);
            OverallResourceAmount = resources.Length;
            InitializeAgents();
            if (CalculateOverallResource() > resources.Length)
            {
                throw new MissingComponentException("There is more resources then intended");
            }

            InitializeResource();
            foreach (Agent n in agents)
            {
                if (n != null)
                {
                    n.GetComponent <NNAI>().Begin();
                }
            }
            PreStore();
        }

        Started = true;
        Timer.Begin();
    }