private static IEnumerable <Tuple <Vector2, Vector2> > FindRoute(Vector2 startingBuilding, Vector2 destinationBuilding, IEnumerable <Tuple <Vector2, Vector2> > roads) { var graph = new Graph(); var bestPath = new List <Tuple <Vector2, Vector2> >(); // adding the startingbuilding, the destination and all roads to graph graph.AddVertex(startingBuilding); graph.AddVertex(destinationBuilding); foreach (var tuple in roads) { var origin = tuple.Item1; var terminator = tuple.Item2; if (!graph.Vertices.ContainsKey(origin)) { graph.AddVertex(origin); } if (!graph.Vertices.ContainsKey(terminator)) { graph.AddVertex(terminator); } graph.AddEdge(origin, terminator, Euclosure.Invoke(terminator).Invoke(destinationBuilding)); } var result = Dijkstra.GetPath(graph, startingBuilding, destinationBuilding); return(result); }
private static IEnumerable <IEnumerable <Vector2> > FindSpecialBuildingsWithinDistanceFromHouse( IEnumerable <Vector2> specialBuildings, IEnumerable <Tuple <Vector2, float> > housesAndDistances) { Func <Tuple <Vector2, float>, Predicate <Vector2> > predicate = t => v => Euclosure.Invoke(t.Item1).Invoke(v) < t.Item2; var specialBuildingsTree = Tree2D.FromEnumerable(specialBuildings); var newSpecialBuildings = new List <List <Vector2> >(); foreach (var tuple in housesAndDistances) { var p = predicate.Invoke(tuple); newSpecialBuildings.Add(Tree2D.FilterTree(specialBuildingsTree, p)); } return(newSpecialBuildings); }