Пример #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 void FindMatch(SeekedGameType seekedGameType)
 {
     MatchQueue.Enqueue(seekedGameType);
 }