internal List <Location> FindAdjacent(List <int> allowedDelta, List <Location> excludedComb, List <Location> excludedOddRowComb, List <Location> excludedEvenRowComb, bool wrap, List <int> gridSize) { // for every dimension, we must allow for -1, 0, +1 states // this is really a variations / repitition problem, for the mapping (-1,0,-1) select "dimensions" of them List <Location> outList = new List <Location>(); JPD.Combinatorics.Variations <int> var = new Variations <int>((uint)index.Count, 3, true, allowedDelta); for (var.First(); !var.AtEnd; var.Next()) { bool exclude = (excludedComb != null && excludedComb.Contains(new Location(var.Current.ToList()))) || ((index[0] % 2 == 1) && excludedOddRowComb != null && excludedOddRowComb.Contains(new Location(var.Current.ToList()))) || ((index[0] % 2 == 0) && excludedEvenRowComb != null && excludedEvenRowComb.Contains(new Location(var.Current.ToList()))); if (!exclude) { Location l = new Location(); for (int d = 0; d < index.Count; d++) { int target = index[d] + var.Current[d]; if (wrap) { target = (target + gridSize[d]) % gridSize[d]; } l.Add(d, target); } outList.Add(l); } } return(outList); }