예제 #1
0
        /// <summary>
        /// создает матч и инициализирует параметры игроков
        /// </summary>
        /// <param name="players_pair">пара ID игроков</param>
        /// <returns>Созданный матч</returns>
        protected virtual MatchInfo CreateMatch(SeedPair players_pair)
        {
            MatchInfo match = new MatchInfo();

            match.PlayerA.Id = players_pair.playerIdA;
            if (match.PlayerA.Id == 0)
            {
                match.PlayerA.Name = "-";
            }
            else
            {
                match.PlayerA.Name = Competition.Players[players_pair.playerIdA].NickName;
                match.PlayerA.Guid = Competition.Players[players_pair.playerIdA].Identifier;
            }
            match.PlayerB.Id = players_pair.playerIdB;
            if (match.PlayerB.Id == 0)
            {
                match.PlayerB.Name = "-";
            }
            else
            {
                match.PlayerB.Name = Competition.Players[players_pair.playerIdB].NickName;
                match.PlayerB.Guid = Competition.Players[players_pair.playerIdB].Identifier;
            }
            return(match);
        }
        /// <summary>
        /// создает матч и инициализирует параметры игроков
        /// </summary>
        /// <param name="players_pair">пара ID игроков</param>
        /// <returns>Созданный матч</returns>
        public static MatchInfo CreateMatch(Competition competition, SeedPair players_pair)
        {
            MatchInfo match = new MatchInfo();

            match.PlayerA.Id = players_pair.playerIdA;
            if (match.PlayerA.Id == 0)
            {
                match.PlayerA.Name = "-";
            }
            else
            {
                match.PlayerA.Name = competition.Players[players_pair.playerIdA].NickName;
                match.PlayerA.Guid = competition.Players[players_pair.playerIdA].Identifier;
            }

            match.PlayerB.Id = players_pair.playerIdB;
            if (match.PlayerB.Id == 0)
            {
                match.PlayerB.Name = "-";
            }
            else
            {
                match.PlayerB.Name = competition.Players[players_pair.playerIdB].NickName;
                match.PlayerB.Guid = competition.Players[players_pair.playerIdB].Identifier;
            }

            return(match);
        }
        private void CreateGroupMatches(int groupNo, CompetitionPlayerList groupPlayers)
        {
            int[] plrs = new int[groupPlayers.Count];                                               // Список игроков для рассеивания

            SeedPair[] new_mtchs = new SeedPair[(groupPlayers.Count - 1) * groupPlayers.Count / 2]; // Список новых матчей
            int        index     = 0;

            foreach (CompetitionPlayerInfo player in groupPlayers.Values)
            {
                plrs[index++] = player.Id;
            }
            // формируем пары для следующего раунда
            if (!RobinSeeder.Seed(plrs, new_mtchs))
            {
                throw new Exception("Draw error");
            }

            // Создаем матчи и добавляем их в список матчей
            int pc = groupPlayers.Count;

            for (int round = 0; round < pc - 1; round++)              // Кол-во туров равно Кол-во игроков - 1
            {
                for (int match_no = 0; match_no < pc / 2; match_no++) // Кол-во матчей в туре равно Кол-во игрков деленное на два
                {
                    SeedPair  pair  = new_mtchs[round * pc / 2 + match_no];
                    MatchInfo match = RobinController.CreateMatch(Competition, pair);
                    match.Label.Division = groupNo;
                    match.Label.Round    = round + 1;
                    match.Label.MatchNo  = match_no + 1;
                    TA.DB.Manager.DatabaseManager.CurrentDb.CreateMatch(Competition.Info.Id, match);
                    Competition.Matches.Add(match.Id, match);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Подыскивает очередную пару для матча в швейцарской системе
        /// </summary>
        /// <param name="players">Полный список игроков</param>
        /// <param name="matches">Полный список уже сыгранных матчей</param>
        /// <param name="new_matches">Список формируемых матчей</param>
        /// <param name="next_match_index">Индекс матча, для которого подыскиваются игроки</param>
        /// <returns>True, если пара игроков найдена и матч добавлен в список или если все игроки уже заняты</returns>
        public static bool Seed(int[] players, SeedPair[] matches, SeedPair[] new_matches, int next_match_index)
        {
            int match_count = players.Length / 2;

            if (next_match_index >= match_count) //Если необходимое количестсво матчей уже набрано
            {
                return(true);                    //то завершаем рассеивание
            }
            for (int i = 0; i < players.Length - 1; i++)
            {
                if (!PlayerIn(players[i], new_matches, next_match_index))
                {
                    for (int j = i + 1; j < players.Length; j++)
                    {
                        if (!PlayerIn(players[j], new_matches, next_match_index))
                        {
                            SeedPair match = new SeedPair(players[i], players[j]);
                            if (!MatchIn(match, matches))
                            {
                                new_matches[next_match_index] = match;
                                if (Seed(players, matches, new_matches, next_match_index + 1))
                                {
                                    return(true);
                                }
                                else
                                {
                                    new_matches[next_match_index] = null;
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
예제 #5
0
        public static bool Seed(int[] players, SeedPair[] new_matches)
        {
            List <int> players_A = new List <int>();
            List <int> players_B = new List <int>();

            // Делим список на две равные части
            for (int i = 0; i < players.Length; i += 2)
            {
                players_A.Add(players[i]);
                players_B.Add(players[i + 1]);
            }
            int index = 0;

            for (int i = 0; i < players.Length - 1; i++) // количество  туров равно Кол-во игроков - 1
            {
                // Формируем пары
                for (int j = 0; j < players_A.Count; j++)
                {
                    new_matches[index++] = new SeedPair(players_A[j], players_B[j]);
                }
                // Прокручиваем списки для следуюущего круга
                players_B.Insert(0, players_A[1]);
                players_A.RemoveAt(1);
                players_A.Add(players_B[players_B.Count - 1]);
                players_B.RemoveAt(players_B.Count - 1);
            }
            return(true);
        }
예제 #6
0
 public override bool Equals(object obj)
 {
     if (obj is SeedPair)
     {
         SeedPair other = obj as SeedPair;
         return((other.playerIdA == playerIdA && other.playerIdB == playerIdB) || (other.playerIdB == playerIdA && other.playerIdA == playerIdB));
     }
     return(base.Equals(obj));
 }
예제 #7
0
 private static bool MatchIn(SeedPair match, SeedPair[] matches)
 {
     foreach (SeedPair m in matches)
     {
         if (m.Equals(match))
         {
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// Рассеивает игроков по швейцарской системе
        /// </summary>
        /// <returns></returns>
        public virtual bool SeedPlayers()
        {
            // Список игрков для матчей
            List <CompetitionPlayerInfo> players = GetPlayersToSeed();

            int[] plrs = new int[players.Count];                                          // Список игроков для рассеивания

            SeedPair[] new_mtchs = new SeedPair[(players.Count - 1) * players.Count / 2]; // Список новых матчей
            int        index     = 0;

            foreach (CompetitionPlayerInfo player in players)
            {
                plrs[index++] = player.Id;
            }


            // формируем пары для следующего раунда
            if (!RobinSeeder.Seed(plrs, new_mtchs))
            {
                throw new Exception("Draw Error");
            }

            // Создаем матчи и добавляем их в список матчей
            int pc = players.Count;

            for (int round = 0; round < pc - 1; round++)              // Кол-во туров равно Кол-во игроков - 1
            {
                for (int match_no = 0; match_no < pc / 2; match_no++) // Кол-во матчей в туре равно Кол-во игрков деленное на два
                {
                    SeedPair  pair  = new_mtchs[round * pc / 2 + match_no];
                    MatchInfo match = CreateMatch(Competition, pair);
                    match.Label.Division = 1;
                    match.Label.Round    = round + 1;
                    match.Label.MatchNo  = match_no + 1;
                    TA.DB.Manager.DatabaseManager.CurrentDb.CreateMatch(Competition.Info.Id, match);
                    Competition.Matches.Add(match.Id, match);
                }
            }
            return(true);
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
0
        protected override MatchInfo CreateMatch(SeedPair players_pair)
        {
            MatchInfo match = base.CreateMatch(players_pair);

            return(match);
        }