Skip to content

Commit 7678c56

Browse files
committed
Fix missed shiny corner case of PLA fixed-path shiny-hunting programs. Clear them for SBB as well.
1 parent af495fe commit 7678c56

File tree

10 files changed

+70
-43
lines changed

10 files changed

+70
-43
lines changed

SerialPrograms/Source/CommonTools/Async/InferenceRoutines.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include "CommonFramework/Tools/VideoStream.h"
1515
#include "CommonTools/InferenceCallbacks/InferenceCallback.h"
1616

17+
//#include <iostream>
18+
//using std::cout;
19+
//using std::endl;
20+
1721
namespace PokemonAutomation{
1822

1923
class ProgramEnvironment;

SerialPrograms/Source/CommonTools/Async/InterruptableCommands.tpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,6 @@ bool AsyncCommandSession<ControllerType>::cancel(std::exception_ptr exception) n
134134
std::lock_guard<std::mutex> lg(m_lock);
135135
if (m_current != nullptr){
136136
m_current->context.cancel(std::move(exception));
137-
}else{
138-
// cout << "AsyncCommandSession::cancel() - already cancelled" << endl;
139-
// REMOVE: Check that this can actually be deleted.
140-
// try{
141-
// m_controller.stop_all_commands();
142-
// }catch (...){}
143137
}
144138
m_cv.notify_all();
145139
return false;

SerialPrograms/Source/CommonTools/Audio/AudioPerSpectrumDetectorBase.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ using std::endl;
1919
namespace PokemonAutomation{
2020

2121

22+
//std::atomic<bool> force_detected(false);
23+
24+
25+
2226
AudioPerSpectrumDetectorBase::AudioPerSpectrumDetectorBase(
2327
Logger& logger,
2428
std::string label,
@@ -175,6 +179,10 @@ bool AudioPerSpectrumDetectorBase::process_spectrums(
175179
}
176180
}
177181

182+
// if (force_detected){
183+
// return true;
184+
// }
185+
178186
// No shiny detected.
179187
if (m_last_error >= 1.0){
180188
return false;

SerialPrograms/Source/CommonTools/Audio/AudioPerSpectrumDetectorBase.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
namespace PokemonAutomation{
3838

39+
3940
class Logger;
4041
class SpectrogramMatcher;
4142

@@ -65,6 +66,10 @@ class AudioPerSpectrumDetectorBase : public AudioInferenceCallback{
6566

6667
virtual ~AudioPerSpectrumDetectorBase();
6768

69+
WallClock last_detection() const{
70+
return m_last_timestamp;
71+
}
72+
6873
void throw_if_no_sound(std::chrono::milliseconds min_duration = std::chrono::milliseconds(5000)) const;
6974

7075
// To be implemented by derived classes:

SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_SelectorWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SysbotBaseNetwork_SelectorWidget : public QLineEdit{
3535
policy.setHorizontalStretch(3);
3636
this->setSizePolicy(policy);
3737

38-
this->setPlaceholderText("192.168.0.100:5000");
38+
this->setPlaceholderText("192.168.0.100:6000");
3939

4040
if (current == nullptr){
4141
std::shared_ptr<const ControllerDescriptor> descriptor =

SerialPrograms/Source/PokemonLA/Programs/General/PokemonLA_BraviaryHeightGlitch.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ BraviaryHeightGlitch_Descriptor::BraviaryHeightGlitch_Descriptor()
2222
"Increase your height in place using the height glitch.",
2323
FeedbackType::NONE,
2424
AllowCommandsWhenRunning::DISABLE_COMMANDS,
25-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
25+
{ControllerFeature::NintendoSwitch_ProController},
26+
FasterIfTickPrecise::NOT_FASTER
2627
)
2728
{}
2829

SerialPrograms/Source/PokemonLA/Programs/ShinyHunting/PokemonLA_CrobatFinder.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
namespace PokemonAutomation{
2323
namespace NintendoSwitch{
2424
namespace PokemonLA{
25-
using namespace Pokemon;
25+
26+
using namespace Pokemon;
2627

2728

2829
CrobatFinder_Descriptor::CrobatFinder_Descriptor()
@@ -33,7 +34,8 @@ CrobatFinder_Descriptor::CrobatFinder_Descriptor()
3334
"Constantly reset the cave to find Shiny Alpha Crobat.",
3435
FeedbackType::VIDEO_AUDIO,
3536
AllowCommandsWhenRunning::DISABLE_COMMANDS,
36-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
37+
{ControllerFeature::NintendoSwitch_ProController},
38+
FasterIfTickPrecise::NOT_FASTER
3739
)
3840
{}
3941
class CrobatFinder_Descriptor::Stats : public StatsTracker, public ShinyStatIncrementer{
@@ -132,6 +134,7 @@ void CrobatFinder::run_iteration(SingleSwitchProgramEnvironment& env, ProControl
132134
{
133135
float shiny_coefficient = 1.0;
134136
std::atomic<ShinyDetectedActionOption*> shiny_action(&SHINY_DETECTED_ENROUTE);
137+
WallClock destination_time = WallClock::max();
135138

136139
ShinySoundDetector shiny_detector(env.console, [&](float error_coefficient) -> bool{
137140
// Warning: This callback will be run from a different thread than this function.
@@ -146,21 +149,22 @@ void CrobatFinder::run_iteration(SingleSwitchProgramEnvironment& env, ProControl
146149
[&](ProControllerContext& context){
147150

148151
// FORWARD PORTION OF CAVE UNTIL LEDGE
149-
pbf_press_button(context, BUTTON_B, (uint16_t)(2.2 * TICKS_PER_SECOND), 80); // wyrdeer sprint
152+
pbf_press_button(context, BUTTON_B, 2200ms, 640ms); // wyrdeer sprint
150153
pbf_move_left_joystick(context, 0, 128, 10, 20); // turn left
151154
pbf_press_button(context, BUTTON_ZL, 20, 50); // align camera
152155

153156
// ASCEND THE LEDGE WITH BRAVIARY
154157
pbf_press_dpad(context, DPAD_RIGHT, 20, 50); // swap to braviary
155-
pbf_wait(context, (uint16_t)(0.6 * TICKS_PER_SECOND)); // wait for the ascent
156-
pbf_press_button(context, BUTTON_Y, (uint16_t)(2.4 * TICKS_PER_SECOND), 20); // descend to swap to Wyrdeer automatically
158+
pbf_wait(context, 600ms); // wait for the ascent
159+
pbf_press_button(context, BUTTON_Y, 2400ms, 160ms); // descend to swap to Wyrdeer automatically
157160

158161
// TO CROBAT PORTION
159-
pbf_press_button(context, BUTTON_B, (uint16_t)(1.05 * TICKS_PER_SECOND), 80); // sprint forward for a split second
162+
pbf_press_button(context, BUTTON_B, 1050ms, 640ms); // sprint forward for a split second
160163
pbf_move_left_joystick(context, 255, 150, 10, 20); // rotate slightly right
161164
pbf_press_button(context, BUTTON_ZL, 20, 70); // align camera
162165

163166
context.wait_for_all_requests();
167+
destination_time = current_time();
164168
shiny_action.store(&SHINY_DETECTED_DESTINATION, std::memory_order_release);
165169

166170
pbf_move_left_joystick(context, 128, 0, (uint16_t)(3.8 * TICKS_PER_SECOND), 0); // forward to crobat check
@@ -169,7 +173,7 @@ void CrobatFinder::run_iteration(SingleSwitchProgramEnvironment& env, ProControl
169173
{{shiny_detector}}
170174
);
171175
shiny_detector.throw_if_no_sound();
172-
if (ret == 0){
176+
if (ret == 0 || shiny_detector.last_detection() > destination_time){
173177
ShinyDetectedActionOption* action = shiny_action.load(std::memory_order_acquire);
174178
on_shiny_sound(env, env.console, context, *action, shiny_coefficient);
175179
}

SerialPrograms/Source/PokemonLA/Programs/ShinyHunting/PokemonLA_FroslassFinder.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ FroslassFinder_Descriptor::FroslassFinder_Descriptor()
3434
"Constantly reset to find a Alpha Froslass or any Shiny in the path.",
3535
FeedbackType::VIDEO_AUDIO,
3636
AllowCommandsWhenRunning::DISABLE_COMMANDS,
37-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
37+
{ControllerFeature::NintendoSwitch_ProController},
38+
FasterIfTickPrecise::NOT_FASTER
3839
)
3940
{}
4041
class FroslassFinder_Descriptor::Stats : public StatsTracker, public ShinyStatIncrementer{
@@ -117,6 +118,7 @@ void FroslassFinder::run_iteration(SingleSwitchProgramEnvironment& env, ProContr
117118
{
118119
float shiny_coefficient = 1.0;
119120
std::atomic<ShinyDetectedActionOption*> shiny_action(&SHINY_DETECTED_ENROUTE);
121+
WallClock destination_time = WallClock::max();
120122

121123
ShinySoundDetector shiny_detector(env.console, [&](float error_coefficient) -> bool{
122124
// Warning: This callback will be run from a different thread than this function.
@@ -130,26 +132,29 @@ void FroslassFinder::run_iteration(SingleSwitchProgramEnvironment& env, ProContr
130132
env.console, context,
131133
[&](ProControllerContext& context){
132134
// Route to cave entrance
133-
pbf_press_button(context, BUTTON_B, (uint16_t)(2 * TICKS_PER_SECOND), 10); //Get some distance from the moutain
134-
pbf_press_button(context, BUTTON_Y, (uint16_t)(4 * TICKS_PER_SECOND), 10); //Descend
135+
pbf_press_button(context, BUTTON_B, 2000ms, 80ms); //Get some distance from the moutain
136+
pbf_press_button(context, BUTTON_Y, 4000ms, 80ms); //Descend
135137
pbf_press_button(context, BUTTON_B, DASH_DURATION0, 80ms); //Reach to the cave entrance
136-
pbf_wait(context, (uint16_t)(0.5 * TICKS_PER_SECOND));
137-
pbf_press_button(context, BUTTON_PLUS, 10,10);
138-
pbf_wait(context, (uint16_t)(1.1 * TICKS_PER_SECOND));
139-
pbf_press_button(context, BUTTON_PLUS, 10,10);
140-
pbf_press_button(context, BUTTON_B, (uint16_t)(2.8 * TICKS_PER_SECOND), 10); // Braviary Second Push
138+
pbf_wait(context, 500ms);
139+
pbf_press_button(context, BUTTON_PLUS, 80ms, 80ms);
140+
pbf_wait(context, 1100ms);
141+
pbf_press_button(context, BUTTON_PLUS, 80ms, 80ms);
142+
pbf_press_button(context, BUTTON_B, 2800ms, 80ms); // Braviary Second Push
141143

142144
context.wait_for_all_requests();
145+
destination_time = current_time();
143146
shiny_action.store(&SHINY_DETECTED_DESTINATION, std::memory_order_release);
144147

145148
// Move to Froslass
146-
pbf_press_dpad(context, DPAD_LEFT, 20, 20);
147-
pbf_press_button(context, BUTTON_B, (uint16_t)(4.5 * TICKS_PER_SECOND), 10);
149+
pbf_press_dpad(context, DPAD_LEFT, 160ms, 160ms);
150+
pbf_press_button(context, BUTTON_B, 5000ms, 2000ms);
151+
context.wait_for_all_requests();
152+
148153
},
149154
{{shiny_detector}}
150155
);
151156
shiny_detector.throw_if_no_sound();
152-
if (ret == 0){
157+
if (ret == 0 || shiny_detector.last_detection() > destination_time){
153158
ShinyDetectedActionOption* action = shiny_action.load(std::memory_order_acquire);
154159
on_shiny_sound(env, env.console, context, *action, shiny_coefficient);
155160
}

SerialPrograms/Source/PokemonLA/Programs/ShinyHunting/PokemonLA_GalladeFinder.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ GalladeFinder_Descriptor::GalladeFinder_Descriptor()
3131
"Constantly reset the Snowpoint Temple to find Shiny Alpha Gallade.",
3232
FeedbackType::VIDEO_AUDIO,
3333
AllowCommandsWhenRunning::DISABLE_COMMANDS,
34-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
34+
{ControllerFeature::NintendoSwitch_ProController},
35+
FasterIfTickPrecise::NOT_FASTER
3536
)
3637
{}
3738
class GalladeFinder_Descriptor::Stats : public StatsTracker, public ShinyStatIncrementer{
@@ -105,6 +106,7 @@ void GalladeFinder::run_iteration(SingleSwitchProgramEnvironment& env, ProContro
105106
{
106107
float shiny_coefficient = 1.0;
107108
std::atomic<ShinyDetectedActionOption*> shiny_action(&SHINY_DETECTED_ENROUTE);
109+
WallClock destination_time = WallClock::max();
108110

109111
ShinySoundDetector shiny_detector(env.console, [&](float error_coefficient) -> bool{
110112
// Warning: This callback will be run from a different thread than this function.
@@ -118,43 +120,44 @@ void GalladeFinder::run_iteration(SingleSwitchProgramEnvironment& env, ProContro
118120
env.console, context,
119121
[&](ProControllerContext& context){
120122
// forward portion
121-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, (uint16_t)(6.8 * TICKS_PER_SECOND)); // forward while running until stairs, mash y a few times down the stairs
122-
pbf_mash_button(context, BUTTON_Y,(uint16_t)(2.8 * TICKS_PER_SECOND)); // roll down the stairs, recover stamina
123-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, (uint16_t)(4.0 * TICKS_PER_SECOND)); // forward while sprinting again
124-
pbf_mash_button(context, BUTTON_Y,(uint16_t)(2.0 * TICKS_PER_SECOND)); // two mashes and then one y
125-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, (uint16_t)(3.8 * TICKS_PER_SECOND)); // forward while sprinting again
123+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, 6800ms); // forward while running until stairs, mash y a few times down the stairs
124+
pbf_mash_button(context, BUTTON_Y, 2800ms); // roll down the stairs, recover stamina
125+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, 4000ms); // forward while sprinting again
126+
pbf_mash_button(context, BUTTON_Y, 2000ms); // two mashes and then one y
127+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, 3800ms); // forward while sprinting again
126128
// basic map layout is walk forward for a while, move right, run back, then align camera, then walk left then forward to Gallade
127129

128130
// right portion
129-
pbf_move_left_joystick(context, 255, 128, (uint16_t)(0.5 * TICKS_PER_SECOND), 0); // right alone
130-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 255, 128, 128, 128, (uint16_t)(2.4 * TICKS_PER_SECOND)); // forward while running until stairs
131-
pbf_mash_button(context, BUTTON_Y,(uint16_t)(1.8 * TICKS_PER_SECOND)); // roll down the stairs, recover stamina
132-
pbf_move_left_joystick(context, 255, 128, (uint16_t)(1.8 * TICKS_PER_SECOND), 20); // right alone
131+
pbf_move_left_joystick(context, 255, 128, 500ms, 0ms); // right alone
132+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 255, 128, 128, 128, 2400ms); // forward while running until stairs
133+
pbf_mash_button(context, BUTTON_Y, 1800ms); // roll down the stairs, recover stamina
134+
pbf_move_left_joystick(context, 255, 128, 1800ms, 160ms); // right alone
133135

134136
// down portion
135137
// pbf_move_left_joystick(context, 128, 255, (uint16_t)(1.9 * TICKS_PER_SECOND), 20); // OLD down
136-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 255, 128, 128, (uint16_t)(1.8 * TICKS_PER_SECOND));
138+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 255, 128, 128, 1800ms);
137139

138140
// camera align
139141
pbf_press_button(context, BUTTON_ZL, 20, 0); // camera align
140142
pbf_wait(context, 70);
141143

142144
context.wait_for_all_requests();
145+
destination_time = current_time();
143146
shiny_action.store(&SHINY_DETECTED_DESTINATION, std::memory_order_release);
144147

145-
pbf_move_left_joystick(context, 0, 128, 2 * TICKS_PER_SECOND, 0); // left
148+
pbf_move_left_joystick(context, 0, 128, 2000ms, 0ms); // left
146149

147150
// then forward left
148-
pbf_move_left_joystick(context, 0, 0, (uint16_t)(1.1 * TICKS_PER_SECOND), 0);
151+
pbf_move_left_joystick(context, 0, 0, 1100ms, 0ms);
149152

150153
//pbf_move_left_joystick(context, 128, 0, 3.9 * TICKS_PER_SECOND, 0); // OLD forward
151-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, (uint16_t)(3.5 * TICKS_PER_SECOND)); // forward while sprinting until stairs, mash y a few times down the stairs
154+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, 3500ms); // forward while sprinting until stairs, mash y a few times down the stairs
152155
// we should easily be in range of gallade at this point, so if there's no shiny we're done
153156
},
154157
{{shiny_detector}}
155158
);
156159
shiny_detector.throw_if_no_sound();
157-
if (ret == 0){
160+
if (ret == 0 || shiny_detector.last_detection() > destination_time){
158161
ShinyDetectedActionOption* action = shiny_action.load(std::memory_order_acquire);
159162
on_shiny_sound(env, env.console, context, *action, shiny_coefficient);
160163
}

SerialPrograms/Source/PokemonLA/Programs/ShinyHunting/PokemonLA_UnownFinder.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ UnownFinder_Descriptor::UnownFinder_Descriptor()
3535
"Constantly reset to find a Shiny Unown or any Shiny in the path.",
3636
FeedbackType::VIDEO_AUDIO,
3737
AllowCommandsWhenRunning::DISABLE_COMMANDS,
38-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
38+
{ControllerFeature::NintendoSwitch_ProController},
39+
FasterIfTickPrecise::NOT_FASTER
3940
)
4041
{}
4142
class UnownFinder_Descriptor::Stats : public StatsTracker, public ShinyStatIncrementer{
@@ -127,6 +128,7 @@ void UnownFinder::run_iteration(SingleSwitchProgramEnvironment& env, ProControll
127128
{
128129
float shiny_coefficient = 1.0;
129130
std::atomic<ShinyDetectedActionOption*> shiny_action(&SHINY_DETECTED_ENROUTE);
131+
WallClock destination_time = WallClock::max();
130132

131133
ShinySoundDetector shiny_detector(env.console, [&](float error_coefficient) -> bool{
132134
// Warning: This callback will be run from a different thread than this function.
@@ -142,14 +144,15 @@ void UnownFinder::run_iteration(SingleSwitchProgramEnvironment& env, ProControll
142144
ruins_entrance_route(context);
143145

144146
context.wait_for_all_requests();
147+
destination_time = current_time();
145148
shiny_action.store(&SHINY_DETECTED_DESTINATION, std::memory_order_release);
146149

147150
enter_ruins(context);
148151
},
149152
{{shiny_detector}}
150153
);
151154
shiny_detector.throw_if_no_sound();
152-
if (ret == 0){
155+
if (ret == 0 || shiny_detector.last_detection() > destination_time){
153156
ShinyDetectedActionOption* action = shiny_action.load(std::memory_order_acquire);
154157
on_shiny_sound(env, env.console, context, *action, shiny_coefficient);
155158
}

0 commit comments

Comments
 (0)