예제 #1
0
        private void Run()
        {
            var size     = 100;
            var input    = File.ReadAllText(@"C:\Users\Bakke\source\repos\AdventOfCode2019\AdventOfCode2019\Data\Day19.txt").Split(",").Select(int.Parse).ToArray();
            var analyser = new Day19.BeamAnalyzer(input);

            bool IsAffected(int r, int c)
            {
                var isAffected = analyser.IsAffected(r, c);

                // draw a pixel for each call
                if (!closed)
                {
                    BeginInvoke((MethodInvoker) delegate { UpdateImage(c, r, isAffected ? Color.Green : Color.Red); });
                }
                return(isAffected);
            }

            var(col, row) = Day19.FindBoxStart(size, IsAffected);

            // draw a box around the result to verify
            for (int c1 = col - 5; c1 < col + 5 + size; c1++)
            {
                for (int r2 = row - 5; r2 < row + 5 + size; r2++)
                {
                    IsAffected(c1, r2);
                }
            }

            if (!closed)
            {
                BeginInvoke((MethodInvoker) delegate { DrawBox(col, row, size); });
            }
        }