Ejemplo n.º 1
0
def main():  # type: () -> None
    """Open two plots."""
    datalist = [(1, 2), (2, 3), (5, 4), (8, 3), (9, 2)]
    dataset = {1: 3, 2: 4, 5: 5, 8: 4, 9: 3}

    filename = None

    if SIMPLEGUICS2PYGAME:
        from sys import argv  # pylint: disable=import-outside-toplevel

        if len(argv) == 2:
            filename = argv[1]

    simpleplot.plot_lines('Test plot_lines 1', 400, 400, 'x', 'y',
                          (datalist, dataset))

    if filename is None:
        simpleplot.plot_lines('Test plot_lines 2', 400, 400, 'x', 'y',
                              (datalist, dataset), True,
                              ('datalist', 'dataset'))
    else:
        simpleplot.plot_lines('Test plot_lines 2',
                              400,
                              400,
                              'x',
                              'y', (datalist, dataset),
                              True, ('datalist', 'dataset'),
                              _filename=filename)

    if SIMPLEGUICS2PYGAME and (len(argv) != 2):
        simpleplot._block()  # pylint: disable=protected-access
Ejemplo n.º 2
0
def init():  # type: () -> None
    """Init list of shapes, corresponding to the current step."""
    global FPS  # pylint: disable=global-statement
    global FREEZED  # pylint: disable=global-statement
    global NB_SHAPES  # pylint: disable=global-statement
    global NB_FRAMES_DRAWED  # pylint: disable=global-statement
    global NB_SECONDS  # pylint: disable=global-statement
    global SHAPES  # pylint: disable=global-statement
    global TO_NEXT_STEP  # pylint: disable=global-statement

    if len(LIST_NB_SHAPES) == 0:
        TIMER.stop()

        final_result = dict_to_ordered_list(RESULTS)

        print('Results: {' + ', '
              .join(['%d: %d' % result for result in final_result]) + '}')

        try:
            FRAME.stop()
        except Exception as e:  # pylint: disable=broad-except
            # To avoid failed when run with simpleguitk
            print('FRAME.stop():' + str(e))

        if PLOT:
            try:
                simpleplot.plot_lines('Stress Balls', 800, 650,
                                      '# balls', 'FPS',
                                      (final_result, ), True)
                if SIMPLEGUICS2PYGAME:
                    simpleplot._block()  # pylint: disable=protected-access
            except Exception as e:  # pylint: disable=broad-except
                # To avoid fail if no simpleplot
                print('simpleplot.plot_lines():' + str(e))

        flush()

        return

    if LIST_NB_SHAPES:
        NB_SHAPES = LIST_NB_SHAPES.pop(0)

    assert isinstance(NB_SHAPES, int)

    FPS = 0
    FREEZED = False
    NB_FRAMES_DRAWED = 0
    NB_SECONDS = 0
    TO_NEXT_STEP = False

    SHAPES = tuple([Shape((47 + n % (WIDTH - 100),
                           47 + n % (HEIGHT - 100)),  # position
                          19 + n % 11,  # radius
                          n_to_rgba((n + 1) % len(RGB_COLORS),
                                    .2 + float(n % 13) / 15),  # color of border  # noqa
                          n_to_rgba((n + 2) % len(RGB_COLORS),
                                    .2 + float((n + 3) % 14) / 17),  # fill color  # noqa
                          (3 + n % 7, 2 + n % 5),  # velocity
                          (n + 2) % 6)  # shape
                    for n in range(NB_SHAPES)])
def init():
    global balls
    global fps
    global freezed
    global nb_balls
    global nb_frames_drawed
    global nb_seconds
    global results
    global to_next_step

    if len(list_nb_balls) == 0:
        timer.stop()

        results = dict_to_ordered_list(results)

        print('Results: {' +
              ', '.join(['%d: %d' % result for result in results]) + '}')

        try:
            frame.stop()
        except Exception as e:  # to avoid simpleguitk failed
            print('frame.stop():' + str(e))

        try:
            simpleplot.plot_lines('Stress Balls', 800, 650, '# balls', 'FPS',
                                  (results, ), True)
            if SIMPLEGUICS2PYGAME:
                simpleplot._block()
        except Exception as e:  # to avoid fail if no simpleplot
            print('simpleplot.plot_lines():' + str(e))

        return

    if list_nb_balls:
        nb_balls = list_nb_balls.pop(0)

    fps = 0
    freezed = False
    nb_frames_drawed = 0
    nb_seconds = 0
    to_next_step = False

    balls = tuple([
        Ball(
            [47 + n % (WIDTH - 100), 47 + n % (HEIGHT - 100)],  # position
            19 + n % 11,  # radius
            n_to_rgba((n + 1) % len(RGB_COLORS),
                      .2 + float(n % 13) / 15),  # color of border
            n_to_rgba((n + 2) % len(RGB_COLORS), .2 + float(
                (n + 3) % 14) / 17),  # fill color
            [3 + n % 7, 2 + n % 5],  # velocity
            (n + 2) % 6)  # shape
        for n in range(nb_balls)
    ])
def init():
    global balls
    global fps
    global freezed
    global nb_balls
    global nb_frames_drawed
    global nb_seconds
    global results
    global to_next_step

    if len(list_nb_balls) == 0:
        timer.stop()

        results = dict_to_ordered_list(results)

        print('Results: {' + ', '
              .join(['%d: %d' % result for result in results]) + '}')

        try:
            frame.stop()
        except Exception as e:  # to avoid simpleguitk failed
            print('frame.stop():' + str(e))

        try:
            simpleplot.plot_lines('Stress Balls', 800, 650,
                                  '# balls', 'FPS',
                                  (results, ), True)
            if SIMPLEGUICS2PYGAME:
                simpleplot._block()
        except Exception as e:  # to avoid fail if no simpleplot
            print('simpleplot.plot_lines():' + str(e))

        return

    if list_nb_balls:
        nb_balls = list_nb_balls.pop(0)

    fps = 0
    freezed = False
    nb_frames_drawed = 0
    nb_seconds = 0
    to_next_step = False

    balls = tuple([Ball([47 + n % (WIDTH - 100),
                         47 + n % (HEIGHT - 100)],  # position
                        19 + n % 11,  # radius
                        n_to_rgba((n + 1) % len(RGB_COLORS),
                                  .2 + float(n % 13)/15),  # color of border
                        n_to_rgba((n + 2) % len(RGB_COLORS),
                                  .2 + float((n + 3) % 14)/17),  # fill color
                        [3 + n % 7, 2 + n % 5],  # velocity
                        (n + 2) % 6)  # shape
                   for n in range(nb_balls)])
Ejemplo n.º 5
0
def run_simulations():
    """ Run simulations for several possible bribe increments """
    plot_type = LOGLOG  # we choose the logarithmic plot
    days = 70
    inc_0 = greedy_boss(days, 0, plot_type)
    inc_500 = greedy_boss(days, 500, plot_type)
    inc_1000 = greedy_boss(days, 1000, plot_type)
    inc_2000 = greedy_boss(days, 2000, plot_type)
    simpleplot.plot_lines(
        "Greedy boss", 600, 600, "days", "total earnings",
        [inc_0, inc_500, inc_1000, inc_2000], False, [
            "Bribe increment = 0", "Bribe increment = 500",
            "Bribe increment = 1000", "Bribe increment = 2000"
        ])
    simpleplot._block()
Ejemplo n.º 6
0
def run_strategy(
    strategy_name, time, strategy
):  # function runs the simulation, prints out the final state of the game after the given time and then plots the total number of cookies over time.
    """ Run a simulation for the given time with one strategy. """
    state = simulate_clicker(provided.BuildInfo(), time, strategy)
    print "Strategy name:", strategy_name
    print(
        state
    )  # this line is to print the details of each strategy in the console

    # Plot total cookies over time
    history = state.get_history()
    history = [(item[0], item[3]) for item in history]
    simpleplot.plot_lines(strategy_name, 1000, 400, 'Time', 'Total Cookies',
                          [history], True)
    simpleplot._block()
    r = []

    for nb in nb_balls:
        r.append((nb, data[nb]))

    datas.append(r)


# Display
print('|'.join(['%4d' % nb for nb in alls_nb]) + '|Environment')

print('----+'*len(alls_nb) + '-----------')
for legend in legends:
    l = []
    for nb in alls_nb:
        fps = all_results[legend].get(nb, None)
        l.append(('%4d' % fps if fps is not None
                  else ' '*4))
    print('|'.join(l) + '|' + legend)


# Graph
try:
    simpleplot.plot_lines('Stress Balls', 800, 650, '# balls', 'FPS',
                          datas, True, legends)
    if SIMPLEGUICS2PYGAME:
        simpleplot._block()
except Exception as e:  # to avoid fail if no simpleplot
    print('!simpleplot.plot_lines():' + str(e))
Ejemplo n.º 8
0
def run_simulations():
    """
    Run simulations for several possible bribe increments
    """
    plot_type = LOGLOG
    days = 150
    inc_0 = greedy_boss(days, 0, plot_type)
    inc_500 = greedy_boss(days, 500, plot_type)
    inc_1000 = greedy_boss(days, 1000, plot_type)
    inc_2000 = greedy_boss(days, 2000, plot_type)
    simpleplot.plot_lines("Greedy boss", 600, 600, "days", "total earnings",
                          [inc_0], False, ["Bribe increment = 0"])


#run_simulations()

# print greedy_boss(35, 100)
# should print [(0, 0), (10, 1000), (16, 2200), (20, 3400), (23, 4600), (26, 6100), (29, 7900), (31, 9300), (33, 10900), (35, 12700)]

print greedy_boss(70, 0)
# should print [(0, 0), (10, 1000), (15, 2000), (19, 3200), (21, 4000), (23, 5000), (25, 6200), (27, 7600), (28, 8400), (29, 9300), (30, 10300), (31, 11400), (32, 12600), (33, 13900), (34, 15300), (34, 15300), (35, 16900)]

if SIMPLEGUICS2PYGAME:
    simpleplot._block()

# print greedy_boss(50, 1000)
#
# for d in range(51):
#     print "day:", d, ", slr:", 50*(d/10+1)*d