@@ -75,15 +75,18 @@ class JacintheInfiniteFarmer_Descriptor::Stats : public StatsTracker{
7575public:
7676 Stats ()
7777 : rounds(m_stats[" Rounds" ])
78+ , defeats(m_stats[" Defeats" ])
7879 , errors(m_stats[" Errors" ])
7980 {
8081 m_display_order.emplace_back (" Rounds" );
82+ m_display_order.emplace_back (" Defeats" , HIDDEN_IF_ZERO);
8183 m_display_order.emplace_back (" Errors" , HIDDEN_IF_ZERO);
8284
8385 m_aliases[" Battles" ] = " Rounds" ;
8486 }
8587
8688 std::atomic<uint64_t >& rounds;
89+ std::atomic<uint64_t >& defeats;
8790 std::atomic<uint64_t >& errors;
8891};
8992std::unique_ptr<StatsTracker> JacintheInfiniteFarmer_Descriptor::make_stats () const {
@@ -167,6 +170,7 @@ bool JacintheInfiniteFarmer::talk_to_jacinthe(SingleSwitchProgramEnvironment& en
167170
168171 bool seen_selection_arrow = false ;
169172 bool confirm_entering_battle = false ;
173+ bool seen_flat_white_dialog = false ;
170174 while (true ){
171175 context.wait_for_all_requests ();
172176
@@ -203,12 +207,22 @@ bool JacintheInfiniteFarmer::talk_to_jacinthe(SingleSwitchProgramEnvironment& en
203207
204208 switch (ret){
205209 case 0 :
210+ // There cases where the function detects A button:
211+ // - At start of the program, press A to start talking to Jacinthe
212+ // - When stopping the battle, the program fininshes all the dialog with Jacinethe and returns
213+ // to the overworld, where button A appears.
214+ // - When we lose to Jacinthe, we have some dialog after the battle and returns to the overworld.
206215 env.log (" Detected A button." );
207216 env.console .overlay ().add_log (" Button A Detected" );
208217 if (m_stop_after_current.load (std::memory_order_relaxed)){
209- return true ;
218+ return true ; // true means the program should stop
219+ }
220+
221+ if (seen_flat_white_dialog){
222+ // we shouldn't stop the program but we find A button. This means we lost.
223+ stats.defeats ++;
224+ env.update_stats ();
210225 }
211-
212226 pbf_press_button (context, BUTTON_A, 160ms, 80ms);
213227 continue ;
214228
@@ -231,6 +245,7 @@ bool JacintheInfiniteFarmer::talk_to_jacinthe(SingleSwitchProgramEnvironment& en
231245 case 2 :
232246 env.log (" Detected white dialog." );
233247 env.console .overlay ().add_log (" Advance Dialog" );
248+ seen_flat_white_dialog = true ;
234249 pbf_press_button (context, BUTTON_B, 160ms, 80ms);
235250 continue ;
236251
0 commit comments