def getF4ABracket(model, year): bracket = np.repeat(-1, 63) for region in range(4): winner = getF4SeedTogether(year, model) bracket[region * 15:region * 15 + 15] = fixRegionalBits(winner) # ... r1_probs = [getP(model, year, i) for i in range(8)] counts = [np.random.binomial(4, r1_prob) for r1_prob in r1_probs] positions = [ np.random.choice([0, 1, 2, 3], count, replace=False) for count in counts ] for bit, pos in enumerate(positions): for region in range(4): if bracket[region * 15 + bit] != -1: continue if region in pos: bracket[region * 15 + bit] = 1 else: bracket[region * 15 + bit] = 0 return fillEmptySpaces(bracket, model, year)
def generateBracket(model, year): fmt = model.get('format', 'TTT') bracket = [] # random.seed() endModel = 'None' if 'endModel' in model: endModel = model['endModel'] e8Seeds = [] if endModel == 'E8': for i in range(4): e8Seeds.append(getE8SeedTop(year)) e8Seeds.append(getE8SeedBottom(year)) else: e8Seeds = [-1, -1, -1, -1, -1, -1, -1, -1] f4Seeds = [] if endModel == 'F4_1': for i in range(4): f4Seeds.append(getF4SeedTogether(year)) elif endModel == 'F4_2': for i in range(4): f4Seeds.append(getF4SeedSplit(year)) else: f4Seeds = [-1, -1, -1, -1] ncgSeeds = [-1, -1] if 'Rev' in endModel: champion = getChampion(year) runnerUp = getRunnerUp(year) champRegion = int(floor(random.random() * 4)) champHalf = champRegion / 2 ruRegion = int(floor(random.random() * 2)) if champHalf == 0: ncgSeeds = [champion, runnerUp] else: ncgSeeds = [runnerUp, champion] ffrRegion = 1 - ruRegion if champRegion < 2: ruRegion += 2 ffrRegion += 2 ffcRegion = 1 - champRegion else: ffcRegion = 5 - champRegion f4Seeds[champRegion] = champion f4Seeds[ruRegion] = runnerUp else: champRegion = -1 ruRegion = -1 if endModel == 'Rev_4': f4Seeds[ffcRegion] = getF4SeedTogether(year) f4Seeds[ffrRegion] = getF4SeedTogether(year) # Loop through regional rounds R64, R32, and S16 for region in range(4): seeds = [1, 16, 8, 9, 5, 12, 4, 13, 6, 11, 3, 14, 7, 10, 2, 15] for roundNum in range(1, 5): numGames = int(len(seeds) / 2) newSeeds = [] for gameNum in range(numGames): s1 = seeds[2 * gameNum] s2 = seeds[2 * gameNum + 1] # Force any fixed F4/E8 seeds to make it through s1Wins = (s1 == f4Seeds[region]) or ( (roundNum < 4) and ((s1 == e8Seeds[2 * region]) or (s1 == e8Seeds[2 * region + 1]))) s2Wins = (s2 == f4Seeds[region]) or ( (roundNum < 4) and ((s2 == e8Seeds[2 * region]) or (s2 == e8Seeds[2 * region + 1]))) if s1Wins: p = 1 elif s2Wins: p = 0 else: p = getP(s1, s2, model, year, roundNum) if random.random() <= p: bracket.append(1 if fmt == 'TTT' else ( 1 if s1 < s2 else 0)) newSeeds.append(s1) else: bracket.append(0 if fmt == 'TTT' else ( 1 if s2 < s1 else 0)) newSeeds.append(s2) seeds = newSeeds f4Seeds[region] = seeds[0] bracket = bracket + [-1, -1, -1] # Round 5: for gameNum in range(2): s1 = f4Seeds[2 * gameNum] s2 = f4Seeds[2 * gameNum + 1] if 'Rev' in endModel: if (2 * gameNum == champRegion) or (2 * gameNum == ruRegion): p = 1 elif (2 * gameNum + 1 == champRegion) or (2 * gameNum + 1 == ruRegion): p = 0 else: p = getP(s1, s2, model, year, 5) else: p = getP(s1, s2, model, year, 5) if random.random() <= p: bracket[60 + gameNum] = 1 ncgSeeds[gameNum] = s1 else: bracket[60 + gameNum] = 0 ncgSeeds[gameNum] = s2 # Round 6: s1 = ncgSeeds[0] s2 = ncgSeeds[1] if 'Rev' in endModel: if champHalf == 0: p = 1 else: p = 0 else: p = getP(s1, s2, model, year, 6) if random.random() <= p: bracket[-1] = 1 else: bracket[-1] = 0 # assert len(bracket) == 63 # assert np.count_nonzero(np.array(bracket) == -1) == 0 return bracket
def generateBracket(model, year): bracket = [] regionWinners = [] random.seed() isFinalFourSampleModel1 = "True" in model['isFinalFourSampleModel1'] isFinalFourSampleModel2 = "True" in model['isFinalFourSampleModel2'] f4seeds = [] if isFinalFourSampleModel1: for i in range(4): f4seeds.append(getF4SeedTogether(year)) elif isFinalFourSampleModel2: for i in range(4): f4seeds.append(getF4SeedSplit(year)) else: f4seeds = [-1, -1, -1, -1] # Loop through all regional rounds for region in range(4): seeds = [1, 16, 8, 9, 5, 12, 4, 13, 6, 11, 3, 14, 7, 10, 2, 15] for roundNum in range(1, 5): numGames = int(len(seeds) / 2) newSeeds = [] for gameNum in range(numGames): s1 = seeds[2 * gameNum] s2 = seeds[2 * gameNum + 1] # Force the region winner to make it through if s1 == f4seeds[region]: p = 1 elif s2 == f4seeds[region]: p = 0 else: p = getP(s1, s2, model, year, roundNum) if random.random() <= p: bracket.append(1) newSeeds.append(s1) else: bracket.append(0) newSeeds.append(s2) seeds = newSeeds # regionWinners.append(seeds[0]) # Not needed since using f4seeds # Round 5: semiFinalists = [] for gameNum in range(2): s1 = f4seeds[2 * gameNum] s2 = f4seeds[2 * gameNum + 1] p = getP(s1, s2, model, year, 5) if random.random() <= p: bracket.append(1) semiFinalists.append(s1) else: bracket.append(0) semiFinalists.append(s2) # Round 6: s1 = semiFinalists[0] s2 = semiFinalists[1] p = getP(s1, s2, model, year, 6) if random.random() <= p: bracket.append(1) else: bracket.append(0) return bracket