Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'''
return cfg
def measure_time(msg, func, *args, **kwargs):
start_time = time.time()
ret = func(*args, **kwargs)
print("%-11s %.3f" % (msg, time.time() - start_time))
return ret
if __name__ == "__main__":
n_step = 10
# init the game "forest" (or "battle" here)
env = gw.GridWorld(load_forest())
env.reset()
# add two groups of animals
deer_handle, tiger_handle = env.get_handles()
env.add_agents(deer_handle, method="random", n=1000000)
env.add_agents(tiger_handle, method="random", n=1000000)
# init two models
model1 = RandomActor(env, deer_handle)
model2 = RandomActor(env, tiger_handle)
total_reward = 0
print(env.get_view_space(deer_handle))
print(env.get_view_space(tiger_handle))
def load_forest():
cfg = gw.Config()
cfg.set({"map_width": 10000, "map_height": 10000})
cfg.set({"minimap_mode": 0})
cfg.set({"turn_mode": 0})
cfg.set({"embedding_size": 8})
deer = cfg.register_agent_type(
name="deer",
attr={'width': 1, 'length': 1, 'hp': 10, 'speed': 1,
'view_range': gw.CircleRange(7), 'attack_range': gw.CircleRange(0),
'damage': 0, 'step_recover': 0, 'kill_supply': 8})
tiger = cfg.register_agent_type(
name="tiger",
attr={'width': 1, 'length': 1, 'hp': 10, 'speed': 1,
'view_range': gw.CircleRange(6), 'attack_range': gw.CircleRange(2),
def load_config(map_size):
gw = magent.gridworld
cfg = gw.Config()
cfg.set({"map_width": map_size, "map_height": map_size})
cfg.set({"minimap_mode": True})
cfg.set({"embedding_size": 12})
goal = cfg.register_agent_type(
"goal",
{'width': 1, 'length': 1,
'can_absorb': True
}
)
agent = cfg.register_agent_type(
"agent",
def load_config(map_size):
gw = magent.gridworld
cfg = gw.Config()
cfg.set({"map_width": map_size, "map_height": map_size})
cfg.set({"minimap_mode": True})
cfg.set({"embedding_size": 10})
melee = cfg.register_agent_type(
"melee",
{'width': 1, 'length': 1, 'hp': 10, 'speed': 1,
'view_range': gw.CircleRange(6), 'attack_range': gw.CircleRange(1),
'damage': 2, 'step_recover': 0.1, 'attack_in_group': True,
'step_reward': -0.01, 'kill_reward': 0, 'dead_penalty': -0.1, 'attack_penalty': -1,
})
def load_config(map_size):
gw = magent.gridworld
cfg = gw.Config()
cfg.set({"map_width": map_size, "map_height": map_size})
cfg.set({"minimap_mode": True})
cfg.set({"embedding_size": 12})
goal = cfg.register_agent_type(
"goal",
{'width': 1, 'length': 1,
'can_absorb': True
}
)
agent = cfg.register_agent_type(
"agent",
def get_config(map_size):
gw = magent.gridworld
cfg = gw.Config()
cfg.set({"map_width": map_size, "map_height": map_size})
cfg.set({"view_width": 13, "view_height": 13})
cfg.set({"embedding_size": 10})
return cfg
def load_config(map_size):
gw = magent.gridworld
cfg = gw.Config()
cfg.set({"map_width": map_size, "map_height": map_size})
cfg.set({"minimap_mode": True})
cfg.set({"embedding_size": 10})
small = cfg.register_agent_type(
"small",
{'width': 1, 'length': 1, 'hp': 10, 'speed': 2,
'view_range': gw.CircleRange(6), 'attack_range': gw.CircleRange(1.5),
'damage': 2, 'step_recover': 0.1,
'step_reward': -0.001, 'kill_reward': 100, 'dead_penalty': -0.05, 'attack_penalty': -1,
})
g0 = cfg.add_group(small)
def load_config(map_size):
gw = magent.gridworld
cfg = gw.Config()
cfg.set({"map_width": map_size, "map_height": map_size})
cfg.set({"minimap_mode": True})
cfg.set({"embedding_size": 12})
goal = cfg.register_agent_type(
"goal",
{'width': 1, 'length': 1,
'can_absorb': True
}
)
agent = cfg.register_agent_type(
"agent",
def get_config(map_size):
gw = magent.gridworld
cfg = gw.Config()
cfg.set({"map_width": map_size, "map_height": map_size})
cfg.set({"embedding_size": 10})
deer = cfg.register_agent_type(
"deer",
{'width': 1, 'length': 1, 'hp': 5, 'speed': 1,
'view_range': gw.CircleRange(1), 'attack_range': gw.CircleRange(0),
'damage': 0, 'step_recover': 0.2,
'food_supply': 0, 'kill_supply': 8,
})
tiger = cfg.register_agent_type(
"tiger",