1313#include " PokemonSV/Inference/Boxes/PokemonSV_BoxDetection.h"
1414#include " PokemonSV_BoxRelease.h"
1515
16+ // #include <iostream>
17+ // using std::cout;
18+ // using std::endl;
19+
1620namespace PokemonAutomation {
1721namespace NintendoSwitch {
1822namespace PokemonSV {
@@ -26,6 +30,7 @@ void release_one_pokemon(
2630 bool release_attempted = false ;
2731 bool release_completed = false ;
2832 int expected = 0 ;
33+ int consecutive_box_neutrals = 0 ;
2934 WallClock start = current_time ();
3035 while (true ){
3136 if (current_time () - start > std::chrono::seconds (60 )){
@@ -36,6 +41,7 @@ void release_one_pokemon(
3641 }
3742
3843 SomethingInBoxSlotDetector exists (COLOR_BLUE);
44+ // GradientArrowDetector change_marks(COLOR_MAGENTA, GradientArrowType::DOWN, {0.28, 0.38, 0.30, 0.10});
3945 BoxWatcher box_detector (COLOR_RED);
4046 BoxSelectWatcher selected (COLOR_YELLOW, std::chrono::milliseconds (100 ));
4147 PromptDialogWatcher confirm (COLOR_CYAN, std::chrono::milliseconds (100 ));
@@ -49,7 +55,7 @@ void release_one_pokemon(
4955 box_detector,
5056 selected,
5157 confirm,
52- advance_dialog,
58+ advance_dialog
5359 }
5460 );
5561 context.wait_for (std::chrono::milliseconds (50 ));
@@ -62,16 +68,37 @@ void release_one_pokemon(
6268 ret = 2 ;
6369 }
6470 }
71+ // cout << "consecutive_box_neutrals = " << consecutive_box_neutrals << endl;
6572
6673 switch (ret){
6774 case 0 :{
75+ auto screenshot = stream.video ().snapshot ();
76+ #if 0
77+ // Disambiguate with mark change.
78+ if (change_marks.detect(screenshot)){
79+ stream.log("Detected mark change.", COLOR_RED);
80+ pbf_press_button(context, BUTTON_B, 20, 20);
81+ expected = 0;
82+ continue;
83+ }
84+ #endif
85+
6886 if (ret == expected){
6987 stream.log (" Detected box neutral." );
88+ consecutive_box_neutrals = 0 ;
7089 }else {
90+ // Disambiguate with mark change.
7191 stream.log (" Detected box neutral. (unexpected)" , COLOR_RED);
7292 errors++;
93+ consecutive_box_neutrals++;
94+ // cout << "consecutive_box_neutrals = " << consecutive_box_neutrals << endl;
95+ if (consecutive_box_neutrals >= 5 ){
96+ pbf_press_button (context, BUTTON_B, 20 , 20 );
97+ expected = 0 ;
98+ continue ;
99+ }
73100 }
74- auto screenshot = stream. video (). snapshot ();
101+
75102 if (exists.detect (screenshot)){
76103 if (release_attempted && release_completed){
77104 return ;
@@ -127,7 +154,9 @@ void release_one_pokemon(
127154 continue ;
128155 default :
129156 dump_image_and_throw_recoverable_exception (
130- info, stream, " NoStateReleasingPokemon" , " No recognized state while releasing a pokemon after 10 seconds."
157+ info, stream,
158+ " NoStateReleasingPokemon" ,
159+ " No recognized state while releasing a pokemon after 10 seconds."
131160 );
132161 }
133162 }
0 commit comments