Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using Greedy.Architecture;
- using Greedy.Architecture.Drawing;
- namespace Greedy
- {
- public class GreedyPathFinder : IPathFinder
- {
- public List<Point> FindPathToCompleteGoal(State state)
- {
- var chestsFound = 0;
- var path = new List<Point>();
- while (chestsFound < state.Goal)
- {
- var shortPath = new DijkstraPathFinder()
- .GetPathsByDijkstra(state, state.Position, state.Chests)
- .FirstOrDefault();
- if (shortPath == null)
- return new List<Point>();
- path.AddRange(shortPath.Path.Skip(1));
- state.Energy -= shortPath.Cost;
- state.Position = shortPath.End;
- if (state.Energy < 0) return new List<Point>();
- state.Chests.Remove(shortPath.End);
- chestsFound++;
- }
- return path;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement