OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-rocca commits / e1ae92d

Improvements to the env
e1ae92dc33e62a7388ac7e8ffd1eda6cd2750776
by Hedra <tanksh24@gmail.com> · 2022-03-08T17:45:09.000Z

Changed files (1) +92 -20

rocca/envs/malmo_demo/flatworld_env.py +92 -20
……@@ -61,6 +61,20 @@ def GenCuboid(x1, y1, z1, x2, y2, z2, blocktype):
6161 )
6262
6363
64def drawItem(x, y, z, item_type):
65 return (
66 '<DrawItem x="'
67 + str(x)
68 + '" y="'
69 + str(y)
70 + '" z="'
71 + str(z)
72 + '" type="'
73 + item_type
74 + '"/>'
75 )
76
77
6478def drawLine(x1, y1, z1, x2, y2, z2, blocktype, face):
6579 return (
6680 '<DrawLine x1="'
……@@ -91,13 +105,13 @@ def build_house(x, y, z, width, length, height, blocktype):
91105
92106 genstring = ""
93107 y_cur = y
94 for i in range(height):
108 for i in range(height + 1):
95109 z_cur = z
96110 x_cur = x
97 for j in range(width):
111 for j in range(width + 1):
98112 genstring = genstring + drawBlock(x_front, y_cur, z_cur, "glass") + "\n"
99113 genstring = genstring + drawBlock(x_back, y_cur, z_cur, blocktype) + "\n"
100 if j > 0 and j < width - 1:
114 if j > 0 and j < width:
101115 genstring = (
102116 genstring
103117 + drawBlock(x_back + 1, y_cur, z_cur, "diamond_block")
……@@ -106,7 +120,7 @@ def build_house(x, y, z, width, length, height, blocktype):
106120 z_cur = z_cur + 1 if z_cur >= 0 else z_cur - 1
107121
108122 for k in range(length):
109 if k % 2 == 0:
123 if k % 2 != 0:
110124 genstring = genstring + drawBlock(x_cur, y_cur, z_left, "glass") + "\n"
111125 genstring = genstring + drawBlock(x_cur, y_cur, z_right, "glass") + "\n"
112126 else:
……@@ -122,12 +136,12 @@ def build_house(x, y, z, width, length, height, blocktype):
122136
123137 # floor
124138 genstring = genstring + GenCuboid(
125 x_back + 1 if x_back >= 0 else x_back - 1,
139 -15,
126140 y,
127 z_left + 1 if z_left >= 0 else z_left - 1,
128 x - 1 if x >= 0 else x + 1,
141 15,
142 15,
129143 y,
130 z - 1 if x >= 0 else z + 1,
144 -15,
131145 blocktype,
132146 )
133147 # ceiling
……@@ -140,16 +154,61 @@ def build_house(x, y, z, width, length, height, blocktype):
140154 z - 1 if x >= 0 else z + 1,
141155 blocktype,
142156 )
157 genstring = genstring + GenCuboid(
158 x_back,
159 y_cur + 1,
160 z_left,
161 x,
162 y_cur + 1,
163 z,
164 blocktype,
165 )
166 genstring = genstring + GenCuboid(
167 x_back - 1 if x_back >= 0 else x_back + 1,
168 y_cur + 2,
169 z_left - 1 if z_left >= 0 else z_left + 1,
170 x + 1 if x >= 0 else x - 1,
171 y_cur + 2,
172 z + 1 if x >= 0 else z - 1,
173 blocktype,
174 )
175 genstring = genstring + GenCuboid(
176 x_back,
177 y_cur,
178 z_left,
179 x,
180 y_cur,
181 z,
182 "air",
183 )
184 genstring = genstring + GenCuboid(
185 x_back - 1 if x_back >= 0 else x_back + 1,
186 y_cur + 1,
187 z_left - 1 if z_left >= 0 else z_left + 1,
188 x + 1 if x >= 0 else x - 1,
189 y_cur + 1,
190 z + 1 if x >= 0 else z - 1,
191 "air",
192 )
193 genstring = genstring + GenCuboid(
194 x_back - 2 if x_back >= 0 else x_back + 2,
195 y_cur + 2,
196 z_left - 2 if z_left >= 0 else z_left + 2,
197 x + 2 if x >= 0 else x - 2,
198 y_cur + 2,
199 z + 2 if x >= 0 else z - 2,
200 "glass",
201 )
143202
144203 return genstring
145204
146205
147206# Initialize the location coordinates
148agent_x, agent_y, agent_z, agent_yaw = 19, 230, -2, 90
207agent_x, agent_y, agent_z, agent_yaw = 13, 230, -2, 90
149208key_x, key_y, key_z = 7, 228, -10
150209door_x, door_y, door_z = -4, 228, -3
151210diamond_x, diamond_y, diamond_z = -18, 228, -3
152start_x, start_y, start_z, width, length, height = -4, 226, -1, 6, 15, 5
211start_x, start_y, start_z, width, length, height = -4, 226, -1, 6, 9, 3
153212hold_key = False
154213
155214# relocates the agent to the starting point
……@@ -230,21 +289,32 @@ def inside_house(x, z):
230289 )
231290
232291
292def get_txt(obs):
293 if obs:
294 return ",".join(
295 ["{}({},{})".format(ob, obs[ob][0], obs[ob][1]) for ob in obs.keys()]
296 )
297 else:
298 return ""
299
300
233301# Move the agent towards the key
234302# reward=0
235303def go_to_key(agent):
304 agent.sendCommand("chat Grab key")
236305 global hold_key
237 agent.sendCommand("chat go_to_key")
238306 reward = 0
239307 observation = {}
240308 curr_x, curr_y, curr_z = get_curr_loc(agent)
241309 if inside_house(curr_x, curr_z):
242310 observation["inside"] = ["self", "house"]
311 agent.sendCommand("chat => {}".format(get_txt(observation)))
243312 return observation, reward, is_mission_running
244313 else:
245314 observation["outside"] = ["self", "house"]
246315 if hold_key:
247316 observation["hold"] = ["self", "key"]
317 agent.sendCommand("chat => {}".format(get_txt(observation)))
248318 return observation, reward, is_mission_running
249319 turn_to(agent, curr_x, curr_y, curr_z, key_x, key_y, key_z)
250320 time.sleep(0.2)
……@@ -256,20 +326,21 @@ def go_to_key(agent):
256326 hold_key = True
257327 else:
258328 observation = []
259 agent.sendCommand("chat {}".format(observation))
329 agent.sendCommand("chat => {}".format(get_txt(observation)))
260330 return observation, reward, is_mission_running
261331
262332
263333# Move the agent towards the house and enter the house.
264334# reward = 0
265335def go_to_house(agent):
336 agent.sendCommand("chat Open door")
266337 global hold_key
267 agent.sendCommand("chat go_to_house")
268338 reward = 0
269339 observation = {}
270340 curr_x, curr_y, curr_z = get_curr_loc(agent)
271341 if inside_house(curr_x, curr_z):
272342 observation["inside"] = ["self", "house"]
343 agent.sendCommand("chat => {}".format(get_txt(observation)))
273344 return observation, reward, is_mission_running
274345 turn_to(agent, curr_x, curr_y, curr_z, door_x + 2, door_y, door_z)
275346 time.sleep(0.2)
……@@ -287,14 +358,14 @@ def go_to_house(agent):
287358 observation["outside"] = ["self", "house"]
288359 observation["nextto"] = ["self", "closed_door"]
289360 reward = 0
290 agent.sendCommand("chat {}".format(observation))
361 agent.sendCommand("chat => {}".format(get_txt(observation)))
291362 return observation, reward, is_mission_running
292363
293364
294365# Move the agent towards the diamond and collect it.
295366# reward = 1
296367def go_to_diamonds(agent):
297 agent.sendCommand("chat go_to_diamonds")
368 agent.sendCommand("chat Collect diamonds")
298369 observation = {}
299370 curr_x, curr_y, curr_z = get_curr_loc(agent)
300371 turn_to(agent, curr_x, curr_y, curr_z, diamond_x, diamond_y, diamond_z)
……@@ -315,10 +386,11 @@ def go_to_diamonds(agent):
315386 observation["outside"] = ["self", "house"]
316387 if hold_key:
317388 observation["hold"] = ["self", "key"]
318 if observation:
319 agent.sendCommand("chat {}".format(observation))
320389 if reward > 0:
321 agent.sendCommand("chat Reward: {}".format(reward))
390 agent.sendCommand("chat => Reward {}".format(reward))
391 else:
392 agent.sendCommand("chat => {}".format(get_txt(observation)))
393
322394 return observation, reward, is_mission_running
323395
324396
……@@ -345,12 +417,12 @@ missionXML = (
345417 <FlatWorldGenerator generatorString="3;7,220*1,5*3,2;1;biome_1"/>
346418 <DrawingDecorator>
347419 """
348 + build_house(start_x, start_y, start_z, width, length, height, "planks")
420 + build_house(start_x, start_y, start_z, width, length, height, "brick_block")
349421 + drawBlock(
350422 door_x, door_y - 1, door_z, "dark_oak_door", variant="lower", face="WEST"
351423 )
352424 + drawBlock(door_x, door_y, door_z, "dark_oak_door", variant="upper", face="WEST")
353 + drawBlock(key_x, key_y - 1, key_z, "command_block")
425 + drawBlock(key_x, key_y - 1, key_z, "stone")
354426 + drawBlock(key_x, key_y, key_z, "tripwire_hook")
355427 + """
356428