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 }; } } }
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); } } }
public void FindMatch(SeekedGameType seekedGameType) { MatchQueue.Enqueue(seekedGameType); }