-
Notifications
You must be signed in to change notification settings - Fork 333
/
double_attack.py
42 lines (32 loc) · 1.18 KB
/
double_attack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
A cooperation game, tigers must attack a same deer simultaneously to get reward
"""
import magent
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),
'step_recover': 0.2,
'kill_supply': 8,
})
tiger = cfg.register_agent_type(
"tiger",
{'width': 1, 'length': 1, 'hp': 10, 'speed': 1,
'view_range': gw.CircleRange(4), 'attack_range': gw.CircleRange(1),
'damage': 1, 'step_recover': -0.2,
})
deer_group = cfg.add_group(deer)
tiger_group = cfg.add_group(tiger)
a = gw.AgentSymbol(tiger_group, index='any')
b = gw.AgentSymbol(tiger_group, index='any')
c = gw.AgentSymbol(deer_group, index='any')
# tigers get reward when they attack a deer simultaneously
e1 = gw.Event(a, 'attack', c)
e2 = gw.Event(b, 'attack', c)
cfg.add_reward_rule(e1 & e2, receiver=[a, b], value=[1, 1])
return cfg