Beispiel #1
0
        private IEnumerable <ScheduleView> GenerateOddTeamRoundRobin(List <string> teamNames)
        {
            var seasonInfo = _rosterService.GetSeasonInfoView().Result;

            var views = new List <ScheduleView>();

            var startDate = seasonInfo.SeasonInfo.SeasonStartDate;

            for (var week = 0; week < teamNames.Count; week++)
            {
                var date          = startDate.AddDays(7 * week);
                var weeklyMatches = new List <ScheduleView>();
                if (teamNames.Count == 5)
                {
                    weeklyMatches.AddRange(CreateFor5TeamWeek(week, teamNames, date));
                }
                else if (teamNames.Count == 7)
                {
                    weeklyMatches.AddRange(CreateFor7TeamWeek(week, teamNames, date));
                }

                foreach (var match in weeklyMatches)
                {
                    var swap = TrueRandom.TrueRandomGenerator();
                    if (!swap)
                    {
                        var temp = match.HomeTeam;
                        match.HomeTeam = match.AwayTeam;
                        match.AwayTeam = temp;
                    }
                }
                views.AddRange(weeklyMatches);
            }

            return(views);
        }
Beispiel #2
0
        private IEnumerable <ScheduleView> GenerateRoundRobin(List <string> teamNames, string divisionName)
        {
            var seasonInfo = _rosterService.GetSeasonInfoView().Result;

            var views = new List <ScheduleView>();

            if (teamNames.Count % 2 == 1)
            {
                return(GenerateOddTeamRoundRobin(teamNames));
            }

            var teamSize = teamNames.Count;

            var weeks    = Math.Min(teamSize - 1, 7);
            var halfSize = teamSize / 2;
            var teams    = new List <string>();

            teams.AddRange(teamNames);
            teams.RemoveAt(0);

            teamSize--;

            var startDate = seasonInfo.SeasonInfo.SeasonStartDate;

            for (var week = 0; week < weeks; week++)
            {
                var date       = startDate.AddDays(7 * week);
                var teamIndex  = week % teamSize;
                var firstTeam  = teams[teamIndex];
                var secondTeam = teamNames[0];

                views.Add(new ScheduleView
                {
                    ScheduleId    = Guid.NewGuid(),
                    HomeTeam      = firstTeam,
                    AwayTeam      = secondTeam,
                    HomeTeamScore = 0,
                    AwayTeamScore = 0,
                    WeekOf        = date
                });

                for (var index = 1; index < halfSize; index++)
                {
                    firstTeam  = teams[(week + index) % teamSize];
                    secondTeam = teams[(week + teamSize - index) % teamSize];

                    var swap = TrueRandom.TrueRandomGenerator();

                    if (!swap)
                    {
                        var temp = firstTeam;
                        firstTeam  = secondTeam;
                        secondTeam = temp;
                    }

                    views.Add(new ScheduleView
                    {
                        ScheduleId    = Guid.NewGuid(),
                        HomeTeam      = firstTeam,
                        AwayTeam      = secondTeam,
                        HomeTeamScore = 0,
                        AwayTeamScore = 0,
                        WeekOf        = date
                    });
                }
            }

            if (weeks < 4)
            {
                var tempViews = new List <ScheduleView>(views);
                foreach (var view in views)
                {
                    var round2 = new ScheduleView
                    {
                        ScheduleId    = Guid.NewGuid(),
                        HomeTeam      = view.AwayTeam,
                        AwayTeam      = view.HomeTeam,
                        HomeTeamScore = 0,
                        AwayTeamScore = 0,
                        WeekOf        = view.WeekOf.AddDays(21)
                    };
                    tempViews.Add(round2);
                }

                views = tempViews;
            }

            return(views);
        }