Esempio n. 1
0
    def recommend_sensing(self):
        """
        Recommend where we should take the next measurement in the grid.
        The position should be the most promising unobserved location.
        If all remaining unobserved locations have a probability of 0, return
        the unobserved location that is closest to the (observed) location with
        the highest probability.

        :return: tuple representing the position where we should take the
           next measurement
        """
        # Enter your code and remove the statement below

        # best = max(self.open, key=lambda p:self.current_distribution[p])

        # Create dictionary with keys as the open and value as the probability
        open_prob = {p: self.current_distribution[p] for p in self.open}

        # Instrumentation
        # print('open prob', open_prob)

        # Get the open position with the best probability
        best = max(open_prob, key=lambda p: open_prob[p])

        # check if all open probabilities are 0
        if self.current_distribution[best] == 0:
            # Find the position with the highest probability from the visited
            observed_max = max(self.current_distribution.keys(), key=lambda p: self.current_distribution[p])
            # print('OBSERVED MAX', observed_max)
            # get the location from open that is closest to the observed max above
            second_best = utils.closest_point(observed_max, self.open)
            # print('SB', second_best)
            return second_best
        return best
Esempio n. 2
0
 def find_nearest_health(self) -> Collectable:
     recently_seen = self.recently_seen_collectables(5, typ='HealthPickup')
     if len(recently_seen) == 0:
         return None
     positions = list(map(lambda t: t.position, recently_seen))
     i = positions.index(closest_point(self.position, positions))
     return recently_seen[i]
    def recommend_sensing(self):
        """
        Recommend where we should take the next measurement in the grid.
        The position should be the most promising unobserved location.
        If all remaining unobserved locations have a probability of 0, return
        the unobserved location that is closest to the (observed) location with
        the highest probability.

        :return: tuple representing the position where we should take the
           next measurement
        """
        # Enter your code and remove the statement below
        # should select from unobserved location
        # unobserved = open: with largest probability
        best_unobserved = max(self.open,
                              key=lambda position: self.tprob[position])
        # if max is 0, then unobserved ones all have zero probabilities
        if self.tprob[best_unobserved] != 0:
            return best_unobserved
        # directly using max, will return the max key in a dictionary
        # should find observed locations instead of all positions
        # all locations - unobserved locations = observed locations
        # tprob.keys() is views, which can be used as set
        best_observed = max(self.tprob.keys() - self.open,
                            key=lambda position: self.tprob[position])
        return utils.closest_point(best_observed, self.open)
Esempio n. 4
0
    def recommend_sensing(self):
        """
        Recommend where we should take the next measurement in the grid.
        The position should be the most promising unobserved location.
        If all remaining unobserved locations have a probability of 0,
        return the unobserved location that is closest to the (observed)
        location with he highest probability.
        If there are no remaining unobserved locations return the
        (observed) location with the highest probability.

        :return: tuple representing the position where we should take
            the next measurement
        """

        for p in self.open:
            open_prob = {p: self.current_distribution}
            #print(open_prob)
        #position that there is high chance of treasure
        treasure_closet = max(open_prob, key=lambda p: open_prob[p])

        if self.current_distribution[treasure_closet] == 0:

            full_observed = max(self.current_distribution.keys(),
                                key=lambda p: self.current_distribution[p])
            #second closet to the treasure
            second_closet = utils.closest_point(full_observed, self.open)
            return second_closet
        return treasure_closet
Esempio n. 5
0
 def find_nearest_enemy(self) -> Enemy:
     """ Find the nearest enemy tank """
     recently_seen = self.recently_seen_tanks(1)
     if len(recently_seen) == 0:
         return None
     positions = list(map(lambda t: t.current_pos(), recently_seen))
     i = positions.index(closest_point(self.position, positions))
     return recently_seen[i]
Esempio n. 6
0
def search(inst: instance.Instance, point: utils.Point):
    # remove all that don't have any items
    points_with_items = _filter_no_items(inst, inst.all_points)
    anchor = utils.closest_point(points_with_items, point)

    # nothing around us has any trash so lets return
    if anchor is None:
        LOG.info(f'No items found around {point}')
        return

    LOG.info(
        f'Found {len(points_with_items)} points with items. Starting to search.'
    )
    LOG.info(f'Using {anchor} as anchor point')
    point_within_radius = utils.points_around(anchor, inst.radius, inst.x_size,
                                              inst.y_size)
    point_within_radius = _filter_no_items(inst, point_within_radius)
    current_point = anchor
    while current_point is not None:
        LOG.info(f'Moving to {current_point}')
        inst.move_to_point(current_point)

        # Make a shallow copy of the list because collect will delete from located
        x, y = current_point
        for item_id in list(inst.located[x][y]):
            LOG.info(f'Collecting {item_id} in ({x}, {y})')
            inst.collect(x, y, item_id)

        point_within_radius = list(
            filter(lambda p: p != current_point, point_within_radius))
        current_point = utils.closest_point(point_within_radius, current_point)

    # move back to the anchor position
    LOG.info(f'Moving back to {anchor} and scanning')
    inst.move_to_point(anchor)
    inst.scan()

    LOG.info('Scanning again.')
    search(inst, anchor)
    def recommend_sensing(self):
        """
        Recommend where we should take the next measurement in the grid.
        The position should be the most promising unobserved location.
        If all remaining unobserved locations have a probability of 0,
        return the unobserved location that is closest to the (observed)
        location with he highest probablity.
        If there are no remaining unobserved locations return the
        (observed) location with the highest probability.
        :return: tuple representing the position where we should take
            the next measurement
        """
        # Enter your code and remove the statement below
        # for perc in self.open:
        #    prob = self.current_distribution[perc]

        # finds highest observed location
        highObserved = max(self.current_distribution,
                           key=self.current_distribution.get)

        # finds highest unobserved location
        recommend = max(self.open, key=self.current_distribution.get)

        # how many unobserved spots are left
        unobs = len(self.open)

        # checks for remaining unobserved locations
        if unobs > 0:
            # check if probabilities above 0
            if self.current_distribution.get(recommend) > 0:
                return recommend
            else:
                closest = utils.closest_point(highObserved, self.open)
                return closest
        else:
            return highObserved
Esempio n. 8
0
 def test_closest_point(self):
     assert_equals(closest_point((12, 10.5), [(12, 12), (-12, -10.5)]), (12, 12))
     assert_equals(closest_point((-34.32, 89), [(-40, 100), (-33, -100)]), (-40, 100))
     assert_equals(closest_point((1, 0), [(0, 0), (0, 1)]), (0, 0))
     assert_equals(closest_point((134.999, 67.234), [(120, -70), (130, 55)]), (130, 55))
     assert_equals(closest_point((23, -90), [(19.342, 0), (23, 180)]), (23, 180))
Esempio n. 9
0
    def perform(self):
        goals = [(0, 100), (0, -100)]

        closestGoal = closest_point(self.status.position, goals)

        self.body_controls.movetopoint(closestGoal)
Esempio n. 10
0
 def perform(self) -> None:
     if self.closest_ammo is not None:
         self.body_controls.movetopoint(self.closest_ammo.position)
     else:
         self.body_controls.movetopoint(
             closest_point(self.status.position, COLLECTABLE_CHECKPOINTS))