Skip to content

Commit 7c37ce6

Browse files
committed
use better balls
1 parent 79b0a69 commit 7c37ce6

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

pgoapi/inventory.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,40 +75,37 @@ def take_masterball(self):
7575

7676
def take_ultraball(self):
7777
self.ultra_balls -= 1
78-
79-
def take_next_ball(self, capture_priority=None):
80-
if not capture_priority:
81-
capture_priority = {1: 35.0, 2: 45.0, 3: 55.0}
82-
priority = Inventory.__get_ball_priority(capture_priority)
83-
if self.can_attempt_catch() and priority <= Inventory_Enum.ITEM_MASTER_BALL:
84-
if priority <= Inventory_Enum.ITEM_POKE_BALL and self.poke_balls > 0:
78+
def best_ball(self):
79+
if self.master_balls:
80+
return Inventory_Enum.ITEM_MASTER_BALL
81+
elif self.ultra_balls:
82+
return Inventory_Enum.ITEM_ULTRA_BALL
83+
elif self.great_balls:
84+
return Inventory_Enum.ITEM_GREAT_BALL
85+
else:
86+
return Inventory_Enum.ITEM_POKE_BALL
87+
#FIXME make not bad, this should be configurable
88+
def take_next_ball(self, capture_probability):
89+
if self.can_attempt_catch():
90+
if capture_probability.get(Inventory_Enum.ITEM_POKE_BALL,0) > 0.15 and self.poke_balls:
8591
self.take_pokeball()
8692
return Inventory_Enum.ITEM_POKE_BALL
87-
if priority <= Inventory_Enum.ITEM_GREAT_BALL and self.great_balls > 0:
93+
elif capture_probability.get(Inventory_Enum.ITEM_GREAT_BALL,0) > 0.15 and self.great_balls:
8894
self.take_greatball()
8995
return Inventory_Enum.ITEM_GREAT_BALL
90-
if priority <= Inventory_Enum.ITEM_ULTRA_BALL and self.ultra_balls > 0:
96+
elif capture_probability.get(Inventory_Enum.ITEM_ULTRA_BALL,0) > 0.15 and self.ultra_balls:
9197
self.take_ultraball()
9298
return Inventory_Enum.ITEM_ULTRA_BALL
93-
if priority <= Inventory_Enum.ITEM_MASTER_BALL and self.master_balls > 0:
99+
elif capture_probability.get(Inventory_Enum.ITEM_MASTER_BALL,0) > 0.15 and self.master_balls:
94100
self.take_masterball()
95101
return Inventory_Enum.ITEM_MASTER_BALL
96102
else:
97-
return self.take_next_ball()
103+
best_ball = self.best_ball()
104+
self.take_ball(self.best_ball())
105+
return best_ball
98106
else:
99107
return -1
100108

101-
@staticmethod
102-
def __get_ball_priority(capture_priority):
103-
if capture_priority.get(Inventory_Enum.ITEM_POKE_BALL, 0.0) > 0.30:
104-
return Inventory_Enum.ITEM_POKE_BALL
105-
if capture_priority.get(Inventory_Enum.ITEM_GREAT_BALL, 0.0) > 0.30:
106-
return Inventory_Enum.ITEM_GREAT_BALL
107-
if capture_priority.get(Inventory_Enum.ITEM_ULTRA_BALL, 0.0) > 0.30:
108-
return Inventory_Enum.ITEM_ULTRA_BALL
109-
else:
110-
return Inventory_Enum.ITEM_MASTER_BALL
111-
112109
def take_ball(self, ball_id):
113110
if ball_id == Inventory_Enum.ITEM_POKE_BALL:
114111
self.poke_balls -= 1

0 commit comments

Comments
 (0)