def main():
    """Main script.
    """

    # Use Agg backend for matplotlib. Why?
    matplotlib.use('Agg')

    # Load in parameters
    params = PARAMS.copy()

    # Calculate dimension of the strategy arrays
    params['DIMENSION'] = (100 / params['GRANULARITY'] + 1)

    # Calculate the value of a single unit of a strategy based on uniform dist.
    params['STARTING_PCT'] = 1.0 / (params['DIMENSION']**2)

    # Initialize teams
    teams = initialize_starting_distribution(**params)

    species_breakdown = [1.0 / 3.0] * 3

    species_breakdown_history = [[], [], []]

    # Initialize average deal data lists
    avg_deal_data = [[], [], []]

    data = teams

    fig, axarr, img, cbar = initialize_figure(avg_deal_data, data, **params)

    # MAIN LOOP
    for round_number in range(params['ROUNDS']):
        # Calculate fitness
        game.calc_scores(**params)

        # Update data
        results = game.update_data()

        teams = results[0]
        avg_deal_data = results[1]
        species_breakdown = results[2]
        species_breakdown_history = results[3]
        center_of_mass = results[4]

        update_figures(fig, axarr, img, cbar, teams, avg_deal_data,
                       species_breakdown_history, center_of_mass, i, **params)

        filename = params['SIM_NAME'] + "%04d.png" % i
        fig.savefig(os.path.join("output", "tmp", filename), dpi=150)

    remove_file(os.path.join("output", "videos", params["SIM_NAME"] + ".mp4"))

    create_video_from_frames(params['SIM_NAME'])

    clear_directory(os.path.join("output", "tmp"))
def main():
    """Main script.
    """

    # Use Agg backend for matplotlib. Why?
    matplotlib.use('Agg')

    # Load in parameters
    params = PARAMS.copy()

    # Calculate dimension of the strategy arrays
    params['DIMENSION'] = (100 / params['GRANULARITY'] + 1)

    # Calculate the value of a single unit of a strategy based on uniform dist.
    params['STARTING_PCT'] = 1.0 / (params['DIMENSION'] ** 2)

    # Initialize teams
    teams = initialize_starting_distribution(**params)

    species_breakdown = [1.0 / 3.0] * 3

    species_breakdown_history = [[], [], []]

    # Initialize average deal data lists
    avg_deal_data = [[], [], []]

    data = teams

    fig, axarr, img, cbar = initialize_figure(avg_deal_data, data, **params)

    # MAIN LOOP
    for round_number in range(params['ROUNDS']):
        # Calculate fitness
        game.calc_scores(**params)

        # Update data
        results = game.update_data()

        teams = results[0]
        avg_deal_data = results[1]
        species_breakdown = results[2]
        species_breakdown_history = results[3]
        center_of_mass = results[4]

        update_figures(fig, axarr, img, cbar, teams, avg_deal_data, 
               species_breakdown_history, center_of_mass, i, **params)

        filename = params['SIM_NAME'] + "%04d.png" % i
        fig.savefig(os.path.join("output", "tmp", filename), dpi=150)

    remove_file(os.path.join("output", "videos", params["SIM_NAME"] + ".mp4"))

    create_video_from_frames(params['SIM_NAME'])

    clear_directory(os.path.join("output", "tmp"))
def main():
    SIM_NAME = params["SIM_NAME"]
    VID_NAME = params["VID_NAME"]
    SNAPSHOT_START = params["SNAPSHOT_START"]
    SNAPSHOT_END = params["SNAPSHOT_END"]
    RESOLUTION = params["RESOLUTION"]

    prep_dir(os.path.join("output", SIM_NAME, "tmp"))

    dataframes = load_csv(os.path.join("output", SIM_NAME, "data"))

    # Initialize plot here
    limits = get_limits(dataframes)
    (fig, ax) = init_plot(dataframes, limits, RESOLUTION)

    tenth = (SNAPSHOT_END + 1 - SNAPSHOT_START) / 10

    current_tenth = 0
    
    print "Drawing frames..."

    for snapshot in range(SNAPSHOT_START, SNAPSHOT_END + 1):
        # Update plot here
        fig, ax = update_plot(dataframes, fig, ax, limits, snapshot)

        # Save plot here
        filename = VID_NAME + "%04d.png" % snapshot
        fig.savefig(os.path.join("output", SIM_NAME, "tmp", filename), dpi=120)

        if snapshot == (current_tenth + 1) * tenth:
            current_tenth += 1
            percent = str(current_tenth * 10) + "%"
            print percent, "of frames finished drawing."

    print "All frames finished drawing."
            


    # Delete old mp4 if it exists
    remove_file(os.path.join("output", SIM_NAME, "video", VID_NAME + ".mp4"))

    # Ensure the directory exists
    ensure_dir(os.path.join("output", SIM_NAME, "video"))

    print "\nCreating video from frames..."

    # Create mp4
    create_video_from_frames(SIM_NAME, VID_NAME, fps=60)

    print "\nClearing tmp directory..."

    # Clear snapshot directory
    prep_dir(os.path.join("output", SIM_NAME, "tmp"))

    print "Finished."
def main():
    """Main script.
    """

    # Use Agg backend for matplotlib. Why?
    matplotlib.use('Agg')

    # Load in parameters
    params = PARAMS.copy()

    # Calculate dimension of the strategy arrays
    params['DIMENSION'] = (100 / params['GRANULARITY'] + 1)

    # Calculate the value of a single unit of a strategy based on uniform dist.
    params['UNIT_VALUE'] = 1.0 / (params['DIMENSION']**2)

    params['NUMBER_OF_TEAMS'] = len(params['TEAM_SPEC'])

    # Initialize game
    game = Game(**params)

    # Initialize plot
    fig, axarr, img, cbar = initialize_figure(game, **params)

    # MAIN LOOP
    for round_number in range(params['ROUNDS']):
        game.calc_scores(**params)

        game.update_data(round_number, **params)

        print "*******************************"
        print "round_number:", round_number

        for team in game.teams:
            print team.stats.loc[round_number]

        print "*******************************"

        fig, axarr, img, cbar = update_figures(fig, axarr, img, cbar, game,
                                               round_number, **params)

        filename = params['SIM_NAME'] + "%04d.png" % round_number
        fig.savefig(os.path.join("output", "tmp", filename), dpi=120)

    remove_file(os.path.join("output", "videos", params["SIM_NAME"] + ".mp4"))

    create_video_from_frames(params['SIM_NAME'])

    clear_directory(os.path.join("output", "tmp"))
def main():
    """Main script.
    """

    # Use Agg backend for matplotlib. Why?
    matplotlib.use('Agg')

    # Load in parameters
    params = PARAMS.copy()

    # Calculate dimension of the strategy arrays
    params['DIMENSION'] = (100 / params['GRANULARITY'] + 1)

    # Calculate the value of a single unit of a strategy based on uniform dist.
    params['UNIT_VALUE'] = 1.0 / (params['DIMENSION'] ** 2)

    params['NUMBER_OF_TEAMS'] = len(params['TEAM_SPEC'])

    # Initialize game
    game = Game(**params)

    # Initialize plot
    fig, axarr, img, cbar = initialize_figure(game, **params)

    # MAIN LOOP
    for round_number in range(params['ROUNDS']):
        game.calc_scores(**params)

        game.update_data(round_number, **params)

        print "*******************************"
        print "round_number:", round_number

        for team in game.teams:
            print team.stats.loc[round_number]

        print "*******************************"

        fig, axarr, img, cbar = update_figures(fig, axarr, img, cbar, game, 
                                               round_number, **params)

        filename = params['SIM_NAME'] + "%04d.png" % round_number
        fig.savefig(os.path.join("output", "tmp", filename), dpi=120)

    remove_file(os.path.join("output", "videos", params["SIM_NAME"] + ".mp4"))

    create_video_from_frames(params['SIM_NAME'])

    clear_directory(os.path.join("output", "tmp"))