Repository: PokemonGoF/PokemonGo-Bot

Issue:
Smart pinap function
### Short Description
<!-- Tell us a short description of your request -->
I made a "smart pinap" function to maximize the use of pinap berries.
Ex1) If catch rate is over 85% for a normal mon use a pinap, but spare 3 for VIPs
Ex2) If catch rate is over a threshold (90%) for a VIP use a pinap, if under that threshold the original razz berry logic kicks in.
The current logic for VIP is fixed to razz or pinap, and for normal mon the level or CP determines the use of pinap. I think the actual catch rate is more important.

How do I add this to the bot? I am new to github, and I want to contribute to this bot.

### Possible solution
<!-- Tell us how you would include it in the current bot -->
I made something like this in pokemon_catch_worker.py
            # SMART_PINAP: Use pinap when high catch rate, but spare some for VIP with high catch rate
            if self.smart_pinap_enabled and ( (not is_vip and self.inventory.get(ITEM_PINAPBERRY).count > self.smart_pinap_to_keep and catch_rate_by_ball[current_ball] > self.pinap_threshold) or (is_vip and self.inventory.get(ITEM_PINAPBERRY).count > 0 and catch_rate_by_ball[current_ball] >= self.vip_berry_threshold) ) and not used_berry:
                berry_id = ITEM_PINAPBERRY
                new_catch_rate_by_ball = self._use_berry(berry_id, berry_count, encounter_id, catch_rate_by_ball, current_ball)
                self.inventory.get(berry_id).remove(1)
                berry_count -= 1
                used_berry = True


### How it would help others
<!-- Tell us how you think it would help yourself and other users -->
Instead of throwing away pinap berries, you can get more candy!

<!-- ==========END OF FEATURE REQUEST SECTION========== -->



Discussion:

Resolving patch:
diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py
--- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py
+++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py
@@ -109,6 +109,9 @@ def initialize(self):
         self.catchsim_newtodex_wait_min = self.catchsim_config.get('newtodex_wait_min', 20)
         self.catchsim_newtodex_wait_max = self.catchsim_config.get('newtodex_wait_max', 30)
 
+        self.smart_pinap_enabled = self.config.get('smart_pinap_enabled', False)
+        self.smart_pinap_threshold = self.config.get('smart_pinap_threshold', 0.85)
+        self.smart_pinap_to_keep = self.config.get('smart_pinap_to_keep', 3)
 
 
 
@@ -532,7 +535,15 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
 
             changed_ball = False
 
-            # use a berry if we are under our ideal rate and have berries to spare
+            # SMART_PINAP: Use pinap when high catch rate, but spare some for VIP with high catch rate
+            if self.smart_pinap_enabled and ( (not is_vip and self.inventory.get(ITEM_PINAPBERRY).count > self.smart_pinap_to_keep and catch_rate_by_ball[current_ball] > self.smart_pinap_threshold) or (is_vip and self.inventory.get(ITEM_PINAPBERRY).count > 0 and catch_rate_by_ball[current_ball] >= self.vip_berry_threshold) ) and not used_berry:
+                berry_id = ITEM_PINAPBERRY
+                new_catch_rate_by_ball = self._use_berry(berry_id, berry_count, encounter_id, catch_rate_by_ball, current_ball)
+                self.inventory.get(berry_id).remove(1)
+                berry_count -= 1
+                used_berry = True
+
+				# use a berry if we are under our ideal rate and have berries to spare
             if catch_rate_by_ball[current_ball] < ideal_catch_rate_before_throw and berries_to_spare and not used_berry:
                 new_catch_rate_by_ball = self._use_berry(berry_id, berry_count, encounter_id, catch_rate_by_ball, current_ball)
                 if new_catch_rate_by_ball != catch_rate_by_ball:


Test patch: