public void SetNeighbourOrder(NeighbourOrder no) { TileSelectionMethod = no; }
public List<Tile> GetNeighbours(Tile t, NeighbourOrder order) { for(int x = 0; x < Width; x++) { for(int y = 0; y < Height; y++) { Tile current = Grid[x, y]; if(current.Equals(t)) { List<Tile> returnList = new List<Tile>(); if(x > 0) { returnList.Add(Grid[x - 1, y]);//Left } if(x < Width - 1) { returnList.Add(Grid[x + 1, y]);//Right } if(y > 0) { returnList.Add(Grid[x, y - 1]);//Top } if(y < Height - 1) { returnList.Add(Grid[x, y + 1]);//Bottom } if(order == NeighbourOrder.RANDOM) { Random ran = new Random(); int n = returnList.Count; while(n > 1) { n--; int k = ran.Next(n + 1); var value = returnList[k]; returnList[k] = returnList[n]; returnList[n] = value; } } else if(order == NeighbourOrder.SMART) { var SmartList = new List<Tile>(); var SmartListScores = new int[returnList.Count]; for(int i = 0; i < returnList.Count(); i++) { SmartListScores[i] = NonDiagonalDistanceToEnd(returnList[i]); } for(int j = 0; j < returnList.Count(); j++) { int lowestIndex = -1; int lowest = Int32.MaxValue; for(int i = 0; i < SmartListScores.Count(); i++) { if(SmartListScores[i] != -1) { if(lowest > SmartListScores[i]) { lowest = SmartListScores[i]; lowestIndex = i; } } } SmartList.Add(returnList[lowestIndex]); SmartListScores[lowestIndex] = -1; } returnList = SmartList; } return returnList; } } } return null; }