def on_start(self, event):
# choose a random object
self.target_obj, = random.sample(objects, 1)
# find a random cell around the learner
self.direction = random.choice(list(self.get_world().valid_directions
.keys()))
ws = self.get_world().state
p = ws.learner_pos + self.get_world().valid_directions[self.direction]
self.state.initial_count = ws.learner_inventory[self.target_obj]
# place the object there
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} {direction} from you, "
"pick up the {object}.".format(
indef_object=msg.indef_article(self.target_obj),
direction=self.direction,
object=self.target_obj))
评论列表
文章目录