Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var lines          = File.ReadAllLines("input.txt");
            var ascii          = AsciiMap.CreateFrom(lines);
            var map            = ascii.ToAbstractMap(MapItem.FromChar);
            var interestPoints = map.Where(item => item.IsDoor || item.IsKey).Select(JustCoords).ToHashSet();
            var crossroads     = map.Where((col, row, item) => {
                if (item.IsWall)
                {
                    return(false);
                }
                return(map.Neibneighbors(col, row)
                       .Where(_ => _.item.IsOpen)
                       .Count() != 2);
            }).Select(JustCoords).ToHashSet();
            var turns = map.Where((col, row, item) => {
                if (item.IsWall)
                {
                    return(false);
                }
                var neibneighbors = map.Neibneighbors(col, row).Where(_ => _.item.IsOpen).ToList();
                if (neibneighbors.Count != 2)
                {
                    return(false);
                }
                if (neibneighbors[0].col == neibneighbors[1].col)
                {
                    return(false);
                }
                if (neibneighbors[0].row == neibneighbors[1].row)
                {
                    return(false);
                }
                return(true);
            }).Select(JustCoords).ToHashSet();
            var nodes = interestPoints.Union(crossroads).Union(turns);



            foreach ((var col, var row) in nodes)
            {
                ascii[col, row] = 'O';
            }

            ascii.WriteTo(Console.Out);

            (int col, int row) JustCoords((int col, int row, MapItem _) item) => (item.col, item.row);
        }
        public void CreateFrom_Text_Samples(string text)
        {
            var map = AsciiMap.CreateFrom(text);

            Assert.Equal(text.TrimEnd(), map.ToString().TrimEnd());
        }