Пример #1
0
        public void Match(MakeMatch request)
        {
            var requestedByUserRating = _userRatingRepository.GetByUserGameType(request.RequestedByUserId,
                                                                                request.GameType);

            if (requestedByUserRating == null)
            {
                _log.LogWarning("User {UserId} does not have a rating for GameType of {GameType}", request.RequestedByUserId, request.GameType.ToString());

                return;
            }

            // Add the match definition as needed
            var match = _matchTransformer.To(request);

            var matchId = _matchRepository.AddIgnore(match);

            // For now, simply going to always take found possible matches and add them as matches you could pick to play. Naturally this could get
            // a lot more complex, including duplicate checking (though there would likely be some threshold at which the duplicates do not apply any
            // longer since time has gone on and things have changed), or to match only a certain number of a particular strategy (i..e. the easiest or most
            // difficult, or those I haven't played before, etc.)
            foreach (var userRating in _userRatingRepository.GetPossibleMatches(requestedByUserRating.Rating, request)
                     .Where(ur => ur.UserId != requestedByUserRating.UserId))
            {
                // Just insert matches
                var matchPair = _matchPairTransformer.To(userRating);

                matchPair.RequestedUserId  = request.RequestedByUserId;
                matchPair.RequestedUserMmr = requestedByUserRating.Rating;
                matchPair.MatchId          = matchId;

                _matchPairRepository.Add(matchPair);
            }
        }
Пример #2
0
        public IEnumerable <UserRating> GetPossibleMatches(double rating, MakeMatch makeMatch)
        {
            var within = makeMatch.MaxMmrGap ?? _settingsRepository.GetDefaultSetting().DefaultMaxMmrGap;

            // If asked for Harder matches only, lower bound is the rating.
            // Otherwise, it is the rating minus the within requested
            var lower = makeMatch.MatchType == MatchType.HarderOnly
                            ? rating
                            : rating - Math.Abs(within);

            // If asked for easier matches only, upper bound is the rating
            // Otherwise, it is the rating plus the within requested
            var upper = makeMatch.MatchType == MatchType.EasierOnly
                            ? rating
                            : rating + Math.Abs(within);

            return(_dbModels.Values.Where(v => v.GameType == makeMatch.GameType &&
                                          v.Rating >= lower &&
                                          v.Rating <= upper));
        }
Пример #3
0
        public void Enqueue(MakeMatch request)
        {
            _queue.Enqueue(request);

            NotifyObservers();
        }