public Team AddTeamByDescribe(TeamDescribe describe) { Team team = new Team(describe); teams.Add(team.id, team); return(team); }
public Team TryAddTeamByDescribe(TeamDescribe describe) { if (!teams.ContainsKey(describe.id)) { return(AddTeamByDescribe(describe)); } return(null); }
//目前的逻辑中,万不得已不用的生成队伍 public TeamDescribe GenerateDescribe(int teamID) { if (describes.Count < 2) { return(new TeamDescribe { id = teamID, color = Color.HSVToRGB(Random.Range(0, 1), Random.Range(0.5f, 1), Random.Range(0.5f, 1)), name = GetStuffing() + GetStuffing() }); } else { //int dcount = describes.Count - 1; TeamDescribe d1 = describes[Random.Range(0, describes.Count)]; TeamDescribe d2 = describes[Random.Range(0, describes.Count)]; return(new TeamDescribe { id = teamID, color = Color.Lerp(d1.color, d2.color, Random.Range(0.3f, 0.7f)), name = d1.name + GetStuffing() + d2.name, }); } }
/// <summary> /// 分配一个队伍 /// </summary> /// <returns></returns> public int DistributeOneTeam() { if (teams.Count < describes.Count) { //如果Team数量少于场地上限 List <TeamDescribe> unuseDescs = describes.Where((TeamDescribe desc) => !teams.ContainsKey(desc.id)).ToList(); //在describes中却没在teams中的队伍 TeamDescribe randomOne = unuseDescs[Random.Range(0, unuseDescs.Count)]; //随机一个 AddTeamByDescribe(randomOne); return(randomOne.id); } //如果Team达到上限甚至突破上限(?) int minNum = int.MaxValue; int minTeamID = -1; foreach (Team team in teams.Values) //找一个人最少的队伍 { if (team.Count < minNum) { minNum = team.Count; minTeamID = team.id; } } if (minTeamID == -1) //基本不会进这个逻辑 { if (teams.Count == 0) { minTeamID = 1; } else { minTeamID = teams.Keys.Max() + 1; } AddTeamByDescribe(GenerateDescribe(minTeamID)); } return(minTeamID); }
public Team(TeamDescribe describe) { id = describe.id; name = describe.name; teamColor = describe.color; }