| … | … | @@ -61,6 +61,20 @@ def GenCuboid(x1, y1, z1, x2, y2, z2, blocktype): |
| 61 | 61 | ) |
| 62 | 62 | |
| 63 | 63 | |
| 64 | def 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 | |
| 64 | 78 | def drawLine(x1, y1, z1, x2, y2, z2, blocktype, face): |
| 65 | 79 | return ( |
| 66 | 80 | '<DrawLine x1="' |
| … | … | @@ -91,13 +105,13 @@ def build_house(x, y, z, width, length, height, blocktype): |
| 91 | 105 | |
| 92 | 106 | genstring = "" |
| 93 | 107 | y_cur = y |
| 94 | | for i in range(height): |
| 108 | for i in range(height + 1): |
| 95 | 109 | z_cur = z |
| 96 | 110 | x_cur = x |
| 97 | | for j in range(width): |
| 111 | for j in range(width + 1): |
| 98 | 112 | genstring = genstring + drawBlock(x_front, y_cur, z_cur, "glass") + "\n" |
| 99 | 113 | 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: |
| 101 | 115 | genstring = ( |
| 102 | 116 | genstring |
| 103 | 117 | + drawBlock(x_back + 1, y_cur, z_cur, "diamond_block") |
| … | … | @@ -106,7 +120,7 @@ def build_house(x, y, z, width, length, height, blocktype): |
| 106 | 120 | z_cur = z_cur + 1 if z_cur >= 0 else z_cur - 1 |
| 107 | 121 | |
| 108 | 122 | for k in range(length): |
| 109 | | if k % 2 == 0: |
| 123 | if k % 2 != 0: |
| 110 | 124 | genstring = genstring + drawBlock(x_cur, y_cur, z_left, "glass") + "\n" |
| 111 | 125 | genstring = genstring + drawBlock(x_cur, y_cur, z_right, "glass") + "\n" |
| 112 | 126 | else: |
| … | … | @@ -122,12 +136,12 @@ def build_house(x, y, z, width, length, height, blocktype): |
| 122 | 136 | |
| 123 | 137 | # floor |
| 124 | 138 | genstring = genstring + GenCuboid( |
| 125 | | x_back + 1 if x_back >= 0 else x_back - 1, |
| 139 | -15, |
| 126 | 140 | 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, |
| 129 | 143 | y, |
| 130 | | z - 1 if x >= 0 else z + 1, |
| 144 | -15, |
| 131 | 145 | blocktype, |
| 132 | 146 | ) |
| 133 | 147 | # ceiling |
| … | … | @@ -140,16 +154,61 @@ def build_house(x, y, z, width, length, height, blocktype): |
| 140 | 154 | z - 1 if x >= 0 else z + 1, |
| 141 | 155 | blocktype, |
| 142 | 156 | ) |
| 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 | ) |
| 143 | 202 | |
| 144 | 203 | return genstring |
| 145 | 204 | |
| 146 | 205 | |
| 147 | 206 | # Initialize the location coordinates |
| 148 | | agent_x, agent_y, agent_z, agent_yaw = 19, 230, -2, 90 |
| 207 | agent_x, agent_y, agent_z, agent_yaw = 13, 230, -2, 90 |
| 149 | 208 | key_x, key_y, key_z = 7, 228, -10 |
| 150 | 209 | door_x, door_y, door_z = -4, 228, -3 |
| 151 | 210 | diamond_x, diamond_y, diamond_z = -18, 228, -3 |
| 152 | | start_x, start_y, start_z, width, length, height = -4, 226, -1, 6, 15, 5 |
| 211 | start_x, start_y, start_z, width, length, height = -4, 226, -1, 6, 9, 3 |
| 153 | 212 | hold_key = False |
| 154 | 213 | |
| 155 | 214 | # relocates the agent to the starting point |
| … | … | @@ -230,21 +289,32 @@ def inside_house(x, z): |
| 230 | 289 | ) |
| 231 | 290 | |
| 232 | 291 | |
| 292 | def 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 | |
| 233 | 301 | # Move the agent towards the key |
| 234 | 302 | # reward=0 |
| 235 | 303 | def go_to_key(agent): |
| 304 | agent.sendCommand("chat Grab key") |
| 236 | 305 | global hold_key |
| 237 | | agent.sendCommand("chat go_to_key") |
| 238 | 306 | reward = 0 |
| 239 | 307 | observation = {} |
| 240 | 308 | curr_x, curr_y, curr_z = get_curr_loc(agent) |
| 241 | 309 | if inside_house(curr_x, curr_z): |
| 242 | 310 | observation["inside"] = ["self", "house"] |
| 311 | agent.sendCommand("chat => {}".format(get_txt(observation))) |
| 243 | 312 | return observation, reward, is_mission_running |
| 244 | 313 | else: |
| 245 | 314 | observation["outside"] = ["self", "house"] |
| 246 | 315 | if hold_key: |
| 247 | 316 | observation["hold"] = ["self", "key"] |
| 317 | agent.sendCommand("chat => {}".format(get_txt(observation))) |
| 248 | 318 | return observation, reward, is_mission_running |
| 249 | 319 | turn_to(agent, curr_x, curr_y, curr_z, key_x, key_y, key_z) |
| 250 | 320 | time.sleep(0.2) |
| … | … | @@ -256,20 +326,21 @@ def go_to_key(agent): |
| 256 | 326 | hold_key = True |
| 257 | 327 | else: |
| 258 | 328 | observation = [] |
| 259 | | agent.sendCommand("chat {}".format(observation)) |
| 329 | agent.sendCommand("chat => {}".format(get_txt(observation))) |
| 260 | 330 | return observation, reward, is_mission_running |
| 261 | 331 | |
| 262 | 332 | |
| 263 | 333 | # Move the agent towards the house and enter the house. |
| 264 | 334 | # reward = 0 |
| 265 | 335 | def go_to_house(agent): |
| 336 | agent.sendCommand("chat Open door") |
| 266 | 337 | global hold_key |
| 267 | | agent.sendCommand("chat go_to_house") |
| 268 | 338 | reward = 0 |
| 269 | 339 | observation = {} |
| 270 | 340 | curr_x, curr_y, curr_z = get_curr_loc(agent) |
| 271 | 341 | if inside_house(curr_x, curr_z): |
| 272 | 342 | observation["inside"] = ["self", "house"] |
| 343 | agent.sendCommand("chat => {}".format(get_txt(observation))) |
| 273 | 344 | return observation, reward, is_mission_running |
| 274 | 345 | turn_to(agent, curr_x, curr_y, curr_z, door_x + 2, door_y, door_z) |
| 275 | 346 | time.sleep(0.2) |
| … | … | @@ -287,14 +358,14 @@ def go_to_house(agent): |
| 287 | 358 | observation["outside"] = ["self", "house"] |
| 288 | 359 | observation["nextto"] = ["self", "closed_door"] |
| 289 | 360 | reward = 0 |
| 290 | | agent.sendCommand("chat {}".format(observation)) |
| 361 | agent.sendCommand("chat => {}".format(get_txt(observation))) |
| 291 | 362 | return observation, reward, is_mission_running |
| 292 | 363 | |
| 293 | 364 | |
| 294 | 365 | # Move the agent towards the diamond and collect it. |
| 295 | 366 | # reward = 1 |
| 296 | 367 | def go_to_diamonds(agent): |
| 297 | | agent.sendCommand("chat go_to_diamonds") |
| 368 | agent.sendCommand("chat Collect diamonds") |
| 298 | 369 | observation = {} |
| 299 | 370 | curr_x, curr_y, curr_z = get_curr_loc(agent) |
| 300 | 371 | turn_to(agent, curr_x, curr_y, curr_z, diamond_x, diamond_y, diamond_z) |
| … | … | @@ -315,10 +386,11 @@ def go_to_diamonds(agent): |
| 315 | 386 | observation["outside"] = ["self", "house"] |
| 316 | 387 | if hold_key: |
| 317 | 388 | observation["hold"] = ["self", "key"] |
| 318 | | if observation: |
| 319 | | agent.sendCommand("chat {}".format(observation)) |
| 320 | 389 | 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 | |
| 322 | 394 | return observation, reward, is_mission_running |
| 323 | 395 | |
| 324 | 396 | |
| … | … | @@ -345,12 +417,12 @@ missionXML = ( |
| 345 | 417 | <FlatWorldGenerator generatorString="3;7,220*1,5*3,2;1;biome_1"/> |
| 346 | 418 | <DrawingDecorator> |
| 347 | 419 | """ |
| 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") |
| 349 | 421 | + drawBlock( |
| 350 | 422 | door_x, door_y - 1, door_z, "dark_oak_door", variant="lower", face="WEST" |
| 351 | 423 | ) |
| 352 | 424 | + 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") |
| 354 | 426 | + drawBlock(key_x, key_y, key_z, "tripwire_hook") |
| 355 | 427 | + """ |
| 356 | 428 | |