/// <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_Shape = obsType == Match3ObservationType.Vector ? new[] { m_Rows *m_Columns *(m_NumCellTypes + SpecialTypeSize) } : new[] { 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; } }
/// <summary> /// Create a sensor that encodes the cell special types as observations. Returns null if the board's /// NumSpecialTypes is 0 (indicating the sensor isn't needed). /// </summary> /// <param name="board">The abstract board.</param> /// <param name="obsType">Whether to produce vector or visual observations</param> /// <param name="name">Name of the sensor.</param> /// <returns></returns> public static Match3Sensor SpecialTypeSensor(AbstractBoard board, Match3ObservationType obsType, string name) { var maxBoardSize = board.GetMaxBoardSize(); if (maxBoardSize.NumSpecialTypes == 0) { return(null); } var specialSize = maxBoardSize.NumSpecialTypes + 1; return(new Match3Sensor(board, board.GetSpecialType, specialSize, obsType, name)); }
/// <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); }
/// <summary> /// Create a sensor that encodes the cell special types as observations. /// </summary> /// <param name="board">The abstract board.</param> /// <param name="obsType">Whether to produce vector or visual observations</param> /// <param name="name">Name of the sensor.</param> /// <returns></returns> public static Match3Sensor SpecialTypeSensor(AbstractBoard board, Match3ObservationType obsType, string name) { var specialSize = board.NumSpecialTypes == 0 ? 0 : board.NumSpecialTypes + 1; return(new Match3Sensor(board, board.GetSpecialType, specialSize, obsType, name)); }
/// <summary> /// Create a sensor that encodes the board cells as observations. /// </summary> /// <param name="board">The abstract board.</param> /// <param name="obsType">Whether to produce vector or visual observations</param> /// <param name="name">Name of the sensor.</param> /// <returns></returns> public static Match3Sensor CellTypeSensor(AbstractBoard board, Match3ObservationType obsType, string name) { return(new Match3Sensor(board, board.GetCellType, board.NumCellTypes, obsType, name)); }
/// <summary> /// Create a sensor that encodes the board cells as observations. /// </summary> /// <param name="board">The abstract board.</param> /// <param name="obsType">Whether to produce vector or visual observations</param> /// <param name="name">Name of the sensor.</param> /// <returns></returns> public static Match3Sensor CellTypeSensor(AbstractBoard board, Match3ObservationType obsType, string name) { var maxBoardSize = board.GetMaxBoardSize(); return(new Match3Sensor(board, board.GetCellType, maxBoardSize.NumCellTypes, obsType, name)); }