-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
big refactor to Stepper class (#737)
* big refactor to Stepper class We now have a: - StepWalker class, responsible for walking a small distance towards a final destination. - SpiralNavigator class, which around an area in a spiral. It determines points to walk to and uses to StepWalker to slowly go from one point to another. This architecture enables us to have different Navigators, although it doesn’t implement a nice Navigator configuration YET. * small fixes to workers * Merging * Fixing arguments * Moving the distance log line
- Loading branch information
1 parent
c4d589a
commit 586a0dc
Showing
7 changed files
with
164 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import json | ||
import time | ||
import pprint | ||
|
||
from math import ceil | ||
from s2sphere import CellId, LatLng | ||
from google.protobuf.internal import encoder | ||
|
||
from human_behaviour import sleep, random_lat_long_delta | ||
from cell_workers.utils import distance, i2f, format_time, format_dist | ||
|
||
from pgoapi.utilities import f2i, h2f | ||
import logger | ||
|
||
|
||
class SpiralNavigator(object): | ||
def __init__(self, bot): | ||
self.bot = bot | ||
self.api = bot.api | ||
self.config = bot.config | ||
|
||
self.pos = 1 | ||
self.x = 0 | ||
self.y = 0 | ||
self.dx = 0 | ||
self.dy = -1 | ||
self.steplimit = self.config.max_steps | ||
self.steplimit2 = self.steplimit**2 | ||
self.origin_lat = self.bot.position[0] | ||
self.origin_lon = self.bot.position[1] | ||
|
||
def take_step(self): | ||
position = (self.origin_lat, self.origin_lon, 0.0) | ||
|
||
logger.log('[#] Scanning area for objects....') | ||
# logger.log('[#] Scanning area for objects ({} / {})'.format( | ||
# (step + 1), self.steplimit**2)) | ||
if self.config.debug: | ||
logger.log( | ||
'steplimit: {} x: {} y: {} pos: {} dx: {} dy {}'.format( | ||
self.steplimit2, self.x, self.y, self.pos, self.dx, | ||
self.dy)) | ||
# Scan location math | ||
|
||
if -self.steplimit2 / 2 < self.x <= self.steplimit2 / 2 and -self.steplimit2 / 2 < self.y <= self.steplimit2 / 2: | ||
position = (self.x * 0.0025 + self.origin_lat, | ||
self.y * 0.0025 + self.origin_lon, 0) | ||
if self.config.walk > 0: | ||
|
||
dist = distance( | ||
i2f(self.api._position_lat), | ||
i2f(self.api._position_lng), | ||
position[0], | ||
position[1] | ||
) | ||
|
||
logger.log('[#] Walking from ' + str((i2f(self.api._position_lat), i2f( | ||
self.api._position_lng))) + " to " + str((str(position[0:2]))) + " " + format_dist(dist, self.config.distance_unit)) | ||
self.bot.step_walker.step(self.config.walk, *position[0:2]) | ||
else: | ||
self.api.set_position(*position) | ||
if self.x == self.y or self.x < 0 and self.x == -self.y or self.x > 0 and self.x == 1 - self.y: | ||
(self.dx, self.dy) = (-self.dy, self.dx) | ||
|
||
(self.x, self.y) = (self.x + self.dx, self.y + self.dy) | ||
sleep(10) | ||
return position[0:2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import logger | ||
|
||
from cell_workers.utils import distance, i2f, format_time | ||
from human_behaviour import random_lat_long_delta, sleep | ||
from math import ceil | ||
|
||
|
||
class StepWalker(object): | ||
|
||
def __init__(self, bot): | ||
self.bot = bot | ||
self.api = bot.api | ||
|
||
def step(self, speed, lat, lng): | ||
if self.api._position_lat == lat and self.api._position_lng == lng: | ||
return True | ||
|
||
dLat = (lat - i2f(self.api._position_lat)) | ||
dLng = (lng - i2f(self.api._position_lng)) | ||
|
||
cLat = i2f(self.api._position_lat) + dLat + random_lat_long_delta() | ||
cLng = i2f(self.api._position_lng) + dLng + random_lat_long_delta() | ||
|
||
self.api.set_position(cLat, cLng, 0) | ||
self.bot.heartbeat() | ||
sleep(1) # sleep one second plus a random delta | ||
# self._work_at_position( | ||
# i2f(self.api._position_lat), i2f(self.api._position_lng), | ||
# alt, False) |
This file was deleted.
Oops, something went wrong.