Пример #1
0
    public override void OnActionReceived(float[] vectorAction)
    {
        var action = Mathf.FloorToInt(vectorAction[0]);

        switch (action)
        {
        case k_NoAction:
            myLogger.setAction("No Action");
            break;

        case k_ChangeRender:
            myLogger.setAction("Change Render");
            if (lightOn)
            {
                SwitchLightOff();
                AddReward(-0.2f);
                myLogger.SetRewardValue(-0.2f);
                myLogger.AddRewardCumulatedValue(-0.2f);
            }
            else
            {
                SwitchLightOn();
                AddReward(0.2f);
                myLogger.SetRewardValue(+0.2f);
                myLogger.AddRewardCumulatedValue(+0.2f);
            }
            break;

        case k_MoveLeft:
            myLogger.setAction("Move Left");
            if (lightOn)
            {
                transform.position += new Vector3(-1.0f, 0.0f, 0.0f);
            }
            break;

        case k_MoveRight:
            myLogger.setAction("Move Right");
            if (lightOn)
            {
                transform.position += new Vector3(1.0f, 0.0f, 0.0f);
            }
            break;

        case k_MoveFront:
            myLogger.setAction("Move Front");
            if (lightOn)
            {
                transform.position += new Vector3(0.0f, 0.0f, 1.0f);
            }
            break;

        case k_MoveBack:
            myLogger.setAction("Move Back");
            if (lightOn)
            {
                transform.position += new Vector3(0.0f, 0.0f, -1.0f);
            }
            break;
        }

        // Si déborde r = -1
        if (transform.position.x < -4.5f || transform.position.x > 4.5f || transform.position.z < -4.5f || transform.position.z > 4.5f)
        {
            SetReward(-1.0f);
            myLogger.AddRewardCumulatedValue(-1.0f);
            EndEpisode();
        }
        else if (transform.position.x == goal.transform.position.x && transform.position.z == goal.transform.position.z)
        {
            SetReward(1.0f);
            myLogger.AddRewardCumulatedValue(1.0f);
            EndEpisode();
        }
    }