Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify SpiralTask to use 70m as stepsize and diameter as step_count #2194

Merged
merged 20 commits into from
Aug 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@
}
},
{
"type": "FollowSpiral"
"type": "FollowSpiral",
"config": {
"diameter": 4,
"step_size": 70
}
}
],
"map_object_cache_time": 5,
"max_steps": 5,
"forts": {
"avoid_circles": true,
"max_circle_size": 50
Expand Down
12 changes: 1 addition & 11 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,6 @@ def init_config():
type=str,
default=None
)
add_config(
parser,
load,
short_flag="-ms",
long_flag="--max_steps",
help=
"Set the steps around your initial location(DEFAULT 5 mean 25 cells around your location)",
type=int,
default=50
)

add_config(
parser,
Expand Down Expand Up @@ -367,7 +357,7 @@ def task_configuration_error(flag_name):
""".format(flag_name))

old_flags = ['mode', 'catch_pokemon', 'spin_forts', 'forts_spin', 'hatch_eggs', 'release_pokemon', 'softban_fix',
'longer_eggs_first', 'evolve_speed', 'use_lucky_egg', 'item_filter', 'evolve_all', 'evolve_cp_min']
'longer_eggs_first', 'evolve_speed', 'use_lucky_egg', 'item_filter', 'evolve_all', 'evolve_cp_min', 'max_steps']
for flag in old_flags:
if flag in load:
task_configuration_error(flag)
Expand Down
33 changes: 24 additions & 9 deletions pokemongo_bot/cell_workers/follow_spiral.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

import math

import pokemongo_bot.logger as logger
from pokemongo_bot.cell_workers.utils import distance, format_dist
from pokemongo_bot.step_walker import StepWalker
from pokemongo_bot.cell_workers.base_task import BaseTask


class FollowSpiral(BaseTask):
def initialize(self):
self.steplimit = self.bot.config.max_steps
self.steplimit = self.config.get("diameter", 4)
self.step_size = self.config.get("step_size", 70)
self.origin_lat = self.bot.position[0]
self.origin_lon = self.bot.position[1]

self.diameter_to_steps = (self.steplimit+1) ** 2
self.points = self._generate_spiral(
self.origin_lat, self.origin_lon, 0.0018, self.steplimit
self.origin_lat, self.origin_lon, self.step_size, self.diameter_to_steps
)

self.ptr = 0
self.direction = 1
self.cnt = 0


@staticmethod
def _generate_spiral(starting_lat, starting_lng, step_size, step_limit):
"""
Expand All @@ -34,18 +40,24 @@ def _generate_spiral(starting_lat, starting_lng, step_size, step_limit):
coords = [{'lat': starting_lat, 'lng': starting_lng}]
steps, x, y, d, m = 1, 0, 0, 1, 1

rlat = starting_lat * math.pi
latdeg = 111132.93 - 559.82 * math.cos(2*rlat) + 1.175*math.cos(4*rlat)
lngdeg = 111412.84 * math.cos(rlat) - 93.5 * math.cos(3*rlat)
step_size_lat = step_size / latdeg
step_size_lng = step_size / lngdeg

while steps < step_limit:
while 2 * x * d < m and steps < step_limit:
x = x + d
steps += 1
lat = x * step_size + starting_lat
lng = y * step_size + starting_lng
lat = x * step_size_lat + starting_lat
lng = y * step_size_lng + starting_lng
coords.append({'lat': lat, 'lng': lng})
while 2 * y * d < m and steps < step_limit:
y = y + d
steps += 1
lat = x * step_size + starting_lat
lng = y * step_size + starting_lng
lat = x * step_size_lat + starting_lat
lng = y * step_size_lng + starting_lng
coords.append({'lat': lat, 'lng': lng})

d *= -1
Expand Down Expand Up @@ -88,9 +100,12 @@ def work(self):
point['lat'],
point['lng']
) <= 1 or (self.bot.config.walk > 0 and step_walker == None):
if self.ptr + self.direction == len(self.points) or self.ptr + self.direction == -1:
if self.ptr + self.direction >= len(self.points) or self.ptr + self.direction <= -1:
self.direction *= -1
self.ptr += self.direction
if len(self.points) != 1:
self.ptr += self.direction
else:
self.ptr = 0
self.cnt = 0

return [point['lat'], point['lng']]