public static TileSelection SelectContiguous(Tile start, TileSelection tiles) { var time = Time.realtimeSinceStartup; TileSelection result = new TileSelection(); TileSelection open = new TileSelection(); open.Add(start); var i = 0; while (open.Count() > 0) { i++; if (i > tiles.Count()) { throw(new Exception("Fill fail")); } var t = open[0]; open.Remove(t); result.Add(t); foreach (var n in t.adjacent.tiles) { if (result.DoesNotContain(n) && tiles.Contains(n)) { open.Add(n); } } } _gui_manager.selected_tiles = result; return(result); }