Пример #1
0
        private static void FindMatch(SeekedGameType seekedGameType)
        {
            lock (_pendingMatches)
            {
                FoundGameType foundMatch = Algorithms.SeekGame(seekedGameType, _pendingMatches.Values.ToList());

                if (foundMatch != null)
                {
                    var foundMatch_PendingMatchPairInstance = _pendingMatches.First(x => x.Value.HosterId == foundMatch.HosterId);

                    _madeMatches.Add(foundMatch);
                    _pendingMatches.Remove(foundMatch_PendingMatchPairInstance.Key);
                    _pendingPlayers.Remove(foundMatch.HosterId);
                    _pendingPlayers.Remove(foundMatch.SeekerId);

                    ConsoleLogger.Current.Log(foundMatch.ToString());
                    if (MatchFoundEvent != null)
                    {
                        MatchFoundEvent.Invoke(foundMatch, new EventArgs());
                    }
                }
                else
                {
                    _pendingMatches[DateTime.Now] = new HostedGameType
                    {
                        HosterId = seekedGameType.SeekerId,
                        HosterRating = seekedGameType.SeekerRating,
                        StartTime = seekedGameType.StartTime,
                        AddedTimePerMove = seekedGameType.AddedTimePerMove,
                        OpponentRatingFrom = seekedGameType.OpponentRatingFrom,
                        OpponentRatingTo = seekedGameType.OpponentRatingTo
                    };
                }
            }
        }
Пример #2
0
 public static void Enqueue(SeekedGameType seekedGameType)
 {
     lock (_pendingMatches)
     {
         if (!_pendingPlayers.Where(x => x == seekedGameType.SeekerId).Any())
         {
             _pendingPlayers.Add(seekedGameType.SeekerId);
             ConsoleLogger.Current.Log("Find match for " + seekedGameType.SeekerId);
             FindMatch(seekedGameType);
         }
     }
 }
Пример #3
0
 public static FoundGameType SeekGame(SeekedGameType gameType, List <HostedGameType> hostedGames)
 {
     foreach (var hostedGame in hostedGames)
     {
         if (hostedGame.StartTime == gameType.StartTime &&
             hostedGame.AddedTimePerMove == gameType.AddedTimePerMove &&
             hostedGame.HosterRating >= gameType.OpponentRatingFrom &&
             hostedGame.HosterRating <= gameType.OpponentRatingTo &&
             gameType.SeekerRating >= hostedGame.OpponentRatingFrom &&
             gameType.SeekerRating <= hostedGame.OpponentRatingTo)
         {
             return(new FoundGameType
             {
                 HosterId = hostedGame.HosterId,
                 SeekerId = gameType.SeekerId,
                 StartTime = hostedGame.StartTime,
                 AddedTimePerMove = hostedGame.AddedTimePerMove
             });
         }
     }
     return(null);
 }
Пример #4
0
 public static FoundGameType SeekGame(SeekedGameType gameType, List<HostedGameType> hostedGames)
 {
     foreach (var hostedGame in hostedGames)
     {
         if (hostedGame.StartTime == gameType.StartTime
             && hostedGame.AddedTimePerMove == gameType.AddedTimePerMove
             && hostedGame.HosterRating >= gameType.OpponentRatingFrom
             && hostedGame.HosterRating <= gameType.OpponentRatingTo
             && gameType.SeekerRating >= hostedGame.OpponentRatingFrom
             && gameType.SeekerRating <= hostedGame.OpponentRatingTo)
         {
             return new FoundGameType
             {
                 HosterId = hostedGame.HosterId,
                 SeekerId = gameType.SeekerId,
                 StartTime = hostedGame.StartTime,
                 AddedTimePerMove = hostedGame.AddedTimePerMove
             };
         }
     }
     return null;
 }
Пример #5
0
 public void FindMatch(SeekedGameType seekedGameType)
 {
     MatchQueue.Enqueue(seekedGameType);
 }