Skip to content

Commit 219e6b7

Browse files
authored
Segments 12 to 13 (#511)
* Segments 12 to 13 * remove spaces
1 parent 7c27a02 commit 219e6b7

12 files changed

+619
-23
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,11 @@ file(GLOB MAIN_SOURCES
14611461
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_10.cpp
14621462
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_10.h
14631463
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.cpp
1464-
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.h
1464+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.h
1465+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_12.cpp
1466+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_12.h
1467+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_13.cpp
1468+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_13.h
14651469
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp
14661470
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h
14671471
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,8 @@ SOURCES += \
730730
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_09.cpp \
731731
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_10.cpp \
732732
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.cpp \
733+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_12.cpp \
734+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_13.cpp \
733735
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp \
734736
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp \
735737
Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp \
@@ -1834,6 +1836,8 @@ HEADERS += \
18341836
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_09.h \
18351837
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_10.h \
18361838
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.h \
1839+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_12.h \
1840+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_13.h \
18371841
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h \
18381842
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h \
18391843
Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h \

SerialPrograms/Source/PokemonSV/Inference/Dialogs/PokemonSV_DialogDetector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class AdvanceDialogWatcher : public DetectorToFinder<AdvanceDialogDetector>{
8080

8181

8282
// Detect dialog that prompts the player to make a choice.
83+
// i.e. detects that Dialog box and Gradient arrow are present
8384
class PromptDialogDetector : public StaticScreenDetector{
8485
public:
8586
// Will catch any prompt.

SerialPrograms/Source/PokemonSV/Inference/Map/PokemonSV_DestinationMarkerDetector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ std::vector<ImageFloatBox> DestinationMarkerDetector::detect_all(const ImageView
8888
};
8989

9090

91-
const double rmsd_threshold = 80.0; // from my testing: RMSD is 15 at 1080p, 60 at 720p
91+
const double rmsd_threshold = 65.0; // from my testing: RMSD is 15 at 1080p, 60 at 720p
9292
const double min_object_size = 150.0;
9393

9494
const double screen_rel_size = (screen.height() / 1080.0);
@@ -123,7 +123,7 @@ std::vector<ImageFloatBox> DestinationMarkerDetector::detect_all_yellow(const Im
123123
};
124124

125125

126-
const double rmsd_threshold = 80.0; // from my testing, RMSD ranges from 15-50, even at 720p
126+
const double rmsd_threshold = 60.0; // from my testing, RMSD ranges from 15-50, even at 720p
127127
/*
128128
- min object size restrictions also helps to filter out false positives
129129
at pokemon centers

SerialPrograms/Source/PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,16 @@ void DirectionDetector::change_direction(
170170
double direction
171171
) const{
172172
size_t i = 0;
173-
size_t MAX_ATTEMPTS = 10;
173+
size_t MAX_ATTEMPTS = 20;
174174
bool is_minimap_definitely_unlocked = false;
175+
uint8_t scale_factor = 80;
176+
double push_magnitude_scale_factor = 1;
175177
while (i < MAX_ATTEMPTS){ // 10 attempts to move the direction to the target
176178
context.wait_for_all_requests();
177179
VideoSnapshot screen = console.video().snapshot();
178180
double current = get_current_direction(console, screen);
179181
if (current < 0){
182+
console.log("Unable to detect current direction.");
180183
return;
181184
}
182185
double target = std::fmod(direction, (2 * PI));
@@ -212,16 +215,23 @@ void DirectionDetector::change_direction(
212215
}
213216
is_minimap_definitely_unlocked = true;
214217

215-
if (abs_diff < 0.02){
218+
if (abs_diff < 0.01){
216219
// return when we're close enough to the target
217220
return;
218221
}
219222

220-
uint8_t scale_factor = 80;
223+
224+
if (scale_factor > 40 && abs_diff < 0.05){
225+
scale_factor = 40;
226+
}
227+
228+
if (abs_diff < 0.05){
229+
push_magnitude_scale_factor = 0.5;
230+
}
221231

222232
uint16_t push_duration = std::max(uint16_t(std::abs(diff * scale_factor)), uint16_t(8));
223233
int16_t push_direction = (diff > 0) ? -1 : 1;
224-
double push_magnitude = std::max(double(128 / (i + 1)), double(20)); // push less with each iteration/attempt
234+
double push_magnitude = std::max(double((128 * push_magnitude_scale_factor) / (i + 1)), double(15)); // push less with each iteration/attempt
225235
uint8_t push_x = uint8_t(std::max(std::min(int(128 + (push_direction * push_magnitude)), 255), 0));
226236
console.log("push magnitude: " + std::to_string(push_x) + ", push duration: " + std::to_string(push_duration));
227237
pbf_move_right_joystick(context, push_x, 128, push_duration, 100);

SerialPrograms/Source/PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ std::pair<double, double> OverworldDetector::locate_ball(const ImageViewRGB32& s
9494

9595
// yellow arrow has area of 70-80. the yellow ball, when only partially filled (i.e. only the outer ring is waterfilled), has an area of 200.
9696
// when the ball is fully filled in, it has an area of 550
97-
const double min_object_size = strict_requirements ? 150.0 : 0;
97+
const double min_object_size = strict_requirements ? 150.0 : 50;
9898
const double rmsd_threshold = strict_requirements ? 35.0 : 50.0;
9999

100100
const double screen_rel_size = (screen.height() / 1080.0);

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
#include "PokemonSV_AutoStory_Segment_08.h"
2727
#include "PokemonSV_AutoStory_Segment_09.h"
2828
#include "PokemonSV_AutoStory_Segment_10.h"
29-
// #include "PokemonSV_AutoStory_Segment_11.h"
30-
// #include "PokemonSV_AutoStory_Segment_12.h"
31-
// #include "PokemonSV_AutoStory_Segment_13.h"
29+
#include "PokemonSV_AutoStory_Segment_11.h"
30+
#include "PokemonSV_AutoStory_Segment_12.h"
31+
#include "PokemonSV_AutoStory_Segment_13.h"
3232
// #include "PokemonSV_AutoStory_Segment_14.h"
3333
// #include "PokemonSV_AutoStory_Segment_15.h"
3434
#include "PokemonSV_AutoStory.h"
@@ -61,9 +61,9 @@ std::vector<std::unique_ptr<AutoStory_Segment>> make_autoStory_segment_list(){
6161
segment_list.emplace_back(std::make_unique<AutoStory_Segment_08>());
6262
segment_list.emplace_back(std::make_unique<AutoStory_Segment_09>());
6363
segment_list.emplace_back(std::make_unique<AutoStory_Segment_10>());
64-
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_11>());
65-
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_12>());
66-
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_13>());
64+
segment_list.emplace_back(std::make_unique<AutoStory_Segment_11>());
65+
segment_list.emplace_back(std::make_unique<AutoStory_Segment_12>());
66+
segment_list.emplace_back(std::make_unique<AutoStory_Segment_13>());
6767
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_14>());
6868

6969
return segment_list;
@@ -483,12 +483,12 @@ void AutoStory::test_checkpoints(
483483
checkpoint_list.push_back([&](){checkpoint_21(env, context, notif_status_update);});
484484
checkpoint_list.push_back([&](){checkpoint_22(env, context, notif_status_update);});
485485
checkpoint_list.push_back([&](){checkpoint_23(env, context, notif_status_update);});
486-
// checkpoint_list.push_back([&](){checkpoint_24(env, context, notif_status_update);});
487-
// checkpoint_list.push_back([&](){checkpoint_25(env, context, notif_status_update);});
488-
// checkpoint_list.push_back([&](){checkpoint_26(env, context, notif_status_update);});
489-
// checkpoint_list.push_back([&](){checkpoint_27(env, context, notif_status_update);});
490-
// checkpoint_list.push_back([&](){checkpoint_28(env, context, notif_status_update);});
491-
// checkpoint_list.push_back([&](){checkpoint_29(env, context, notif_status_update);});
486+
checkpoint_list.push_back([&](){checkpoint_24(env, context, notif_status_update);});
487+
checkpoint_list.push_back([&](){checkpoint_25(env, context, notif_status_update);});
488+
checkpoint_list.push_back([&](){checkpoint_26(env, context, notif_status_update);});
489+
checkpoint_list.push_back([&](){checkpoint_27(env, context, notif_status_update);});
490+
checkpoint_list.push_back([&](){checkpoint_28(env, context, notif_status_update);});
491+
checkpoint_list.push_back([&](){checkpoint_29(env, context, notif_status_update);});
492492
// checkpoint_list.push_back([&](){checkpoint_30(env, context, notif_status_update);});
493493
// checkpoint_list.push_back([&](){checkpoint_31(env, context, notif_status_update);});
494494
// checkpoint_list.push_back([&](){checkpoint_32(env, context, notif_status_update);});
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/* AutoStory
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "CommonFramework/GlobalSettingsPanel.h"
8+
#include "CommonFramework/Exceptions/FatalProgramException.h"
9+
#include "CommonFramework/Exceptions/OperationFailedException.h"
10+
#include "CommonFramework/InferenceInfra/InferenceRoutines.h"
11+
#include "CommonFramework/Notifications/ProgramNotifications.h"
12+
#include "CommonFramework/Tools/StatsTracking.h"
13+
#include "CommonFramework/Tools/VideoResolutionCheck.h"
14+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
15+
#include "Pokemon/Pokemon_Strings.h"
16+
#include "PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h"
17+
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
18+
#include "PokemonSV/Programs/PokemonSV_SaveGame.h"
19+
#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h"
20+
#include "PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h"
21+
#include "PokemonSV/Inference/Overworld/PokemonSV_NoMinimapDetector.h"
22+
#include "PokemonSV_AutoStoryTools.h"
23+
#include "PokemonSV_AutoStory_Segment_12.h"
24+
25+
//#include <iostream>
26+
//using std::cout;
27+
//using std::endl;
28+
//#include <unordered_map>
29+
//#include <algorithm>
30+
31+
namespace PokemonAutomation{
32+
namespace NintendoSwitch{
33+
namespace PokemonSV{
34+
35+
using namespace Pokemon;
36+
37+
38+
39+
40+
std::string AutoStory_Segment_12::name() const{
41+
return "10.3: Cortondo Gym - Gym battle";
42+
}
43+
44+
std::string AutoStory_Segment_12::start_text() const{
45+
return "Start: Beat Cortondo Gym challenge.";
46+
}
47+
48+
std::string AutoStory_Segment_12::end_text() const{
49+
return "End: Beat Cortondo Gym battle. At Cortondo West Pokecenter.";
50+
}
51+
52+
53+
void AutoStory_Segment_12::run_segment(SingleSwitchProgramEnvironment& env, BotBaseContext& context, AutoStoryOptions options) const{
54+
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
55+
56+
context.wait_for_all_requests();
57+
env.console.overlay().add_log("Start Segment 10.3: Cortondo Gym - Gym battle", COLOR_ORANGE);
58+
59+
checkpoint_28(env, context, options.notif_status_update);
60+
61+
context.wait_for_all_requests();
62+
env.console.log("End Segment 10.3: Cortondo Gym - Gym battle", COLOR_GREEN);
63+
stats.m_segment++;
64+
env.update_stats();
65+
66+
}
67+
68+
69+
void checkpoint_28(
70+
SingleSwitchProgramEnvironment& env,
71+
BotBaseContext& context,
72+
EventNotificationOption& notif_status_update
73+
){
74+
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
75+
bool first_attempt = true;
76+
while (true){
77+
try{
78+
if (first_attempt){
79+
checkpoint_save(env, context, notif_status_update);
80+
first_attempt = false;
81+
}
82+
context.wait_for_all_requests();
83+
DirectionDetector direction;
84+
do_action_and_monitor_for_battles(env.program_info(), env.console, context,
85+
[&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
86+
direction.change_direction(env.program_info(), env.console, context, 2.71);
87+
pbf_move_left_joystick(context, 128, 0, 375, 100);
88+
direction.change_direction(env.program_info(), env.console, context, 1.26);
89+
pbf_move_left_joystick(context, 128, 0, 1750, 100);
90+
});
91+
92+
direction.change_direction(env.program_info(), env.console, context, 2.73);
93+
94+
NoMinimapWatcher no_minimap(env.console, COLOR_RED, Milliseconds(2000));
95+
int ret = run_until(
96+
env.console, context,
97+
[&](BotBaseContext& context){
98+
handle_when_stationary_in_overworld(env.program_info(), env.console, context,
99+
[&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
100+
pbf_move_left_joystick(context, 128, 0, 10 * TICKS_PER_SECOND, 100);
101+
},
102+
[&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
103+
pbf_move_left_joystick(context, 0, 0, 100, 20);
104+
},
105+
5, 3
106+
);
107+
},
108+
{no_minimap}
109+
);
110+
if (ret < 0){
111+
throw OperationFailedException(
112+
ErrorReport::SEND_ERROR_REPORT,
113+
env.logger(),
114+
"Failed to enter Cortondo Gym."
115+
);
116+
}
117+
118+
wait_for_overworld(env.program_info(), env.console, context);
119+
120+
// talk to receptionist
121+
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 10);
122+
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW});
123+
124+
// battle Katy
125+
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::GRADIENT_ARROW}, true);
126+
mash_button_till_overworld(env.console, context, BUTTON_A, 360);
127+
128+
// leave gym building
129+
pbf_move_left_joystick(context, 128, 255, 500, 100);
130+
pbf_wait(context, 3 * TICKS_PER_SECOND);
131+
// wait for overworld after leaving gym
132+
wait_for_overworld(env.program_info(), env.console, context, 30);
133+
134+
pbf_move_left_joystick(context, 128, 0, 450, 100);
135+
direction.change_direction(env.program_info(), env.console, context, 1.26);
136+
pbf_move_left_joystick(context, 128, 0, 1600, 100);
137+
fly_to_overlapping_flypoint(env.program_info(), env.console, context);
138+
139+
break;
140+
}catch (...){
141+
context.wait_for_all_requests();
142+
env.console.log("Resetting from checkpoint.");
143+
reset_game(env.program_info(), env.console, context);
144+
stats.m_reset++;
145+
env.update_stats();
146+
}
147+
}
148+
149+
}
150+
151+
152+
153+
154+
}
155+
}
156+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* Autostory
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonSV_AutoStory_Segment_12_H
8+
#define PokemonAutomation_PokemonSV_AutoStory_Segment_12_H
9+
10+
#include <functional>
11+
#include "Common/Cpp/Options/EnumDropdownOption.h"
12+
#include "CommonFramework/Notifications/EventNotificationsTable.h"
13+
#include "CommonFramework/Options/LanguageOCROption.h"
14+
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
15+
#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h"
16+
#include "PokemonSV/Programs/PokemonSV_Navigation.h"
17+
#include "PokemonSV_AutoStoryTools.h"
18+
19+
namespace PokemonAutomation{
20+
namespace NintendoSwitch{
21+
namespace PokemonSV{
22+
23+
class AutoStory_Segment_12 : public AutoStory_Segment{
24+
public:
25+
virtual std::string name() const override;
26+
virtual std::string start_text() const override;
27+
virtual std::string end_text() const override;
28+
virtual void run_segment(
29+
SingleSwitchProgramEnvironment& env,
30+
BotBaseContext& context,
31+
AutoStoryOptions options) const override;
32+
};
33+
34+
// start: At Cortondo East Pokecenter.
35+
// end: Beat Cortondo Gym. At Cortondo West Pokecenter.
36+
void checkpoint_28(SingleSwitchProgramEnvironment& env, BotBaseContext& context, EventNotificationOption& notif_status_update);
37+
38+
}
39+
}
40+
}
41+
#endif

0 commit comments

Comments
 (0)