예제 #1
0
        private void GenerateForAbnormal(Turnyras turnyras, int CurrentRoundNr, Raundas Raundas, List <Tuple <int, int> > TeamsSplit, int TimePerGame)
        {
            var Zonos    = new List <KompiuteriuZona>(turnyras.KompiuteriuZonos);
            var curZone  = Zonos.First(z => z.KompiuteriuSkaicius >= 10);
            var remCount = curZone.KompiuteriuSkaicius;
            var incValue = 0;

            Zonos.Remove(curZone);
            foreach (var TeamPair in TeamsSplit)
            {
                if (remCount < 10)
                {
                    if (Zonos.Count > 0)
                    {
                        curZone = Zonos.First(z => z.KompiuteriuSkaicius >= 10);
                        Zonos.Remove(curZone);
                        remCount = curZone.KompiuteriuSkaicius;
                    }
                    else
                    {
                        Zonos    = new List <KompiuteriuZona>(turnyras.KompiuteriuZonos);
                        curZone  = Zonos.First(z => z.KompiuteriuSkaicius >= 10);
                        remCount = curZone.KompiuteriuSkaicius;
                        incValue++;
                    }
                }
                DateTime gameStartTime = turnyras.PradziosData;
                gameStartTime = gameStartTime.AddMinutes(TimePerGame * (CurrentRoundNr - 1 + incValue));
                var game = CreateGame(TeamPair.Item1, TeamPair.Item2, curZone.Id, Raundas.Id, gameStartTime);
                Raundas.Zaidimai.Add(game);
                remCount -= 10;
            }
        }
예제 #2
0
        Raundas CreateRound(int Tournament, int Nr)
        {
            var Raundas = new Raundas {
                TurnyrasId = Tournament, Numeris = Nr
            };

            _context.Raundas.Add(Raundas);
            _context.SaveChanges();
            return(Raundas);
        }
예제 #3
0
        private Raundas GenerateTimetable(Turnyras turnyras, List <KomandaTurnyras> teamTournaments)
        {
            var teams = _context.Komanda.Where(k => teamTournaments.Any(tt => tt.KomandaId == k.Id)).ToList();

            teams = teams.OrderBy(t => t.Laimejimai / (t.Pralaimejimai + 1)).ToList();
            var     Reitingai      = teams.Select(t => new { Reitingas = t.Laimejimai / (t.Pralaimejimai + 1), id = t.Id });
            var     rounds         = _context.Raundas.Where(r => r.TurnyrasId == turnyras.Id);
            int     CurrentRoundNr = rounds.Count() > 0 ? rounds.Max(r => r.Numeris) + 1 : 1;
            Raundas Raundas        = CreateRound(turnyras.Id, CurrentRoundNr);

            Raundas.Zaidimai = new List <Zaidimas>();
            var TeamsSplit = new List <Tuple <int, int> >();

            if (rounds.Count() > 0)
            {
                var winTeam = new List <Tuple <int, int> >();
                CalculateWins(teams, rounds, winTeam);
                winTeam.OrderByDescending(wt => wt.Item1);
                PairTeams(TeamsSplit, winTeam);
            }
            else
            {
                while (teams.Count > 1)
                {
                    var two = teams.Take(2).ToArray();
                    TeamsSplit.Add(new Tuple <int, int>(two[0].Id, two[1].Id));
                    teams.Remove(two[0]);
                    teams.Remove(two[1]);
                }
            }
            if (TeamsSplit.Count * 10 <= turnyras.KompiuteriuZonos.Sum(kz => kz.KompiuteriuSkaicius))
            {
                GenerateForNormal(turnyras, CurrentRoundNr, Raundas, TeamsSplit);
            }
            else
            {
                var compCount   = turnyras.KompiuteriuZonos.Sum(kz => kz.KompiuteriuSkaicius);
                var TimeBlocks  = Math.Ceiling(TeamsSplit.Count / (Math.Floor((double)compCount / 10)));
                var TimePerGame = Convert.ToInt32(Math.Floor(50 / (TimeBlocks)));
                CalculateWaitingTimes(TeamsSplit, TimePerGame);

                var RatedTeams = TeamsSplit.OrderBy(ts => Reitingai.First(r => ts.Item1 == r.id).Reitingas + Reitingai.First(r => ts.Item2 == r.id).Reitingas).ToList();
                //Generate games
                GenerateForAbnormal(turnyras, CurrentRoundNr, Raundas, RatedTeams, TimePerGame);
            }
            return(Raundas);
        }