Exemple #1
0
        public static ParticipationCombatModel ConvertToCombat(this ParticipationModel input)
        {
            var result = new ParticipationCombatModel();

            result.CategoriePratiquantId = input.CategoriePratiquantId;
            result.ParticipantId         = input.ParticipantId;
            result.ClubId    = input.ClubId;
            result.Club      = input.Club;
            result.EpreuveId = input.EpreuveId;
            result.Nom       = input.Nom;
            result.Prenom    = input.Prenom;
            result.Id        = input.Id;
            result.Vainqueur = null;
            return(result);
        }
 private static ParticipationCombatModel CloneParticipant(ParticipationCombatModel participationCombatModel, string color, RankContest rank)
 {
     Console.WriteLine(participationCombatModel.Nom);
     return(new ParticipationCombatModel
     {
         Club = participationCombatModel.Club,
         ClubId = participationCombatModel.ClubId,
         CategoriePratiquantId = participationCombatModel.CategoriePratiquantId,
         Couleur = color,
         EpreuveId = participationCombatModel.EpreuveId,
         Id = participationCombatModel.Id,
         Nom = participationCombatModel.Nom,
         ParticipantId = participationCombatModel.ParticipantId,
         Prenom = participationCombatModel.Prenom,
         Present = participationCombatModel.Present,
         Vainqueur = null,
         Rank = rank
     });
 }
        public static IEnumerable <MatchPairModel> BuildRounds(IOrderedEnumerable <ParticipationCombatModel> competiteurs, int roundNumber = 2)
        {
            var list        = new List <MatchPairModel>();
            var copy        = competiteurs.ToList();
            int fightNumber = 1;

            if (copy.Count == 2)
            {
                list.Add(new MatchPairModel
                {
                    Blue      = copy[0],
                    Red       = copy[1],
                    Rencontre = "Rencontre 1"
                });
                return(list);
            }

            if (copy.Count == 3)
            {
                list.Add(new MatchPairModel
                {
                    Blue      = copy[0],
                    Red       = copy[1],
                    Rencontre = "Rencontre 1"
                });
                list.Add(new MatchPairModel
                {
                    Blue      = copy[1],
                    Red       = copy[2],
                    Rencontre = "Rencontre 2"
                });
                list.Add(new MatchPairModel
                {
                    Blue      = copy[0],
                    Red       = copy[2],
                    Rencontre = "Rencontre 3"
                });
                return(list);
            }

            var countIsEven = copy.Count % 2 == 0;
            int neededCall  = countIsEven ? copy.Count / 2 : (copy.Count - 1) / 2;

            var blues = copy.Take(neededCall).ToList();
            var reds  = copy.Skip(neededCall).Take(neededCall).Reverse().ToList();
            List <ParticipationCombatModel> deadMenWaiting = new List <ParticipationCombatModel>();
            ParticipationCombatModel        excluded       = countIsEven ? null : copy.Last();

            for (int i = 0; i < roundNumber; i++)
            {
                //Pairing
                for (int j = 0; j < neededCall; j++)
                {
                    list.Add(new MatchPairModel
                    {
                        Blue      = blues[j],
                        Red       = reds[j],
                        Rencontre = string.Format("Rencontre {0}", fightNumber)
                    });
                    fightNumber++;
                }

                //Building from alone players
                if (!countIsEven)
                {
                    if (deadMenWaiting.Count == 0)
                    {
                        deadMenWaiting.Add(excluded);
                    }
                    else
                    {
                        list.Add(new MatchPairModel
                        {
                            Blue      = deadMenWaiting[0],
                            Red       = excluded,
                            Rencontre = string.Format("Rencontre {0}", fightNumber)
                        });
                        fightNumber++;
                        deadMenWaiting.Clear();
                    }

                    //Shifting reds and blues
                    reds.Add(excluded);
                    excluded = blues.Last();
                    blues.Insert(1, reds.First());
                    reds.RemoveAt(0);
                    blues.RemoveAt(blues.Count - 1);
                }
                else
                {
                    reds.Add(blues.Last());
                    blues.Insert(1, reds.First());
                    reds.RemoveAt(0);
                    blues.RemoveAt(blues.Count - 1);
                }
            }

            return(list);
        }