Need help scripting toString Function - Pretty stumped

Need help scripting toString Function - Pretty stumped

Hi,

I'm working on an automated scheduler function to fill out teams into game slots in an ice hockey league season. I want to have one game per team, per week, based on the criteria supplied in the team lookup field that "Team 1" is based on in the code below:
  1. void schedule_teams.mhl_scheduling_module.toString()
  2. {
  3.     for each r in MHL_Scheduling_Module  [(((Season == "Winter 2013" && Reverse_Record == false) && (Team_1 is null)) && (Team_2 is null))] sort by  Team_1 
  4.     {
  5.         scheduleteam15  =  MHL_Team_Contact_Info_Entry  [((((Current_Last_Season_New == r.Season && Nights_Playing == r.Day) && Team_Name != "(Non-League Opponent)") && Team_Name != "(TBA)") && Rinks_Playing == r.Rink)];
  6.         r.Team_1 = scheduleteam15.Team_Name;
  7.         r.Team_1_Level = scheduleteam15.Level;
  8.         r.Team_1_Div = scheduleteam15.Division;
  9.         r.Team_1_Bal_Remain = scheduleteam15.Bal_Remain;
  10.         r.Team_1_Pct_Paid = scheduleteam15.Pct_Paid;
  11.         r.Team_2 = scheduleteam15.Team_Name;
  12.         r.Team_2_Div = scheduleteam15.Division;
  13.         r.Team_2_Bal_Remain = scheduleteam15.Bal_Remain;
  14.         r.Team_2_Pct_Paid = scheduleteam15.Pct_Paid;
  15.     }
  16. }
When I hit "execute", this is what I get returned:



I know why I'm getting only the alphabetically first available choices under the criteria, I just haven't been able to find a work-around to ensure that each team gets a maximum of one game per week. 

I've tried limiting the count of how many records can match a value for Team 1 in a week, but a function such as this doesn't appear to allow for more than one variable to be stated in any meaningful way. ("Team 2" isn't really a concern at this point, have a fix in mind  )

So really I could use some suggestions/example code regarding the following: 

 - How and where can I state another variable to limit the number of times a team can be assigned a game per week?

 - What's the best way to separate secondary actions within a function?

 - Should/can the values for Team 1 be updated by some other criteria to have this make more sense?




Thanks in advance for your help,

Dan