Example #1
0
        /// <summary>
        /// Create a sensor for the board with the specified observation type.
        /// </summary>
        /// <param name="board"></param>
        /// <param name="obsType"></param>
        /// <param name="name"></param>
        public Match3Sensor(AbstractBoard board, Match3ObservationType obsType, string name)
        {
            m_Board           = board;
            m_Name            = name;
            m_Rows            = board.Rows;
            m_Columns         = board.Columns;
            m_NumCellTypes    = board.NumCellTypes;
            m_NumSpecialTypes = board.NumSpecialTypes;

            m_ObservationType = obsType;
            m_ObservationSpec = obsType == Match3ObservationType.Vector
                ? ObservationSpec.Vector(m_Rows * m_Columns * (m_NumCellTypes + SpecialTypeSize))
                : ObservationSpec.Visual(m_Rows, m_Columns, m_NumCellTypes + SpecialTypeSize);

            // See comment in GetCompressedObservation()
            var cellTypePaddedSize = 3 * ((m_NumCellTypes + 2) / 3);

            m_SparseChannelMapping = new int[cellTypePaddedSize + SpecialTypeSize];
            // If we have 4 cell types and 2 special types (3 special size), we'd have
            // [0, 1, 2, 3, -1, -1, 4, 5, 6]
            for (var i = 0; i < m_NumCellTypes; i++)
            {
                m_SparseChannelMapping[i] = i;
            }

            for (var i = m_NumCellTypes; i < cellTypePaddedSize; i++)
            {
                m_SparseChannelMapping[i] = -1;
            }

            for (var i = 0; i < SpecialTypeSize; i++)
            {
                m_SparseChannelMapping[cellTypePaddedSize + i] = i + m_NumCellTypes;
            }
        }
Example #2
0
    public BoardSensor(Board board)
    {
        this.board = board;
        this.name  = "BoardSensor";

        // This might be 85 or 85*3
        observationSpec = ObservationSpec.Vector(85 * 3);
    }
Example #3
0
    public GameStateSensor(Board board)
    {
        this.board = board;
        this.name  = "GameStateSensor";

        // This might be 85 or 85*3
        observationSpec = ObservationSpec.Vector(2);
    }
Example #4
0
 public ReflectionSensorBase(ReflectionSensorInfo reflectionSensorInfo, int size)
 {
     m_Object              = reflectionSensorInfo.Object;
     m_FieldInfo           = reflectionSensorInfo.FieldInfo;
     m_PropertyInfo        = reflectionSensorInfo.PropertyInfo;
     m_ObservableAttribute = reflectionSensorInfo.ObservableAttribute;
     m_SensorName          = reflectionSensorInfo.SensorName;
     m_ObservationSpec     = ObservationSpec.Vector(size);
     m_NumFloats           = size;
 }
Example #5
0
        /// <summary>
        /// Create a sensor for the GridValueProvider with the specified observation type.
        /// </summary>
        /// <remarks>
        /// Use Match3Sensor.CellTypeSensor() or Match3Sensor.SpecialTypeSensor() instead of calling
        /// the constructor directly.
        /// </remarks>
        /// <param name="board">The abstract board. This is only used to get the size.</param>
        /// <param name="gvp">The GridValueProvider, should be either board.GetCellType or board.GetSpecialType.</param>
        /// <param name="oneHotSize">The number of possible values that the GridValueProvider can return.</param>
        /// <param name="obsType">Whether to produce vector or visual observations</param>
        /// <param name="name">Name of the sensor.</param>
        public Match3Sensor(AbstractBoard board, GridValueProvider gvp, int oneHotSize, Match3ObservationType obsType, string name)
        {
            m_Name       = name;
            m_Rows       = board.Rows;
            m_Columns    = board.Columns;
            m_GridValues = gvp;
            m_OneHotSize = oneHotSize;

            m_ObservationType = obsType;
            m_ObservationSpec = obsType == Match3ObservationType.Vector
                ? ObservationSpec.Vector(m_Rows * m_Columns * oneHotSize)
                : ObservationSpec.Visual(m_Rows, m_Columns, oneHotSize);
        }
        /// <summary>
        /// Create a sensor for the GridValueProvider with the specified observation type.
        /// </summary>
        /// <remarks>
        /// Use Match3Sensor.CellTypeSensor() or Match3Sensor.SpecialTypeSensor() instead of calling
        /// the constructor directly.
        /// </remarks>
        /// <param name="board">The abstract board.</param>
        /// <param name="gvp">The GridValueProvider, should be either board.GetCellType or board.GetSpecialType.</param>
        /// <param name="oneHotSize">The number of possible values that the GridValueProvider can return.</param>
        /// <param name="obsType">Whether to produce vector or visual observations</param>
        /// <param name="name">Name of the sensor.</param>
        public Match3Sensor(AbstractBoard board, GridValueProvider gvp, int oneHotSize, Match3ObservationType obsType, string name)
        {
            var maxBoardSize = board.GetMaxBoardSize();

            m_Name         = name;
            m_MaxBoardSize = maxBoardSize;
            m_GridValues   = gvp;
            m_OneHotSize   = oneHotSize;
            m_Board        = board;

            m_ObservationType = obsType;
            m_ObservationSpec = obsType == Match3ObservationType.Vector
                ? ObservationSpec.Vector(maxBoardSize.Rows * maxBoardSize.Columns * oneHotSize)
                : ObservationSpec.Visual(maxBoardSize.Rows, maxBoardSize.Columns, oneHotSize);
        }
        public void TestVectorObsSpec()
        {
            var obsSpec = ObservationSpec.Vector(5);

            Assert.AreEqual(1, obsSpec.Rank);

            var shape = obsSpec.Shape;

            Assert.AreEqual(1, shape.Length);
            Assert.AreEqual(5, shape[0]);

            var dimensionProps = obsSpec.DimensionProperties;

            Assert.AreEqual(1, dimensionProps.Length);
            Assert.AreEqual(DimensionProperty.None, dimensionProps[0]);

            Assert.AreEqual(ObservationType.Default, obsSpec.ObservationType);
        }
        public PhysicsBodySensor(ArticulationBody rootBody, PhysicsSensorSettings settings, string sensorName = null)
        {
            var poseExtractor = new ArticulationBodyPoseExtractor(rootBody);

            m_PoseExtractor = poseExtractor;
            m_SensorName    = string.IsNullOrEmpty(sensorName) ? $"ArticulationBodySensor:{rootBody?.name}" : sensorName;
            m_Settings      = settings;

            var numJointExtractorObservations = 0;

            m_JointExtractors = new List <IJointExtractor>(poseExtractor.NumEnabledPoses);
            foreach (var articBody in poseExtractor.GetEnabledArticulationBodies())
            {
                var jointExtractor = new ArticulationBodyJointExtractor(articBody);
                numJointExtractorObservations += jointExtractor.NumObservations(settings);
                m_JointExtractors.Add(jointExtractor);
            }

            var numTransformObservations = m_PoseExtractor.GetNumPoseObservations(settings);

            m_ObservationSpec = ObservationSpec.Vector(numTransformObservations + numJointExtractorObservations);
        }
        /// <summary>
        /// Construct a new PhysicsBodySensor
        /// </summary>
        /// <param name="poseExtractor"></param>
        /// <param name="settings"></param>
        /// <param name="sensorName"></param>
        public PhysicsBodySensor(
            RigidBodyPoseExtractor poseExtractor,
            PhysicsSensorSettings settings,
            string sensorName
            )
        {
            m_PoseExtractor = poseExtractor;
            m_SensorName    = sensorName;
            m_Settings      = settings;

            var numJointExtractorObservations = 0;

            m_JointExtractors = new List <IJointExtractor>(poseExtractor.NumEnabledPoses);
            foreach (var rb in poseExtractor.GetEnabledRigidbodies())
            {
                var jointExtractor = new RigidBodyJointExtractor(rb);
                numJointExtractorObservations += jointExtractor.NumObservations(settings);
                m_JointExtractors.Add(jointExtractor);
            }

            var numTransformObservations = m_PoseExtractor.GetNumPoseObservations(settings);

            m_ObservationSpec = ObservationSpec.Vector(numTransformObservations + numJointExtractorObservations);
        }
 public DummySensor(int dim1)
 {
     m_ObservationSpec = ObservationSpec.Vector(dim1);
 }
Example #11
0
 /// <inheritdoc/>
 public override ObservationSpec GetObservationSpec()
 {
     return(ObservationSpec.Vector(BasicController.k_Extents));
 }