Parser.cs 692 B

123456789101112131415161718192021222324252627282930
  1. using System.Text.RegularExpressions;
  2. namespace Day23;
  3. public partial class Parser
  4. {
  5. [GeneratedRegex(@".*")]
  6. private partial Regex LineMatch();
  7. public Map Parse(string inputFile)
  8. {
  9. var lines = File.ReadAllLines(inputFile);
  10. var width = lines[0].Length;
  11. var height = lines.Length;
  12. var tiles = new Tile[width, height];
  13. var row = 0;
  14. foreach (var line in lines)
  15. {
  16. for (var col = 0; col < width; col++)
  17. {
  18. tiles[col, row] = new Tile(line[col], new Vec(col, row));
  19. }
  20. row++;
  21. }
  22. return new Map(tiles);
  23. }
  24. }