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

Added circle avoidance #1515

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
4 changes: 4 additions & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"longer_eggs_first": true,
"evolve_captured": false,
"release_pokemon": true,
"spin_forts": {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already key spin_forts, don't they conflict? Shouldn't avoid_circles and max_circle_size be on the same level as spin_forts ? (Sorry if I'm wrong, not a Python man)

"avoid_circles": false,
"max_circle_size": 10
},
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"},
"// Example of always catching Rattata:": {},
Expand Down
4 changes: 4 additions & 0 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"longer_eggs_first": true,
"evolve_captured": false,
"release_pokemon": true,
"spin_forts": {
"avoid_circles": false,
"max_circle_size": 10
},
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or" },

Expand Down
18 changes: 18 additions & 0 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,24 @@ def init_config():
type=bool,
default=True
)
add_config(
parser,
load,
short_flag="-ac",
long_flag="--avoid_circles",
help="Avoids circles (pokestops) of the max size set in max_circle_size flag",
type=bool,
default=False
)
add_config(
parser,
load,
short_flag="-mcs",
long_flag="--max_circle_size",
help="If avoid_circles flag is set, this flag specifies the maximum size of circles (pokestops) avoided",
type=int,
default=10
)

# Start to parse other attrs
config = parser.parse_args()
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, config):
self.metrics = Metrics(self)
self.latest_inventory = None
self.cell = None
self.recent_forts = [None] * config.max_circle_size

def start(self):
self._setup_logging()
Expand Down
2 changes: 2 additions & 0 deletions pokemongo_bot/cell_workers/seen_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def work(self):
'PokeStops you are indeed softbanned. Please try again '
'in a few hours.')
raise RuntimeError(message)

self.bot.recent_forts = self.bot.recent_forts[1:] + [self.fort['id']]
elif spin_result == 2:
logger.log("[#] Pokestop out of range")
elif spin_result == 3:
Expand Down
5 changes: 5 additions & 0 deletions pokemongo_bot/cell_workers/spin_nearest_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def __init__(self, bot):
self.cell = bot.cell
self.fort_timeouts = bot.fort_timeouts
self.position = bot.position
self.recent_forts = bot.recent_forts

def work(self):
if not self.should_run():
Expand Down Expand Up @@ -46,6 +47,10 @@ def get_nearest_fort(self):
# Remove stops that are still on timeout
forts = filter(lambda x: x["id"] not in self.fort_timeouts, forts)

# Remove all forts which were spun in the last ticks to avoid circles if set
if self.config.avoid_circles:
forts = filter(lambda x: x["id"] not in self.recent_forts, forts)

# Sort all by distance from current pos- eventually this should
# build graph & A* it
forts.sort(key=lambda x: distance(self.position[
Expand Down