@@ -15,6 +15,10 @@ def wait_until_reward_stable(self, timeout=8.6, required_consecutive_matches=3,
1515 checks if all rewards have appeared, via first doing a predicted grid, 3 types to account for the Ui
1616 change due to Meta xp, then verifies via amount ocr, after that waits till the reward area has no changes
1717 e.g all drops appeared
18+
19+ timeout: may or may not need adjustment, after gathering data\\
20+ required_consecutive_matches: 3 seems a good compromise\\
21+ similarity_threshold: in testing the similarity ranged in 0.002- 0.01 ranges so opted for 0.999
1822 """
1923 logger .info ('wait until area stable' )
2024
@@ -68,7 +72,7 @@ def wait_until_reward_stable(self, timeout=8.6, required_consecutive_matches=3,
6872 logger .info ("Grid 0 validated, checking Grid 1 for potentially more rewards..." )
6973 grid1_x , grid1_y = GRID_ORIGINS [1 ]
7074 grid1 = ButtonGrid (origin = (grid1_x , grid1_y ), ** GRID_PARAMS )
71- grid1_matched = self ._verify_grid_via_ocr (grid1 , 1 , original_bgr )
75+ grid1_matched = self ._verify_grid_via_ocr (grid1 , 1 , original_bgr , check_first_button_only = True )
7276
7377 if grid1_matched :
7478 logger .info ("Grid 1 also validated - using Grid 1 for wider coverage" )
@@ -116,13 +120,14 @@ def wait_until_reward_stable(self, timeout=8.6, required_consecutive_matches=3,
116120 logger .error (f'Stabilization failure: { str (e )} ' )
117121 return False
118122
119- def _verify_grid_via_ocr (self , grid , grid_idx , bgr_image ):
123+ def _verify_grid_via_ocr (self , grid , grid_idx , bgr_image , check_first_button_only = False ):
120124 """
121- Double checks if grid correct via the item amount on the bottom right of grid buttons
122- Enhanced with better logging for grid comparison
125+ double checks if grid correct via the item amount on the bottom right of grid buttons
126+ special handling for grid0 vs grid1
123127 """
124128 amount_ocr = AmountOcr ([], threshold = 96 , name = 'Amount_ocr' )
125129 detected_amounts = []
130+ first_button_has_amount = False
126131
127132 for btn_idx , btn in enumerate (grid .buttons ):
128133 try :
@@ -140,24 +145,39 @@ def _verify_grid_via_ocr(self, grid, grid_idx, bgr_image):
140145 if len (amount_img .shape ) == 2 :
141146 amount_img = cv2 .cvtColor (amount_img , cv2 .COLOR_GRAY2BGR )
142147
143- # 4. OCR detection
148+ # 4. OCR just like the one in ItemGrid in item.py
144149 amount = amount_ocr .ocr ([amount_img ], direct_ocr = True )[0 ]
145150 if amount > 0 :
146151 detected_amounts .append (amount )
147152 logger .info (f"Grid { grid_idx } , Button { btn_idx } : amount={ amount } " )
153+
154+ # Track if first button (index 0) has amount
155+ if btn_idx == 0 :
156+ first_button_has_amount = True
148157
149158 except Exception as e :
150159 logger .warning (f"Grid { grid_idx } , Button { btn_idx } check failed: { str (e )} " )
151160 continue
152161
153- # Log summary for this grid
162+ # Determine validation result
154163 total_detected = len (detected_amounts )
155- if total_detected > 0 :
156- logger .info (f"Grid { grid_idx } summary: { total_detected } buttons with amounts detected" )
157- return True
164+
165+ if check_first_button_only :
166+ # For Grid 1 validation: only valid if first button has amount
167+ if first_button_has_amount :
168+ logger .info (f"Grid { grid_idx } summary: First button validated with amount - Grid 1 captures additional reward!" )
169+ return True
170+ else :
171+ logger .info (f"Grid { grid_idx } summary: First button has no amount - Grid 1 offers no advantage" )
172+ return False
158173 else :
159- logger .info (f"Grid { grid_idx } summary: No amounts detected" )
160- return False
174+ # Standard validation: any button with amount is sufficient
175+ if total_detected > 0 :
176+ logger .info (f"Grid { grid_idx } summary: { total_detected } buttons with amounts detected" )
177+ return True
178+ else :
179+ logger .info (f"Grid { grid_idx } summary: No amounts detected" )
180+ return False
161181
162182 def reward_area_stable_check (self , monitor_area , timeout , required_matches , similarity_threshold ):
163183 """
0 commit comments