예제 #1
0
 private bool PlayerIsQualified(PlayerPivot player)
 {
     return(player != null && Matches.Any(match =>
                                          (match.Winner == player && match.WinnerEntry?.IsQualification == true) ||
                                          (match.Loser == player && match.LoserEntry?.IsQualification == true)
                                          ));
 }
예제 #2
0
            public bool isMatch(bool[] toMatch)
            {
                if (toMatch.Length != Matches[0].Length)
                {
                    return(false);
                }

                return(Matches.Any(m => m.SequenceEqual(toMatch)));
            }
        public bool Score(int selectedMatch, int score1, int score2)
        {
            var match = Matches[selectedMatch];

            if (match.State == MatchState.Ended)
            {
                return(false);
            }

            if (score1 == score2)
            {
                return(false);
            }

            string matchWinner;

            if (score1 > score2)
            {
                matchWinner = match.Team1;
            }
            else
            {
                matchWinner = match.Team2;
            }

            match.Score1 = score1;
            match.Score2 = score2;
            match.State  = MatchState.Ended;

            //Select a match that only have one team(is considered a Open Match)
            //If dont exist, create a new one
            var nextMatch = Matches.Where(m => m.State == MatchState.Open).FirstOrDefault();

            if (nextMatch == null)
            {
                nextMatch = new Match(matchWinner, String.Empty, MatchState.Open);
                Matches.Add(nextMatch);
            }
            else
            {
                nextMatch.Team2 = matchWinner;
                nextMatch.State = MatchState.Closed;
            }

            //If the collection dont have any Closed Match avaiable,
            //that means all the matches are ended and this winner is the Tournament Winner
            if (!Matches.Any(m => m.State == MatchState.Closed))
            {
                Winner = matchWinner;
                state  = TournamentState.Ended;
                return(true);
            }

            return(true);
        }
예제 #4
0
 private void Matches_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (!Matches.Any())
     {
         HasNoMatches = true;
     }
     else
     {
         HasNoMatches = false;
     }
 }
예제 #5
0
 private List <Dictionary <string, int> > GetCalculatedData()
 {
     return(new List <Dictionary <string, int> >
     {
         new Dictionary <string, int>()
         {
             { "NumberOfRounds", Matches.Any() ? Matches.Max(m => m.Round) : 0 },
             { "CurrentId", Tournaments.Any() ? Tournaments.Max(t => int.Parse(t.ID)) : 0 }
         }
     });
 }
예제 #6
0
        private void OnEntryAdded(EntryAddedMessage msg)
        {
            Search();

            if (Matches.Any(m => m.Model.Id == msg.Entry.Id))
            {
                return;
            }

            MessengerInstance.Send(new NotificationMessage(Strings.NewEntryNotMatched));
        }
예제 #7
0
        internal bool AddMiss(Hint hint)
        {
            if (Misses.Any(m => m.Text == hint.Text) ||
                Matches.Any(m => m.Text == hint.Text))
            {
                return(false);
            }

            Misses.Add(hint.Clone());

            return(true);
        }
예제 #8
0
        internal bool AddMatch(Hint hint, TokenEnumerator enumerator)
        {
            if (Matches.Any(m => m.Text == hint.Text))
            {
                return(false);
            }

            Matches.Add(new HintMatch
            {
                Text     = hint.Text,
                Optional = hint.Optional,
                Location = enumerator.Location.Clone()
            });

            return(true);
        }
예제 #9
0
 /// <summary>
 /// Add one, and only one, match between every player in the competition
 /// </summary>
 /// <param name="Players">The list of Members to match</param>
 private void MatchAllPlayersOnce(List <Member> Players)
 {
     foreach (Member self in Players)
     {
         this.Players.Add(self, 0m);
         foreach (Member other in Players)
         {
             if (self == other)
             {
                 continue;
             }
             if (Matches.Any(x => x.HasMatch(self, other)))
             {
                 continue;
             }
             Matches.Add(new Match(self, other, this.CompetitionId));
         }
     }
 }
예제 #10
0
        private bool TryConcatMatch(Token token, object value, FileLocation location)
        {
            if (token.Concatenate == false)
            {
                return(false);
            }

            if (Matches.Any(m => m.Token.Name == token.Name) == false)
            {
                return(false);
            }

            var match = Matches.First(m => m.Token.Name == token.Name);

            if (token.CanConcatenate(match.Value, value) == false)
            {
                return(false);
            }

            match.Value = token.ConcatenateValues(match.Value, value, token.ConcatenationString);

            return(true);
        }
예제 #11
0
        private void RecordMatch(MatchContext matchContext)
        {
            switch (Config.UniqueMatches)
            {
            case UniqueMatches.Off:
                Matches.Add(matchContext);
                break;

            case UniqueMatches.KeepFirst:
                if (!Matches.Any(m => m.Match.Value == matchContext.Match.Value))
                {
                    Matches.Add(matchContext);
                }
                break;

            case UniqueMatches.KeepLast:
                Matches.RemoveAll(m => m.Match.Value == matchContext.Match.Value);
                Matches.Add(matchContext);
                break;

            default:
                throw new NotImplementedException();
            }
        }
예제 #12
0
        /// <summary>
        /// Gets the number of points gained by a specified player for this edition. The gain might vary regarding of the ruleset.
        /// </summary>
        /// <param name="player">A <see cref="PlayerPivot"/></param>
        /// <param name="rankingVersion">A <see cref="RankingRulePivot"/> (ruleset of current ranking).</param>
        /// <returns>Number of points for this player at this edition; 0 if any argument is <c>Null</c>.</returns>
        internal uint GetPlayerPoints(PlayerPivot player, RankingVersionPivot rankingVersion)
        {
            uint points = 0;

            if (player == null || rankingVersion == null)
            {
                return(points);
            }

            // If qualifcation rule applies and player comes from qualifications for this edition.
            if (rankingVersion.ContainsRule(RankingRulePivot.IncludingQualificationBonus) && PlayerIsQualified(player))
            {
                points = QualificationPointPivot.GetByLevelAndDrawSize(Level.Id, DrawSize)?.Points ?? 0;
            }

            // Cumulable points (round robin).
            points += (uint)Matches
                      .Where(match => match.Winner == player && match.Round.IsRoundRobin)
                      .Sum(match => match.PointGrid?.Points ?? 0);

            var bestWin = Matches
                          .Where(match => match.Winner == player && !match.Round.IsRoundRobin && !match.Round.IsBronzeReward)
                          .OrderBy(match => match.Round.Importance)
                          .FirstOrDefault();
            var bestLose = Matches
                           .Where(match => match.Loser == player && !match.Round.IsRoundRobin && !match.Round.IsBronzeReward)
                           .OrderBy(match => match.Round.Importance)
                           .FirstOrDefault();

            if (Matches.Any(match => match.Round.IsBronzeReward && match.Players.Contains(player)))
            {
                if (Matches.Any(match => match.Winner == player && match.Round.IsBronzeReward))
                {
                    // Third place points.
                    points += Matches
                              .First(match => match.Winner == player && match.Round.IsBronzeReward)
                              .PointGrid?.Points ?? 0;
                }
                else
                {
                    // Fourth place points.
                    points += GridPointPivot.GetByLevelAndRound(Level.Id, RoundPivot.GetQuarterFinal().Id)?.Points ?? 0;
                }
            }
            else
            {
                // Unable to detect a lose by walkover the next round than a win by walkover.
                // In that case, points from the win by walkover are ignored.
                if (bestLose == null)
                {
                    points += bestWin?.PointGrid?.Points ?? 0;
                }
                else if (bestWin != null)
                {
                    var lastWinRound = RoundPivot.GetByImportance(bestLose.Round.Importance + 1);
                    var grid         = bestWin.PointGrid;
                    if (bestWin.Round.Importance > lastWinRound.Importance)
                    {
                        grid = GridPointPivot.GetByLevelAndRound(Level.Id, lastWinRound.Id);
                    }
                    points += grid?.Points ?? 0;
                }
                else
                {
                    points += bestLose.PointGrid?.ParticipationPoints ?? 0;
                }
            }

            return(points);
        }
예제 #13
0
 public bool IsEmpty()
 {
     return(!Matches.Any());
 }
예제 #14
0
 private bool PlayerHasMatch(Player piPlayer)
 {
     return(Matches.Any(match => match.Players.Contains(piPlayer)));
 }
예제 #15
0
 public bool InActiveMatch(PlayerMobile pm)
 {
     return(Matches.Any(o => !o.IsComplete && o.Contains(pm)));
 }
예제 #16
0
 /// <summary>
 /// Checks if the specified player is involved in this edition.
 /// </summary>
 /// <param name="player">The <see cref="PlayerPivot"/> to check.</param>
 /// <returns><c>True</c> if involved in this edition; <c>False</c> otherwise.</returns>
 internal bool InvolvePlayer(PlayerPivot player)
 {
     return(player != null && Matches.Any(match => match.Players.Contains(player)));
 }
예제 #17
0
파일: NSFW.cs 프로젝트: ZeroCry/Passive-BOT
        private static async Task <string> HentaiAsync(HttpClient HttpClient, Random Random, NsfwType NsfwType,
                                                       List <string> Tags)
        {
            string          Url = null;
            string          Result;
            MatchCollection Matches;

            Tags = !Tags.Any() ? new[] { "boobs", "t**s", "ass", "sexy", "neko" }.ToList() : Tags;
            switch (NsfwType)
            {
            case NsfwType.Danbooru:
                Url =
                    $"http://danbooru.donmai.us/posts?page={Random.Next(0, 15)}{string.Join("+", Tags.Select(x => x.Replace(" ", "_")))}";
                break;

            case NsfwType.Gelbooru:
                Url =
                    $"http://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=100&tags={string.Join("+", Tags.Select(x => x.Replace(" ", "_")))}";
                break;

            case NsfwType.Rule34:
                Url =
                    $"http://rule34.xxx/index.php?page=dapi&s=post&q=index&limit=100&tags={string.Join("+", Tags.Select(x => x.Replace(" ", "_")))}";
                break;

            case NsfwType.Cureninja:
                Url =
                    $"https://cure.ninja/booru/api/json?f=a&o=r&s=1&q={string.Join("+", Tags.Select(x => x.Replace(" ", "_")))}";
                break;

            case NsfwType.Konachan:
                Url =
                    $"http://konachan.com/post?page={Random.Next(0, 5)}&tags={string.Join("+", Tags.Select(x => x.Replace(" ", "_")))}";
                break;

            case NsfwType.Yandere:
                Url =
                    $"https://yande.re/post.xml?limit=25&page={Random.Next(0, 15)}&tags={string.Join("+", Tags.Select(x => x.Replace(" ", "_")))}";
                break;
            }

            var Get = await HttpClient.GetStringAsync(Url).ConfigureAwait(false);

            switch (NsfwType)
            {
            case NsfwType.Danbooru:
                Matches = Regex.Matches(Get, "data-large-file-url=\"(.*)\"");
                break;

            case NsfwType.Yandere:
            case NsfwType.Gelbooru:
            case NsfwType.Rule34:
                Matches = Regex.Matches(Get, "file_url=\"(.*?)\" ");
                break;

            case NsfwType.Cureninja:
                Matches = Regex.Matches(Get, "\"url\":\"(.*?)\"");
                break;

            case NsfwType.Konachan:
                Matches = Regex.Matches(Get, "<a class=\"directlink smallimg\" href=\"(.*?)\"");
                break;

            default:
                Matches = Regex.Matches(Get, "\"url\":\"(.*?)\"");
                break;
            }

            if (!Matches.Any())
            {
                return(null);
            }
            switch (NsfwType)
            {
            case NsfwType.Danbooru:
                Result = $"http://danbooru.donmai.us/{Matches[Random.Next(Matches.Count)].Groups[1].Value}";
                break;

            case NsfwType.Konachan:
            case NsfwType.Gelbooru:
            case NsfwType.Yandere:
            case NsfwType.Rule34:
                Result = $"{Matches[Random.Next(Matches.Count)].Groups[1].Value}";
                break;

            case NsfwType.Cureninja:
                Result = Matches[Random.Next(Matches.Count)].Groups[1].Value.Replace("\\/", "/");
                break;

            default:
                return(null);
            }

            Result = Result.EndsWith("/") ? Result.Substring(0, Result.Length - 1) : Result;
            return(Result);
        }