예제 #1
0
        /// <inheritdoc/>
        public byte[] GetCompressedObservation()
        {
            var height      = m_Rows;
            var width       = m_Columns;
            var tempTexture = new Texture2D(width, height, TextureFormat.RGB24, false);
            var converter   = new OneHotToTextureUtil(height, width);
            var bytesOut    = new List <byte>();

            // Encode the cell types and special types as separate batches of PNGs
            // This is potentially wasteful, e.g. if there are 4 cell types and 1 special type, we could
            // fit in in 2 images, but we'll use 3 here (2 PNGs for the 4 cell type channels, and 1 for
            // the special types). Note that we have to also implement the sparse channel mapping.
            // Optimize this it later.
            var numCellImages = (m_NumCellTypes + 2) / 3;

            for (var i = 0; i < numCellImages; i++)
            {
                converter.EncodeToTexture(m_Board.GetCellType, tempTexture, 3 * i);
                bytesOut.AddRange(tempTexture.EncodeToPNG());
            }

            var numSpecialImages = (SpecialTypeSize + 2) / 3;

            for (var i = 0; i < numSpecialImages; i++)
            {
                converter.EncodeToTexture(m_Board.GetSpecialType, tempTexture, 3 * i);
                bytesOut.AddRange(tempTexture.EncodeToPNG());
            }

            DestroyTexture(tempTexture);
            return(bytesOut.ToArray());
        }
예제 #2
0
        /// <inheritdoc/>
        public byte[] GetCompressedObservation()
        {
            m_Board.CheckBoardSizes(m_MaxBoardSize);
            var height           = m_MaxBoardSize.Rows;
            var width            = m_MaxBoardSize.Columns;
            var tempTexture      = new Texture2D(width, height, TextureFormat.RGB24, false);
            var converter        = new OneHotToTextureUtil(height, width);
            var bytesOut         = new List <byte>();
            var currentBoardSize = m_Board.GetCurrentBoardSize();

            // Encode the cell types or special types as batches of PNGs
            // This is potentially wasteful, e.g. if there are 4 cell types and 1 special type, we could
            // fit in in 2 images, but we'll use 3 total (2 PNGs for the 4 cell type channels, and 1 for
            // the special types).
            var numCellImages = (m_OneHotSize + 2) / 3;

            for (var i = 0; i < numCellImages; i++)
            {
                converter.EncodeToTexture(
                    m_GridValues,
                    tempTexture,
                    3 * i,
                    currentBoardSize.Rows,
                    currentBoardSize.Columns
                    );
                bytesOut.AddRange(tempTexture.EncodeToPNG());
            }

            DestroyTexture(tempTexture);
            return(bytesOut.ToArray());
        }