title: Generating an NFL schedule in C#
body: <p>I'm working on a project and I need to generate an NFL schedule. I'm really struggling to get it to come out right. It should come out with 256 games spread across 17 weeks - each team has 16 games.</p>
  
  <p>Each Team object I have has an ArrayList of opponents that the team has to play for the season. This part is working correctly.</p>
  
  <p>So now, I'm at the point where I have an ArrayList of 32 teams and each team has an ArrayList of 16 opponents. I need to create 17 weeks based on these opponents and being mindful of each team's bye week.</p>
  
  <p>Here's the code that I am using:</p>
  
  <pre><code>ArrayList weeks = new ArrayList();
              for (int i = 0; i &lt; Constants.RegularSeasonWeeks; i++)
              {
                  Week w = new Week(i + 1);
                  for (int j = 0; j &lt; teams.Count; j++)
                  {
                      Team team = (Team)teams[j];
                      if (!(team.ByeWeek == w.WeekNumber) &amp;&amp;     !w.DoesTeamPlayThisWeek(team))
                      {
                          for (int k = 0; k &lt; team.Opponents.Count; k++)
                          {
                              Team awayTeam = (Team)team.Opponents[k];
                              if (!awayTeam.Scheduled)
                              { 
                                  if (!(GetOpponentsByeWeek(teams,   awayTeam.TeamID) == w.WeekNumber) &amp;&amp; !w.DoesTeamPlayThisWeek(awayTeam))
                                  {
                                      Game gm = new Game(awayTeam, team);
                                      w.AddGame(gm);
                                      ((Team)team.Opponents[k]).Scheduled = true; 
                                      for (int l = 0; l &lt; teams.Count; l++)
                                      {
                                          Team t = (Team)teams[l];
                                          if (t.TeamID == awayTeam.TeamID)
                                          {
                                              ArrayList tOpps = ((Team)teams[l]).Opponents;
                                              for (int m = 0; m &lt; 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;
  </code></pre>
  
  <p>This is coming close, but something is still off.. Is there a better way to do this?</p>
  
  <p>EDIT ---</p>
  
  <p>When I run it at this point, I come out with ~248 games. It varies by a game or two every time. No team has more than 16 games, but a couple of teams have 14 or 15.</p>