Skip to content

Instantly share code, notes, and snippets.

@mkirlin
Created October 20, 2023 04:15
Show Gist options
  • Save mkirlin/a6a4561fc559461b4ebd71b054ec8d24 to your computer and use it in GitHub Desktop.
Save mkirlin/a6a4561fc559461b4ebd71b054ec8d24 to your computer and use it in GitHub Desktop.
FBB Schedule Generator
import itertools
import random
# Define the team names, divisions, positions from the previous year, and designated rivals
teams = [
{"name": "Team A", "division": 1, "position": 1, "rival": "Team B"},
{"name": "Team B", "division": 1, "position": 2, "rival": "Team A"},
{"name": "Team C", "division": 1, "position": 3, "rival": "Team D"},
{"name": "Team D", "division": 1, "position": 4, "rival": "Team C"},
{"name": "Team E", "division": 2, "position": 1, "rival": "Team F"},
{"name": "Team F", "division": 2, "position": 2, "rival": "Team E"},
{"name": "Team G", "division": 2, "position": 3, "rival": "Team H"},
{"name": "Team H", "division": 2, "position": 4, "rival": "Team G"},
{"name": "Team I", "division": 3, "position": 1, "rival": "Team J"},
{"name": "Team J", "division": 3, "position": 2, "rival": "Team I"},
{"name": "Team K", "division": 3, "position": 3, "rival": "Team L"},
{"name": "Team L", "division": 3, "position": 4, "rival": "Team K"},
]
# Split teams by division
divisions = {1: [], 2: [], 3: []}
for team in teams:
divisions[team["division"]].append(team)
# Generate a schedule with 9 weeks of divisional matchups, 4 weeks of specific matchups, 6 weeks of random matchups, and 1 week of designated rival matchups
schedule = []
random_teams = list(teams) # Make a copy of teams to shuffle for random matchups
used_random_matchups = set() # Track used random matchups
for week in range(1, 21):
matchups = []
if week <= 9:
# Divisional matchups
for division_teams in divisions.values():
# Create all possible pairings within the division
pairings = list(itertools.combinations(division_teams, 2))
# Shuffle the pairings for variety
random.shuffle(pairings)
# Append pairings to matchups
matchups.extend(pairings)
elif 9 < week <= 13:
# Specific matchups for 4 weeks
specific_matchups = []
for position in range(1, 5):
same_position_teams = [team for team in teams if team["position"] == position]
same_position_teams.remove(random.choice(same_position_teams)) # Avoid self-matching
random.shuffle(same_position_teams)
specific_matchups.extend(itertools.combinations(same_position_teams, 2))
matchups = specific_matchups
elif week == 20:
# Designated rival matchups for 1 week
designated_rival_matchups = [(team1, team2) for team1, team2 in zip(teams, teams) if team1["name"] == team2["rival"]]
matchups = designated_rival_matchups
else:
# Random matchups for 6 weeks
random.shuffle(random_teams)
possible_matchups = list(itertools.combinations(random_teams, 2))
random_matchup = None
# Find an unused random matchup
for possible_matchup in possible_matchups:
if possible_matchup not in used_random_matchups:
random_matchup = possible_matchup
used_random_matchups.add(random_matchup)
break
matchups = [random_matchup]
schedule.append({"week": week, "matchups": matchups})
# Randomize the order of weeks
random.shuffle(schedule)
# Display the schedule
for week_info in schedule:
week = week_info["week"]
print(f"Week {week} Schedule:")
for matchup in week_info["matchups"]:
team1 = matchup[0]["name"]
team2 = matchup[1]["name"]
print(f"{team1} vs {team2}")
print("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment