Skip to content

Instantly share code, notes, and snippets.

@jelloslinger
Created February 13, 2015 05:04
Show Gist options
  • Select an option

  • Save jelloslinger/ebfd893ac9c871be0200 to your computer and use it in GitHub Desktop.

Select an option

Save jelloslinger/ebfd893ac9c871be0200 to your computer and use it in GitHub Desktop.
Jeepers Keepers Fantasy Baseball Schedule Generator
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from copy import copy
import itertools
import random
SEEDS = (
(0, 1, 2, 3, )
, (4, 5, 6, 7, )
, (8, 9, 10, 11, )
, (12, 13, 14, 15, )
)
TEAMS = (
'Polar Vortexes'
, 'Vista Beach Brains'
, 'JP Aaroncibia'
, 'Gyro Balls'
, 'Diamond Cutters'
, 'Fast Eddie\'s Coffee'
, 'MGD'
, 'Circle Gyorko'
, 'Fister n\' Dicker'
, 'Alderwood Aggies'
, 'Big\'s Slam-Dunk Team'
, 'David\'s Dandy Team'
, 'The Loyal Order'
, 'The Fat Juans'
, 'The Marx'
, 'Flags Fly Forever'
)
def get_rivalry_matchups():
pool = [[], [], [], []]
schedule = [[], [], []]
for i, s in enumerate(SEEDS):
for p in itertools.combinations(s, 2):
pool[i].append(p)
i = 0
for p in pool:
candidates = copy(p)
while candidates:
match = random.choice(candidates)
candidates.remove(match)
schedule[i % 3].append(match)
for c in copy(candidates):
if match[0] != c[0] and match[0] != c[1] and match[1] != c[0] and match[1] != c[1]:
candidates.remove(c)
schedule[i % 3].append(c)
break
i += 1
return schedule
def get_random_round_robin():
seeds = [i for j in SEEDS for i in j]
count = len(seeds)
half = count / 2
schedule = []
for turn in range(count - 1):
left = seeds[:half]
right = seeds[count - half - 1 + 1:][::-1]
pairings = zip(left, right)
if turn % 2 == 1:
pairings = [(y, x) for (x, y) in pairings]
seeds.insert(1, seeds.pop())
schedule.append(pairings)
random.shuffle(schedule)
return schedule
def get_schedule(week_number, pairings):
schedule = 'WEEK #{0}'.format(week_number) + '\n'
schedule += '-'*80 + '\n'
for i, p in enumerate(pairings):
schedule += ' MATCHUP #{0}: {1} vs. {2}'.format(
unicode(i + 1)
, TEAMS[p[0]].rjust(30)
, TEAMS[p[1]].ljust(30)
)
schedule += '\n'
schedule += '\n'
return schedule
if __name__ == '__main__':
schedule = ''
for i, r in enumerate(get_rivalry_matchups()):
schedule += get_schedule(i + 1, r)
for j, r in enumerate(get_random_round_robin()):
schedule += get_schedule(i + j + 2, r)
conference = [
[(0, 4), (1, 5), (2, 6), (3, 7), (8, 12), (9, 13), (10, 14), (11, 15)]
, [(5, 0), (6, 1), (7, 2), (4, 3), (13, 8), (14, 9), (15, 10), (12, 11)]
, [(0, 6), (1, 7), (2, 4), (3, 5), (8, 14), (9, 15), (10, 12), (11, 13)]
, [(7, 0), (4, 1), (5, 2), (6, 3), (15, 8), (12, 9), (13, 10), (14, 11)]
]
random.shuffle(conference)
for k, r in enumerate(conference):
schedule += get_schedule(i + j + k + 3, r)
for m, r in enumerate(get_rivalry_matchups()):
schedule += get_schedule(i + j + k + m + 4, r)
print schedule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment