OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-rocca commits / a8bf343

Fixes to the formatting
a8bf343ecdaf2b2030663c2490e6aca90e588517
by Hedra <tanksh24@gmail.com> · 2022-01-12T15:53:22.000Z

Changed files (3) +267 -160

examples/flatworld.py +7 -3
……@@ -46,6 +46,7 @@ class AbstractMalmoWrapper(MalmoWrapper):
4646 print("Error sending command:", e)
4747 return obs_list, mk_evaluation("Reward", reward), done
4848
49
4950class FlatworldAgent(OpencogAgent):
5051 def __init__(self, env, atomspace):
5152 set_default_atomspace(atomspace)
……@@ -53,7 +54,7 @@ class FlatworldAgent(OpencogAgent):
5354 # Create Action Space. The set of allowed actions an agent can take.
5455 # TODO take care of action parameters.
5556 action_space = {
56 ExecutionLink(SchemaNode("go_to_the_key")),
57 ExecutionLink(SchemaNode("go_to_the_key")),
5758 ExecutionLink(SchemaNode("go_to_the_house")),
5859 ExecutionLink(SchemaNode("go_to_the_diamonds")),
5960 }
……@@ -73,6 +74,7 @@ class FlatworldAgent(OpencogAgent):
7374 # Todo: restart the environment to get an initial reward
7475 self.initial_reward = EvaluationLink(PredicateNode("Reward"), NumberNode("0"))
7576
77
7678if __name__ == "__main__":
7779 atomspace = AtomSpace()
7880 set_default_atomspace(atomspace)
……@@ -84,7 +86,7 @@ if __name__ == "__main__":
8486 # agent_log.set_sync(True)
8587 ure_logger().set_level("info")
8688
87 #
89 #
8890 wrapped_env = AbstractMalmoWrapper(missionXML=missionXML, validate=True)
8991
9092 cog_agent = FlatworldAgent(wrapped_env, atomspace)
……@@ -111,5 +113,7 @@ if __name__ == "__main__":
111113 "Accumulated reward during {}th iteration = {}".format(i + 1, nar)
112114 )
113115 agent_log.info(
114 "Action counter during {}th iteration:\n{}".format(i + 1, cog_agent.action_counter)
116 "Action counter during {}th iteration:\n{}".format(
117 i + 1, cog_agent.action_counter
118 )
115119 )
rocca/envs/malmo_demo/flatworld_env.py +232 -142
……@@ -9,6 +9,7 @@ import math
99import signal
1010from contextlib import contextmanager
1111
12
1213@contextmanager
1314def timeout(time):
1415 # Register a function to raise a TimeoutError on the signal.
……@@ -24,180 +25,254 @@ def timeout(time):
2425 # if the timeout is not reached.
2526 signal.signal(signal.SIGALRM, signal.SIG_IGN)
2627
28
2729def raise_timeout(signum, frame):
2830 raise TimeoutError
2931
32
3033def drawBlock(x, y, z, type):
3134 return """<DrawBlock x='{0}' y='{1}' z='{2}' type='{3}'/>""".format(x, y, z, type)
3235
36
3337def GenCuboid(x1, y1, z1, x2, y2, z2, blocktype):
34 return '<DrawCuboid x1="' + str(x1) + '" y1="' + str(y1) + '" z1="' + str(z1) + '" x2="' + str(x2) + '" y2="' + str(y2) + '" z2="' + str(z2) + '" type="' + blocktype + '"/>'
38 return (
39 '<DrawCuboid x1="'
40 + str(x1)
41 + '" y1="'
42 + str(y1)
43 + '" z1="'
44 + str(z1)
45 + '" x2="'
46 + str(x2)
47 + '" y2="'
48 + str(y2)
49 + '" z2="'
50 + str(z2)
51 + '" type="'
52 + blocktype
53 + '"/>'
54 )
55
3556
3657def drawLine(x1, y1, z1, x2, y2, z2, blocktype, face):
37 return '<DrawLine x1="' + str(x1) + '" y1="' + str(y1) + '" z1="' + str(z1) + '" x2="' + str(x2) + '" y2="' + str(y2) + '" z2="' + str(z2) + '" type="' + blocktype + '" face="' + face +'"/>'
58 return (
59 '<DrawLine x1="'
60 + str(x1)
61 + '" y1="'
62 + str(y1)
63 + '" z1="'
64 + str(z1)
65 + '" x2="'
66 + str(x2)
67 + '" y2="'
68 + str(y2)
69 + '" z2="'
70 + str(z2)
71 + '" type="'
72 + blocktype
73 + '" face="'
74 + face
75 + '"/>'
76 )
77
3878
3979def build_house(x, y, z, width, length, height, blocktype):
4080 x_front = x
41 x_back = x + length if x >= 0 else x-length
42 z_left = z + width if z >= 0 else z-width
81 x_back = x + length if x >= 0 else x - length
82 z_left = z + width if z >= 0 else z - width
4383 z_right = z
4484
4585 genstring = ""
4686 y_cur = y
4787 for i in range(height):
48 z_cur = z
49 x_cur = x
50 for j in range(width):
51 genstring = genstring + drawBlock(x_front, y_cur, z_cur, "glass") + "\n"
52 genstring = genstring + drawBlock(x_back, y_cur, z_cur, "diamond_block") + "\n"
53 genstring = genstring + drawBlock(x_back-1, y_cur, z_cur, blocktype) + "\n"
54 z_cur = z_cur + 1 if z_cur >= 0 else z_cur-1
55
56 for k in range(length):
57 if k % 2 == 0:
58 genstring = genstring + drawBlock(x_cur, y_cur, z_left, "glass") + "\n"
59 genstring = genstring + drawBlock(x_cur, y_cur, z_right, "glass") + "\n"
60 else:
61 genstring = genstring + drawBlock(x_cur, y_cur, z_left, blocktype) + "\n"
62 genstring = genstring + drawBlock(x_cur, y_cur, z_right, blocktype) + "\n"
63 x_cur = x_cur + 1 if x_cur >= 0 else x_cur-1
88 z_cur = z
89 x_cur = x
90 for j in range(width):
91 genstring = genstring + drawBlock(x_front, y_cur, z_cur, "glass") + "\n"
92 genstring = (
93 genstring + drawBlock(x_back, y_cur, z_cur, "diamond_block") + "\n"
94 )
95 genstring = (
96 genstring + drawBlock(x_back - 1, y_cur, z_cur, blocktype) + "\n"
97 )
98 z_cur = z_cur + 1 if z_cur >= 0 else z_cur - 1
99
100 for k in range(length):
101 if k % 2 == 0:
102 genstring = genstring + drawBlock(x_cur, y_cur, z_left, "glass") + "\n"
103 genstring = genstring + drawBlock(x_cur, y_cur, z_right, "glass") + "\n"
104 else:
105 genstring = (
106 genstring + drawBlock(x_cur, y_cur, z_left, blocktype) + "\n"
107 )
108 genstring = (
109 genstring + drawBlock(x_cur, y_cur, z_right, blocktype) + "\n"
110 )
111 x_cur = x_cur + 1 if x_cur >= 0 else x_cur - 1
112
113 y_cur = y_cur + 1 if y_cur >= 0 else y_cur - 1
64114
65 y_cur = y_cur + 1 if y_cur >= 0 else y_cur-1
66
67115 # floor
68 genstring = genstring + GenCuboid(x_back + 1 if x_back >= 0 else x_back - 1, y, z_left + 1 if z_left >= 0 else z_left - 1, x - 1 if x >= 0 else x + 1, y, z - 1 if x >= 0 else z + 1, blocktype )
116 genstring = genstring + GenCuboid(
117 x_back + 1 if x_back >= 0 else x_back - 1,
118 y,
119 z_left + 1 if z_left >= 0 else z_left - 1,
120 x - 1 if x >= 0 else x + 1,
121 y,
122 z - 1 if x >= 0 else z + 1,
123 blocktype,
124 )
69125 # ceiling
70 genstring = genstring + GenCuboid(x_back + 1 if x_back >= 0 else x_back - 1, y_cur, z_left + 1 if z_left >= 0 else z_left - 1, x - 1 if x >= 0 else x + 1, y_cur, z - 1 if x >= 0 else z + 1, blocktype )
71
126 genstring = genstring + GenCuboid(
127 x_back + 1 if x_back >= 0 else x_back - 1,
128 y_cur,
129 z_left + 1 if z_left >= 0 else z_left - 1,
130 x - 1 if x >= 0 else x + 1,
131 y_cur,
132 z - 1 if x >= 0 else z + 1,
133 blocktype,
134 )
135
72136 return genstring
73137
74# Initialize the location coordinates
138
139# Initialize the location coordinates
75140agent_x, agent_y, agent_z, agent_yaw = 19, 230, -2, 90
76141key_x, key_y, key_z = 7, 228, -10
77142door_x, door_y, door_z = -4, 228, -3
78143diamond_x, diamond_y, diamond_z = -18, 228, -3
79start_x, start_y, start_z, width, length, height = -4, 226, -1,6,15,5
144start_x, start_y, start_z, width, length, height = -4, 226, -1, 6, 15, 5
80145holds_key = False
81146
82# relocates the agent to the starting point
147# relocates the agent to the starting point
83148def relocate_agent(agent):
84 print("Agent relocated to original place")
85 agent.sendCommand("tp {} {} {}".format(agent_x, agent_y, agent_z))
86 agent.sendCommand("setYaw {}".format(agent_yaw))
87 time.sleep(0.2)
149 print("Agent relocated to original place")
150 agent.sendCommand("tp {} {} {}".format(agent_x, agent_y, agent_z))
151 agent.sendCommand("setYaw {}".format(agent_yaw))
152 time.sleep(0.2)
153
88154
89# stop the agent
155# stop the agent
90156def stop_condition(agent, blocktype, sec=10):
91 print("Moving to the {}".format(blocktype))
92 def stop(agent, blocktype):
93 done = False
157 print("Moving to the {}".format(blocktype))
158
159 def stop(agent, blocktype):
160 done = False
161 world_state = agent.peekWorldState()
162 while not done:
163 world_state = agent.peekWorldState()
164 if world_state.number_of_observations_since_last_state > 0:
165 ob = json.loads(world_state.observations[-1].text)
166 if blocktype in ob["BlocksInFront"]:
167 print("reached at {}".format(blocktype))
168 agent.sendCommand("move 0")
169 done = True
170
171 with timeout(sec):
172 try:
173 stop(agent, blocktype)
174 return True
175 except TimeoutError:
176 print("*********** Time out **************")
177 agent.sendCommand("move 0")
178 relocate_agent(agent)
179 return False
180
181
182# Get realtime location coordinates
183def get_curr_loc(agent):
184 loc = (agent_x, agent_y, agent_z)
94185 world_state = agent.peekWorldState()
95 while not done:
96 world_state = agent.peekWorldState()
97 if world_state.number_of_observations_since_last_state > 0:
186 # while world_state.is_mission_running:
187 # world_state = agent.peekWorldState()
188 if world_state.number_of_observations_since_last_state > 0:
98189 ob = json.loads(world_state.observations[-1].text)
99 if blocktype in ob["BlocksInFront"]:
100 print("reached at {}".format(blocktype))
101 agent.sendCommand("move 0")
102 done = True
103
104 with timeout(sec):
105 try:
106 stop(agent, blocktype)
107 return True
108 except TimeoutError:
109 print("*********** Time out **************")
110 agent.sendCommand("move 0")
111 relocate_agent(agent)
112 return False
190 loc = (int(ob[u"XPos"]), int(ob[u"YPos"]), int(ob[u"ZPos"]))
113191
114# Get realtime location coordinates
115def get_curr_loc(agent):
116 loc = (agent_x, agent_y, agent_z)
117 world_state = agent.peekWorldState()
118 # while world_state.is_mission_running:
119 # world_state = agent.peekWorldState()
120 if world_state.number_of_observations_since_last_state > 0:
121 ob = json.loads(world_state.observations[-1].text)
122 loc = (int(ob[u'XPos']), int(ob[u'YPos']), int(ob[u'ZPos']))
123
124 return loc
125
126# Turns the agent towards the location given
192 return loc
193
194
195# Turns the agent towards the location given
127196def turn_to(agent, x1, y1, z1, x2, y2, z2):
128 def get_angle(x1, y1, z1, x2, y2, z2):
129 x_dist = abs(x1 - x2)
130 z_dist = abs(z1 - z2)
131 h = math.sqrt(x_dist**2 + z_dist**2)
132 return math.degrees(z_dist/h) if h != 0 else 0
133
134 angle = get_angle(x1, y1, z1, x2, y2, z2)
135 yaw = 90 if x1 > x2 else -90
136 if yaw > 0:
137 angle = yaw - angle if z1 < z2 else yaw + angle
138 else:
139 angle = yaw + angle if z1 < z2 else yaw - angle
140 agent.sendCommand("setYaw {}".format(angle))
197 def get_angle(x1, y1, z1, x2, y2, z2):
198 x_dist = abs(x1 - x2)
199 z_dist = abs(z1 - z2)
200 h = math.sqrt(x_dist ** 2 + z_dist ** 2)
201 return math.degrees(z_dist / h) if h != 0 else 0
202
203 angle = get_angle(x1, y1, z1, x2, y2, z2)
204 yaw = 90 if x1 > x2 else -90
205 if yaw > 0:
206 angle = yaw - angle if z1 < z2 else yaw + angle
207 else:
208 angle = yaw + angle if z1 < z2 else yaw - angle
209 agent.sendCommand("setYaw {}".format(angle))
210
141211
142212def is_mission_running(agent):
143 world_state = agent.peekWorldState()
144 return world_state.is_mission_running
213 world_state = agent.peekWorldState()
214 return world_state.is_mission_running
215
145216
146217# Move the agent towards the key
147# reward=0
218# reward=0
148219def go_to_the_key(agent):
149 global holds_key
150 curr_x, curr_y, curr_z = get_curr_loc(agent)
151 turn_to(agent,curr_x, curr_y, curr_z, key_x, key_y, key_z)
152 time.sleep(0.2)
153 agent.sendCommand("move 1")
154 action_complete = stop_condition(agent, 'tripwire_hook')
155 if action_complete:
156 agent.sendCommand("hotbar.2 1")
157 observation = {"observation":["holds_key"]}
158 holds_key = True
159 else:
160 observation = []
161 reward = 0
162 return observation, reward, is_mission_running
220 global holds_key
221 curr_x, curr_y, curr_z = get_curr_loc(agent)
222 turn_to(agent, curr_x, curr_y, curr_z, key_x, key_y, key_z)
223 time.sleep(0.2)
224 agent.sendCommand("move 1")
225 action_complete = stop_condition(agent, "tripwire_hook")
226 if action_complete:
227 agent.sendCommand("hotbar.2 1")
228 observation = {"observation": ["holds_key"]}
229 holds_key = True
230 else:
231 observation = []
232 reward = 0
233 return observation, reward, is_mission_running
234
163235
164236# Move the agent towards the house and enter the house.
165237# reward = 0
166238def go_to_the_house(agent):
167 curr_x, curr_y, curr_z = get_curr_loc(agent)
168 turn_to(agent, curr_x, curr_y, curr_z, door_x, door_y, door_z)
169 time.sleep(0.2)
170 agent.sendCommand("move 1")
171 action_complete = stop_condition(agent, 'dark_oak_door')
172 if action_complete:
173 observation = {"observation":[]}
174 if holds_key:
175 agent.sendCommand("tp {} {} {}".format(door_x, door_y, door_z))
176 observation["observation"].append("inside_the_house")
177 observation["observation"].append("holds_key")
239 curr_x, curr_y, curr_z = get_curr_loc(agent)
240 turn_to(agent, curr_x, curr_y, curr_z, door_x, door_y, door_z)
241 time.sleep(0.2)
242 agent.sendCommand("move 1")
243 action_complete = stop_condition(agent, "dark_oak_door")
244 if action_complete:
245 observation = {"observation": []}
246 if holds_key:
247 agent.sendCommand("tp {} {} {}".format(door_x, door_y, door_z))
248 observation["observation"].append("inside_the_house")
249 observation["observation"].append("holds_key")
250 else:
251 observation["observation"].append("nextto_closed_door")
252
178253 else:
179 observation["observation"].append("nextto_closed_door")
254 observation = []
255 reward = 0
256 return observation, reward, is_mission_running
180257
181 else:
182 observation = []
183 reward = 0
184 return observation, reward, is_mission_running
185258
186259# Move the agent towards the diamond and collect it.
187260# reward = 1
188261def go_to_the_diamonds(agent):
189 curr_x, curr_y, curr_z = get_curr_loc(agent)
190 turn_to(agent,curr_x, curr_y, curr_z, diamond_x, diamond_y, diamond_z)
191 time.sleep(0.2)
192 agent.sendCommand("move 1")
193 action_complete = stop_condition(agent, 'diamond_block')
194 if action_complete:
195 reward = 1
196 else:
197 reward = 0
198 return [], reward, is_mission_running
262 curr_x, curr_y, curr_z = get_curr_loc(agent)
263 turn_to(agent, curr_x, curr_y, curr_z, diamond_x, diamond_y, diamond_z)
264 time.sleep(0.2)
265 agent.sendCommand("move 1")
266 action_complete = stop_condition(agent, "diamond_block")
267 if action_complete:
268 reward = 1
269 else:
270 reward = 0
271 return [], reward, is_mission_running
272
199273
200missionXML = '''
274missionXML = (
275 """
201276<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
202277<Mission xmlns="http://ProjectMalmo.microsoft.com"
203278 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
……@@ -218,10 +293,20 @@ missionXML = '''
218293 <ServerHandlers>
219294 <FlatWorldGenerator generatorString="3;7,220*1,5*3,2;1;biome_1"/>
220295 <DrawingDecorator>
221 '''+build_house(start_x, start_y, start_z, width, length, height,"planks")+'''
222 '''+drawLine(door_x, door_y-1, door_z, door_x, door_y, door_z, "dark_oak_door", "EAST")+'''
223 '''+drawBlock(key_x, key_y-1, key_z, "command_block")+'''
224 '''+drawBlock(key_x, key_y, key_z, "tripwire_hook")+'''
296 """
297 + build_house(start_x, start_y, start_z, width, length, height, "planks")
298 + """
299 """
300 + drawLine(
301 door_x, door_y - 1, door_z, door_x, door_y, door_z, "dark_oak_door", "EAST"
302 )
303 + """
304 """
305 + drawBlock(key_x, key_y - 1, key_z, "command_block")
306 + """
307 """
308 + drawBlock(key_x, key_y, key_z, "tripwire_hook")
309 + """
225310
226311 </DrawingDecorator>
227312 <ServerQuitFromTimeUp description="" timeLimitMs="1000000"/>
……@@ -232,7 +317,11 @@ missionXML = '''
232317 <AgentSection mode="Survival">
233318 <Name>Cog Agent</Name>
234319 <AgentStart>
235 '''+'<Placement x="{}" y="{}" z="{}" yaw="{}"/>'.format(agent_x, agent_y, agent_z, agent_yaw)+'''
320 """
321 + '<Placement x="{}" y="{}" z="{}" yaw="{}"/>'.format(
322 agent_x, agent_y, agent_z, agent_yaw
323 )
324 + """
236325 <Inventory>
237326 <InventoryItem slot="0" type="diamond_pickaxe"/>
238327 <InventoryItem slot="1" type="tripwire_hook"/>
……@@ -258,7 +347,8 @@ missionXML = '''
258347
259348</Mission>
260349
261'''
350"""
351)
262352
263353if __name__ == "__main__":
264354 """
……@@ -275,25 +365,25 @@ if __name__ == "__main__":
275365 rw, ob, done = malmoWrapper.restart()
276366 total_reward = 0
277367 agent = malmoWrapper.agent_host
278 _, rw, _= go_to_the_key(agent)
368 _, rw, _ = go_to_the_key(agent)
279369 print(ob)
280370 total_reward += rw
281371 world_state = agent.getWorldState()
282372 while world_state.is_mission_running:
283 world_state = agent.getWorldState()
284 if world_state.number_of_rewards_since_last_state > 0:
285 total_reward += world_state.rewards[-1].getValue()
286 print("total reward minecraft = {}".format(total_reward))
373 world_state = agent.getWorldState()
374 if world_state.number_of_rewards_since_last_state > 0:
375 total_reward += world_state.rewards[-1].getValue()
376 print("total reward minecraft = {}".format(total_reward))
287377
288 ob, rw, _ = go_to_the_house(agent)
289 print(ob)
290 total_reward += rw
378 ob, rw, _ = go_to_the_house(agent)
379 print(ob)
380 total_reward += rw
291381
292 ob, rw, _ = go_to_the_diamonds(agent)
293 print(ob)
294 total_reward += rw
382 ob, rw, _ = go_to_the_diamonds(agent)
383 print(ob)
384 total_reward += rw
295385
296 time.sleep(2)
297 print("total reward = {}".format(total_reward))
386 time.sleep(2)
387 print("total reward = {}".format(total_reward))
298388 print()
299389 print("Mission ended")
rocca/malmo/malmoutils.py +28 -15
……@@ -1,15 +1,15 @@
11# ------------------------------------------------------------------------------------------------
22# Copyright (c) 2016 Microsoft Corporation
3#
3#
44# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
55# associated documentation files (the "Software"), to deal in the Software without restriction,
66# including without limitation the rights to use, copy, modify, merge, publish, distribute,
77# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
88# furnished to do so, subject to the following conditions:
9#
9#
1010# The above copyright notice and this permission notice shall be included in all copies or
1111# substantial portions of the Software.
12#
12#
1313# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
1414# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1515# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
……@@ -19,7 +19,7 @@
1919
2020from __future__ import print_function
2121
22# Allow MalmoPython to be imported both from an installed
22# Allow MalmoPython to be imported both from an installed
2323# malmo module and (as an override) separately as a native library.
2424try:
2525 from rocca.malmo import MalmoPython
……@@ -30,6 +30,7 @@ import os
3030import sys
3131import errno
3232
33
3334def fix_print():
3435 # We want to flush the print output immediately, so that we can view test output as it happens.
3536 # The way to do this changed completely between Python 2 and 3, with the result that setting this
……@@ -37,24 +38,31 @@ def fix_print():
3738 # Rather than include this mess in every single sample, it's nice to wrap it into a handy
3839 # function - hence this.
3940 if sys.version_info[0] == 2:
40 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) # flush print output immediately
41 sys.stdout = os.fdopen(
42 sys.stdout.fileno(), "w", 0
43 ) # flush print output immediately
4144 else:
4245 import functools
46
4347 # Have to assign to builtins or the change won't make it outside of this module's scope
4448 import builtins
49
4550 builtins.print = functools.partial(print, flush=True)
4651
52
4753def parse_command_line(agent_host, argv=None):
4854 if argv is None:
49 argv = sys.argv
55 argv = sys.argv
5056 # Add standard options required by test suite:
51 agent_host.addOptionalStringArgument( "recording_dir,r", "Path to location for saving mission recordings", "" )
52 agent_host.addOptionalFlag( "record_video,v", "Record video stream" )
57 agent_host.addOptionalStringArgument(
58 "recording_dir,r", "Path to location for saving mission recordings", ""
59 )
60 agent_host.addOptionalFlag("record_video,v", "Record video stream")
5361 # Attempt to parse:
5462 try:
5563 agent_host.parse(argv)
5664 except RuntimeError as e:
57 print('ERROR:',e)
65 print("ERROR:", e)
5866 print(agent_host.getUsage())
5967 exit(1)
6068 if agent_host.receivedArgument("help"):
……@@ -63,7 +71,12 @@ def parse_command_line(agent_host, argv=None):
6371
6472
6573def get_video_xml(agent_host):
66 return '<VideoProducer><Width>860</Width><Height>480</Height></VideoProducer>' if agent_host.receivedArgument("record_video") else ''
74 return (
75 "<VideoProducer><Width>860</Width><Height>480</Height></VideoProducer>"
76 if agent_host.receivedArgument("record_video")
77 else ""
78 )
79
6780
6881def get_default_recording_object(agent_host, filename):
6982 # Convenience method for setting up a recording object - assuming the recording_dir and record_video
……@@ -77,18 +90,19 @@ def get_default_recording_object(agent_host, filename):
7790 my_mission_record.recordObservations()
7891 my_mission_record.recordCommands()
7992 if agent_host.receivedArgument("record_video"):
80 my_mission_record.recordMP4(24,2000000)
93 my_mission_record.recordMP4(24, 2000000)
8194 return my_mission_record
8295
96
8397def get_recordings_directory(agent_host):
8498 # Check the dir passed in:
85 recordingsDirectory = agent_host.getStringArgument('recording_dir')
99 recordingsDirectory = agent_host.getStringArgument("recording_dir")
86100 if recordingsDirectory:
87101 # If we're running as an integration test, we want to send all our recordings
88102 # to the central test location specified in the environment variable MALMO_TEST_RECORDINGS_PATH:
89103 if agent_host.receivedArgument("test"):
90104 try:
91 test_path = os.environ['MALMO_TEST_RECORDINGS_PATH']
105 test_path = os.environ["MALMO_TEST_RECORDINGS_PATH"]
92106 if test_path:
93107 recordingsDirectory = os.path.join(test_path, recordingsDirectory)
94108 except:
……@@ -97,7 +111,6 @@ def get_recordings_directory(agent_host):
97111 try:
98112 os.makedirs(recordingsDirectory)
99113 except OSError as exception:
100 if exception.errno != errno.EEXIST: # ignore error if already existed
114 if exception.errno != errno.EEXIST: # ignore error if already existed
101115 raise
102116 return recordingsDirectory
103