Path.cs 921 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 = prev == null
  15. ? 0
  16. : vRun == Prev?.VRun ? Prev!.LRun + 1 : 1;
  17. Cost = (prev?.Cost ?? 0) + tile.Cost;
  18. }
  19. public virtual IEnumerable<Vec> Next()
  20. {
  21. yield return VRun.RotatePositive();
  22. if (LRun < 3)
  23. {
  24. yield return VRun;
  25. }
  26. yield return VRun.RotateNegative();
  27. }
  28. public virtual bool CanStop()
  29. {
  30. return true;
  31. }
  32. public string GetKey()
  33. {
  34. return $"{Tile.Position.X}/{Tile.Position.Y},{VRun.X}/{VRun.Y},{LRun}";
  35. }
  36. }