コード例 #1
0
ファイル: animat.py プロジェクト: snisarg/263C
    def move(self, game_clock):
        if game_clock % (config.predator_speed() + 1) == 0:
            return

        if self.wait_time > 0:
            self.wait_time -= 1
            return

        anim = self.__closest_animat()
        if anim is None:
            coord = None    # No prey in sight
        else:
            coord = anim.position   # anim is in sight

        current_state = self.sense_state(anim)
        current_action = self.qlearn.choose_action(current_state)

        if current_action[0] == Action.SignalForHelp:
            self.signal = True

        if current_action[0] == Action.TowardsEasyPrey or current_action[0] == Action.TowardsHardPrey \
            or current_action[0] == Action.TowardsSignal or current_action[0] == Action.SignalForHelp:
            coord = normalise_distance(
                distance_diff(self.position, coord, config.predator_range()), config.predator_range())
        else:
            coord = random_walk()
            while grid.singleton_grid.is_obstacle(coord):
                coord = random_walk()
        grid.singleton_world.move_animat(self, coord)
コード例 #2
0
ファイル: animat.py プロジェクト: snisarg/263C
 def __closest_animat(self):
     closest_animats = grid.singleton_world.around_point(self.position, config.predator_range())
     for level in closest_animats:
         for block in level:
             for anim in block:
                 if isinstance(anim, Predator) and anim.signal is True:
                     return anim
             for anim in block:
                 if isinstance(anim, EPrey) or isinstance(anim, HPrey):
                     return anim # Return the anim object which is closest
     return None