示例#1
0
def genNCGBracket(model, year):
    bracket = np.repeat(-1, 63)
    champion = getChampion(year, model)
    runnerUp = getRunnerUp(year, model)
    ncg_triplet = getValues(bracket, year, 'NCG')
    bracket[[60, 61, 62]] = ncg_triplet
    bracket = fixBitsFromNCG(bracket, champion, runnerUp)

    # ...
    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)
示例#2
0
def getCombinedEndModelBracket(model, year):
    bracket = np.repeat(-1, 63)
    champion = getChampion(year, model)
    runnerUp = getRunnerUp(year, model)
    ncg_triplet = getValues(bracket, year, 'NCG')
    bracket[[60, 61, 62]] = ncg_triplet
    bracket = fixBitsFromNCG(bracket, champion, runnerUp)

    # ...
    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

    f4_seeds = [getF4SeedSplit(year, model) for _ in range(4)]
    for region in range(4):
        if bracket[region * 15 + 14] == -1:
            bracket[region * 15:region * 15 + 15] = fixRegionalBits(
                f4_seeds[region])
    try:
        assert np.all(bracket[[14, 29, 44, 59]] != -1)
    except:
        import pdb
        pdb.set_trace()
    return fillEmptySpaces(bracket, model, year)
示例#3
0
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