| … | … | @@ -150,7 +150,7 @@ key_x, key_y, key_z = 7, 228, -10 |
| 150 | 150 | door_x, door_y, door_z = -4, 228, -3 |
| 151 | 151 | diamond_x, diamond_y, diamond_z = -18, 228, -3 |
| 152 | 152 | start_x, start_y, start_z, width, length, height = -4, 226, -1, 6, 15, 5 |
| 153 | | holds_key = False |
| 153 | hold_key = False |
| 154 | 154 | |
| 155 | 155 | # relocates the agent to the starting point |
| 156 | 156 | def relocate_agent(agent): |
| … | … | @@ -233,7 +233,8 @@ def inside_house(x, z): |
| 233 | 233 | # Move the agent towards the key |
| 234 | 234 | # reward=0 |
| 235 | 235 | def go_to_key(agent): |
| 236 | | global holds_key |
| 236 | global hold_key |
| 237 | agent.sendCommand("chat go_to_key") |
| 237 | 238 | reward = 0 |
| 238 | 239 | observation = {} |
| 239 | 240 | curr_x, curr_y, curr_z = get_curr_loc(agent) |
| … | … | @@ -242,26 +243,28 @@ def go_to_key(agent): |
| 242 | 243 | return observation, reward, is_mission_running |
| 243 | 244 | else: |
| 244 | 245 | observation["outside"] = ["self", "house"] |
| 245 | | if holds_key: |
| 246 | | observation["holds"] = ["self", "key"] |
| 246 | if hold_key: |
| 247 | observation["hold"] = ["self", "key"] |
| 247 | 248 | return observation, reward, is_mission_running |
| 248 | 249 | turn_to(agent, curr_x, curr_y, curr_z, key_x, key_y, key_z) |
| 249 | 250 | time.sleep(0.2) |
| 250 | 251 | agent.sendCommand("move 1") |
| 251 | 252 | action_complete = stop_condition(agent, "tripwire_hook") |
| 252 | 253 | if action_complete: |
| 253 | | observation["holds"] = ["self", "key"] |
| 254 | observation["hold"] = ["self", "key"] |
| 254 | 255 | agent.sendCommand("hotbar.2 1") |
| 255 | | holds_key = True |
| 256 | hold_key = True |
| 256 | 257 | else: |
| 257 | 258 | observation = [] |
| 259 | agent.sendCommand("chat {}".format(observation)) |
| 258 | 260 | return observation, reward, is_mission_running |
| 259 | 261 | |
| 260 | 262 | |
| 261 | 263 | # Move the agent towards the house and enter the house. |
| 262 | 264 | # reward = 0 |
| 263 | 265 | def go_to_house(agent): |
| 264 | | global holds_key |
| 266 | global hold_key |
| 267 | agent.sendCommand("chat go_to_house") |
| 265 | 268 | reward = 0 |
| 266 | 269 | observation = {} |
| 267 | 270 | curr_x, curr_y, curr_z = get_curr_loc(agent) |
| … | … | @@ -273,22 +276,25 @@ def go_to_house(agent): |
| 273 | 276 | agent.sendCommand("move 1") |
| 274 | 277 | action_complete = stop_condition(agent, "dark_oak_door") |
| 275 | 278 | if action_complete: |
| 276 | | if holds_key: |
| 279 | if hold_key: |
| 280 | time.sleep(0.2) |
| 277 | 281 | agent.sendCommand("tp {} {} {}".format(door_x, door_y, door_z)) |
| 278 | 282 | time.sleep(0.2) |
| 279 | 283 | observation["inside"] = ["self", "house"] |
| 280 | 284 | agent.sendCommand("hotbar.1 1") |
| 281 | | holds_key = False |
| 285 | hold_key = False |
| 282 | 286 | else: |
| 283 | 287 | observation["outside"] = ["self", "house"] |
| 284 | 288 | observation["nextto"] = ["self", "closed_door"] |
| 285 | 289 | reward = 0 |
| 290 | agent.sendCommand("chat {}".format(observation)) |
| 286 | 291 | return observation, reward, is_mission_running |
| 287 | 292 | |
| 288 | 293 | |
| 289 | 294 | # Move the agent towards the diamond and collect it. |
| 290 | 295 | # reward = 1 |
| 291 | 296 | def go_to_diamonds(agent): |
| 297 | agent.sendCommand("chat go_to_diamonds") |
| 292 | 298 | curr_x, curr_y, curr_z = get_curr_loc(agent) |
| 293 | 299 | turn_to(agent, curr_x, curr_y, curr_z, diamond_x, diamond_y, diamond_z) |
| 294 | 300 | time.sleep(0.2) |
| … | … | @@ -302,8 +308,12 @@ def go_to_diamonds(agent): |
| 302 | 308 | observation = {} |
| 303 | 309 | if not inside_house(curr_x, curr_z): |
| 304 | 310 | 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)) |
| 307 | 317 | return observation, reward, is_mission_running |
| 308 | 318 | |
| 309 | 319 | |
| … | … | @@ -340,7 +350,6 @@ missionXML = ( |
| 340 | 350 | + """ |
| 341 | 351 | |
| 342 | 352 | </DrawingDecorator> |
| 343 | | <ServerQuitFromTimeUp description="" timeLimitMs="100000000"/> |
| 344 | 353 | <ServerQuitWhenAnyAgentFinishes/> |
| 345 | 354 | </ServerHandlers> |
| 346 | 355 | </ServerSection> |
| … | … | @@ -370,6 +379,7 @@ missionXML = ( |
| 370 | 379 | <ContinuousMovementCommands turnSpeedDegs="180"/> |
| 371 | 380 | <AbsoluteMovementCommands /> |
| 372 | 381 | <InventoryCommands/> |
| 382 | <ChatCommands/> |
| 373 | 383 | <RewardForTouchingBlockType> |
| 374 | 384 | <Block type="diamond_block" reward="1.0"/> |
| 375 | 385 | </RewardForTouchingBlockType> |