private void FindNeighboursForEachPattern(PatternDataResults patternFinderResult, Dictionary <int, PatternNeighbours> result) { for (int row = 0; row < patternFinderResult.GetGridLengthY(); row++) { for (int col = 0; col < patternFinderResult.GetGridLengthX(); col++) { PatternNeighbours neighbours = PatternFinder.CheckNeighboursInEachDirection(col, row, patternFinderResult); PatternFinder.AddNeighboursToDictionary(result, patternFinderResult.GetIndexAt(col, row), neighbours); } } }
public void AddNeighbour(PatternNeighbours neighbours) { foreach (var item in neighbours.directionPatternNeighbourDictionary) { if (directionPatternNeighbourDictionary.ContainsKey(item.Key) == false) { directionPatternNeighbourDictionary.Add(item.Key, new HashSet <int>()); } directionPatternNeighbourDictionary[item.Key].UnionWith(item.Value); } }
public static PatternNeighbours CheckNeighboursInEachDirection(int x, int y, PatternDataResults patternDataResults) { PatternNeighbours patternNeighbours = new PatternNeighbours(); foreach (Direction dir in Enum.GetValues(typeof(Direction))) { int PossiblePatternIndex = patternDataResults.GetNeighbourInDirection(x, y, dir); if (PossiblePatternIndex >= 0) { patternNeighbours.AddPatternToDictionary(dir, PossiblePatternIndex); } } return(patternNeighbours); }
public static void AddNeighboursToDictionary(Dictionary <int, PatternNeighbours> dictionary, int patternIndex, PatternNeighbours neighbours) { if (dictionary.ContainsKey(patternIndex) == false) { dictionary.Add(patternIndex, neighbours); } dictionary[patternIndex].AddNeighbour(neighbours); }