Skip to content

Commit

Permalink
Revert "Making the SpiralNavigator a worker" (#1698)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascamata authored Jul 29, 2016
1 parent 9a29c0f commit d5acc70
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
7 changes: 5 additions & 2 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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 @@ -37,8 +38,7 @@ class PokemonGoBot(object):
cell_workers.CatchVisiblePokemonWorker,
cell_workers.MoveToFortWorker,
cell_workers.CatchLuredPokemonWorker,
cell_workers.SeenFortWorker,
cell_workers.SpiralNavigator
cell_workers.SeenFortWorker
]

@property
Expand All @@ -62,6 +62,7 @@ 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 @@ -93,6 +94,8 @@ 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: 0 additions & 1 deletion pokemongo_bot/cell_workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@
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: 1 addition & 0 deletions pokemongo_bot/cell_workers/move_to_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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,7 +1,9 @@
# -*- coding: utf-8 -*-
from pokemongo_bot import logger
from pokemongo_bot.cell_workers.utils import distance, format_dist
from pokemongo_bot.step_walker import StepWalker
import logger
from cell_workers.utils import distance, i2f, format_dist
from human_behaviour import sleep
from step_walker import StepWalker


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

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

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

if self.cnt == 1:
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)
))
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))

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

0 comments on commit d5acc70

Please sign in to comment.