我有一个联赛系统,用户可以在每个赛事中进入公共联赛。系统将接受输入并将其添加到联盟规模尚未满足的可用联赛中。一旦联赛结束,系统将在进入程序中创建一个新联盟,然后该过程将填满并重新开始。
在活动开始前5分钟我锁定了活动,然后我希望对房间进行洗牌以使它们尽可能相等。一个规则是用户每个联盟只能存在一次,但每个事件可以输入多个联赛,即
League1 (25 members max) For Event 1 = 25 members
League2 (25 members max) For Event 1 = 25 members
League3 (25 members max) For Event 1 = 4 members
我有一个查询,它将返回未达到定义大小的联赛,这将给我:
LeagueID EventID LeagueSize Remaining Players FullRoomCount
3 1 25 4 2
如果完整的房间数是满足的房间数量
我现在正试图通过将参赛作品重新分配给另一个联盟来对这些房间进行改组。这是我当前的方法,伪代码:
(noOfPlayers = Math.Ceiling(remainingPlayers % FullRoomCount)
这将为我提供我需要分配给每个联赛的球员数量我的问题是此列表中的最后一点。如果用户存在于联盟中我已经在循环,那么这会导致我需要找到一个替代联盟的问题,并且它会破坏我使用noOfPlayerstoAddPerLeague
变量来平等的能力。
// get the ratio of number of players to add to a league
Decimal noOfPlayerstoAddPerLeague = (Decimal)league.RemainingPlayers % (Decimal)league.FullRoomCount;
// get players in the remainder league
List<League_SelectEntriesResult> entriesToAssign = ctl.League_SelectEntries(league.LeagueID);
List<Int32> League_EntryIDCantAssign = new List<Int32>();
foreach(League_SelectEntriesResult entry in entriesToAssign)
{
// get the leagues that are full
List<League_GetFullRoomsResult> fullRooms = ctl.League_GetFullRooms(meetingID);
// loop leages until all entries satisfied
foreach(League_GetFullRoomsResult room in fullRooms)
{
// any entries left?
if(entriesToAssign.Count == 0)
{
break;
}
// assign user if possible
if(ctl.League_Entry_Reassign(entry.League_EntryID, entry.LeagueID, entry.UserID, room.LeagueID))
{
break;
}
// if we got this far then the user has not been assigned
// add the users we cannot re-assign to this list
League_EntryIDCantAssign.Add(entry.League_EntryID);
}
}