Skip to content

Commit

Permalink
Added circle avoidance (#1515)
Browse files Browse the repository at this point in the history
* Added circle avoidance

* Changed to add_config

* Changed path to recent_forts.
Put config keys into spin_forts key
  • Loading branch information
MFizz authored and douglascamata committed Jul 29, 2016
1 parent ee9e32c commit cb52ba8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
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": {

This comment has been minimized.

Copy link
@bigkraig

bigkraig Jul 29, 2016

Contributor

should the other "spin_forts": true be removed?

This comment has been minimized.

Copy link
@Shoh

Shoh Jul 29, 2016

Contributor

I don't think this is supposed to even be in a "spin_forts" object... the code says otherwise:

self.recent_forts = [None] * config.max_circle_size

...

if self.config.avoid_circles:

This comment has been minimized.

Copy link
@douglascamata

douglascamata Jul 29, 2016

Member

This config changed, check the example please.

"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

0 comments on commit cb52ba8

Please sign in to comment.