我正在从事一个项目,我需要制定NFL计划。我真的很难让它出来正确。它应该会在17周内推出256场比赛 - 每支球队有16场比赛。
我拥有的每个Team对象都有一个对手的ArrayList,球队必须为本赛季打球。这部分工作正常。
所以现在,我已经拥有了32个团队的ArrayList,每个团队都有一个16个对手的ArrayList。我需要根据这些对手创造17周的时间,并留意每个球队的一周。
这是我正在使用的代码:
ArrayList weeks = new ArrayList();
for (int i = 0; i < Constants.RegularSeasonWeeks; i++)
{
Week w = new Week(i + 1);
for (int j = 0; j < teams.Count; j++)
{
Team team = (Team)teams[j];
if (!(team.ByeWeek == w.WeekNumber) && !w.DoesTeamPlayThisWeek(team))
{
for (int k = 0; k < team.Opponents.Count; k++)
{
Team awayTeam = (Team)team.Opponents[k];
if (!awayTeam.Scheduled)
{
if (!(GetOpponentsByeWeek(teams, awayTeam.TeamID) == w.WeekNumber) && !w.DoesTeamPlayThisWeek(awayTeam))
{
Game gm = new Game(awayTeam, team);
w.AddGame(gm);
((Team)team.Opponents[k]).Scheduled = true;
for (int l = 0; l < teams.Count; l++)
{
Team t = (Team)teams[l];
if (t.TeamID == awayTeam.TeamID)
{
ArrayList tOpps = ((Team)teams[l]).Opponents;
for (int m = 0; m < tOpps.Count; m++)
{
if (((Team)teams[m]).TeamID == team.TeamID)
{
((Team)teams[m]).Scheduled = true;
}
}
}
}
break;
}
}
}
}
else
{
if (team.ByeWeek == w.WeekNumber)
{
}
}
}
weeks.Add(w);
}
return weeks;
这种情况即将结束,但有些事情仍未解决。有没有更好的方法呢?
编辑---
当我在这时运行它时,我出来了~248场比赛。它每次都会有一两场比赛的变化。没有球队有超过16场比赛,但有几支球队有14或15场比赛。