Beispiel #1
0
 private static void InitializeApplication()
 {
     ReadConfigurationFile();
     _inputter  = new ConsoleInputter();
     _outputter = new ConsoleOutputter();
     _printer   = new Printer(_outputter);
 }
Beispiel #2
0
        private static void Day05_A()
        {
            const string defaultFilename = @"TEST_diagnostic.txt";

            try
            {
                string fullFilename = Path.Combine(Environment.CurrentDirectory, "Day05", defaultFilename);
                Console.WriteLine();
                Console.WriteLine($"Loading IntCode data from '{fullFilename}'...");
                Console.WriteLine();

                var        factory         = new Factory();
                IInputter  inputter        = factory.CreateAutoInputter(1);
                IOutputter outputter       = factory.CreateConsoleOutputter();
                var        intCodeComputer = factory.CreateIntCodeComputerFromFile(fullFilename, inputter, outputter);
                Console.WriteLine(
                    $"There are #{intCodeComputer.InitialIntCodes.Count} Op codes in this IntCode program.");
                Console.WriteLine();

                var finalOpCodes = intCodeComputer.Run();
                Console.WriteLine(
                    $"The value left at position 0 is '{finalOpCodes[0]}' after running the IntCode program.");
                Console.WriteLine();

                Console.WriteLine();
                Console.WriteLine(
                    $"The last value outputted during the diagnosis of TEST is '{intCodeComputer.Outputter.OutputValues.Last()}'.");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occured '{ex.Message}'.{Environment.NewLine}Details: '{ex}'");
            }
        }
Beispiel #3
0
        protected override void OnComAwake()
        {
            m_KeyCodeTracker = new KeyCodeTracker();
            m_KeyCodeTracker.SetDefaultProcessListener(ShowBackKeydownTips);

            m_KeyboardInputter = new KeyboardInputter();
            m_KeyboardInputter.RegisterKeyCodeMonitor(KeyCode.F1, null, OnClickF1, null);
            m_KeyboardInputter.RegisterKeyCodeMonitor(KeyCode.F2, null, OnClickF2, null);
            m_KeyboardInputter.RegisterKeyCodeMonitor(KeyCode.F3, null, OnClickF3, null);
            m_KeyboardInputter.RegisterKeyCodeMonitor(KeyCode.F4, null, OnClickF4, null);
        }
Beispiel #4
0
        // constructor
        public RockPaperScissorsGame(IInputter i, IOutputter o, IRpsStrategy strategy)
        {
            _input    = i;
            _output   = o;
            _strategy = strategy;
            // we're using a principle called dependency inversion here

            // the specific way we're doing that
            // is called dependency injection
            //   as opposed to going "new RandomStrategy()" right here,
            //   i can get someone else to inject the dependency to me
            //   (as a parameter, which is what i'm doing here)
        }
Beispiel #5
0
        public IntCodeComputer CreateIntCodeComputerFromFile(
            string fullFileName, IInputter inputter, IOutputter outputter)
        {
            List <int> opCodes = new List <int>();

            using (var fileStream = File.OpenRead(fullFileName))
                using (var streamReader = new StreamReader(fileStream, Encoding.UTF8, true, BufferSize))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        // line has only one value
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            var opCodesTextInLine = line.Split(',');
                            var opCodesInLine     = opCodesTextInLine.Select(int.Parse).ToList();
                            opCodes.AddRange(opCodesInLine);
                        }
                    }
                }
            var tempIntCodeComputer = new IntCodeComputer(opCodes.ToList(), inputter, outputter);

            return(tempIntCodeComputer);
        }
Beispiel #6
0
 public IOController(IInputter inputter, IOutputter outputter)
 {
     Input  = inputter;
     Output = outputter;
 }
Beispiel #7
0
 public IntCodeComputer(List <int> initialIntCodes, IInputter inputter, IOutputter outputter)
 {
     InitialIntCodes = initialIntCodes;
     Inputter        = inputter;
     Outputter       = outputter;
 }
Beispiel #8
0
 public IntCodeComputer(List <int> initialIntCodes, IInputter inputter)
     : this(initialIntCodes, inputter, new ConsoleOutputter())
 {
 }
Beispiel #9
0
 public GetRecipe(IInputter inputter)
 {
     _inputter = inputter ?? throw new ArgumentNullException(nameof(inputter));
 }