Skip to content

Commit 2990239

Browse files
committed
Improve fault tolerance of TeraRoller.
1 parent 724a720 commit 2990239

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

SerialPrograms/Source/PokemonSV/Inference/Dialogs/PokemonSV_GradientArrowDetector.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ const ImageMatch::ExactImageMatcher& GRADIENT_ARROW_VERTICAL(){
3737

3838
bool is_gradient_arrow(
3939
GradientArrowType type,
40+
const ImageViewRGB32& original_screen,
4041
const ImageViewRGB32& image,
4142
WaterfillObject& object,
4243
const WaterfillObject& yellow, const WaterfillObject& blue
4344
){
4445
object = yellow;
4546
object.merge_assume_no_overlap(blue);
4647

47-
if (object.width() < 20){
48+
size_t object_box_area = object.width() * object.height();
49+
double min_area = original_screen.total_pixels() * (2000. / (1920*1080));
50+
if (object_box_area < min_area){
4851
return false;
4952
}
5053

@@ -66,6 +69,9 @@ bool is_gradient_arrow(
6669
}
6770
double rmsd = GRADIENT_ARROW_HORIZONTAL().rmsd(cropped);
6871
// cout << "rmsd = " << rmsd << endl;
72+
// if (rmsd <= THRESHOLD){
73+
// cout << "object_box_area = " << object_box_area << endl;
74+
// }
6975
return rmsd <= THRESHOLD;
7076
}
7177
case GradientArrowType::DOWN:{
@@ -223,7 +229,7 @@ bool GradientArrowDetector::detect(ImageFloatBox& box, const ImageViewRGB32& scr
223229
for (WaterfillObject& yellow : yellows){
224230
for (WaterfillObject& blue : blues){
225231
WaterfillObject object;
226-
if (is_gradient_arrow(m_type, region, object, yellow, blue)){
232+
if (is_gradient_arrow(m_type, screen, region, object, yellow, blue)){
227233
// hits.emplace_back(translate_to_parent(screen, m_box, object));
228234
// extract_box_reference(region, object).save("object.png");
229235
box = translate_to_parent(screen, m_box, object);

SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraRoller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void TeraRoller::program(SingleSwitchProgramEnvironment& env, ProControllerConte
184184
env.console.overlay().add_log("Entering tera raid...", COLOR_WHITE);
185185

186186
// Run away from the tera raid battle
187-
run_from_tera_battle(env.program_info(), env.console, context);
187+
run_from_tera_battle(env, env.console, context, &stats.m_errors);
188188
context.wait_for_all_requests();
189189

190190
env.console.log("Checking if tera raid is shiny...");

SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraRoutines.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,12 @@ TeraResult run_tera_summary(
670670
}
671671

672672

673-
void run_from_tera_battle(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
673+
void run_from_tera_battle(
674+
ProgramEnvironment& env,
675+
VideoStream& stream,
676+
ProControllerContext& context,
677+
std::atomic<uint64_t>* stat_errors
678+
){
674679
stream.log("Running away from tera raid battle...");
675680

676681
WallClock start = current_time();
@@ -688,9 +693,10 @@ void run_from_tera_battle(const ProgramInfo& info, VideoStream& stream, ProContr
688693
GradientArrowWatcher leave_confirm(
689694
COLOR_RED,
690695
GradientArrowType::RIGHT,
691-
{0.557621, 0.471074, 0.388476, 0.247934}
696+
{0.557621, 0.471074, 0.25, 0.247934}
692697
);
693698
OverworldWatcher overworld(stream.logger(), COLOR_CYAN);
699+
TeraCardWatcher tera_card(COLOR_BLUE);
694700
context.wait_for_all_requests();
695701

696702
int ret = wait_until(
@@ -700,6 +706,7 @@ void run_from_tera_battle(const ProgramInfo& info, VideoStream& stream, ProContr
700706
battle_menu,
701707
leave_confirm,
702708
overworld,
709+
tera_card,
703710
}
704711
);
705712

@@ -718,7 +725,19 @@ void run_from_tera_battle(const ProgramInfo& info, VideoStream& stream, ProContr
718725
case 2:
719726
stream.log("Detected overworld.");
720727
return;
728+
case 3:
729+
stream.log("Detected a raid. (unexpected)", COLOR_RED);
730+
if (stat_errors){
731+
(*stat_errors)++;
732+
env.update_stats();
733+
}
734+
pbf_press_button(context, BUTTON_B, 160ms, 80ms);
735+
continue;
721736
default:
737+
if (stat_errors){
738+
(*stat_errors)++;
739+
env.update_stats();
740+
}
722741
OperationFailedException::fire(
723742
ErrorReport::SEND_ERROR_REPORT,
724743
"run_from_tera_battle(): No recognized state after 1 minutes.",

SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraRoutines.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ TeraResult run_tera_summary(
112112
);
113113

114114
// Run away from tera battle.
115-
void run_from_tera_battle(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context);
115+
void run_from_tera_battle(
116+
ProgramEnvironment& env,
117+
VideoStream& stream,
118+
ProControllerContext& context,
119+
std::atomic<uint64_t>* stat_errors
120+
);
116121

117122
bool is_sparkling_raid(VideoStream& stream, ProControllerContext& context);
118123

0 commit comments

Comments
 (0)