OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-rocca commits / 16d4366

Add chat message
16d4366059dda41bb5abc8f66bb750cf08ba032b
by Hedra <tanksh24@gmail.com> · 2022-02-04T19:59:59.000Z

Changed files (1) +22 -12

rocca/envs/malmo_demo/flatworld_env.py +22 -12
……@@ -150,7 +150,7 @@ key_x, key_y, key_z = 7, 228, -10
150150door_x, door_y, door_z = -4, 228, -3
151151diamond_x, diamond_y, diamond_z = -18, 228, -3
152152start_x, start_y, start_z, width, length, height = -4, 226, -1, 6, 15, 5
153holds_key = False
153hold_key = False
154154
155155# relocates the agent to the starting point
156156def relocate_agent(agent):
……@@ -233,7 +233,8 @@ def inside_house(x, z):
233233# Move the agent towards the key
234234# reward=0
235235def go_to_key(agent):
236 global holds_key
236 global hold_key
237 agent.sendCommand("chat go_to_key")
237238 reward = 0
238239 observation = {}
239240 curr_x, curr_y, curr_z = get_curr_loc(agent)
……@@ -242,26 +243,28 @@ def go_to_key(agent):
242243 return observation, reward, is_mission_running
243244 else:
244245 observation["outside"] = ["self", "house"]
245 if holds_key:
246 observation["holds"] = ["self", "key"]
246 if hold_key:
247 observation["hold"] = ["self", "key"]
247248 return observation, reward, is_mission_running
248249 turn_to(agent, curr_x, curr_y, curr_z, key_x, key_y, key_z)
249250 time.sleep(0.2)
250251 agent.sendCommand("move 1")
251252 action_complete = stop_condition(agent, "tripwire_hook")
252253 if action_complete:
253 observation["holds"] = ["self", "key"]
254 observation["hold"] = ["self", "key"]
254255 agent.sendCommand("hotbar.2 1")
255 holds_key = True
256 hold_key = True
256257 else:
257258 observation = []
259 agent.sendCommand("chat {}".format(observation))
258260 return observation, reward, is_mission_running
259261
260262
261263# Move the agent towards the house and enter the house.
262264# reward = 0
263265def go_to_house(agent):
264 global holds_key
266 global hold_key
267 agent.sendCommand("chat go_to_house")
265268 reward = 0
266269 observation = {}
267270 curr_x, curr_y, curr_z = get_curr_loc(agent)
……@@ -273,22 +276,25 @@ def go_to_house(agent):
273276 agent.sendCommand("move 1")
274277 action_complete = stop_condition(agent, "dark_oak_door")
275278 if action_complete:
276 if holds_key:
279 if hold_key:
280 time.sleep(0.2)
277281 agent.sendCommand("tp {} {} {}".format(door_x, door_y, door_z))
278282 time.sleep(0.2)
279283 observation["inside"] = ["self", "house"]
280284 agent.sendCommand("hotbar.1 1")
281 holds_key = False
285 hold_key = False
282286 else:
283287 observation["outside"] = ["self", "house"]
284288 observation["nextto"] = ["self", "closed_door"]
285289 reward = 0
290 agent.sendCommand("chat {}".format(observation))
286291 return observation, reward, is_mission_running
287292
288293
289294# Move the agent towards the diamond and collect it.
290295# reward = 1
291296def go_to_diamonds(agent):
297 agent.sendCommand("chat go_to_diamonds")
292298 curr_x, curr_y, curr_z = get_curr_loc(agent)
293299 turn_to(agent, curr_x, curr_y, curr_z, diamond_x, diamond_y, diamond_z)
294300 time.sleep(0.2)
……@@ -302,8 +308,12 @@ def go_to_diamonds(agent):
302308 observation = {}
303309 if not inside_house(curr_x, curr_z):
304310 observation["outside"] = ["self", "house"]
305 if holds_key:
306 observation["holds"] = ["self", "key"]
311 if hold_key:
312 observation["hold"] = ["self", "key"]
313 if observation:
314 agent.sendCommand("chat {}".format(observation))
315 if reward > 0:
316 agent.sendCommand("chat Reward: {}".format(reward))
307317 return observation, reward, is_mission_running
308318
309319
……@@ -340,7 +350,6 @@ missionXML = (
340350 + """
341351
342352 </DrawingDecorator>
343 <ServerQuitFromTimeUp description="" timeLimitMs="100000000"/>
344353 <ServerQuitWhenAnyAgentFinishes/>
345354 </ServerHandlers>
346355 </ServerSection>
……@@ -370,6 +379,7 @@ missionXML = (
370379 <ContinuousMovementCommands turnSpeedDegs="180"/>
371380 <AbsoluteMovementCommands />
372381 <InventoryCommands/>
382 <ChatCommands/>
373383 <RewardForTouchingBlockType>
374384 <Block type="diamond_block" reward="1.0"/>
375385 </RewardForTouchingBlockType>