Esempio n. 1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Advent Of Code 2016, day 10");

            var input   = new AntlrInputStream(InputUtils.GetInput(args));
            var lexer   = new BotsScriptLexer(input);
            var tokens  = new CommonTokenStream(lexer);
            var parser  = new BotsScriptParser(tokens);
            var program = parser.program();

            IList <ITask> tasks          = new List <ITask>();
            var           botsPlayground = new BotsPlayground();
            var           listener       = new ExecutingListener(tasks, botsPlayground);

            var walker = new ParseTreeWalker();

            walker.Walk(listener, program);

            while (tasks.Any())
            {
                foreach (var task in tasks)
                {
                    if (task.AttemptToExecute(Inspect))
                    {
                        tasks.Remove(task);
                        break;
                    }
                }
            }

            var output0 = botsPlayground.GetOutput(0);
            var output1 = botsPlayground.GetOutput(1);
            var output2 = botsPlayground.GetOutput(2);

            Console.WriteLine($"O0 * O1 * O2 = {output0.Value*output1.Value*output2.Value}");
        }
        private IDestination ParseDest(BotsScriptParser.DestContext destContext)
        {
            var bot    = destContext.bot();
            var output = destContext.output();

            if (bot != null)
            {
                return(_playground.GetBot(int.Parse(bot.id.Text)));
            }

            if (output != null)
            {
                return(_playground.GetOutput(int.Parse(output.id.Text)));
            }

            throw new ArgumentException();
        }