Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Neural MMO
neural-mmo-starter-kit
Commits
30f949bd
Commit
30f949bd
authored
Jun 07, 2021
by
Siddhartha Laghuvarapu
Browse files
Update rollout.py and players.yaml
parent
5a57e9f3
Changes
2
Hide whitespace changes
Inline
Side-by-side
players.yaml
View file @
30f949bd
...
...
@@ -11,17 +11,14 @@ opponent_agents:
agent_1
:
file
:
random_agent
agent_class
:
RandomNeuralMMOAgent
start_sequence
:
1
end_sequence
:
50
num_agents
:
50
agent_2
:
file
:
random_agent
agent_class
:
RandomNeuralMMOAgent
start_sequence
:
51
end_sequence
:
100
num_agents
:
51
agent_3
:
file
:
random_agent
agent_class
:
RandomNeuralMMOAgent
start_sequence
:
101
end_sequence
:
127
num_agents
:
101
rollout.py
View file @
30f949bd
import
gym
import
sys
import
yaml
from
tqdm
import
trange
import
importlib
import
gym
def
get_agent
(
agent_dict
):
sys
.
path
.
append
(
'agents/'
)
module
=
importlib
.
import_module
(
agent_dict
[
'file'
])
agent
=
getattr
(
module
,
agent_dict
[
'agent_class'
])()
return
agent
def
load_agents
(
agents_config
):
with
open
(
agents_config
,
'r'
)
as
stream
:
...
...
@@ -15,25 +21,23 @@ def load_agents(agents_config):
return
player_agent
,
def
main
():
env
=
gym
.
make
(
"neuralmmo-eval"
)
player_agent
,
opponent_agents
=
load_agents
()
agent
=
PlayerAgent
()
env
.
set_eval_agents
(
get_eval_agents
())
obs
=
env
.
reset
()
action
=
agent
.
register_reset
(
obs
)
player_agent
,
opponent_agents
=
load_agents
(
'players.yaml'
)
env
.
set_player_agent
(
player_agent
)
env
.
set_eval_agents
(
opponent_agents
)
n_episodes
=
100
total_rewards
=
0
for
_
in
trange
(
100000000
):
obs
,
reward
,
done
,
info
=
env
.
step
(
action
)
total_rewards
+=
reward
if
don
e
:
obs
=
env
.
reset
()
action
=
agent
.
register_reset
(
obs
)
else
:
action
=
agent
.
compute_action
(
obs
,
info
)
print
(
"Total reward is "
,
total_rewards
)
for
_
in
trange
(
n_episodes
):
obs
=
env
.
reset
(
)
done
=
False
while
done
==
Fals
e
:
obs
,
dones
,
rewards
,
_
=
env
.
step
()
total_rewards
+=
rewards
[
'player'
]
done
=
dones
[
'player'
]
print
(
"T
he t
otal reward is "
,
total_rewards
)
if
__name__
==
"__main__"
:
main
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment