Пример #1
0
    for x in range(10):
        model.add_agent(Robot())
    model.speed_factor = 1
    for t in model.tiles:
        if randint(0, 50) == 50:
            t.color = (0, 255, 255)
            t.info["has_mineral"] = True
        else:
            t.color = (200, 100, 0)
            t.info["has_mineral"] = False
    model.add_agent(Homebase())
    model.clear_plots()
    model.minerals_collected = 0


def step(model):
    for ag in model.agents:
        ag.step(model)
    model.update_plots()


miner_model.add_button("Setup", setup)

miner_model.add_toggle_button("Go", step)

miner_model.add_slider("speed_factor", 1, 1, 5)

miner_model.line_chart(["minerals_collected"], [(0, 200, 200)])

run(miner_model)
Пример #2
0
    # Write min, average and max bug size to file
    file_handle.write(
        str(bug_min) + " " + str(bug_mean) + " " + str(bug_max) + "\n")

    # Update plots
    model.update_plots()


def close(model):
    if file_handle:
        file_handle.close()


stupid_model = Model("StupidModel w. file output (stupid08)",
                     100,
                     100,
                     tile_size=5)
stupid_model.add_button("setup", setup)
stupid_model.add_button("step", step)
stupid_model.add_toggle_button("go", step)
stupid_model.add_controller_row()
stupid_model.add_slider("initial_bugs", 100, 10, 300)
stupid_model.add_controller_row()
stupid_model.add_slider("max_food_eat", 1.0, 0.1, 1.0)
stupid_model.add_controller_row()
stupid_model.add_slider("max_food_prod", 0.01, 0.01, 0.1)
stupid_model.histogram("grow_size", 0, 10, 5, (0, 0, 0))
stupid_model.on_close(close)
run(stupid_model)
Пример #3
0
    for tile in model.tiles:
        tile.color = (tile.info["value"], tile.info["value"], 0)
    seekers = set([Seeker() for i in range(200)])
    model.add_agents(seekers)


def step(model):
    for tile in model.tiles:
        if tile.info["value"] > 255:
            tile.info["value"] = 0
        tile.color = (tile.info["value"], tile.info["value"], 0)
    for agent in model.agents:
        agent.step(model)


def invisible(model):
    model.invisible = not model.invisible
    if model.invisible:
        for a in model.agents:
            a.size = 0
    else:
        for a in model.agents:
            a.size = 4


urban_model = Model("urban", 50, 50)
urban_model.add_button("Setup", setup)
urban_model.add_toggle_button("Go", step)
urban_model.add_button("Invisible", invisible)
run(urban_model)