long PlayGame() { var intCode = new IntCode(4096); var instructions = Instructions.ToList(); instructions[0] = 2; var score = 0L; while (true) { if (intCode.IsPaused) { intCode.Resume(); } else { intCode.Execute(instructions); } var tiles = GetTiles(intCode.Outputs.ToList()); intCode.ClearOutput(); var paddle = (Tile?)tiles.FirstOrDefault(x => x.TileType == TileType.Paddle); var ball = (Tile?)tiles.FirstOrDefault(x => x.TileType == TileType.Ball); var scoreInfo = (Tile?)tiles.FirstOrDefault(x => x.IsScore); if (scoreInfo.HasValue) { score = scoreInfo.Value.Score; } if (!intCode.IsPaused) { break; } var nextInput = paddle.HasValue && ball.HasValue ? GetInput(paddle.Value, ball.Value) : 0; intCode.SetInputs(nextInput); } return(score); }