-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.py
88 lines (76 loc) · 2.59 KB
/
run.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
import marlo
import os
import json
def get_join_tokens():
if marlo.is_grading():
"""
In the crowdAI Evaluation environment obtain the join_tokens
from the evaluator
the `params` parameter passed to the `evaluator_join_token` only allows
the following keys :
"seed",
"tick_length",
"max_retries",
"retry_sleep",
"step_sleep",
"skip_steps",
"videoResolution",
"continuous_to_discrete",
"allowContinuousMovement",
"allowDiscreteMovement",
"allowAbsoluteMovement",
"add_noop_command",
"comp_all_commands"
# TODO: Add this to the official documentation ?
# Help Wanted :D Pull Requests welcome :D
"""
join_tokens = marlo.evaluator_join_token(params={})
else:
"""
When debugging locally,
Please ensure that you have a Minecraft client running on port 10000
by doing :
$MALMO_MINECRAFT_ROOT/launchClient.sh -port 10000
"""
client_pool = [('127.0.0.1', 10000)]
join_tokens = marlo.make('MarLo-FindTheGoal-v0',
params={
"client_pool": client_pool
})
return join_tokens
def run_episode():
"""
Single episode run
"""
join_tokens = get_join_tokens()
# As this is a single agent scenario,there will just be a single token
assert len(join_tokens) == 1
join_token = join_tokens[0]
#
# # Initialize the environment
env = marlo.init(join_token)
# Get the first observation
observation = env.reset()
# Enter game loop
done = False
while not done:
_action = env.action_space.sample()
observation, reward, done, info = env.step(_action)
print("reward:", reward)
print("done:", done)
print("info", info)
# It is important to do this env.close()
env.close()
if __name__ == "__main__":
"""
In case of debugging locally, run the episode just once
and in case of when the agent is being evaluated, continue
running episodes for as long as the evaluator keeps supplying
join_tokens.
"""
if not marlo.is_grading():
print("Running single episode...")
run_episode()
else:
while True:
run_episode()