Exemple #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //Debug.Log(UnityEngine.Random.value);
        //Debug.Log(positiveChange + " " + negativeChange +" "+ DTTResourceChange);

        if (tree == null || nnai.neuralNetwork == null || deadEndAgentCounter <= 0)
        {
            Debug.Log("Memory bug. " + ObserverInstance.SimulationNumber + " simulation is inconsisnent.");


            //TODO add DeadEng label into agent stored data


            ObserverInstance.RemoveAgent(gameObject);
        }
        nnai.InputReset();
        if (positiveChange > 0 || negativeChange > 0 || DTTResourceChange > 0)
        {
            tree.ChangeOutcomes(positiveChange, (short)(negativeChange + DTTResourceChange));
            nnai.DecisionBackPropagation(tree.RebalanceValue, decision);
            nnai.DirectionBackPropagation(tree.RebalanceValue, Direction);
            tree.RebalanceValue = 0;
            //Debug.Log("Rebalance of " + decision);

            if (negativeChange > 0 || positiveChange > 0)
            {
                tree.moveTo(tree.Root);
                deadEndAgentCounter = DeadEndAgentCounterValue;
            }
            resetResourceChange();

            decision = nnai.GetDecision();
            if (decision != oldDecision)
            {
                DeadEndReset();
                oldDecision = decision;
            }
            processDecision(decision);
            tree.WalkWith(decision);
        }
        Direction = nnai.GetDirection();
        if (Direction != oldDirection)
        {
            DeadEndReset();
            oldDirection = Direction;
        }
        //Debug.Log("Direction: " + RadianToDegree(CalcAngle(Direction.normalized)));
        //Debug.Log("Velocity: " + RadianToDegree(CalcAngle(rb.velocity.normalized)));
        rb.AddForce(Direction * Step);
    }