예제 #1
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            TeamFootball opponent = obj as TeamFootball;

            if (opponent != null)
            {
                // Below comparison implements: https://en.wikipedia.org/wiki/UEFA_Euro_2016#Tiebreakers
                // skippings criteria 1,2,3,4 as we don t record scores per match
                if (Score != opponent.Score)
                {
                    return(Score.CompareTo(opponent.Score));
                }
                else if (GoalsDifference != opponent.GoalsDifference)
                {
                    return(GoalsDifference.CompareTo(opponent.GoalsDifference));
                }
                else
                {
                    return(Points.CompareTo(opponent.Points));
                }
            }
            else
            {
                throw new ArgumentException("Object in comparison is not TeamFootball");
            }
        }
예제 #2
0
        public TeamFootball[] PlayCompetition()
        {
            TeamFootball[] finalRanking = new TeamFootball[nTeams];
            int            k            = 0;

            foreach (TeamFootball[] group in Groups.Values)
            {
                foreach (TeamFootball team in group)
                {
                    finalRanking[k] = team;
                    k++;
                }
            }
            //First we play all the groups games to rank teams in each group
            foreach (TeamFootball[] group in Groups.Values)
            {
                for (int i = 0; i < group.Length - 1; i++)
                {
                    for (int j = i + 1; j < group.Length; j++)
                    {
                        TeamFootball team1 = group[i];
                        TeamFootball team2 = group[j];
                        TeamFootball winner;
                        if (team1.Name != team2.Name)
                        {
                            winner = Goals.PlayMatch(team1, team2, true);
                        }
                    }
                }
            }
            populateMatches();

            // We now play the knockout phase
            for (int i = 8; i > 0; i /= 2)
            {
                for (int j = 0; j < i; j += 2)
                {
                    Tuple <TeamFootball, TeamFootball> match1 = MatchesKnockout[i - 1 + j];
                    Tuple <TeamFootball, TeamFootball> match2 = MatchesKnockout[i + j];
                    TeamFootball winnerOne = Goals.PlayMatch(match1.Item1, match1.Item2, false);
                    TeamFootball winnerTwo = Goals.PlayMatch(match2.Item1, match2.Item2, false);
                    if (i > 1)
                    {
                        MatchesKnockout[(i + j) / 2 - 1] = new Tuple <TeamFootball, TeamFootball>(winnerOne, winnerTwo);
                    }
                }
            }
            Array.Sort(finalRanking);
            Array.Reverse(finalRanking);
            return(finalRanking);
        }
예제 #3
0
        public TeamFootball PlayMatch(TeamFootball team1, TeamFootball team2, bool allowDrawn)
        // returns true for winner, false for loser, and (true,true) if drawn
        // also populates the teams points numbers
        {
            // TODO: -find a better drawing system
            //       -populate team1 and team2 with the goals
            int goals1, goals2;

            switch (Method)
            {
            case MethodToUse.stupid:
                (goals1, goals2) = StupidMethod(team1.Points, team2.Points, allowDrawn);
                break;

            case MethodToUse.poisson:
                (goals1, goals2) = Poisson(team1.Points, team2.Points, allowDrawn);
                break;

            case MethodToUse.quickWeighted:
                (goals1, goals2) = QuickRandWeightedDrawn(team1.Points, team2.Points, allowDrawn);
                break;

            default:
                (goals1, goals2) = StupidMethod(team1.Points, team2.Points, allowDrawn);
                break;
            }
            if (goals1 == goals2)
            {
                team1.OneNada(goals1, goals2);
                team2.OneNada(goals2, goals1);
                return(team1);
            }
            if (goals1 > goals2)
            {
                team1.OneUp(goals1, goals2);
                team2.OneDown(goals2, goals1);
                return(team1);
            }
            else
            {
                team1.OneDown(goals1, goals2);
                team2.OneUp(goals2, goals1);
                return(team2);
            }
        }