private bool GetChallengerColor(ChallengeDatabaseModel challenge) { bool isChallengerWhite; if (challenge.ChallengerColor == ChallengerColor.Random) { isChallengerWhite = _random.NextDouble() > 0.5; } else { isChallengerWhite = challenge.ChallengerColor == ChallengerColor.White; } return(isChallengerWhite); }
private Game CreateNewGame(ChallengeDatabaseModel challenge, User challenger, User recipient) { var game = new Game(); var startingFen = GameConstants.STANDARD_START_POSITION_FEN; var isChallengerWhite = GetChallengerColor(challenge); game.WhitePlayer = isChallengerWhite ? challenger : recipient; game.BlackPlayer = isChallengerWhite ? recipient : challenger; game.Fen = startingFen; var newGameId = _stringIdGenerator.GenerateId(); _gameRepository.CreateGame(newGameId, game.WhitePlayer.Id, game.BlackPlayer.Id); _gameRepository.AddPositionToGame(newGameId, game.Fen); game.Id = newGameId; return(game); }