Exemple #1
0
    def _get_to_wall_directions(self, wall_position, can_re_walk=False):
        """

        Return possible directions for given wall

        :param wall_position: position of looked wall
        :param can_re_walk: allow directions on already walked position
        :return: list of directions
        """
        around_this_wall_positions = around_positions_of(wall_position)

        # Keep positions in host visible field
        visible_around_this_wall_positions = self._reduce_positions_by_host_visibility(around_this_wall_positions)

        if not can_re_walk:
            # We can't re walk, so we remove positions already walked
            free_positions = self._reduce_positions_by_not_walked(visible_around_this_wall_positions, wall_position)
            return self._change_positions_to_directions(free_positions)
        elif self.is_re_walking():
            # When re walking, we forbid to go back
            visible_around_this_wall_positions = self._reduce_by_not_last_walk(visible_around_this_wall_positions, wall_position)
            # Order it to prioritize far away move
            self._order_by_far_away(visible_around_this_wall_positions)

        return self._change_positions_to_directions(visible_around_this_wall_positions)
Exemple #2
0
    def _get_next_visible_walls_positions(self, from_position):
        """

        Return positions of ant visible walls

        :return: list: list of positions
        """
        walls_to_look_around = [from_position]
        for wall_to_look_around in walls_to_look_around:
            around_wall_positions = around_positions_of(wall_to_look_around)
            around_wall_walls = (pos for pos in around_wall_positions
                                 if self._position_is_around_host(pos)
                                 and not self._feeler.position_is_free(pos)
                                 and pos not in walls_to_look_around
                                 and pos != self._get_current_wall_position())
            walls_to_look_around.extend(around_wall_walls)

        return walls_to_look_around
Exemple #3
0
 def _get_direction_for_current_wall(self):
     around_wall_positions = around_positions_of(self._get_current_wall_position())
     # Keep positions in host visible field
     visible_around_wall_positions = self._reduce_positions_by_host_visibility(around_wall_positions)
     ordered_visible_around_wall_positions = self._order_positions_by_not_walked(visible_around_wall_positions)
     return next(self._change_positions_to_directions(ordered_visible_around_wall_positions))
Exemple #4
0
 def _update_host_around_positions(self):
     self._around_host_positions = around_positions_of(self._host.get_position())