public static IFinder GetFinder(FinderType finderType, Graph graph) { switch (finderType) { case FinderType.Default: return(new DefaultFinder(graph)); case FinderType.Dijkstra: return(new DijkstraFinder(graph)); default: throw new ArgumentException(String.Format("Finder type {0} is not supported", finderType)); } }
public static RecordFinder GetFinder(FinderType type) { switch (type) { case FinderType.Employee: return(new EmployeeRecordFinder()); case FinderType.Tank: return(new TankRecordFinder()); default: return(new EmployeeRecordFinder()); } }
private FinderResult FindPair(IEnumerable<FinderResult> pairs, FinderType finderType) { var orderedPairs = pairs.OrderBy(r => r.AgeDifference); return finderType == FinderType.Closest ? orderedPairs.First() : orderedPairs.Last(); }
public FinderResult Find(FinderType finderType) { var pairs = GetDistinctPairs(); return pairs.Any() ? FindPair(pairs, finderType) : new FinderResult(); }
Tile Find(Vector3 position, Tile start, Tile target, float radius, float heightStairs, FinderType type) { PriorityQueue <Tile> queue = new PriorityQueue <Tile>(); queue.Enqueue(start, 0); cameFrom = new Dictionary <Tile, Tile>(); cameFrom[start] = null; costSoFar = new Dictionary <Tile, float>(); costSoFar[start] = 0; path = new Dictionary <Tile, Tile>(); while (queue.Count != 0) { Tile current = queue.Dequeue(); int res = 0; switch (type) { case FinderType.Food: res = Food(start, current, radius); break; case FinderType.Path: res = Path(target, current); break; } if (res == 1) { BuildPath(current); path[current] = null; return(current); } else if (res == -1) { return(null); } List <Tile> neighbors = new List <Tile>(); neighbors.Add(current.left); neighbors.Add(current.back); neighbors.Add(current.right); neighbors.Add(current.forward); foreach (Tile next in neighbors) { if (next == null) { continue; } if (Heuristic(next, current) > 1f) { continue; } float newCost = costSoFar[current] + next.GetCost(current, Own); if (newCost >= 100) { continue; } if (!cameFrom.ContainsKey(next)) { costSoFar[next] = newCost; float dist = Vector3.Distance(position, next.ToVector3()); queue.Enqueue(next, newCost + dist); cameFrom[next] = current; } } } return(null); }