Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Drawing;
  3. using System.Linq;
  4. using Greedy.Architecture;
  5. using Greedy.Architecture.Drawing;
  6.  
  7. namespace Greedy
  8. {
  9.     public class GreedyPathFinder : IPathFinder
  10.     {
  11.         public List<Point> FindPathToCompleteGoal(State state)
  12.         {
  13.             var chestsFound = 0;
  14.             var path = new List<Point>();
  15.             while (chestsFound < state.Goal)
  16.             {
  17.                 var shortPath = new DijkstraPathFinder()
  18.                     .GetPathsByDijkstra(state, state.Position, state.Chests)
  19.                     .FirstOrDefault();
  20.                 if (shortPath == null)
  21.                     return new List<Point>();
  22.                 path.AddRange(shortPath.Path.Skip(1));
  23.                 state.Energy -= shortPath.Cost;
  24.                 state.Position = shortPath.End;
  25.                 if (state.Energy < 0) return new List<Point>();
  26.                 state.Chests.Remove(shortPath.End);
  27.                 chestsFound++;
  28.             }
  29.  
  30.             return path;
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement