def main(champions):
    # Pre-selection
    ranks = {}
    count = 1
    total = len(champions)

    for champion in champions:
        ranks[champion] = Rank(Champion.fromfile(champion))

    util.tprint('Champions', '%d' % (len(champions)))
    print ''

    util.tprint('Pre-selections (one VS one)')
    for champion in champions:
        rank = ranks[champion]
        util.twrite('Champion', '%s' % (colored('%-32s' % (rank.champion.name), 'cyan', attrs = ['bold'])))
        (win, defeat, reports) = blindtest.run(champion, champions, False, one = True)
        results(win, defeat, count, total)
        rank.win += win
        rank.defeat += defeat

        count += 1
    print ''

    ladder = [key for (key, value) in sorted(ranks.items(), key = lambda item: item[1].ratio(), reverse = True)]

    melees = [
        (128, min(8, len(champions)))
    ]

    best = ladder[0:16]

    count = 1
    total = len(best)

    best = ladder[0:16]

    util.tprint('Matches (Melee)')
    for champion in best:
        rank = ranks[champion]
        util.twrite('Champion', '%s' % (colored('%-32s' % (rank.champion.name), 'cyan', attrs = ['bold'])))
        (win, defeat, reports) = blindtest.run(champion, best, False, melees = melees)
        results(win, defeat, count, total)
        rank.win += win
        rank.defeat += defeat

        count += 1
    print ''

    ranks = sorted(ranks.values(), key = lambda rank: rank.ratio(), reverse = True)
    winner = ranks[0]
    util.tprint('Winner', '%s %s %s' % (colored('%-32s' % (winner.champion.name), 'green', attrs = ['bold']),
                                        colored('->', 'white', attrs = ['bold']),
                                        ratio_str(winner.win, winner.defeat)))

    result_file = open('logs/result.json', 'w+')
    result_file.write(json.dumps([rank.encode() for rank in ranks], indent=4, separators=(',', ': '), sort_keys = False))
    result_file.close()
def main(filename, champions, display, one, melee):
    util.Logger.install(os.path.basename(filename).replace('.cor', '.stdout.log'), 'w+')
    (win, defeat, reports) = blindtest.run(filename, champions, display, one = one, melee = melee)

    if win + defeat != 0:
        ratio = float(win) / (win + defeat) * 100
    else:
        ratio = 0
    if display:
        ratio_str = '%s / %s / %s / %s' % (colored('Win: %d' % (win), 'green', attrs = ['bold']),
                                           colored('Defeat: %d' % (defeat), 'red', attrs = ['bold']),
                                           colored('Total: %d' % (win + defeat), 'white', attrs = ['bold']),
                                           colored('%d%%' % (ratio), 'yellow', attrs = ['bold']))
        util.tprint('Ratio', ratio_str)
        print ''

    logfilename = os.path.basename(filename).replace('.cor', '.log')
    logfile = open('logs/%s' % (logfilename), 'w+')
    writelog(logfile, filename, win, defeat, ratio, reports)
    logfile.close()