Beispiel #1
0
        public static Schedule CreateGamesSingleGroup(Competition competition, int year, int lastGameNumber, int startDay, List <ITeam> teams, bool homeAndAway, GameRules rules, IGameCreator gameCreator)
        {
            int[,] array = CreateArrayForScheduling(teams.Count);

            int totalDays = teams.Count % 2 == 0 ? teams.Count - 1 : teams.Count;


            var schedule = new Schedule();

            for (int i = 0; i < totalDays; i++)
            {
                schedule.AddDay(i + startDay);
            }
            //agorithm for swapping the values


            for (int d = startDay; d < totalDays + startDay; d++)
            {
                for (int i = 0; i < array.GetLength(0); i++)
                {
                    if (array[i, 0] != -1)
                    {
                        var g = gameCreator.CreateGame(0, i, year, teams[array[i, 0]], teams[array[i, 1]], rules);
                        //var g = new ScheduleGame(competition, 0, i, year, teams[array[i, 0]], teams[array[i, 1]], 0, 0, false, 1, 0, rules, false);
                        schedule.Days[d].Games.Add(g);
                    }
                }

                array = ProcessNextPosition(array);
            }

            if (homeAndAway)
            {
                CreateAwayGamesForHomeAndAway(schedule, totalDays + startDay, rules, gameCreator);
            }

            foreach (KeyValuePair <int, ScheduleDay> data in schedule.Days)
            {
                lastGameNumber = UpdateGameNumbers(lastGameNumber, data.Value);
            }

            return(schedule);
        }
Beispiel #2
0
        //this doesn't add it to the schedule at all
        public IList <PlayoffGame> CreateRequiredGames(IGameCreator gameCreater)
        {
            var newGames = new List <PlayoffGame>();

            if (!Complete)
            {
                int winsRequired = RequiredWins - HomeWins <= RequiredWins - AwayWins ? RequiredWins - HomeWins : RequiredWins - AwayWins;

                int inCompleteOrUnProcessedGames = GetInCompelteOrUnProcessedGames().Count;

                for (int i = 0; i < (winsRequired - inCompleteOrUnProcessedGames); i++)
                {
                    var newGame = (PlayoffGame)gameCreater.CreateGame(Home, Away);
                    newGame.Series = this;
                    newGames.Add(newGame);
                    Games.Add(newGame);
                }
            }

            return(newGames);
        }
Beispiel #3
0
        public static Schedule CreateAwayGamesForHomeAndAway(Schedule schedule, int dayToStartHomeAndAway, IGameCreator gameCreator)
        {
            int count = 0;

            schedule.Days.Keys.ToList().ForEach(dayNumber =>
            {
                int newDay = dayToStartHomeAndAway + count;
                if (!schedule.Days.ContainsKey(newDay))
                {
                    schedule.Days.Add(newDay, new ScheduleDay(dayToStartHomeAndAway + count));
                }

                schedule.Days[dayNumber].Games.ToList().ForEach(game =>
                {
                    var g = gameCreator.CreateGame(game.Away, game.Home);
                    schedule.Days[newDay].Games.Add(g);
                });

                count++;
            });
            return(schedule);
        }
Beispiel #4
0
        public static Schedule CreateAwayGamesForHomeAndAway(Schedule schedule, int dayToStartHomeAndAway, GameRules rules, IGameCreator gameCreator)
        {
            int count = 0;

            schedule.Days.Keys.ToList().ForEach(dayNumber =>
            {
                int newDay = dayToStartHomeAndAway + count;
                if (!schedule.Days.ContainsKey(newDay))
                {
                    schedule.Days.Add(newDay, new ScheduleDay(dayToStartHomeAndAway + count));
                }

                schedule.Days[dayNumber].Games.ForEach(game =>
                {
                    var g = gameCreator.CreateGame(0, newDay, game.Year, game.Away, game.Home, rules);
                    //var g = new ScheduleGame(game.Competition, 0, newDay, game.Year, game.Away, game.Home, 0, 0, false, 1, 0, rules, false);
                    schedule.Days[newDay].Games.Add(g);
                });

                count++;
            });
            return(schedule);
        }
Beispiel #5
0
 public void Execute()
 {
     _gameCreator.CreateGame(_gameSettings, _manipulator);
 }
Beispiel #6
0
        //Assumption is that they can add days afterwards.  Different methods need to handle adding games to already established days
        //todo need to rework this
        public static Schedule CreateGamesTwoDifferentGroups(Competition competition, int year, int lastGameNumber, int startDay, List <ITeam> homeTeams, List <ITeam> awayTeams, bool homeAndAway, GameRules rules, IGameCreator gameCreator)
        {
            int  initialDays        = 0;
            var  aTeamList          = new List <ITeam>();
            var  bTeamList          = new List <ITeam>();
            bool reverseHomeAndAway = false;

            //the larger team list has to be the top loop
            if (homeTeams.Count >= awayTeams.Count)
            {
                aTeamList   = homeTeams;
                bTeamList   = awayTeams;
                initialDays = homeTeams.Count;
            }
            else
            {
                bTeamList          = homeTeams;
                aTeamList          = awayTeams;
                reverseHomeAndAway = true;
                initialDays        = awayTeams.Count;
            }

            int maxDay = initialDays + startDay - 1;

            var schedule = new Schedule();

            for (int i = 0 + startDay; i <= maxDay; i++)
            {
                schedule.AddDay(i);
            }

            int currentDay   = startDay;
            int teamStartDay = currentDay;

            aTeamList.ForEach(aTeam =>
            {
                currentDay = teamStartDay;
                //for each home team loop through the away teams, increment the day by one and add the next game.
                bTeamList.ForEach(bTeam =>
                {
                    var game = gameCreator.CreateGame(0, currentDay, year, reverseHomeAndAway ? bTeam : aTeam, reverseHomeAndAway ? aTeam : bTeam, rules);

                    /*
                     * var game = new ScheduleGame(competition, 0, currentDay, year,
                     *  reverseHomeAndAway ? bTeam:aTeam, reverseHomeAndAway ? aTeam:bTeam,
                     *  0, 0, false, 1, 0, rules, false);
                     */
                    schedule.Days[currentDay].AddGame(game);

                    currentDay = GetNextDay(currentDay, startDay, maxDay, 1);
                });
                //when done the home team games, start on the previous day the last team started on and go through it again
                teamStartDay = GetNextDay(teamStartDay, startDay, maxDay, -1);
            });


            if (homeAndAway)
            {
                CreateAwayGamesForHomeAndAway(schedule, maxDay + 1, rules, gameCreator);
            }
            //do the game numbers last so that they are in order by day
            foreach (KeyValuePair <int, ScheduleDay> data in schedule.Days)
            {
                lastGameNumber = UpdateGameNumbers(lastGameNumber, data.Value);
            }

            return(schedule);
        }
Beispiel #7
0
 public async Task <GameCreateResult> Create([FromBody] GameCreate model)
 {
     return(await gameCreator.CreateGame(model));
 }