def on_start(self, event):
# choose a random object
self.target_obj, = random.sample(objects, 1)
ws = self.get_world().state
# select a random number of steps
self.n = random.randint(1, PickUpInFrontTask.max_steps_forward)
# place the object that number of steps in front of the learner
p = ws.learner_pos + self.n * self.get_world().valid_directions[
ws.learner_direction]
self.state.initial_count = ws.learner_inventory[self.target_obj]
self.get_world().put_entity(p, self.target_obj, True, True)
self.add_handler(
on_state_changed(lambda ws, ts:
ws.learner_inventory[self.target_obj] ==
ts.initial_count + 1)
(self.on_object_picked_up))
self.set_message("There is {indef_object} {n} steps forward, "
"pick up the {object}."
.format(
indef_object=msg.indef_article(self.target_obj),
n=msg.number_to_string(self.n),
object=self.target_obj))
评论列表
文章目录