Ejemplo n.º 1
0
        public void ProcessGrid <T>(ValuesManager <T> valueManager, bool equalWeights, string strategyName = null)
        {
            NeighbourStrategyFactory strategyFactory = new NeighbourStrategyFactory();

            strategy = strategyFactory.CreteInstance(strategyName == null ? _patternSize + "" : strategyName);
            CreatePatterns(valueManager, strategy, equalWeights);
        }
Ejemplo n.º 2
0
        private void CreatePatterns <T>(ValuesManager <T> valueManager, IFindNeighbourStrategy strategy, bool equalWeights)
        {
            var patternFinderResult = PatternFinder.GetPatternDataFromGrid(valueManager, _patternSize, equalWeights);

            //StringBuilder builder = null;
            //List<string> list = new List<string>();
            //for (int row = 0; row < patternFinderResult.GetGridLengthY(); row++)
            //{
            //    builder = new StringBuilder();
            //    for (int col = 0; col < patternFinderResult.GetGridLengthX(); col++)
            //    {
            //        builder.Append(patternFinderResult.GetIndexAt(col,row) + " ");
            //    }
            //    list.Add(builder.ToString());
            //}
            //list.Reverse();
            //foreach (var item in list)
            //{
            //    Debug.Log(item);
            //}
            patternDataIndexDictionary = patternFinderResult.PatternIndexDictionary;
            GetPatternNeighbours(patternFinderResult, strategy);
        }
Ejemplo n.º 3
0
 public TileMapOutput(ValuesManager <TileBase> valuesManager, Tilemap outputImage)
 {
     this.outputImage   = outputImage;
     this.valuesManager = valuesManager;
 }
Ejemplo n.º 4
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));
        }