Skip to content

Commit 1058faf

Browse files
committed
checkpoint_104: defeat AI professor
1 parent c6be34c commit 1058faf

File tree

4 files changed

+88
-10
lines changed

4 files changed

+88
-10
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ std::vector<std::unique_ptr<AutoStory_Segment>> make_autoStory_segment_list(){
135135
segment_list.emplace_back(std::make_unique<AutoStory_Segment_37>());
136136
segment_list.emplace_back(std::make_unique<AutoStory_Segment_38>());
137137
segment_list.emplace_back(std::make_unique<AutoStory_Segment_39>());
138-
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_40>());
138+
segment_list.emplace_back(std::make_unique<AutoStory_Segment_40>());
139139
}
140140
return segment_list;
141141
};
@@ -311,7 +311,7 @@ std::vector<std::unique_ptr<AutoStory_Checkpoint>> make_autoStory_checkpoint_lis
311311
checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_101>());
312312
checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_102>());
313313
checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_103>());
314-
// checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_104>());
314+
checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_104>());
315315
// checkpoint_list.emplace_back(std::make_unique<AutoStory_Checkpoint_105>());
316316

317317
}
@@ -1053,7 +1053,7 @@ void AutoStory::test_checkpoints(
10531053
checkpoint_list.push_back([&](){checkpoint_101(env, context, notif_status_update, stats);});
10541054
checkpoint_list.push_back([&](){checkpoint_102(env, context, notif_status_update, stats);});
10551055
checkpoint_list.push_back([&](){checkpoint_103(env, context, notif_status_update, stats);});
1056-
// checkpoint_list.push_back([&](){checkpoint_104(env, context, notif_status_update, stats);});
1056+
checkpoint_list.push_back([&](){checkpoint_104(env, context, notif_status_update, stats);});
10571057
// checkpoint_list.push_back([&](){checkpoint_105(env, context, notif_status_update, stats);});
10581058

10591059

@@ -1303,7 +1303,7 @@ void AutoStory::test_code(SingleSwitchProgramEnvironment& env, ProControllerCont
13031303
// move_camera_yolo(env, context, CameraAxis::Y, yolo_detector, "tree-tera", 0.294444);
13041304
// move_camera_yolo(env, context, CameraAxis::X, yolo_detector, "tree-tera", 0.604688);
13051305

1306-
1306+
13071307

13081308
return;
13091309
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ void clear_tutorial(VideoStream& stream, ProControllerContext& context, uint16_t
7979

8080
void clear_dialog(VideoStream& stream, ProControllerContext& context,
8181
ClearDialogMode mode, uint16_t seconds_timeout,
82-
std::vector<CallbackEnum> enum_optional_callbacks
82+
std::vector<CallbackEnum> enum_optional_callbacks,
83+
bool press_A
8384
){
8485
bool seen_dialog = false;
8586
WallClock start = current_time();
@@ -148,7 +149,7 @@ void clear_dialog(VideoStream& stream, ProControllerContext& context,
148149
stream, context,
149150
[&](ProControllerContext& context){
150151

151-
if (mode == ClearDialogMode::STOP_TIMEOUT){
152+
if (mode == ClearDialogMode::STOP_TIMEOUT || !press_A){
152153
context.wait_for(Seconds(seconds_timeout));
153154
}else{ // press A every 8 seconds, until we time out.
154155
auto button_press_period = Seconds(8);
@@ -208,6 +209,9 @@ void clear_dialog(VideoStream& stream, ProControllerContext& context,
208209
case CallbackEnum::DIALOG_ARROW:
209210
stream.log("clear_dialog: Detected dialog arrow.");
210211
seen_dialog = true;
212+
if (mode == ClearDialogMode::STOP_BATTLE_DIALOG_ARROW){
213+
return;
214+
}
211215
pbf_press_button(context, BUTTON_A, 20, 105);
212216
break;
213217
case CallbackEnum::BATTLE:

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum class ClearDialogMode{
4545
STOP_TIMEOUT,
4646
STOP_BATTLE,
4747
STOP_TUTORIAL,
48+
STOP_BATTLE_DIALOG_ARROW,
4849
};
4950

5051

@@ -125,7 +126,8 @@ void clear_tutorial(VideoStream& stream, ProControllerContext& context, uint16_t
125126
// also throw exception if dialog is never detected.
126127
void clear_dialog(VideoStream& stream, ProControllerContext& context,
127128
ClearDialogMode mode, uint16_t seconds_timeout = 60,
128-
std::vector<CallbackEnum> optional_callbacks = {}
129+
std::vector<CallbackEnum> optional_callbacks = {},
130+
bool press_A = true
129131
);
130132

131133

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

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*
55
*/
66

7+
#include "PokemonSV/Programs/Battles/PokemonSV_SinglesBattler.h"
8+
79
#include "CommonFramework/Exceptions/OperationFailedException.h"
810
#include "CommonTools/Async/InferenceRoutines.h"
911
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
@@ -74,11 +76,81 @@ void AutoStory_Checkpoint_104::run_checkpoint(SingleSwitchProgramEnvironment& en
7476
// }
7577

7678
void checkpoint_104(SingleSwitchProgramEnvironment& env, ProControllerContext& context, EventNotificationOption& notif_status_update, AutoStoryStats& stats){
77-
// checkpoint_reattempt_loop(env, context, notif_status_update, stats,
78-
// [&](size_t attempt_number){
79+
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
80+
[&](size_t attempt_number){
81+
82+
pbf_press_button(context, BUTTON_L, 30, 10);
83+
pbf_move_left_joystick(context, 128, 0, 400, 50);
84+
pbf_move_left_joystick(context, 0, 128, 130, 50);
85+
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 10);
86+
87+
// now in elevator
88+
mash_button_till_overworld(env.console, context, BUTTON_A);
89+
90+
pbf_move_left_joystick(context, 255, 128, 70, 50);
91+
92+
// talk to the AI professor
93+
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 10);
94+
mash_button_till_overworld(env.console, context, BUTTON_A);
95+
96+
// put the book in the machine
97+
pbf_press_button(context, BUTTON_L, 30, 10);
98+
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 10);
99+
100+
101+
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 120, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW});
102+
103+
104+
env.console.log("Battle AI Professor.");
105+
SinglesMoveEntry move1{SinglesMoveType::Move1, false}; // Moonblast
106+
SinglesMoveEntry move3{SinglesMoveType::Move3, false}; // Psychic
107+
108+
109+
std::vector<SinglesMoveEntry> move_table1 = {move3, move1};
110+
bool terastallized = false;
111+
// start with Psychic to defeat Iron Moth for Violet, which quad resists Moonblast.
112+
bool is_won = run_pokemon(env.console, context, move_table1, true, terastallized);
113+
if (!is_won){// throw exception if we lose
114+
OperationFailedException::fire(
115+
ErrorReport::SEND_ERROR_REPORT,
116+
"Failed to beat the AI Professor. Reset.",
117+
env.console
118+
);
119+
}
120+
121+
122+
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE_DIALOG_ARROW, 120, {CallbackEnum::DIALOG_ARROW}, false);
123+
124+
pbf_mash_button(context, BUTTON_A, 50);
125+
126+
127+
wait_for_gradient_arrow(env.program_info(), env.console, context, {0.75, 0.62, 0.05, 0.35}, 30);
128+
129+
pbf_press_dpad(context, DPAD_DOWN, 13, 20);
130+
pbf_mash_button(context, BUTTON_A, 20);
131+
132+
pbf_wait(context, 1000ms);
133+
pbf_press_dpad(context, DPAD_UP, 13, 20);
134+
pbf_mash_button(context, BUTTON_A, 500);
135+
136+
env.console.log("Battle AI Professor's Koraidon/Miraidon.");
137+
SinglesMoveEntry move4{SinglesMoveType::Move4, false}; // Koraidon/Miraidon: Tera Blast
138+
SinglesMoveEntry move4_tera{SinglesMoveType::Move4, true}; // Koraidon/Miraidon: Tera Blast
139+
std::vector<SinglesMoveEntry> move_table2 = {move4, move4, move4, move4, move4, move4_tera};
140+
is_won = run_pokemon(env.console, context, move_table2, true, terastallized);
141+
if (!is_won){// throw exception if we lose
142+
OperationFailedException::fire(
143+
ErrorReport::SEND_ERROR_REPORT,
144+
"Failed to beat the AI Professor, round 2. This shouldn't be possible. Reset.",
145+
env.console
146+
);
147+
}
148+
149+
mash_button_till_overworld(env.console, context, BUTTON_A, 800);
150+
79151

80152

81-
// });
153+
});
82154
}
83155

84156
void checkpoint_105(SingleSwitchProgramEnvironment& env, ProControllerContext& context, EventNotificationOption& notif_status_update, AutoStoryStats& stats){

0 commit comments

Comments
 (0)