Path.cs 795 B

123456789101112131415161718192021222324252627282930313233343536
  1. namespace Day17;
  2. public class Path
  3. {
  4. public Path? Prev { get; }
  5. public Tile Tile { get; }
  6. public Vec VRun { get; }
  7. public int LRun { get; }
  8. public int Cost { get; }
  9. public Path(Path? prev, Tile tile, Vec vRun)
  10. {
  11. Prev = prev;
  12. Tile = tile;
  13. VRun = vRun;
  14. LRun = vRun == Prev?.VRun ? Prev!.LRun + 1 : 1;
  15. Cost = (prev?.Cost ?? 0) + tile.Cost;
  16. }
  17. public IEnumerable<Vec> Next()
  18. {
  19. yield return VRun.RotatePositive();
  20. if (LRun < 3)
  21. {
  22. yield return VRun;
  23. }
  24. yield return VRun.RotateNegative();
  25. }
  26. public string GetKey()
  27. {
  28. return $"{Tile.Position.X}/{Tile.Position.Y},{VRun.X}/{VRun.Y},{LRun}";
  29. }
  30. }