public Robot Execute() { var controllerTask = _controller.Execute(); while (!controllerTask.IsCompleted) { _robotToControllerPipe.Output(_hull.GetColour(_location)); var colourToPaint = (int)_controllerToRobotPipe.ReadInput().Result; _hull.SetColour(_location, colourToPaint); if (controllerTask.IsCompleted) { break; } var directionToTurn = (int)_controllerToRobotPipe.ReadInput().Result; switch (directionToTurn) { case 0: _direction += 3; break; case 1: _direction += 1; break; } _direction = _direction % 4; _location = new Point( _location.X + _directions[_direction].X, _location.Y + _directions[_direction].Y ); } return(this); }
private static int GetThrustSignal(params int[] phaseSettingInputs) { var amplifiers = Enumerable.Range(1, 5) .Select(x => Intcode.Intcode.LoadFromFile("Day07/AmplifierControllerSoftware.txt")) .ToArray(); var phaseSettings = new PreparedInput(phaseSettingInputs); IInput input = new PreparedInput(0); IOPipe pipe = null; foreach (var amplifier in amplifiers) { var amplifierInputs = new CombinedInput(phaseSettings, input); amplifier.SetInput(amplifierInputs); pipe = new IOPipe(); amplifier.SetOutput(pipe); input = pipe; } foreach (var amplifier in amplifiers) { amplifier.Execute().Wait(); } var result = pipe.ReadInput().Result; return(result); }
private async Task ExecuteAsync(bool render) { _render = render; await _game.Execute(); if (_render) { Console.Clear(); } while (_gameOutput.HasInputToRead()) { var x = (int)await _gameOutput.ReadInput(); var y = (int)await _gameOutput.ReadInput(); var character = (int)await _gameOutput.ReadInput(); Render(x, y, _characters[character]); } if (_render) { Console.WriteLine(); } }
private async Task <long> GetTractorAreaAsync(int fieldSize) { long pullCount = 0; for (var y = 0; y < fieldSize; y++) { for (var x = 0; x < fieldSize; x++) { InitialiseDrone(); var controllerTask = _droneController.Execute(); _droneInput.Output(x); _droneInput.Output(y); var isPulled = await _droneOutput.ReadInput(); pullCount += isPulled; } } return(pullCount); }