Tile.cs 996 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. namespace Day23;
  2. public class Tile
  3. {
  4. public char Value { get; }
  5. public Vec Position { get; }
  6. public IList<PathNode> Incoming { get; } = new List<PathNode>();
  7. public IList<PathNode> Outgoing { get; } = new List<PathNode>();
  8. public bool IsPath => Value == '.' || IsArrow;
  9. public bool IsArrow => Value == '<' || Value == '>' || Value == '^' || Value == 'v';
  10. public Tile(char value, Vec position)
  11. {
  12. Value = value;
  13. Position = position;
  14. }
  15. public IEnumerable<Vec> Neighbors()
  16. {
  17. yield return Position.Add(Vec.Up);
  18. yield return Position.Add(Vec.Right);
  19. yield return Position.Add(Vec.Down);
  20. yield return Position.Add(Vec.Left);
  21. }
  22. public Vec ArrowDirection()
  23. {
  24. return Value switch
  25. {
  26. '^' => Vec.Up,
  27. 'v' => Vec.Down,
  28. '<' => Vec.Left,
  29. '>' => Vec.Right,
  30. _ => Vec.Zero
  31. };
  32. }
  33. }