private static List <Matchup> CreateFirstRound(int byes, List <Team> teams)
        {
            List <Matchup> output = new List <Matchup>();
            Matchup        curr   = new Matchup();

            foreach (Team team in teams)
            {
                curr.Entries.Add(new MatchupEntry {
                    TeamCompeting = team
                });

                if (byes > 0 || curr.Entries.Count > 1)
                {
                    curr.MatchupRound = 1;
                    output.Add(curr);
                    curr = new Matchup();

                    if (byes > 0)
                    {
                        byes -= 1;
                    }
                }
            }
            return(output);
        }
        private static void CreateOtherRounds(Tournament model, int rounds)
        {
            int            round         = 2;
            List <Matchup> previousRound = model.Rounds[0];
            List <Matchup> currRound     = new List <Matchup>();
            Matchup        currMatchup   = new Matchup();

            while (round <= rounds)
            {
                foreach (Matchup match in previousRound)
                {
                    currMatchup.Entries.Add(new MatchupEntry {
                        ParentMatchup = match
                    });

                    if (currMatchup.Entries.Count > 1)
                    {
                        currMatchup.MatchupRound = round;
                        currRound.Add(currMatchup);
                        currMatchup = new Matchup();
                    }
                }

                model.Rounds.Add(currRound);
                previousRound = currRound;
                currRound     = new List <Matchup>();
                round        += 1;
            }
        }
Beispiel #3
0
        public void UpdateMatchups(Matchup model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@winnerId", model.winnerId);
                p.Add("@id", model.Id);

                connection.Execute("dbo.spMatchup_Update", p, commandType: CommandType.StoredProcedure);

                foreach (MatchupEntry entry in model.Entries)
                {
                    p = new DynamicParameters();
                    p.Add("@id", entry.Id);
                    if (entry.CompetingTeamId != 0)
                    {
                        p.Add("@CompetingTeamId", entry.CompetingTeamId);
                    }
                    if (entry.Score != 0)
                    {
                        p.Add("@Score", entry.Score);
                    }

                    connection.Execute("dbo.spMatchupEntry_Update", p, commandType: CommandType.StoredProcedure);
                }
            }
        }
Beispiel #4
0
        private static List <Matchup> CreateFirstRound(int emptyTeams, List <Team> teams)
        {
            List <Matchup> output  = new List <Matchup>();
            Matchup        current = new Matchup();

            //reallyMatchup = teams.Skip(emptyTeams);
            foreach (Team team in teams)
            {
                current.Entries.Add(new MatchupEntry {
                    TeamCompeting = team
                });
                if (emptyTeams > 0 || current.Entries.Count > 1)
                {
                    current.Round = 1;
                    output.Add(current);
                    current = new Matchup();
                    if (emptyTeams > 0)
                    {
                        emptyTeams--;
                    }
                }
            }
            //Put every team from first round in pairs to List<Matchup>
            return(output);
        }
Beispiel #5
0
        private static void OtherRounds(Tournament model, int rounds)
        {
            int            round         = 2;
            int            count         = 0;
            List <Matchup> previousRound = model.Rounds[count];
            List <Matchup> currentRound  = new List <Matchup>();
            Matchup        current       = new Matchup();

            while (round <= rounds)
            {
                foreach (Matchup matchup in previousRound)
                {
                    current.Entries.Add(new MatchupEntry {
                        ParentMatchup = matchup
                    });
                    if (current.Entries.Count > 1)
                    {
                        current.Round = round;
                        currentRound.Add(current);
                        current = new Matchup();
                    }
                }
                round++;
                //count++;
                //model.Rounds[count] = currentRound;
                model.Rounds.Add(currentRound);
                previousRound = currentRound;
                currentRound  = new List <Matchup>();
            }
        }
        private static List <Team> GetTeamsByPlace(Tournament model)
        {
            List <Team>            output = new List <Team>();
            Dictionary <Team, int> teamsBonusPointsDict = new Dictionary <Team, int>();

            foreach (Team t in model.EnteredTeams)
            {
                teamsBonusPointsDict.Add(t, 0);
            }

            Matchup finalMatch = model.Rounds.Last().First();

            output.Add(finalMatch.Winner);

            for (int roundIndex = model.Rounds.Count - 1; roundIndex >= 0; roundIndex--)
            {
                int         counter    = model.Rounds.Count - roundIndex - 1;
                int         bonusScore = (int)Math.Pow(2, counter);
                List <Team> teamsLost  = new List <Team>();
                foreach (Matchup match in model.Rounds[roundIndex])
                {
                    Team matchLoser = match.Entries.Find(me => me.TeamCompeting != match.Winner)?.TeamCompeting;
                    if (matchLoser != null)
                    {
                        teamsLost.Add(matchLoser);
                    }
                    MatchupEntry winnerEntry = match.Entries.Find(m => m.TeamCompeting == match.Winner);
                    ScoreBonusPointsToPreviousMatchups(teamsBonusPointsDict, winnerEntry, bonusScore);
                }

                Dictionary <Team, int> teamsPointsInRound = new Dictionary <Team, int>();
                foreach (Team t in teamsLost)
                {
                    teamsPointsInRound.Add(t, teamsBonusPointsDict[t]);
                }
                teamsPointsInRound.OrderByDescending(t => t.Value);

                while (teamsPointsInRound.Count > 0)
                {
                    Team bestOfLostTeams = teamsPointsInRound.First().Key;
                    output.Add(bestOfLostTeams);
                    teamsPointsInRound.Remove(bestOfLostTeams);
                }
            }
            return(output);
        }
        private static List <Matchup> CreateFirstRound(List <Team> teams, int byes)
        {
            List <Matchup> output         = new List <Matchup>();
            Matchup        currentMatchup = new Matchup();

            foreach (Team t in teams)
            {
                currentMatchup.Entries.Add(new MatchupEntry {
                    TeamCompeting = t
                });
                if (byes > 0 || currentMatchup.Entries.Count > 1)
                {
                    currentMatchup.MatchupRound = 1;
                    output.Add(currentMatchup);
                    currentMatchup = new Matchup();

                    if (byes > 0)
                    {
                        byes--;
                    }
                }
            }
            return(output);
        }