Ejemplo n.º 1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            CompetitionPlayerList new_list  = new CompetitionPlayerList();
            List <int>            to_delete = new List <int>();

            // 1 - создаем текущий список игроков турнира
            foreach (PlayerInfo player in lstPlayers.CheckedObjects)
            {
                CompetitionPlayerInfo cp = new CompetitionPlayerInfo(player);
                new_list.Add(cp.Id, cp);
            }
            // 2 - добавляем тех, кто есть в текущем, но отсутсвует в исходном
            foreach (CompetitionPlayerInfo player in new_list.Values)
            {
                if (!SelectedPlayers.ContainsKey(player.Id))
                {
                    SelectedPlayers.Add(player.Id, player);
                }
            }
            // 3 - формируем список тех, кто есть в исходном списке, но кого нет в текущем списке
            foreach (CompetitionPlayerInfo player in SelectedPlayers.Values)
            {
                if (!new_list.ContainsKey(player.Id))
                {
                    to_delete.Add(player.Id);
                }
            }
            // 4 - удаляем из исходного списка тех, кого нет в текущем
            foreach (int id in to_delete)
            {
                SelectedPlayers.Remove(id);
            }
            DialogResult = DialogResult.OK;
        }
Ejemplo n.º 2
0
        private void SaveDrawing(params object[] aParams)
        {
            CompetitionPlayerList players = aParams[0] as CompetitionPlayerList;

            foreach (CompetitionPlayerInfo player in players.Values)
            {
                DatabaseManager.CurrentDb.CompetitionPlayerInfoSave(player);
            }
            UpdateCompetitionPlayersGrid();
        }
Ejemplo n.º 3
0
        private void btnPlayersList_Click(object sender, EventArgs e)
        {
            CompetitionPlayerList listA = FCompetition.Players;
            List <int>            listB = new List <int>();

            foreach (int id in listA.Keys)
            {
                listB.Add(id);
            }
            if (fPlayerSelect.Select(FCompetition.Info.SportType.Id, listA))
            {
                LongOpertationExecutor.Execute(SaveCompetitionPlayers, listA, listB);
            }
        }
Ejemplo n.º 4
0
        public static bool Select(int gameType, CompetitionPlayerList SelectedPlayers)
        {
            fPlayerSelect form = new fPlayerSelect();

            form.SelectedPlayers = SelectedPlayers;
            form.UpdatePlayersGrid(gameType);
            int height = (form.Height - form.lstPlayers.Height) + form.lstPlayers.ItemHeight * (form.lstPlayers.Count + 1);

            if (height > Screen.PrimaryScreen.Bounds.Height * 2 / 3)
            {
                height = Screen.PrimaryScreen.Bounds.Height * 2 / 3;
            }
            form.Height = height;
            return(form.ShowDialog() == DialogResult.OK);
        }
        private bool CreateFirstRoundMatches()
        {
            // Получить список игроков после жеребьевки
            List <CompetitionPlayerInfo> allPlayers = Competition.Players.GetSortedList(CompetitionPlayerList.SortByField.SeedNo);
            int group_count = FCompetition.GroupCount;
            CompetitionPlayerList groupPlayers = new CompetitionPlayerList();

            int[] draw_order = GetDrawOrder(allPlayers.Count);

            // Рассчитываем количество игроков в группе
            int group_player_count = Competition.Players.Count / FCompetition.GroupCount;

            if (Competition.Players.Count % FCompetition.GroupCount != 0)
            {
                group_player_count++;
            }

            int player_index = 0;

            for (int i = 0; i < group_count; i++)
            {
                // Сформировать список игроков для группы
                groupPlayers.Clear();
                for (int j = 0; j < group_player_count; j++)
                {
                    int pi = draw_order[player_index] - 1;
                    if (pi < allPlayers.Count)
                    {
                        groupPlayers.Add(j, allPlayers[pi]);
                    }
                    player_index++;
                }
                // Создать матчи группы

                /*while (groupPlayers.Count < group_player_count)
                 * {
                 *  groupPlayers.Add(player_index, CompetitionPlayerInfo.Dummy);
                 * }*/
                if (groupPlayers.Count % 2 == 1)
                {
                    groupPlayers.Add(player_index, CompetitionPlayerInfo.Dummy);
                }
                CreateGroupMatches(i + 1, groupPlayers);
            }
            return(false);
        }
Ejemplo n.º 6
0
        private void SaveCompetitionPlayers(params object[] args)
        {
            if (args.Length != 2)
            {
                throw new Exception("Wrong param count");
            }
            CompetitionPlayerList playersToSave   = args[0] as CompetitionPlayerList;
            List <int>            playersToDelete = args[1] as List <int>;

#if FEDITION || STANDARD || FEDITION_PLUS || STANDARD_PLUS
            TA.RatingSystem.PlayersRatingList players_rating = TA.RatingSystem.Builder.RatingSystemBuilder.GetPlayersRating(FCompetition.Info.SportType.Id, FCompetition.Info.Date);
#endif
            foreach (CompetitionPlayerInfo player in playersToSave.Values)
            {
                player.CompetitionId = FCompetition.Info.Id;
#if FEDITION || STANDARD || FEDITION_PLUS || STANDARD_PLUS
                player.RatingBeforeCompetition = players_rating[player.Id].Rating;
#else
                player.RatingBeforeCompetition = 0;
#endif
                if (player.StartPoints == 0)
                {
                    player.StartPoints = LateStartPoints;
                }
                DatabaseManager.CurrentDb.CompetitionPlayerInfoSave(player);
                if (playersToDelete.Contains(player.Id))
                {
                    playersToDelete.Remove(player.Id);
                }
                if (!FCompetition.Players.ContainsKey(player.Id))
                {
                    FCompetition.Players.Add(player.Id, player);
                }
            }
            foreach (int playerId in playersToDelete)
            {
                DatabaseManager.CurrentDb.CompetitionPlayerInfoDelete(FCompetition.Info.Id, playerId);
                FCompetition.Players.Remove(playerId);
            }
            UpdatePlayersList();
        }
Ejemplo n.º 7
0
        private void SeedAuto()
        {
            ArrayList             array   = new ArrayList();
            CompetitionPlayerList players = FCompetition.Players;

            for (int i = 0; i < players.Count; i++)
            {
                array.Add(i);
            }
            Random rnd = new Random();
            int    pc  = players.Count;

            foreach (CompetitionPlayerInfo player in players.Values)
            {
                int index = rnd.Next(pc);
                player.SeedNo = Convert.ToInt32(array[index]) + 1;
                array.RemoveAt(index);
                pc--;
                DatabaseManager.CurrentDb.CompetitionPlayerInfoSave(player);
            }
        }
Ejemplo n.º 8
0
 public CompetitionResultsBuilder(CompetitionPlayerList players, MatchList matches)
     : base()
 {
     // Добавляем всех игроков в список результатов
     foreach (CompetitionPlayerInfo player in players.Values)
     {
         PlayerResults res = CreatePlayerResult();
         res.PlayerId    = player.Id;
         res.StartPoints = player.StartPoints;
         Add(res.PlayerId, res);
     }
     // Добавляем матчи
     foreach (MatchInfo match in matches.Values)
     {
         AddMatch(match.PlayerA.Id, match.PlayerB.Id, match);
         AddMatch(match.PlayerB.Id, match.PlayerA.Id, match);
         if (match.Label.Round > FRoundCount)
         {
             FRoundCount = match.Label.Round;
         }
     }
 }
Ejemplo n.º 9
0
        private void SaveCompetitionPlayers(params object[] args)
        {
            if (args.Length != 2)
            {
                throw new Exception(Localizator.Dictionary.GetString("WRONG_PARAM_COUNT"));
            }
            CompetitionPlayerList playersToSave   = args[0] as CompetitionPlayerList;
            List <int>            playersToDelete = args[1] as List <int>;

#if FEDITION || STANDARD || FEDITION_PLUS || STANDARD_PLUS
            TA.RatingSystem.PlayersRatingList players_rating = TA.RatingSystem.Builder.RatingSystemBuilder.GetPlayersRating(FCompetition.Info.SportType.Id, FCompetition.Info.Date);
#endif
            int seedNo = 1;
            foreach (CompetitionPlayerInfo player in playersToSave.Values)
            {
                if (!FCompetition.NeedsPlayersDrawing)
                {
                    player.SeedNo = seedNo++;
                }
                player.CompetitionId = FCompetition.Info.Id;
#if FEDITION || STANDARD || FEDITION_PLUS || STANDARD_PLUS
                player.RatingBeforeCompetition = players_rating[player.Id].Rating;
#else
                player.RatingBeforeCompetition = 0;
#endif
                DatabaseManager.CurrentDb.CompetitionPlayerInfoSave(player);
                if (playersToDelete.Contains(player.Id))
                {
                    playersToDelete.Remove(player.Id);
                }
            }
            foreach (int playerId in playersToDelete)
            {
                DatabaseManager.CurrentDb.CompetitionPlayerInfoDelete(FCompetition.Info.Id, playerId);
            }
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
 public SwissResultsBuilder(CompetitionPlayerList players, MatchList matches)
     : base(players, matches)
 {
 }