public MatchResults Play(int numberOfRounds, IPlayer player1, IPlayer player2)
        {
            var rounds = new List <MatchResults.Round>();

            for (int roundNumber = 1; roundNumber <= numberOfRounds; roundNumber++)
            {
                var player1Move = player1.Move();
                var player2Move = player2.Move();
                var score       = rules.GetScore(player1Move, player2Move);
                var round       = new MatchResults.Round()
                {
                    Number       = roundNumber,
                    Player1Move  = player1Move,
                    Player2Move  = player2Move,
                    Player1Score = score,
                    Player2Score = -1 * score,
                };
                rounds.Add(round);
                RoundPlayed?.Invoke(this, new RoundEventArgs(round));
            }
            return(new MatchResults()
            {
                Rounds = rounds.AsReadOnly()
            });
        }
        public async Task InitConnectionAsync()
        {
            if (IsConnected)
            {
                return;
            }

            var accessTokenState = await _tokenProvider.RequestAccessToken();

            if (accessTokenState.TryGetToken(out var accessToken))
            {
                var apiBaseUrl        = _configurtion["api:baseUrl"];
                var accessTokenString = accessToken.Value;
                _hubConnection = new HubConnectionBuilder()
                                 .WithUrl($"{apiBaseUrl}tictactoe?access_token={accessTokenString}", options =>
                {
                    options.AccessTokenProvider = () => Task.FromResult(accessTokenString);
                })
                                 .WithAutomaticReconnect(new[] { TimeSpan.Zero, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10) })
                                 .Build();


                _hubConnection.On("StartGame", (GameSession data) =>
                {
                    GameRunning?.Invoke(this, new GameRunningEventArgs {
                        Running = true
                    });
                    ActiveSession?.Invoke(this, new ActiveSessionEventArgs {
                        Session = data
                    });
                });

                _hubConnection.On("GameOver", (string data) =>
                {
                    GameRunning?.Invoke(this, new GameRunningEventArgs {
                        Running = false
                    });
                    ActiveSession?.Invoke(this, new ActiveSessionEventArgs {
                        Session = null
                    });
                    GameOver?.Invoke(this, new GameOverEventArgs {
                        WinnerId = data
                    });
                });

                _hubConnection.On <int>("Play", (data) =>
                {
                    Console.WriteLine($"Round Played. Data is {data}");
                    RoundPlayed?.Invoke(this, new GameEventArgs()
                    {
                        Value = data
                    });
                });

                _hubConnection.Closed += async(exception) => {
                    _toaster.Add(exception.Message, MatToastType.Danger);
                    await _sessionStateManager.SetSignOutState();

                    _navigationManager.NavigateTo("authentication/logout");
                };

                try
                {
                    Console.WriteLine("start signalr connection");
                    await _hubConnection.StartAsync();

                    _toaster.Add("Erfolgreich angemeldet.", MatToastType.Success, null, null, (options) => {
                        options.ShowProgressBar      = false;
                        options.ShowCloseButton      = false;
                        options.VisibleStateDuration = 2500;
                    });
                    await JoinNewSession();
                }
                catch (Exception e)
                {
                    _toaster.Add(
                        $"Beim Verbinden zum Server ist etwas schief gelaufen. Error: {e.Message}",
                        MatToastType.Danger);
                }
            }
        }