Пример #1
0
    /// <summary>
    /// Apply vector action. The agent receives decisions represented in a vector with floating point numbers.
    /// </summary>
    /// <param name="vectorAction">Vector containing float values from -1 to 1. Representing actions the agent will perform.</param>
    /// <param name="textAction"></param>
    public override void AgentAction(float[] vectorAction, string textAction)
    {
        // SPEED
        speed = 50 * vectorAction[2];

        // ROTATION
        Vector3 rotateVector = transform.up * vectorAction[0];

        agentRigidbody.MoveRotation(Quaternion.Euler(agentRigidbody.rotation.eulerAngles + rotateVector * speed));

        // MOVEMENT
        Vector3 moveVector = transform.forward * vectorAction[1];

        agentRigidbody.AddForce(moveVector * speed, ForceMode.VelocityChange);

        // DETERMINE STATE

        if (GetCumulativeReward() <= -1f)
        {
            // Reward is too negative, give up
            Done();
            // Indicate failure with the ground material
            StartCoroutine(agentArea.SwapGroundMaterial(success: false));
        }
        else
        {
            // Encourage movement with a tiny time penalty and update the score text display
            AddReward(-.001f);
            agentArea.UpdateScore(GetCumulativeReward());
        }
    }