OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-rocca commits / fbaaefc

Updated for more observations
fbaaefc2a7a15d943ac42ea9698fff546772eb95
by Hedra <tanksh24@gmail.com> · 2022-01-26T14:55:16.000Z

Changed files (1) +46 -26

rocca/envs/malmo_demo/flatworld_env.py +46 -26
……@@ -30,8 +30,15 @@ def raise_timeout(signum, frame):
3030 raise TimeoutError
3131
3232
33def drawBlock(x, y, z, type):
34 return """<DrawBlock x='{0}' y='{1}' z='{2}' type='{3}'/>""".format(x, y, z, type)
33def drawBlock(x, y, z, type, variant=False, face=False):
34 if variant:
35 return """<DrawBlock x='{0}' y='{1}' z='{2}' type='{3}' variant='{4}' face='{5}'/>""".format(
36 x, y, z, type, variant, face
37 )
38 else:
39 return """<DrawBlock x='{0}' y='{1}' z='{2}' type='{3}' />""".format(
40 x, y, z, type, variant
41 )
3542
3643
3744def GenCuboid(x1, y1, z1, x2, y2, z2, blocktype):
……@@ -183,12 +190,12 @@ def stop_condition(agent, blocktype, sec=10):
183190def get_curr_loc(agent):
184191 loc = (agent_x, agent_y, agent_z)
185192 world_state = agent.peekWorldState()
186 # while world_state.is_mission_running:
187 # world_state = agent.peekWorldState()
188 if world_state.number_of_observations_since_last_state > 0:
189 ob = json.loads(world_state.observations[-1].text)
190 loc = (int(ob[u"XPos"]), int(ob[u"YPos"]), int(ob[u"ZPos"]))
191
193 while world_state.is_mission_running:
194 world_state = agent.peekWorldState()
195 if world_state.number_of_observations_since_last_state > 0:
196 ob = json.loads(world_state.observations[-1].text)
197 loc = (int(ob[u"XPos"]), int(ob[u"YPos"]), int(ob[u"ZPos"]))
198 break
192199 return loc
193200
194201
……@@ -214,20 +221,36 @@ def is_mission_running(agent):
214221 return world_state.is_mission_running
215222
216223
224def inside_house(x, z):
225 return (
226 True
227 if (x in range(start_x, start_x - length, -1))
228 and (z in range(start_z, start_z - width, -1))
229 else False
230 )
231
232
217233# Move the agent towards the key
218234# reward=0
219235def go_to_the_key(agent):
220236 global holds_key
221237 reward = 0
222 observation = {"holds": ["self", "key"]}
238 observation = {}
239 curr_x, curr_y, curr_z = get_curr_loc(agent)
240 if inside_house(curr_x, curr_z):
241 observation["inside"] = ["self", "house"]
242 return observation, reward, is_mission_running
243 else:
244 observation["outside"] = ["self", "house"]
223245 if holds_key:
246 observation["holds"] = ["self", "key"]
224247 return observation, reward, is_mission_running
225 curr_x, curr_y, curr_z = get_curr_loc(agent)
226248 turn_to(agent, curr_x, curr_y, curr_z, key_x, key_y, key_z)
227249 time.sleep(0.2)
228250 agent.sendCommand("move 1")
229251 action_complete = stop_condition(agent, "tripwire_hook")
230252 if action_complete:
253 observation["holds"] = ["self", "key"]
231254 agent.sendCommand("hotbar.2 1")
232255 holds_key = True
233256 else:
……@@ -242,26 +265,23 @@ def go_to_the_house(agent):
242265 reward = 0
243266 observation = {}
244267 curr_x, curr_y, curr_z = get_curr_loc(agent)
245 if curr_x == door_x and curr_z == door_z:
268 if inside_house(curr_x, curr_z):
246269 observation["inside"] = ["self", "house"]
247270 return observation, reward, is_mission_running
248
249 turn_to(agent, curr_x, curr_y, curr_z, door_x, door_y, door_z)
271 turn_to(agent, curr_x, curr_y, curr_z, door_x + 2, door_y, door_z)
250272 time.sleep(0.2)
251273 agent.sendCommand("move 1")
252274 action_complete = stop_condition(agent, "dark_oak_door")
253275 if action_complete:
254276 if holds_key:
255 observation["holds"] = ["self", "key"]
256277 agent.sendCommand("tp {} {} {}".format(door_x, door_y, door_z))
278 time.sleep(0.2)
257279 observation["inside"] = ["self", "house"]
258280 agent.sendCommand("hotbar.1 1")
259281 holds_key = False
260282 else:
283 observation["outside"] = ["self", "house"]
261284 observation["nextto"] = ["self", "closed_door"]
262
263 else:
264 observation = []
265285 reward = 0
266286 return observation, reward, is_mission_running
267287
……@@ -279,7 +299,12 @@ def go_to_the_diamonds(agent):
279299 relocate_agent(agent)
280300 else:
281301 reward = 0
282 return [], reward, is_mission_running
302 observation = {}
303 if not inside_house(curr_x, curr_z):
304 observation["outside"] = ["self", "house"]
305 if holds_key:
306 observation["holds"] = ["self", "key"]
307 return observation, reward, is_mission_running
283308
284309
285310missionXML = (
……@@ -306,16 +331,11 @@ missionXML = (
306331 <DrawingDecorator>
307332 """
308333 + build_house(start_x, start_y, start_z, width, length, height, "planks")
309 + """
310 """
311 + drawLine(
312 door_x, door_y - 1, door_z, door_x, door_y, door_z, "dark_oak_door", "EAST"
334 + drawBlock(
335 door_x, door_y - 1, door_z, "dark_oak_door", variant="lower", face="WEST"
313336 )
314 + """
315 """
337 + drawBlock(door_x, door_y, door_z, "dark_oak_door", variant="upper", face="WEST")
316338 + drawBlock(key_x, key_y - 1, key_z, "command_block")
317 + """
318 """
319339 + drawBlock(key_x, key_y, key_z, "tripwire_hook")
320340 + """
321341