def find_optimal_location(stop_coords, SPIN_RANGE=38.5, CATCH_RANGE=20): global num_locs stop_box = box_around(stop_coords, SPIN_RANGE + CATCH_RANGE) sp = spawnpoints_in_box(stop_box) points = [SpawnPoint(x) for x in sp] in_range_of_stop = [ p for p in points if p.is_within_range(stop_coords, SPIN_RANGE + CATCH_RANGE) ] for idx, x in enumerate(in_range_of_stop): for n in points[idx + 1:]: x.add_neighhbours(n, 60) z = 0 curr = None for x in in_range_of_stop: num_neigh = x.collected_neighbours() if num_neigh > z: curr = x z = num_neigh if not curr: return () neighbours = curr.collected_neighbours() max_spawns = center_geolocation([x.location() for x in neighbours]) m = equi_rect_distance_m(max_spawns, stop_coords) if m > SPIN_RANGE: max_spawns = move_towards(max_spawns, stop_coords, m - SPIN_RANGE) distance = equi_rect_distance_m(max_spawns, stop_coords) return max_spawns, len(neighbours), distance
async def move_to_with_gmo(self, next_pos, is_fast_speed=True, seconds_threshold=25, at_location=None): player_position = self.travel_time.prev_position seconds_between_locations = self.travel_time.time_to_location(next_pos) if seconds_between_locations > seconds_threshold: self.travel_time.set_fast_speed(is_fast_speed) seconds_between_locations = self.travel_time.time_to_location(next_pos) self.log.info("{} seconds to next location using fast speed".format(str(seconds_between_locations))) map_objects = None remaining_distance = equi_rect_distance_m(player_position, next_pos) while remaining_distance > 1: available = self.travel_time.meters_available_until_gmo() player_position = move_towards(player_position, next_pos, available) map_objects = await self.get_map_objects(player_position) num_pokemons = len(catchable_pokemon(map_objects)) self.log.info("Remaining distance is {}, {} meters available, {} pokemon at this pos".format( str(remaining_distance), str(available), str(num_pokemons))) if at_location: await at_location(player_position, map_objects) remaining_distance = equi_rect_distance_m(player_position, next_pos) self.travel_time.use_slow_speed() else: if seconds_between_locations > 0.1: self.log.info("{} seconds to next position {}".format(str(seconds_between_locations), str(next_pos))) map_objects = await self.get_map_objects(next_pos) return map_objects
def __get_cluster_pos(pokestop_position, spawn_cluster, worker_role): if not worker_role: return pokestop_position[0], pokestop_position[1], pokestop_position[2] role_mod = worker_role % 4 if len(spawn_cluster ) > 0 and spawn_cluster[1] > 2: # use spawn cluster for positioning max_spawn_pos = spawn_cluster[0] max_spawn_pos = max_spawn_pos[0], max_spawn_pos[1], pokestop_position[ 2] if role_mod == 0: return max_spawn_pos if role_mod == 1: to_stop = equi_rect_distance_m(max_spawn_pos, pokestop_position) move_in_direction_of(max_spawn_pos, pokestop_position, to_stop + 39) if role_mod == 2: return step_position(max_spawn_pos, 39, 0) # not really catch length ? if role_mod == 3: return step_position(max_spawn_pos, -39, 0) # not really catch length ? if role_mod == 0: return step_position(pokestop_position, 39, 0) if role_mod == 1: return step_position(pokestop_position, -39, 0) if role_mod == 2: return step_position(pokestop_position, 0, 39) if role_mod == 3: return step_position(pokestop_position, 0, -39) log.error("No modulo")
def fort_within_distance(forts, pos, m): with_distance = [ (equi_rect_distance_m(pos, (fort.latitude, fort.longitude)), fort) for fort in forts ] items = [it for it in with_distance if it[0] < m] items.sort() return map(lambda item: item[1], items)
def length_of_route(current_route): length = 0 prev_gym = None for gym in current_route: if prev_gym is not None: length += equi_rect_distance_m(prev_gym, gym["coordinates"]) prev_gym = gym["coordinates"] return length
def create_route(waypoints, step_lengths, north, east): result = [] offseted_wp = [step_position(x, north, east) for x in waypoints] for pos, next_pos in pairwise(offseted_wp): result.append(pos) while equi_rect_distance_m(pos, next_pos) > step_lengths: pos = move_towards(pos, next_pos, step_lengths) result.append(pos) return result
def nearest_pokstop(map_objects, pos): result = None closest = sys.maxsize for pokestop in parse_pokestops(map_objects): distance = equi_rect_distance_m(pos, (pokestop.latitude, pokestop.longitude)) if distance < closest: result = pokestop closest = distance return closest, result
def index_of_closest_match(coord, elements): current = None dist = 10000000 for idx, pair in enumerate(elements): distance = equi_rect_distance_m(coord, pair[0]) if distance < dist: dist = distance current = idx return current, dist
def find_closest(current_list, first): shortest_distance = 10000000 shortest_idx = -1 coordinates_ = first["coordinates"] max_longitude = 1000 for idx, gym in enumerate(current_list): if gym["longitude"] > max_longitude: break current_distance = equi_rect_distance_m(coordinates_, gym["coordinates"]) if current_distance < shortest_distance: shortest_distance = current_distance shortest_idx = idx max_longitude = step_position(gym["coordinates"], 0, current_distance)[1] closes = gym_map[shortest_idx] del gym_map[shortest_idx] return closes
async def beh_spin_pokestop_raw(pogoservice, pokestop, player_position, item_limits=None): await pogoservice.do_pokestop_details(pokestop) spin_response = await pogoservice.do_spin_pokestop(pokestop, player_position) result = spin_response['FORT_SEARCH'].result attempt = 0 if result == 6: print(str(pokestop)) if result == 4: await beh_aggressive_bag_cleaning(pogoservice, item_limits) spin_response = await pogoservice.do_spin_pokestop( pokestop, player_position) result = spin_response['FORT_SEARCH'].result while result == 2 and attempt < 6: stop_pos = (pokestop.latitude, pokestop.longitude) dist = equi_rect_distance_m(stop_pos, player_position) if dist > 40: pogoservice.log.error( "Too far away from stop, {}m. this should not happen".format( str(dist))) return result # give up if attempt == 0: if player_position != stop_pos: player_position = move_towards(player_position, stop_pos, 1) if attempt == 2: objs = await pogoservice.do_get_map_objects(player_position) pogoservice.log.info(u"Extra gmo gave catchanble {}".format( str(len(catchable_pokemon(objs))))) await asyncio.sleep(1) # investigate if really needed attempt += 1 spin_response = await pogoservice.do_spin_pokestop( pokestop, player_position) result = spin_response['FORT_SEARCH'].result pogoservice.log.info(u"{} attempt spinning gave result {}".format( str(attempt), str(result))) return result
def sort_by_distance(result_coords): arranged = [result_coords[0]] del result_coords[0] while len(result_coords) > 0: current = None dist = 10000000 for idx, pair in enumerate(result_coords): coord = pair[0] distance = equi_rect_distance_m(coord, arranged[-1][0]) if distance < dist: dist = distance current = idx if isinstance(current, int): arranged.append(result_coords[current]) del result_coords[current] else: log.info("No more found ?") break return arranged
def distance_route_locs_m(loc1, loc2): return equi_rect_distance_m(loc1[0], loc2[0])
def move_in_direction_of(start, stop, m): """Moves toward another point, can go past point""" dist = equi_rect_distance_m(start, stop) return go_to_step_num(start, stop, dist, m)
def move_towards(start, stop, m): dist = equi_rect_distance_m(start, stop) if dist < m: return stop return go_to_step_num(start, stop, dist, m)
def do_catch_moving(self, map_objects, player_pos, next_pos, pos_idx, catch_condition, broadcast=True): all_caught = {} if not self.is_within_catch_limit(): log.info("Catch limit {} exceeeded, not catching any more".format( str(self.catch_limit))) return catch_list = catchable_pokemon_by_distance(map_objects, next_pos) log.info("{} pokemon in map_objects: {}".format( str(len(catch_list)), pokemon_names([x[1] for x in catch_list]))) while len(catch_list) > 0: to_catch = catch_list[0][1] # print str(to_catch) encounter_id = to_catch.encounter_id pokemon_id = to_catch.pokemon_id unseen_catch = catch_condition.only_unseen and ( pokemon_id not in self.caught_pokemon_ids) candy_catch = catch_condition.is_candy_catch(pokemon_id) candy_12_catch = catch_condition.is_candy_12_catch(pokemon_id) encountered_previously = self.is_encountered_previously( encounter_id) candy_50_catch = catch_condition.is_candy_50_catch(pokemon_id) will_catch = (catch_condition.catch_anything or unseen_catch or candy_catch or candy_12_catch or candy_50_catch) if encountered_previously: log.info("{} {} encountered previously".format( str(pokemon_name(pokemon_id)), str(encounter_id))) elif will_catch: if broadcast and catch_condition.is_candy_pokemon(pokemon_id): self.catch_feed.append(player_pos, to_catch, pos_idx) # log.debug("To_catch={}".format(str(to_catch))) pokemon_distance_to_next_position = catch_list[0][0] player_distance_to_next_position = equi_rect_distance_m( player_pos, next_pos) on_other_side = ( player_pos[1] < next_pos[1] < catch_list[0][1]) or ( player_pos[1] > next_pos[1] > catch_list[0][1]) if on_other_side: available_mobility = self.travel_time.meters_available_right_now( ) actual_meters = min(available_mobility, player_distance_to_next_position) log.info( "Moving closer {} metres. {} meters_available right now" .format(str(actual_meters), str(available_mobility))) player_pos = move_towards(player_pos, next_pos, actual_meters) if pokemon_distance_to_next_position < player_distance_to_next_position: m_to_move = player_distance_to_next_position - pokemon_distance_to_next_position available_mobility = self.travel_time.meters_available_right_now( ) actual_meters = min(available_mobility, m_to_move) log.info( "player_distance_to_next_position={},pokemon_distance_to_next_position={}" .format(str(player_distance_to_next_position), str(pokemon_distance_to_next_position))) log.info( "Could move towards next position {} meters. {} meters_available, {}m by pokemon!" .format(str(actual_meters), str(available_mobility), str(m_to_move))) player_pos = move_towards(player_pos, next_pos, actual_meters) if self.travel_time.must_gmo(): self.worker.do_get_map_objects(player_pos) self.processed_encounters.add( encounter_id) # leaks memory. fix todo log.info( "Catching {} because catch_all={} unseen={} candy_catch={} candy_12_catch={}" .format(pokemon_name(pokemon_id), str(catch_condition.catch_anything), str(unseen_catch), str(candy_catch), str(candy_12_catch))) caught = self.catch_it(player_pos, to_catch, fast=True) if caught: found_new = pokemon_id not in self.caught_pokemon_ids self.caught_pokemon_ids.add(pokemon_id) if isinstance(caught, numbers.Number): all_caught[caught] = pokemon_id else: log.warning("Did not caEtch because {}".format( str(caught))) else: log.info( "{} {} will not catch, is_catch_anything={}, is_unseen_catch={}, is_candy_catch={}, is_candy12_catch={}" .format(str(pokemon_name(pokemon_id)), str(encounter_id), str(catch_condition.catch_anything), str(unseen_catch), str(candy_catch), str(candy_12_catch))) del catch_list[0] self.pokemon_caught += len(all_caught) self.process_evolve_transfer_list(all_caught) return player_pos
def fort_within_distance(forts, pos, m): with_distance = [(equi_rect_distance_m(pos, (fort.latitude, fort.longitude)), fort) for fort in forts] items = [it for it in with_distance if it[0] < m] items.sort() return [x[1] for x in items]
length += equi_rect_distance_m(prev_gym, gym["coordinates"]) prev_gym = gym["coordinates"] return length gym_map = gymscannercoordinates() gym_map = filter_for_geofence(gym_map, args.geofence, args.fencename) log.info(u"There are {} gyms in scan with fence {}".format( str(len(gym_map)), str(args.fencename))) streams = [] initialPosition = location(args) if args.radius is not None: filtered = [ x for x in gym_map if equi_rect_distance_m(initialPosition, x["coordinates"]) < args.radius ] gym_map = filtered while len(gym_map) > 0: prev = gym_map[0] stream = [prev] del gym_map[0] distance = 0 while len(gym_map) > 0: next_gym = find_closest(gym_map, prev) distance += equi_rect_distance_m(prev["coordinates"], next_gym["coordinates"]) if distance > MAX_LEN: streams.append(stream) log.info(u"Created stream " + str(len(streams)) + ", with " +
def is_within_range(self, other, m): return equi_rect_distance_m(self.coords, other.coords) <= m
(53.564979, 9.989293, 10.861, u'd16724a961a841f2b5350ce84da6abed.16')]), ((53.56637, 9.98854, 13.0), [(53.566724, 9.988349, 13.0364, u'458a191fd10640f586759f3f7c8d0f74.16'), (53.566122, 9.988297, 13.0364, u'92561a7e127649c494e19eae330edcfc.16'), (53.566252, 9.988983, 13.0364, u'f63fe38355424498825f6b259dd4e1a0.16')]), ((53.56769, 9.98679, 14.2), [(53.567704, 9.98702, 14.181, u'8c357e74b22048839e99892541adfce2.16'), (53.56768, 9.986559, 14.181, u'662c89b2d1d144de807b9aeea813e568.16')]), ((53.56858, 9.98636, 14.5), [(53.568746, 9.986671, 14.5072, u'b2fce92b3ac5436082eb6e15c732614f.16'), (53.568423, 9.986043, 14.5072, u'ba190979543f4eb8b0580c57e986074f.11')]), ((53.56830, 9.98891, 16.6), [(53.568532, 9.98895, 16.5917, u'0c98ad13ebf2439692e13db4984f1fff.16'), (53.56807, 9.988872, 15.3405, u'fec4776dea8d45f7974be7e52735dd35.16')]), ((53.56253, 9.98210, 16.0), [(53.562233, 9.982438, 15.9971113204956, u'a07a2eda888b4283871660c96abe4231.16'), (53.562817, 9.981766, 15.9971113204956, u'7aa547b749914c4f997b8ccfde4b76ee.12')]), ((53.56723, 9.97248, 18.8), [(53.567277, 9.972046, 18.7696, u'd4ab2c0fd91c485294312c3005c5af76.16'), (53.567192, 9.972919, 18.7696, u'3b6b850ef7544d2691694df26724c690.16')]), ] print len(innerhamnurg) for i in range(0, len(innerhamnurg) - 1): pos = innerhamnurg[i][0] pos2 = innerhamnurg[i + 1][0] dis = equi_rect_distance_m(pos, pos2) print str(dis)