Esempio n. 1
0
    public override void CollectObservations(VectorSensor sensor)
    {
        sensor.AddObservation((transform.position.x - m_Area.transform.position.x) / 20f);
        sensor.AddObservation((transform.position.z - m_Area.transform.position.z) / 20f);

        sensor.AddObservation(transform.forward.x);
        sensor.AddObservation(transform.forward.z);

        foreach (var item in CurrentlyVisibleTilesList)
        {
            // Each observation / tile in the BufferSensor will have 22 values
            // The first 20 are one hot encoding of the value of the tile
            // The 21st and 22nd are the position of the tile relative to the agent
            // The 23rd is a boolean : 1 if the tile was visited already and 0 otherwise
            float[] listObservation = new float[k_HighestTileValue + 3];
            listObservation[item.NumberValue] = 1.0f;
            var tileTransform = item.transform.GetChild(1);
            listObservation[k_HighestTileValue]     = (tileTransform.position.x - transform.position.x) / 20f;
            listObservation[k_HighestTileValue + 1] = (tileTransform.position.z - transform.position.z) / 20f;
            listObservation[k_HighestTileValue + 2] = item.IsVisited ? 1.0f : 0.0f;
            // Here, the observation for the tile is added to the BufferSensor
            m_BufferSensor.AppendObservation(listObservation);
        }
        ;
    }
    public override void CollectObservations(VectorSensor sensor)
    {
        _isPrepared = false;

        // Agent position
        var position = transform.localPosition;

        sensor.AddObservation(position.x);
        sensor.AddObservation(position.z);
        // Agent velocity
        var selfVelocity = _rBody.velocity;

        sensor.AddObservation(selfVelocity.x);
        sensor.AddObservation(selfVelocity.z);
        // Time left for preparation
        if (StepCount > _config.preparingPhaseLength)
        {
            sensor.AddObservation(0.0f);
        }
        else
        {
            sensor.AddObservation(_config.preparingPhaseLength - StepCount);
        }

        foreach (var obj in _viewField.collectVisibleObjects().Where(obj =>
                                                                     obj.CompareTag(hiderTag) || obj.CompareTag(seekerTag) || obj.CompareTag(cubeTag) || obj.CompareTag(rampTag)))
        {
            if (team == Team.Seeker && obj.CompareTag(hiderTag))
            {
                _seenHolder.isAnyHiderSeen = true;
                Debug.DrawLine(transform.position, obj.transform.position, Color.red);
            }

            float[]   observations    = new float[8];
            Rigidbody objectRigidBody = obj.GetComponent <Rigidbody>();
            // Other object position
            var localPosition = obj.transform.localPosition;
            observations[0] = localPosition.x / 10.0f;
            observations[1] = localPosition.z / 10.0f;
            // Other object velocity
            var velocity = objectRigidBody.velocity;
            observations[2] = velocity.x / 100.0f;
            observations[3] = velocity.z / 100.0f;
            // Other object team
            if (obj.CompareTag(hiderTag))
            {
                observations[4] = 1.0f;
            }
            else if (obj.CompareTag(seekerTag))
            {
                observations[5] = 1.0f;
            }
            else if (obj.CompareTag(cubeTag))
            {
                observations[6] = 1.0f;
            }
            else
            {
                observations[7] = 1.0f;
            }
            _bufferSensor.AppendObservation(observations);
        }
    }