예제 #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
        private void OnReportMatch(FoundGameType foundGameType)
        {
            MatchDto matchDto = new MatchDto
            {
                MatchId           = Guid.NewGuid().ToString(),
                IsGameInitialized = false,
                IsDrawOffered     = false,
                GameFoundTime     = DateTime.Now,
                InitialTime       = foundGameType.StartTime,
                AddedTimePerMove  = foundGameType.AddedTimePerMove
            };

            ValilGame valilGame = InitValilGame();

            UserDto hoster = InitPlayer(foundGameType.HosterId, matchDto, valilGame);
            UserDto seeker = InitPlayer(foundGameType.SeekerId, matchDto, valilGame);

            matchDto.White = hoster;
            matchDto.Black = seeker;

            _gameHub.Clients.Group(matchDto.MatchId).reportMatch(matchDto);
        }