@@ -46,15 +46,21 @@ class RestaurantFarmer_Descriptor::Stats : public StatsTracker{
4646public:
4747 Stats ()
4848 : rounds(m_stats[" Rounds" ])
49+ , wins(m_stats[" Wins" ])
50+ , losses(m_stats[" Losses" ])
4951 , errors(m_stats[" Errors" ])
5052 {
5153 m_display_order.emplace_back (" Rounds" );
54+ m_display_order.emplace_back (" Wins" );
55+ m_display_order.emplace_back (" Losses" );
5256 m_display_order.emplace_back (" Errors" , HIDDEN_IF_ZERO);
5357
5458 m_aliases[" Battles" ] = " Rounds" ;
5559 }
5660
5761 std::atomic<uint64_t >& rounds;
62+ std::atomic<uint64_t >& wins;
63+ std::atomic<uint64_t >& losses;
5864 std::atomic<uint64_t >& errors;
5965};
6066std::unique_ptr<StatsTracker> RestaurantFarmer_Descriptor::make_stats () const {
@@ -215,13 +221,23 @@ void RestaurantFarmer::run_round(SingleSwitchProgramEnvironment& env, ProControl
215221
216222 WallClock start = current_time ();
217223
224+ bool won = false ;
225+
218226 while (true ){
219227 context.wait_for_all_requests ();
220228
229+ ButtonWatcher buttonA (
230+ COLOR_RED,
231+ ButtonType::ButtonA,
232+ {0.1 , 0.1 , 0.8 , 0.8 },
233+ &env.console .overlay (),
234+ 1000ms
235+ );
221236 SelectionArrowWatcher arrow (
222237 COLOR_YELLOW, &env.console .overlay (),
223238 SelectionArrowType::RIGHT,
224- {0.654308 , 0.481553 , 0.295529 , 0.312621 }
239+ {0.654308 , 0.481553 , 0.295529 , 0.312621 },
240+ 1000ms
225241 );
226242 ItemReceiveWatcher item_receive (COLOR_RED, &env.console .overlay (), 1000ms);
227243 FlatWhiteDialogWatcher dialog0 (COLOR_RED, &env.console .overlay (), 1000ms);
@@ -236,6 +252,7 @@ void RestaurantFarmer::run_round(SingleSwitchProgramEnvironment& env, ProControl
236252 }
237253 },
238254 {
255+ buttonA,
239256 arrow,
240257 item_receive,
241258 dialog0,
@@ -245,23 +262,38 @@ void RestaurantFarmer::run_round(SingleSwitchProgramEnvironment& env, ProControl
245262
246263 switch (ret){
247264 case 0 :
265+ env.log (" Detected Lobby." );
266+ stats.rounds ++;
267+ if (won){
268+ stats.wins ++;
269+ }else {
270+ stats.losses ++;
271+ }
272+ env.update_stats ();
273+ return ;
274+
275+ case 1 :
248276 env.log (" Detected selection arrow. (unexpected)" , COLOR_RED);
249277 dump_image (env.console .logger (), env.program_info (), env.console .video (), " UnexpectedSelectionArrow" );
250278 stats.errors ++;
251279 env.update_stats ();
252280 continue ;
253281
254282 case 2 :
283+ env.log (" Detected item receive." );
284+ won = true ;
285+ pbf_press_button (context, BUTTON_A, 160ms, 80ms);
286+ continue ;
287+
288+ case 3 :
255289 env.log (" Detected white dialog." );
256290 pbf_press_button (context, BUTTON_B, 160ms, 80ms);
257291 continue ;
258292
259- case 1 :
260- case 3 :
261- env.log (" Detected blue dialog. End of round!" );
262- stats.rounds ++;
263- env.update_stats ();
264- return ;
293+ case 4 :
294+ env.log (" Detected blue dialog." );
295+ pbf_press_button (context, BUTTON_B, 160ms, 80ms);
296+ continue ;
265297
266298 default :
267299 stats.errors ++;
0 commit comments