Ejemplo n.º 1
0
        public void Init()
        {
            int[][] test     = MyCollectionExtension.CreateJaggedArray <int[][]>(1, 1);
            string  hashCode = HashCodeCalculator.CalculateHashCode(test);

            pattern  = new Pattern(test, hashCode, 0);
            pattern2 = new Pattern(test, hashCode, 1);
        }
Ejemplo n.º 2
0
 private void CreateGridOfIndices(IValue <T>[][] gridOfValues)
 {
     _grid = MyCollectionExtension.CreateJaggedArray <int[][]>(gridOfValues.Length, gridOfValues[0].Length);
     for (int i = 0; i < gridOfValues.Length; i++)
     {
         for (int j = 0; j < gridOfValues[i].Length; j++)
         {
             SetIndexToGridPosition(gridOfValues, i, j);
         }
     }
 }
Ejemplo n.º 3
0
 private void CreateGridOfIndices(IValue <T>[][] gridOfValues)
 {
     _grid = MyCollectionExtension.CreateJaggedArray <int[][]>(gridOfValues.Length, gridOfValues[0].Length);
     for (int row = 0; row < gridOfValues.Length; row++)
     {
         for (int col = 0; col < gridOfValues[0].Length; col++)
         {
             SetIndexToGridPosition(gridOfValues, row, col);
         }
     }
 }
Ejemplo n.º 4
0
        public int[][] GetPatternValuesFromGridAt(int x, int y, int patternSize)
        {
            int[][] arrayToReturn = MyCollectionExtension.CreateJaggedArray <int[][]>(patternSize, patternSize);
            for (int row = 0; row < patternSize; row++)
            {
                for (int col = 0; col < patternSize; col++)
                {
                    arrayToReturn[row][col] = GetGridValueIncludingOffset(x + col, y + row);
                }
            }

            return(arrayToReturn);
        }
Ejemplo n.º 5
0
        private TileBase[][] CreateTileBaseGrid(InputImageParameters inputImageParameters)
        {
            TileBase[][] gridOfInputTiles = null;

            gridOfInputTiles = MyCollectionExtension.CreateJaggedArray <TileBase[][]>(inputImageParameters.Height, inputImageParameters.Width);
            for (int row = 0; row < inputImageParameters.Height; row++)
            {
                for (int col = 0; col < inputImageParameters.Width; col++)
                {
                    gridOfInputTiles[row][col] = inputImageParameters.StackOfTiles.Dequeue().Tile;
                }
            }
            return(gridOfInputTiles);
        }
Ejemplo n.º 6
0
 public int[][] GetSolvedOutputGrid()
 {
     int[][] returnGrid = MyCollectionExtension.CreateJaggedArray <int[][]>(this.height, this.width);
     if (CheckIfGridIsSolved() == false)
     {
         return(MyCollectionExtension.CreateJaggedArray <int[][]>(0, 0));
     }
     for (int i = 0; i < returnGrid.Length; i++)
     {
         for (int j = 0; j < returnGrid[0].Length; j++)
         {
             int index = GetIndexFromCoords(j, i);
             returnGrid[i][j] = indexPossiblePatternsDict[index].First();
         }
     }
     return(returnGrid);
 }
 public int[][] GetSolvedOutputGrid()
 {
     int[][] returnGrid = MyCollectionExtension.CreateJaggedArray <int[][]>(this.height, this.width);
     if (CheckIfGridIsSolved() == false)
     {
         return(MyCollectionExtension.CreateJaggedArray <int[][]>(0, 0));
     }
     for (int row = 0; row < this.height; row++)
     {
         for (int col = 0; col < this.width; col++)
         {
             int index = GetIndexFromCoordinates(new Vector2Int(col, row));
             returnGrid[row][col] = indexPossiblePatternDictionary[index].First();
         }
     }
     return(returnGrid);
 }
Ejemplo n.º 8
0
        public IValue <TileBase>[][] ReadInputToGrid()
        {
            var grid = ReadInputTileMap();

            TileBaseValue[][] gridOValues = null;
            if (grid != null)
            {
                gridOValues = MyCollectionExtension.CreateJaggedArray <TileBaseValue[][]>(grid.Length, grid[0].Length);
                for (int row = 0; row < grid.Length; row++)
                {
                    for (int col = 0; col < grid[row].Length; col++)
                    {
                        gridOValues[row][col] = new TileBaseValue(grid[row][col]);
                    }
                }
            }
            return(gridOValues);
        }
Ejemplo n.º 9
0
        public int[][] ConvertPatternToValues <T>(int[][] outputValues)
        {
            int patternOutputWidth  = outputValues[0].Length;
            int patternOutputHeight = outputValues.Length;
            int valueGridWidth      = patternOutputWidth + patternSize - 1;
            int valueGridHeight     = patternOutputHeight + patternSize - 1;

            int[][] valueGrid = MyCollectionExtension.CreateJaggedArray <int[][]>(valueGridHeight, valueGridWidth);
            for (int row = 0; row < patternOutputHeight; row++)
            {
                for (int col = 0; col < patternOutputWidth; col++)
                {
                    Pattern pattern = GetPatternDataFromIndex(outputValues[row][col]).Pattern;
                    GetPatternValues(patternOutputWidth, patternOutputHeight, valueGrid, row, col, pattern);
                }
            }

            return(valueGrid);
        }
Ejemplo n.º 10
0
        public static PatternDataResults GetPatternDataFromGrid <T>(ValuesManager <T> valuesManager, int patternSize, bool equalWeights)
        {
            Dictionary <string, PatternData> patternHashcodeDictionary = new Dictionary <string, PatternData>();
            Dictionary <int, PatternData>    patternIndexDictionary    = new Dictionary <int, PatternData>();
            Vector2 sizeOfGrid = valuesManager.GetGridSize();
            int     patternGridSizeX = 0;
            int     patternGridSizeY = 0;
            int     rowMin = -1, colMin = -1, rowMax = -1, colMax = -1;

            if (patternSize < 3)
            {
                patternGridSizeX = (int)sizeOfGrid.x + 3 - patternSize;
                patternGridSizeY = (int)sizeOfGrid.y + 3 - patternSize;
                rowMax           = patternGridSizeY - 1;
                colMax           = patternGridSizeX - 1;
            }
            else
            {
                patternGridSizeX = (int)sizeOfGrid.x + patternSize - 1;
                patternGridSizeY = (int)sizeOfGrid.y + patternSize - 1;
                rowMin           = 1 - patternSize;
                colMin           = 1 - patternSize;
                rowMax           = (int)sizeOfGrid.y;
                colMax           = (int)sizeOfGrid.x;
            }

            int[][] patternIndicesGrid = MyCollectionExtension.CreateJaggedArray <int[][]>(patternGridSizeY, patternGridSizeX);
            int     totalFrequency     = 0;

            //we loop with offset -1 / +1 to get patterns. At the same time we have to account for patten size.
            //If pattern is of size 2 we will be reaching x+1 and y+1 to check all 4 values. Need visual aid.

            int patternIndex = 0;

            for (int row = rowMin; row < rowMax; row++)
            {
                for (int col = colMin; col < colMax; col++)
                {
                    int[][] gridValues = valuesManager.GetPatternValuesFromGridAt(col, row, patternSize);
                    string  hashValue  = HashCodeCalculator.CalculateHashCode(gridValues);

                    if (patternHashcodeDictionary.ContainsKey(hashValue) == false)
                    {
                        Pattern pattern = new Pattern(gridValues, hashValue, patternIndex);
                        patternIndex++;
                        AddNewPattern(patternHashcodeDictionary, patternIndexDictionary, hashValue, pattern);
                    }
                    else
                    {
                        if (equalWeights == false)
                        {
                            patternIndexDictionary[patternHashcodeDictionary[hashValue].Pattern.Index].AddToFrequency();
                        }
                    }
                    //if (patternSize > colMin || row >= rowMin && row < rowMax-1 && col >= colMin && col < colMax-1)
                    //{

                    //    totalFrequency++;

                    //}
                    totalFrequency++;
                    if (patternSize < 3)
                    {
                        patternIndicesGrid[row + 1][col + 1] = patternHashcodeDictionary[hashValue].Pattern.Index;
                    }
                    else
                    {
                        patternIndicesGrid[row + patternSize - 1][col + patternSize - 1] = patternHashcodeDictionary[hashValue].Pattern.Index;
                    }
                }
            }

            CalculateRelativeFrequency(patternIndexDictionary, totalFrequency);

            return(new PatternDataResults(patternIndicesGrid, patternIndexDictionary));
        }
Ejemplo n.º 11
0
 internal bool CheckIfValidPosition(Vector2Int position)
 {
     return(MyCollectionExtension.ValidateCoordinates(position.x, position.y, this.width, this.height));
 }
Ejemplo n.º 12
0
        internal static PatternDataResults GetPatternDataFromGrid <T>(ValuesManager <T> valuesManager, int patternSize,
                                                                      bool equalWeights)
        {
            Dictionary <string, PatternData> patternHashCodeDictionary = new Dictionary <string, PatternData>();
            Dictionary <int, PatternData>    patternIndexDictionary    = new Dictionary <int, PatternData>();
            Vector2 sizeOfGrid = valuesManager.GetGridSize();
            int     patternGridSizeX = 0, patternGridSizeY = 0;
            int     rowMin = -1, colMin = -1, rowMax = -1, colMax = -1;

            if (patternSize < 3)
            {
                patternGridSizeX = (int)sizeOfGrid.x + 3 - patternSize;
                patternGridSizeY = (int)sizeOfGrid.y + 3 - patternSize;
                rowMax           = patternGridSizeY - 1;
                colMax           = patternGridSizeX - 1;
            }
            else
            {
                patternGridSizeX = (int)sizeOfGrid.x + patternSize - 1;
                patternGridSizeY = (int)sizeOfGrid.y + patternSize - 1;
                rowMin           = 1 - patternSize;
                colMin           = 1 - patternSize;
                rowMax           = (int)sizeOfGrid.y;
                colMax           = (int)sizeOfGrid.x;
            }

            int[][] patternIndicesGrid =
                MyCollectionExtension.CreateJaggedArray <int[][]>(patternGridSizeY, patternGridSizeX);
            int totalFrequency = 0, patternIndex = 0;

            for (int row = rowMin; row < rowMax; row++)
            {
                for (int col = colMin; col < colMax; col++)
                {
                    int[][] gridValues = valuesManager.GetPatternValuesFromGridAt(col, row, patternSize);
                    string  hashValue  = HashCodeCalculator.CalculateHashCode(gridValues);

                    if (patternHashCodeDictionary.ContainsKey(hashValue) == false)
                    {
                        Pattern pattern = new Pattern(gridValues, hashValue, patternIndex);
                        patternIndex++;
                        AddNewPattern(patternHashCodeDictionary, patternIndexDictionary, hashValue, pattern);
                    }
                    else
                    {
                        if (equalWeights == false)
                        {
                            patternIndexDictionary[patternHashCodeDictionary[hashValue].Pattern.Index].AddToFrequency();
                        }
                    }

                    totalFrequency++;
                    if (patternSize < 3)
                    {
                        patternIndicesGrid[row + 1][col + 1] = patternHashCodeDictionary[hashValue].Pattern.Index;
                    }
                    else
                    {
                        patternIndicesGrid[row + patternSize - 1][col + patternSize - 1] =
                            patternHashCodeDictionary[hashValue].Pattern.Index;
                    }
                }
            }

            CalculateRelativeFrequency(patternIndexDictionary, totalFrequency);
            return(new PatternDataResults(patternIndicesGrid, patternIndexDictionary));
        }