Skip to content

Commit e12176c

Browse files
committed
State machine the end of DA sequence to tolerate add to party and nicknames.
1 parent 3798214 commit e12176c

File tree

4 files changed

+81
-10
lines changed

4 files changed

+81
-10
lines changed

SerialPrograms/Source/PokemonSV/Programs/Eggs/PokemonSV_EggAutonomous.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "CommonFramework/Exceptions/ProgramFinishedException.h"
1010
#include "CommonFramework/Exceptions/FatalProgramException.h"
1111
#include "CommonFramework/Exceptions/OperationFailedException.h"
12-
#include "CommonFramework/Exceptions/UnexpectedBattleException.h"
12+
//#include "CommonFramework/Exceptions/UnexpectedBattleException.h"
1313
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
1414
#include "CommonFramework/Notifications/ProgramNotifications.h"
1515
#include "CommonFramework/ProgramStats/StatsTracking.h"

SerialPrograms/Source/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_CatchScreenTracker.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_EndBattle.h"
1313
#include "PokemonSwSh_MaxLair_CatchScreenTracker.h"
1414

15+
//#define PA_FORCE_SLOT_SHINY 2
16+
1517
namespace PokemonAutomation{
1618
namespace NintendoSwitch{
1719
namespace PokemonSwSh{
@@ -34,6 +36,9 @@ size_t CaughtPokemonScreen::total() const{
3436
const CaughtPokemon& CaughtPokemonScreen::operator[](size_t position) const{
3537
return m_mons[position];
3638
}
39+
CaughtPokemon& CaughtPokemonScreen::operator[](size_t position){
40+
return m_mons[position];
41+
}
3742
bool CaughtPokemonScreen::current_position() const{
3843
return m_current_position;
3944
}
@@ -113,6 +118,11 @@ void CaughtPokemonScreen::scroll_to(size_t position){
113118
}
114119
}
115120
void CaughtPokemonScreen::process_detection(Detection detection){
121+
#ifdef PA_FORCE_SLOT_SHINY
122+
if (m_current_position == PA_FORCE_SLOT_SHINY){
123+
detection = Detection::SHINY;
124+
}
125+
#endif
116126
CaughtPokemon& mon = m_mons[m_current_position];
117127
switch (detection){
118128
case SummaryShinySymbolDetector::Detection::NO_DETECTION:

SerialPrograms/Source/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_CatchScreenTracker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class CaughtPokemonScreen{
3131

3232
size_t total() const;
3333
const CaughtPokemon& operator[](size_t position) const;
34+
CaughtPokemon& operator[](size_t position);
3435

3536
bool current_position() const;
3637
bool is_summary() const;

SerialPrograms/Source/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_CaughtScreen.cpp

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1515
#include "Pokemon/Pokemon_Strings.h"
1616
#include "PokemonSwSh/PokemonSwSh_Settings.h"
17+
#include "PokemonSwSh/Inference/PokemonSwSh_DialogTriangleDetector.h"
18+
#include "PokemonSwSh/Inference/PokemonSwSh_SelectionArrowFinder.h"
19+
#include "PokemonSwSh/Inference/PokemonSwSh_DialogBoxDetector.h"
20+
#include "PokemonSwSh/Inference/PokemonSwSh_ReceivePokemonDetector.h"
1721
#include "PokemonSwSh/Programs/PokemonSwSh_GameEntry.h"
1822
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_Entrance.h"
1923
#include "PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_Notifications.h"
@@ -35,23 +39,79 @@ StateMachineAction mash_A_to_entrance(
3539
VideoStream& stream, ProControllerContext& context,
3640
const ImageViewRGB32& entrance
3741
){
38-
EntranceDetector entrance_detector(entrance);
42+
WallClock start = current_time();
43+
while (true){
44+
if (current_time() - start > std::chrono::seconds(60)){
45+
stream.log("Unable to find entrance after 60 seconds.", COLOR_RED);
46+
runtime.session_stats.add_error();
47+
dump_image(stream.logger(), MODULE_NAME, stream.video(), "FailedToDetectEntrance");
48+
return StateMachineAction::RESET_RECOVER;
49+
}
50+
51+
EntranceDetector entrance_detector(entrance);
52+
SelectionArrowFinder prompt(stream.overlay(), {0.362689, 0.282828, 0.625000, 0.580808});
53+
DialogTriangleDetector triangle(stream.logger(), stream.overlay(), true);
54+
BlackDialogBoxDetector dialog(true);
55+
ReceivePokemonDetector receive(true);
56+
57+
context.wait_for_all_requests();
58+
int ret = wait_until(
59+
stream, context,
60+
std::chrono::seconds(10),
61+
{
62+
entrance_detector,
63+
prompt,
64+
triangle,
65+
dialog,
66+
receive,
67+
},
68+
INFERENCE_RATE
69+
);
70+
context.wait_for(std::chrono::milliseconds(100));
71+
switch (ret){
72+
case 0:
73+
stream.log("Detected entrance.");
74+
return StateMachineAction::KEEP_GOING;
75+
case 1:
76+
stream.log("Detected prompt.");
77+
pbf_press_button(context, BUTTON_A, 80ms, 320ms);
78+
break;
79+
case 2:
80+
stream.log("Detected dialog triangle.");
81+
pbf_press_button(context, BUTTON_B, 80ms, 320ms);
82+
break;
83+
case 3:
84+
stream.log("Detected dialog box.");
85+
pbf_press_button(context, BUTTON_B, 80ms, 320ms);
86+
break;
87+
case 4:
88+
stream.log("Detected receive " + Pokemon::STRING_POKEMON + ".");
89+
pbf_press_button(context, BUTTON_B, 80ms, 320ms);
90+
break;
91+
default:
92+
stream.log("No recognized state after 10 seconds.", COLOR_RED);
93+
pbf_press_button(context, BUTTON_B, 80ms, 320ms);
94+
pbf_press_button(context, BUTTON_X, 80ms, 320ms); // In case we landed in the nickname menu.
95+
}
96+
}
3997

40-
int result = run_until<ProControllerContext>(
98+
EntranceDetector entrance_detector(entrance);
99+
int ret = run_until<ProControllerContext>(
41100
stream, context,
42-
[&](ProControllerContext& context){
43-
pbf_mash_button(context, BUTTON_A, 60 * TICKS_PER_SECOND);
101+
[](ProControllerContext& context){
102+
for (size_t c = 0; c < 60; c++){
103+
pbf_press_button(context, BUTTON_B, 80ms, 920ms);
104+
}
44105
},
45-
{{entrance_detector}},
46-
INFERENCE_RATE
106+
{entrance_detector}
47107
);
48-
49-
if (result < 0){
50-
stream.log("Failed to detect entrance.", COLOR_RED);
108+
if (ret < 0){
109+
stream.log("Unable to find entrance after 60 seconds.", COLOR_RED);
51110
runtime.session_stats.add_error();
52111
dump_image(stream.logger(), MODULE_NAME, stream.video(), "FailedToDetectEntrance");
53112
return StateMachineAction::RESET_RECOVER;
54113
}
114+
55115
return StateMachineAction::KEEP_GOING;
56116
}
57117

0 commit comments

Comments
 (0)