|
|
|
|
|
|
// TODO use grid size from env parameters
|
|
|
|
int gridSize = 5; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a BasicSensor.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public override ISensor CreateSensor() |
|
|
|
{ |
|
|
|
return new GridSensor(gridArea, gridSize, pixelsPerCell); |
|
|
|
|
|
|
public class GridSensor : ISensor |
|
|
|
{ |
|
|
|
GridArea m_GridArea; |
|
|
|
int m_PixlesPerCell; |
|
|
|
int m_PixelsPerCell; |
|
|
|
int m_GridSize; |
|
|
|
int[] m_Shape; |
|
|
|
const int k_NumChannels = 4; |
|
|
|
|
|
|
m_GridArea = gridArea; |
|
|
|
m_GridSize = gridSize; |
|
|
|
m_PixlesPerCell = pixelsPerCell; |
|
|
|
m_PixelsPerCell = pixelsPerCell; |
|
|
|
|
|
|
|
m_Shape = new []{ gridSize * pixelsPerCell, gridSize * pixelsPerCell, k_NumChannels }; |
|
|
|
} |
|
|
|
|
|
|
return m_Shape; |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <summary>
|
|
|
|
/// Writes a one-hot encoding of the area state for the observations.
|
|
|
|
/// As a 3x3 example, for this area state:
|
|
|
|
///
|
|
|
|
/// A..
|
|
|
|
/// ..P
|
|
|
|
/// G..
|
|
|
|
///
|
|
|
|
/// The corresponding channels would be
|
|
|
|
/// channel 0 (empty)
|
|
|
|
/// 011
|
|
|
|
/// 110
|
|
|
|
/// 011
|
|
|
|
///
|
|
|
|
/// channel 1 (goal)
|
|
|
|
/// 000
|
|
|
|
/// 000
|
|
|
|
/// 100
|
|
|
|
///
|
|
|
|
/// channel 2 (pit)
|
|
|
|
/// 000
|
|
|
|
/// 001
|
|
|
|
/// 000
|
|
|
|
///
|
|
|
|
/// channel 3 (agent)
|
|
|
|
/// 100
|
|
|
|
/// 000
|
|
|
|
/// 000
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="writer"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
// There is a minimum size to visual observations (see MIN_RESOLUTION_FOR_ENCODER in the python code)
|
|
|
|
// So repeat each cell m_PixelsPerCell times/
|
|
|
|
var height = m_GridSize * m_PixlesPerCell; |
|
|
|
var width = m_GridSize * m_PixlesPerCell; |
|
|
|
var height = m_GridSize * m_PixelsPerCell; |
|
|
|
var width = m_GridSize * m_PixelsPerCell; |
|
|
|
var i = h / m_PixlesPerCell; |
|
|
|
var i = h / m_PixelsPerCell; |
|
|
|
var j = w / m_PixlesPerCell; |
|
|
|
var j = w / m_PixelsPerCell; |
|
|
|
var cellVal = board[i, j]; |
|
|
|
for (var c = 0; c < k_NumChannels; c++) |
|
|
|
{ |
|
|
|