Exemple #1
0
 def setUp(self):
     (self.space, self.newton) = create_space()
     self.teeny_space = create_teeny_space()
     self.test_agent = Agent("test agent")
     self.test_agent2 = Agent("test agent 2")
     self.test_agent3 = Agent("test agent 3")
     self.test_agent4 = Agent("test agent 4")
Exemple #2
0
def create_rholder(name, i, props=None):
    """
    Create an agent.
    """
    k_price = DEF_K_PRICE
    resources = copy.deepcopy(DEF_CAP_WANTED)
    num_resources = len(resources)

    price_list = copy.deepcopy(DEF_EACH_CAP_PRICE)
    if props is not None:
        k_price = props.get('cap_price', DEF_K_PRICE)
        for k in price_list.keys():
            price_list[k] = float("{0:.2f}".format(
                float(k_price * random.uniform(0.5, 1.5))))

    starting_cash = DEF_RHOLDER_CASH
    if props is not None:
        starting_cash = get_prop('rholder_starting_cash', DEF_RHOLDER_CASH)

    if props is not None:
        total_resources = get_prop('rholder_starting_resource_total',
                                   DEF_TOTAL_RESOURCES_RHOLDER_HAVE)
        for k in resources.keys():
            resources[k] = int(
                (total_resources * 2) * (random.random() / num_resources))

    return Agent(name + str(i),
                 action=rholder_action,
                 attrs={
                     "cash": starting_cash,
                     "resources": resources,
                     "price": price_list
                 })
Exemple #3
0
def create_toxin(name, i):
    """
    Create a toxin.
    """
    toxin = Agent(name + str(i), action=toxin_action)
    toxin["max_move"] = get_prop("toxin_move", DEF_TOXIN_MOVE)
    return toxin
Exemple #4
0
def create_agent(i):
    """
    Creates agent for holding sand.
    """
    return Agent(SAND_PREFIX + str(i),
                 action=agent_action,
                 attrs={"grains": 0})
Exemple #5
0
def create_wolf(i):
    global wolves_created
    wolves_created += 1
    return Agent(AGT_WOLF_NAME + str(i),
                 duration=WOLF_LIFESPAN,
                 action=wolf_action,
                 attrs={"time_to_repr": WOLF_REPRO_PERIOD})
Exemple #6
0
def create_sheep(i):
    global sheep_created
    sheep_created += 1
    return Agent(AGT_SHEEP_NAME + str(i),
                 duration=SHEEP_LIFESPAN,
                 action=sheep_action,
                 attrs={"time_to_repr": SHEEP_REPRO_PERIOD})
Exemple #7
0
def create_newly_freed(name, i, props=None, state=PR):
    """
    Create an agent.
    """
    return Agent(name + str(i),
                 action=newly_freed_action,
                 attrs={"state": state})
Exemple #8
0
def create_non_drinker(name, i, **kwargs):
    """
    Create an agent.
    """
    execution_key = get_exec_key(kwargs=kwargs)
    return Agent(name + str(i), action=drinker_action,
                 attrs={MOTIV: DEF_MOTIV}, execution_key=execution_key)
Exemple #9
0
def create_trader(name, i, props=None):
    return Agent(name + str(i),
                 action=seek_a_trade,
                 attrs={
                     "goods": {
                         "penguin": {
                             AMT_AVAIL: 0,
                             UTIL_FUNC: "penguin_util_func",
                             "incr": 0
                         },
                         "cat": {
                             AMT_AVAIL: 0,
                             UTIL_FUNC: "cat_util_func",
                             "incr": 0
                         },
                         "bear": {
                             AMT_AVAIL: 0,
                             UTIL_FUNC: "bear_util_func",
                             "incr": 0
                         },
                         "pet food": {
                             AMT_AVAIL: 0,
                             UTIL_FUNC: GEN_UTIL_FUNC,
                             "incr": 0
                         }
                     },
                     "util": 0,
                     "pre_trade_util": 0,
                     "trades_with": "trader"
                 })
Exemple #10
0
def create_game_cell(x, y):
    """
    Create an agent with the passed x, y value as its name.
    """
    return Agent(name=("(%d,%d)" % (x, y)),
                 action=game_agent_action,
                 attrs={"save_neighbors": True})
Exemple #11
0
def create_bb(name):
    """
    Create a big box store.
    """
    bb_book = {"expense": bb_expense,
               "capital": get_env_attr("bb_capital")}
    return Agent(name=name, attrs=bb_book, action=bb_action)
Exemple #12
0
def create_resident(name, i, group=BLUE, **kwargs):
    """
    Creates agent of specified color type
    """
    execution_key = get_exec_key(kwargs=kwargs)
    if group == BLUE:
        grp_idx = BLUE_GRP_IDX
        mean_tol = get_prop('mean_tol',
                            DEF_TOLERANCE,
                            execution_key=execution_key)
    else:
        grp_idx = RED_GRP_IDX
        mean_tol = -get_prop(
            'mean_tol', DEF_TOLERANCE, execution_key=execution_key)
    dev = get_prop('deviation', DEF_SIGMA, execution_key=execution_key)
    this_tolerance = get_tolerance(mean_tol, dev)
    return Agent(name + str(i),
                 action=seg_agent_action,
                 attrs={
                     TOLERANCE:
                     this_tolerance,
                     GRP_INDEX:
                     grp_idx,
                     "hood_changed":
                     True,
                     "just_moved":
                     False,
                     "hood_size":
                     get_prop('hood_size',
                              DEF_HOOD_SIZE,
                              execution_key=execution_key)
                 },
                 execution_key=execution_key)
Exemple #13
0
def generate_dealer(unused1, unused2, *kwargs):
    dealer = Agent("dealer" + str(random.randint(0, MAX_DEALERS)),
                   action=dealer_action)
    num_emojis = random.randint(1, len(DEF_CORRELATIONS) // 2)
    dealer.attrs["emojis"] = random.sample(emoji_list, num_emojis)
    dealer.attrs["avg_car_life"] = avg_life_from_emojis(dealer.attrs["emojis"])
    return dealer
Exemple #14
0
def create_trader(name, i, props=None):
    return Agent(name + str(i),
                 action=seek_a_trade,
                 attrs={
                     "goods": {
                         "truck": {
                             AMT_AVAILABLE: 0,
                             UTIL_FUNC: "penguin_util_func",
                             "incr": 0,
                             COMPLEMENTS: "fuel"
                         },
                         "land": {
                             AMT_AVAILABLE: 0,
                             UTIL_FUNC: "cat_util_func",
                             "incr": 0,
                             COMPLEMENTS: "wine cellar"
                         },
                         "wine cellar": {
                             AMT_AVAILABLE: 0,
                             UTIL_FUNC: "bear_util_func",
                             "incr": 0,
                             COMPLEMENTS: "land"
                         },
                         "fuel": {
                             AMT_AVAILABLE: 0,
                             UTIL_FUNC: GEN_UTIL_FUNC,
                             "incr": 0,
                             COMPLEMENTS: "truck"
                         }
                     },
                     "util": 0,
                     "pre_trade_util": 0,
                     "trades_with": "trader"
                 })
Exemple #15
0
def create_agent(i, color):
    """
    Creates agent of specified color type
    """
    return Agent(group_names[color] + str(i),
                 action=agent_action,
                 attrs={TOLERANCE: DEF_TOLERANCE,
                        COLOR: color})
Exemple #16
0
def create_nutrient(name, i):
    """
    Create a nutrient.
    """
    nutrient = Agent(name + str(i), action=nutrient_action)
    nutrient["max_move"] = get_prop("nutrient_move",
                                    DEF_NUTRIENT_MOVE)
    return nutrient
Exemple #17
0
def create_bb(name):
    """
    Create a big box store.
    """
    global bb_capital

    bb_book = {"expense": 150, "capital": bb_capital}
    return Agent(name=name, attrs=bb_book, action=bb_action)
Exemple #18
0
def create_tsetter(i, color=RED_SIN):
    """
    Create a trendsetter: all RED_SIN to start.
    """
    return Agent(TSETTER_PRENM + str(i),
                 action=tsetter_action,
                 attrs={COLOR_PREF: color,
                        DISPLAY_COLOR: color})
Exemple #19
0
def create_follower(i, color=BLUE_SIN):
    """
    Create a follower: all BLUE_SIN to start.
    """
    return Agent(FOLLOWER_PRENM + str(i),
                 action=follower_action,
                 attrs={COLOR_PREF: color,
                        DISPLAY_COLOR: color})
Exemple #20
0
def create_grain(x, y, execution_key=None):
    """
    Create an agent with the passed x, y value as its name.
    """
    return Agent(name=("(%d,%d)" % (x, y)),
                 action=None,
                 attrs={"save_neighbors": True},
                 execution_key=execution_key)
Exemple #21
0
def plant_tree(i, state=HE):
    """
    Plant a new tree!
    By default, they start out healthy.
    """
    return Agent(TREE_PREFIX + str(i),
                 action=tree_action,
                 attrs={"state": state})
Exemple #22
0
def create_other_leibniz():
    return Agent("Leibniz",
                 attrs={
                     "place": 1.0,
                     "time": LEIBBYEAR
                 },
                 action=leib_action,
                 duration=20)
Exemple #23
0
def create_consumer(name, i, props=None):
    """
    Create consumers
    """
    spending_power = random.randint(50, 70)
    consumer_books = {"spending power": spending_power,
                      "last util": 0.0,
                      "item needed": get_rand_good()}
    return Agent(name + str(i), attrs=consumer_books, action=consumer_action)
Exemple #24
0
def create_follower(name, i, props=None, color=BLUE_SIN, **kwargs):
    """
    Create a follower: all BLUE to start.
    """
    execution_key = get_exec_key(kwargs=kwargs)
    return Agent(FOLLOWER_PRENM + str(i),
                 action=follower_action,
                 attrs={COLOR_PREF: color,
                        DISPLAY_COLOR: color}, execution_key=execution_key)
Exemple #25
0
def create_tsetter(name, i, props=None, color=RED_SIN, **kwargs):
    """
    Create a trendsetter: all RED to start.
    """
    execution_key = get_exec_key(kwargs=kwargs)
    return Agent(TSETTER_PRENM + str(i),
                 action=tsetter_action,
                 attrs={COLOR_PREF: color,
                        DISPLAY_COLOR: color}, execution_key=execution_key)
Exemple #26
0
def create_mp(store_type, i):
    """
    Create a mom and pop store.
    """
    expense = mp_stores[str(store_type)]
    name = str(store_type) + " " + str(i)
    store_books = {"expense": expense[EXPENSE_INDX],
                   "capital": expense[CAPITAL_INDX]}
    return Agent(name=name, attrs=store_books, action=mp_action)
Exemple #27
0
def create_newton():
    return Agent("Newton",
                 attrs={
                     "place": 0.0,
                     "time": 1658.0,
                     "achieve": 43.9
                 },
                 action=newt_action,
                 duration=30)
Exemple #28
0
def create_geneng(name, i, **kwargs):
    """
    Create an agent.
    """
    dur = get_prop("lifespan", DEF_DURATION)
    return Agent(name + str(i),
                 action=geneng_action,
                 duration=dur,
                 attrs={"height": START_HEIGHT})
Exemple #29
0
def create_central_bank(name, i):
    """
    Create the central bank to distribute the coupons
    """
    central_bank = Agent(name, action=central_bank_action)
    central_bank["percent_change"] = get_prop("percent_change", DEF_PERCENT)
    central_bank["extra_coupons"] = get_prop("extra_coupons", DEF_COUPON)
    central_bank["extra_dev"] = get_prop("extra_deviation", DEF_SIGMA)
    return central_bank
Exemple #30
0
def create_natural(name, i, **kwargs):
    """
    Create an agent.
    """
    dur = get_prop("lifespan", DEF_DURATION)
    height = gauss(START_HEIGHT, DEF_SIGMA)
    return Agent(name + str(i),
                 action=natural_action,
                 duration=dur,
                 attrs={"height": height})