Tile.cs 856 B

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