Skip to contents

This function generates random head to head schedules for a given number of seasons, teams, and weeks.

Usage

ffs_build_schedules(
  n_teams = NULL,
  n_seasons = 100,
  n_weeks = 14,
  franchises = NULL,
  seed = NULL
)

Arguments

n_teams

number of teams in simulation

n_seasons

number of seasons to simulate, default = 100

n_weeks

number of weeks per season, default = 14

franchises

optional: a dataframe of franchises as created by ffs_franchises() - overrides the n_teams argument and will attach actual franchise IDs to the schedule output.

seed

an integer to control reproducibility

Value

a dataframe of schedules

Details

It starts with the circle method for round robin scheduling, grows or shrinks the schedule to match the required number of weeks, and then shuffles both the order that teams are assigned in and the order that weeks are generated. This doesn't "guarantee" unique schedules, but there are n_teams! x n_weeks! permutations of the schedule so it's very very likely that the schedules are unique (3x10^18 possible schedules for a 12 team league playing 13 weeks).

See also

vignette("custom") for example usage

Examples

# \donttest{
ffs_build_schedules(n_teams = 12, n_seasons = 1, n_weeks = 14)
#> # A tidytable: 168 × 4
#>    season  week franchise_id opponent_id
#>     <int> <int>        <int>       <int>
#>  1      1    10            9           3
#>  2      1    10            8           2
#>  3      1    10            6           1
#>  4      1    10           12          10
#>  5      1    10            7           4
#>  6      1    10           11           5
#>  7      1    10            5          11
#>  8      1    10            4           7
#>  9      1    10           10          12
#> 10      1    10            1           6
#> # … with 158 more rows
#> # ℹ Use `print(n = ...)` to see more rows
# }