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

Making the SpiralNavigator a worker #1683

Merged
merged 3 commits into from
Jul 29, 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: 2 additions & 5 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from pokemongo_bot.event_handlers import LoggingHandler
from pokemongo_bot.event_handlers import SocketIoHandler
from pokemongo_bot.socketio_server.runner import SocketIoRunner
from spiral_navigator import SpiralNavigator
from worker_result import WorkerResult
from event_manager import EventManager
from api_wrapper import ApiWrapper
Expand All @@ -38,7 +37,8 @@ class PokemonGoBot(object):
cell_workers.CatchVisiblePokemonWorker,
cell_workers.MoveToFortWorker,
cell_workers.CatchLuredPokemonWorker,
cell_workers.SeenFortWorker
cell_workers.SeenFortWorker,
cell_workers.SpiralNavigator
]

@property
Expand All @@ -62,7 +62,6 @@ def __init__(self, config):
def start(self):
self._setup_logging()
self._setup_api()
self.navigator = SpiralNavigator(self)
random.seed()

def _setup_event_system(self):
Expand Down Expand Up @@ -94,8 +93,6 @@ def tick(self):
if worker(self).work() == WorkerResult.RUNNING:
return

self.navigator.take_step()

def get_meta_cell(self):
location = self.position[0:2]
cells = self.find_close_cells(*location)
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/cell_workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from recycle_items_worker import RecycleItemsWorker
from incubate_eggs_worker import IncubateEggsWorker
from catch_lured_pokemon_worker import CatchLuredPokemonWorker
from spiral_navigator import SpiralNavigator
1 change: 0 additions & 1 deletion pokemongo_bot/cell_workers/move_to_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def __init__(self, bot):
self.config = bot.config
self.fort_timeouts = bot.fort_timeouts
self.recent_forts = bot.recent_forts
self.navigator = bot.navigator
self.position = bot.position

def should_run(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
import logger
from cell_workers.utils import distance, i2f, format_dist
from human_behaviour import sleep
from step_walker import StepWalker

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

class SpiralNavigator(object):
def __init__(self, bot):
Expand Down Expand Up @@ -44,7 +42,7 @@ def _generate_spiral(starting_lat, starting_lng, step_size, step_limit):
m += 1
return coords

def take_step(self):
def work(self):
point = self.points[self.ptr]
self.cnt += 1

Expand All @@ -64,21 +62,23 @@ def take_step(self):
)

if self.cnt == 1:
logger.log('Walking from ' + str((self.api._position_lat,
self.api._position_lng)) + " to " + str([point['lat'], point['lng']]) + " " + format_dist(dist,
self.config.distance_unit))
logger.log('Walking from {} to {} {}'.format(
str((self.api._position_lat, self.api._position_lng)),
str([point['lat'], point['lng']]),
format_dist(dist, self.config.distance_unit)
))

if step_walker.step():
step_walker = None
else:
self.api.set_position(point['lat'], point['lng'])

if distance(
self.api._position_lat,
self.api._position_lng,
point['lat'],
point['lng']
) <= 1 or (self.config.walk > 0 and step_walker == None):
self.api._position_lat,
self.api._position_lng,
point['lat'],
point['lng']
) <= 1 or (self.config.walk > 0 and step_walker is None):
if self.ptr + self.direction == len(self.points) or self.ptr + self.direction == -1:
self.direction *= -1
self.ptr += self.direction
Expand Down