Skip to content

Commit

Permalink
Polyline stuck fix (#4433)
Browse files Browse the repository at this point in the history
* bugfix for polyline

* leftovers

* changed default value of pokecli config aswell

* added fix for #4250

* fixed spiral aswell

* original current and last are wrong...

* seems it was ok, reverted partly...

* upside down

* changed message

* cleanup & polyline support for move_to_fort

* fixed default conf to StepWalker

* fixed ValueError issue

* polyline stucking issue fixed

* minor fix

* removed print
  • Loading branch information
kanemasa1987 authored and solderzzc committed Aug 21, 2016
1 parent 4c6c5f2 commit 6f9ae7d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pokemongo_bot/walkers/polyline_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class PolylineObjectHandler:
More like a namespace...
'''
_cache = None
_instability = 0
_run = False

@staticmethod
def cached_polyline(origin, destination, speed):
Expand All @@ -23,12 +25,26 @@ def cached_polyline(origin, destination, speed):
is_old_cache = lambda : tuple(origin) != PolylineObjectHandler._cache.get_last_pos()
new_dest_set = lambda : tuple(destination) != PolylineObjectHandler._cache.destination

if None == PolylineObjectHandler._cache or is_old_cache() or new_dest_set():
if PolylineObjectHandler._run:
# bot used to have struggle with making a decision.
PolylineObjectHandler._instability -= 1
if PolylineObjectHandler._instability <= 0:
PolylineObjectHandler._instability = 0
PolylineObjectHandler._run = False
pass # use current cache
elif None == PolylineObjectHandler._cache or is_old_cache() or new_dest_set():
# no cache, old cache or new destination set by bot, so make new polyline
PolylineObjectHandler._instability += 2
if 10 <= PolylineObjectHandler._instability:
PolylineObjectHandler._run = True
PolylineObjectHandler._instability = 20 # next N moves use same cache

PolylineObjectHandler._cache = Polyline(origin, destination, speed)
else:
# valid cache found
pass

PolylineObjectHandler._instability -= 1
PolylineObjectHandler._instability = max(PolylineObjectHandler._instability, 0)
pass # use current cache
return PolylineObjectHandler._cache


Expand Down

0 comments on commit 6f9ae7d

Please sign in to comment.