Beispiel #1
0
        private void btnSeedFinish_Click(object sender, EventArgs e)
        {
            if (!fStartCompetition.ShowStartWindow(FCompetitionController))
            {
                return;
            }
            /* Начало изменений */
            SeedingArgs args = SeedingArgs.Empty;

            args.PlayersToSeed = FCompetition.Players;
            args.SeedOrder     = FCompetitionController.GetDrawOrder(args.PlayersToSeed.Count);
            args.SeedType      = Seeding.SeedType.Matches;
            args.AllowRating   = FCompetition.Info.ChangesRating;


            if (FCompetition is Olympic)
            {
                args.SeedType          = Seeding.SeedType.Olympic;
                args.LastPlayerWithBay = 0;
            }
            if (FCompetition is RobinOlympic)
            {
                args.SeedType = Seeding.SeedType.Groups;
                int playersInGroup = FCompetition.Players.Count / (FCompetition as RobinOlympic).GroupCount;
                if (playersInGroup * (FCompetition as RobinOlympic).GroupCount < FCompetition.Players.Count)
                {
                    playersInGroup++;
                }
                args.Param = playersInGroup;
            }

            //if (fGraphicalSeeding.Seed(args) /*конец изменений*/&& fStartCompetition.ShowStartWindow(FCompetitionController))
            if (fGraphicalSeeding.Seed(args))
            {
                if (pnlCompetitionParams != null)
                {
                    pnlCompetitionParams.ReadParameters();
                }
                string error = "";
                if (!FCompetition.CheckCompetitionParams(ref error))
                {
                    if (error != "")
                    {
                        WindowSkin.MessageBox.Show(error, Localizator.Dictionary.GetString("PARAMS_ERROR"));
                    }
                    return;
                }

                LongOpertationExecutor.Execute(SeedPlayers);
                pnlCompetition.OpenCompetition(FCompetition);
                tcMain.SelectedTab       = tpgCompetition;
                FCompetition.Info.Status = CompetitionInfo.CompetitionState.Playing;
                DatabaseManager.CurrentDb.CompetitionInfoSave(FCompetition.Info);
                UpdateButtons();
            }
        }
Beispiel #2
0
        public override bool SeedPlayers()
        {
            SeedingArgs args = SeedingArgs.Empty;

            args.LastPlayerWithBay = 0;
            int round = 0;

            foreach (MatchInfo match in Competition.Matches.Values)
            {
                // Определяем какой игрок в последнием раунде играл с баем
                if (match.PlayerA.Id == 0 && match.Label.Round >= round)
                {
                    args.LastPlayerWithBay = match.PlayerB.Id;
                }
                if (match.PlayerB.Id == 0 && match.Label.Round >= round)
                {
                    args.LastPlayerWithBay = match.PlayerA.Id;
                }

                if (match.Label.Round > round)
                {
                    round = match.Label.Round;
                }
            }
            round++;
            // Список игрков для матчей
            CompetitionPlayerList players = new CompetitionPlayerList();

            foreach (CompetitionPlayerInfo player in GetPlayersToSeed())
            {
                if (round > 1)
                {
                    player.SeedNo = 0;
                }
                players.Add(player.Id, player);
            }
            args.PlayersToSeed = players;
            args.SeedOrder     = GetDrawOrder(args.PlayersToSeed.Count);
            args.SeedType      = Seeding.SeedType.Matches;
            args.AllowRating   = false;

            Dictionary <int, int> current_points = new Dictionary <int, int>(); // Текущее количество набранных игроками очков


            if (round == 1 || fGraphicalSeeding.Seed(args))
            {
                SeedPair[] new_mtchs = new SeedPair[players.Count / 2]; // Список новых матчей
                foreach (CompetitionPlayerInfo player in args.PlayersToSeed.Values)
                {
                    current_points.Add(player.Id, player.AvailablePoints);
                    int seed_index = player.SeedNo - 1;
                    if (seed_index >= 0)
                    {
                        int match_index = seed_index % new_mtchs.Length;
                        if (new_mtchs[match_index] == null)
                        {
                            new_mtchs[match_index] = new SeedPair(0, 0);
                        }
                        if (seed_index < new_mtchs.Length)
                        {
                            new_mtchs[match_index].playerIdA = player.Id;
                        }
                        else
                        {
                            new_mtchs[match_index].playerIdB = player.Id;
                        }
                    }
                }
                int match_no = 1;
                foreach (SeedPair pair in new_mtchs)
                {
                    MatchInfo match = CreateMatch(pair);

                    // Устанавливаем максимальное количество очков в партии
                    if (match.PlayerA.Id > 0 && match.PlayerB.Id > 0)
                    {
                        match.PlayerA.Tag = current_points[match.PlayerA.Id];
                        match.PlayerB.Tag = current_points[match.PlayerB.Id];
                    }

                    match.Label.Division = 1;
                    match.Label.Round    = round;
                    match.Label.MatchNo  = match_no;
                    TA.DB.Manager.DatabaseManager.CurrentDb.CreateMatch(Competition.Info.Id, match);
                    Competition.Matches.Add(match.Id, match);
                    match_no++;
                }
            }

            /**********************************************************************/

            /* int round = 0;
             *
             * int[] plrs = new int[players.Count];  // Список игроков для рассеивания
             * SeedPair[] mtchs = new SeedPair[Competition.Matches.Values.Count]; // Список сыгранных матчей
             * SeedPair[] new_mtchs = new SeedPair[players.Count / 2]; // Список новых матчей
             * Dictionary<int, int> current_points = new Dictionary<int, int>(); // Текущее количество набранных игроками очков
             * int index = 0;
             * foreach (CompetitionPlayerInfo player in players)
             * {
             *   plrs[index++] = player.Id;
             *   current_points.Add(player.Id, player.AvailablePoints);
             * }
             * index = 0;
             * foreach (MatchInfo match in Competition.Matches.Values)
             * {
             *   mtchs[index++] = new SeedPair(match.PlayerA.Id, match.PlayerB.Id);
             *   if (match.Label.Round > round)
             *       round = match.Label.Round;
             * }
             * round++;
             * // формируем пары для следующего раунда
             * if (!SwissSeeder.Seed(plrs, mtchs, new_mtchs, 0))
             *   throw new Exception("Draw error");
             *
             * // Создаем матчи и добавляем их в список матчей
             * int match_no = 1;
             * foreach (SeedPair pair in new_mtchs)
             * {
             *   MatchInfo match = CreateMatch(pair);
             *
             *   // Устанавливаем максимальное количество очков в партии
             *   if (match.PlayerA.Id > 0 && match.PlayerB.Id > 0)
             *   {
             *       match.PlayerA.Tag = current_points[match.PlayerA.Id];
             *       match.PlayerB.Tag = current_points[match.PlayerB.Id];
             *   }
             *
             *   match.Label.Division = 1;
             *   match.Label.Round = round;
             *   match.Label.MatchNo = match_no;
             *   TA.DB.Manager.DatabaseManager.CurrentDb.CreateMatch(Competition.Info.Id, match);
             *   Competition.Matches.Add(match.Id, match);
             *   match_no++;
             * }*/
            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Рассеивает игроков по швейцарской системе
        /// </summary>
        /// <returns></returns>
        public virtual bool SeedPlayers()
        {
            // Список игрков для матчей
            List <CompetitionPlayerInfo> players = GetPlayersToSeed();

            int round = 0;

            int[]                 plrs           = new int[players.Count];                         // Список игроков для рассеивания
            SeedPair[]            mtchs          = new SeedPair[Competition.Matches.Values.Count]; // Список сыгранных матчей
            SeedPair[]            new_mtchs      = new SeedPair[players.Count / 2];                // Список новых матчей
            Dictionary <int, int> current_points = new Dictionary <int, int>();                    // Текущее количество набранных игроками очков
            int index = 0;

            foreach (CompetitionPlayerInfo player in players)
            {
                plrs[index++] = player.Id;
                current_points.Add(player.Id, player.AvailablePoints);
            }
            index = 0;
            foreach (MatchInfo match in Competition.Matches.Values)
            {
                mtchs[index++] = new SeedPair(match.PlayerA.Id, match.PlayerB.Id);
                if (match.Label.Round > round)
                {
                    round = match.Label.Round;
                }
            }
            round++;
            // формируем пары для следующего раунда
            if (!SwissSeeder.Seed(plrs, mtchs, new_mtchs, 0))
            {
                throw new Exception(Localizator.Dictionary.GetString("IMPOSSIBLE_TO_DRAW"));
            }

            if (round > 1)   // Даем возможность изметить рассадку после автоматической жеребьевки начиная со второго тура
            {
                SeedingArgs args = SeedingArgs.Empty;
                args.PlayersToSeed = Competition.Players;
                args.SeedOrder     = GetDrawOrder(args.PlayersToSeed.Count);
                args.SeedType      = Seeding.SeedType.Matches;
                args.AllowAuto     = false; args.AllowManual = false; args.AllowRating = false; args.AllowReset = false;

                for (int i = 0; i < new_mtchs.Length; i++)
                {
                    int seed_no = args.SeedOrder[i * 2];
                    if (new_mtchs[i].playerIdA > 0)
                    {
                        args.PlayersToSeed[new_mtchs[i].playerIdA].SeedNo = seed_no;
                    }
                    seed_no = args.SeedOrder[i * 2 + 1];
                    if (new_mtchs[i].playerIdB > 0)
                    {
                        args.PlayersToSeed[new_mtchs[i].playerIdB].SeedNo = seed_no;
                    }
                }

                if (fGraphicalSeeding.Seed(args))
                {
                    // обнуляем результат автоматической жеребьевки
                    for (int i = 0; i < new_mtchs.Length; i++)
                    {
                        new_mtchs[i].playerIdA = 0;
                        new_mtchs[i].playerIdB = 0;
                    }
                    // Формируем матчи по ручной жеребьевке

                    foreach (CompetitionPlayerInfo player in Competition.Players.Values)
                    {
                        int seed_no = player.SeedNo;
                        for (int i = 0; i < args.SeedOrder.Length; i++)
                        {
                            if (args.SeedOrder[i] == seed_no)
                            {
                                if (i % 2 == 0)
                                {
                                    new_mtchs[i / 2].playerIdA = player.Id;
                                }
                                else
                                {
                                    new_mtchs[i / 2].playerIdB = player.Id;
                                }
                            }
                        }
                    }
                }
            }

            // Создаем матчи и добавляем их в список матчей
            int match_no = 1;

            foreach (SeedPair pair in new_mtchs)
            {
                MatchInfo match = CreateMatch(pair);

                // Устанавливаем максимальное количество очков в партии
                if (match.PlayerA.Id > 0 && match.PlayerB.Id > 0)
                {
                    match.PlayerA.Tag = current_points[match.PlayerA.Id];
                    match.PlayerB.Tag = current_points[match.PlayerB.Id];
                }

                match.Label.Division = 1;
                match.Label.Round    = round;
                match.Label.MatchNo  = match_no;
                TA.DB.Manager.DatabaseManager.CurrentDb.CreateMatch(Competition.Info.Id, match);
                Competition.Matches.Add(match.Id, match);
                match_no++;
            }
            return(true);
        }