-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCustomAgents.py
89 lines (81 loc) · 2.88 KB
/
CustomAgents.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from pettingzoo.mpe import simple_tag_v3
import numpy as np
def escapeFromDronesAgent(observation, env,agent):
min_agent_norm = float('inf')
min_agent_loc = [0, 0]
action = env.action_space(agent).sample() # this is where you would insert your policy
found_enemy = False
for item in observation[4:]:
target_adversery, target_location, target_color = item
if target_adversery:
found_enemy = True
if np.linalg.norm(target_location) < min_agent_norm:
min_agent_norm = np.linalg.norm(target_location)
min_agent_loc = target_location
if abs(min_agent_loc[0]) <= abs(min_agent_loc[1]):
if min_agent_loc[0] <= 0:
action = 1
else:
action = 2
else:
if min_agent_loc[1] <= 0:
action = 3
else:
action = 4
if found_enemy == False:
action = env.action_space(agent).sample()
return action
def escapeFromParastieAgent(observation, env,agent):
min_agent_norm = float('inf')
min_agent_loc = [0, 0]
action = env.action_space(agent).sample() # this is where you would insert your policy
found_enemy = False
for item in observation[4:]:
target_adversery, target_location, target_color = item
if not target_adversery:
found_enemy = True
if np.linalg.norm(target_location) < min_agent_norm:
min_agent_norm = np.linalg.norm(target_location)
min_agent_loc = target_location
if abs(min_agent_loc[0]) > abs(min_agent_loc[1]):
if min_agent_loc[0] <= 0:
action = 1
else:
action = 2
else:
if min_agent_loc[1] <= 0:
action = 3
else:
action = 4
if found_enemy == False:
action = env.action_space(agent).sample()
return action
def chaseParasiteAgent(observation,env,agent):
min_agent_norm = float('inf')
min_agent_loc = [0, 0]
action = env.action_space(agent).sample() # this is where you would insert your policy
found_enemy = False
for item in observation[4:]:
target_adversery, target_location, target_color = item
if not target_adversery:
found_enemy = True
if np.linalg.norm(target_location) < min_agent_norm:
min_agent_norm = np.linalg.norm(target_location)
min_agent_loc = target_location
if abs(min_agent_loc[0]) > abs(min_agent_loc[1]):
if min_agent_loc[0] <= 0:
action = 2
else:
action = 1
else:
if min_agent_loc[1] <= 0:
action = 4
else:
action = 3
if found_enemy == False:
action = env.action_space(agent).sample()
return action
def randomAgent(observation,env,agent):
return env.action_space(agent).sample()
def staticAgent(observation,env,agent):
return 0