コード例 #1
0
        public override Task <TeamResult> MakeTeamAsync(List <MemberName> members, int teamCount, TeamSettingOption option)
        {
            var teamResult = new TeamResult(teamCount);

            var shuffled = RandomShuffle(members, teamResult.TeamNames);

            teamResult.Players = shuffled;
            return(Task.FromResult(teamResult));
        }
コード例 #2
0
        public override async Task <TeamResult> MakeTeamAsync(List <MemberName> names, int teamCount, TeamSettingOption option)
        {
            var members = await SuFcService.GetAllMember();

            // 완전 랜덤으로 20개 뽑아 놓고 가장 좋은걸 골라보자.

            var users = names
                        .Select(name => new { Name = name, Member = members.FirstOrDefault(x => x.Name == name) })
                        .Where(x => x.Member != null)
                        .Select(x => new { x.Name, x.Member, AttendProp = x.Member.GetSpecValue(MemberSpecType.AttendProb) })
                        .ToList();

            var list = Enumerable.Range(0, 10)
                       .Select(_ =>
            {
                var randomTeams = MakeRandomTeam(users.Count, teamCount);
                var teamedUsers = users
                                  .Zip(randomTeams, (x, t) => new { x.Name, x.Member, x.AttendProp, Team = t })
                                  .ToList();
                var avgByTeam = teamedUsers
                                .GroupBy(x => x.Team)
                                .Select(x => new { Team = x.Key, Avg = x.Sum(e => e.AttendProp) })
                                .ToList();
                var sd = avgByTeam.Select(x => x.Avg).StandardDeviation();
                return(new { Users = teamedUsers, AvgByTeam = avgByTeam, Score = sd });
            })
                       .OrderBy(x => x.Score)
                       .ToList();

            // list 에서 만든 데이터 중에서 가장 좋은걸 고른다.
            var best = list.First();

            var teamResult = new TeamResult(teamCount);

            teamResult.Score = best.Users
                               .ToDictionary(x => x.Name, x => x.AttendProp);

            teamResult.Players = best.Users
                                 .Select(x => (x.Name, x.Team))
                                 .ToList();

            return(teamResult);
        }
コード例 #3
0
        public TeamResult MakeTeam_Internal(List <MemberName> names, int teamCount, TeamSettingOption option)
        {
            var teamResult = new TeamResult(teamCount);

            foreach (var splitOption in option.SplitOptions)
            {
                var remainNames  = splitOption.Names.Where(x => teamResult.Players.Empty(e => e.MemberName == x)).ToList();
                var userCount    = remainNames.Count;                                            // count = 5, teamCount = 3
                var teamSetCount = userCount / teamCount + (userCount % teamCount == 0 ? 0 : 1); // teamSetCount = 2
                var teamNames    = Enumerable.Range(1, teamSetCount)
                                   .Select((_, i) => MakeTeamNameList(teamCount))
                                   .SelectMany(x => x)
                                   .Take(userCount)
                                   .RandomShuffle()
                                   .ToList(); // ABCCB (random)

                var splitResult = remainNames.Zip(teamNames, (n, t) => (n, t)).ToList();

                teamResult.Players.AddRange(splitResult);
            }

            var remains = names
                          .Where(x => teamResult.Players.Empty(e => e.MemberName == x))
                          .RandomShuffle()
                          .ToList();

            foreach (var name in remains)
            {
                var newTeam = GetNextTeamName(teamResult);

                teamResult.Players.Add((name, newTeam));
            }

            teamResult.Score = teamResult.Players
                               .ToDictionary(x => x.MemberName, x => WhereIs(option.SplitOptions, x.MemberName));

            return(teamResult);
        }
コード例 #4
0
        private TeamName GetNextTeamName(TeamResult teamResult)
        {
            var ordered = teamResult.TeamNames
                          .Select(x => new { TeamName = x, Count = teamResult.Players.Count(e => e.TeamName == x) })
                          .OrderBy(x => x.Count)
                          .ToList();

            if (ordered.First().Count == ordered.Last().Count)
            {
                // 모든 팀의 멤버 수가 다 같은 상태
                // 아무거나 골라 주자
                var result = ordered
                             .RandomShuffle()
                             .First()
                             .TeamName;
                return(result);
            }
            else
            {
                var result = ordered.First().TeamName;
                return(result);
            }
        }