Skip to content

Commit

Permalink
Segments 12 to 13
Browse files Browse the repository at this point in the history
  • Loading branch information
jw098 committed Nov 16, 2024
1 parent 7c27a02 commit ae6683b
Show file tree
Hide file tree
Showing 12 changed files with 620 additions and 24 deletions.
6 changes: 5 additions & 1 deletion SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,11 @@ file(GLOB MAIN_SOURCES
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_10.cpp
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_10.h
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.cpp
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.h
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.h
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_12.cpp
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_12.h
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_13.cpp
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_13.h
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp
Expand Down
4 changes: 4 additions & 0 deletions SerialPrograms/SerialPrograms.pro
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,8 @@ SOURCES += \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_09.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_10.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_12.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_13.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp \
Expand Down Expand Up @@ -1834,6 +1836,8 @@ HEADERS += \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_09.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_10.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_12.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_13.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class AdvanceDialogWatcher : public DetectorToFinder<AdvanceDialogDetector>{


// Detect dialog that prompts the player to make a choice.
// i.e. detects that Dialog box and Gradient arrow are present
class PromptDialogDetector : public StaticScreenDetector{
public:
// Will catch any prompt.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ std::vector<ImageFloatBox> DestinationMarkerDetector::detect_all(const ImageView
};


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

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


const double rmsd_threshold = 80.0; // from my testing, RMSD ranges from 15-50, even at 720p
const double rmsd_threshold = 60.0; // from my testing, RMSD ranges from 15-50, even at 720p
/*
- min object size restrictions also helps to filter out false positives
at pokemon centers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,16 @@ void DirectionDetector::change_direction(
double direction
) const{
size_t i = 0;
size_t MAX_ATTEMPTS = 10;
size_t MAX_ATTEMPTS = 20;
bool is_minimap_definitely_unlocked = false;
uint8_t scale_factor = 80;
double push_magnitude_scale_factor = 1;
while (i < MAX_ATTEMPTS){ // 10 attempts to move the direction to the target
context.wait_for_all_requests();
VideoSnapshot screen = console.video().snapshot();
double current = get_current_direction(console, screen);
if (current < 0){
console.log("Unable to detect current direction.");
return;
}
double target = std::fmod(direction, (2 * PI));
Expand Down Expand Up @@ -212,16 +215,23 @@ void DirectionDetector::change_direction(
}
is_minimap_definitely_unlocked = true;

if (abs_diff < 0.02){
if (abs_diff < 0.01){
// return when we're close enough to the target
return;
}

uint8_t scale_factor = 80;

if (scale_factor > 40 && abs_diff < 0.05){
scale_factor = 40;
}

if (abs_diff < 0.05){
push_magnitude_scale_factor = 0.5;
}

uint16_t push_duration = std::max(uint16_t(std::abs(diff * scale_factor)), uint16_t(8));
int16_t push_direction = (diff > 0) ? -1 : 1;
double push_magnitude = std::max(double(128 / (i + 1)), double(20)); // push less with each iteration/attempt
double push_magnitude = std::max(double((128 * push_magnitude_scale_factor) / (i + 1)), double(15)); // push less with each iteration/attempt
uint8_t push_x = uint8_t(std::max(std::min(int(128 + (push_direction * push_magnitude)), 255), 0));
console.log("push magnitude: " + std::to_string(push_x) + ", push duration: " + std::to_string(push_duration));
pbf_move_right_joystick(context, push_x, 128, push_duration, 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ std::pair<double, double> OverworldDetector::locate_ball(const ImageViewRGB32& s

// 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.
// when the ball is fully filled in, it has an area of 550
const double min_object_size = strict_requirements ? 150.0 : 0;
const double min_object_size = strict_requirements ? 150.0 : 50;
const double rmsd_threshold = strict_requirements ? 35.0 : 50.0;

const double screen_rel_size = (screen.height() / 1080.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#include "PokemonSV_AutoStory_Segment_08.h"
#include "PokemonSV_AutoStory_Segment_09.h"
#include "PokemonSV_AutoStory_Segment_10.h"
// #include "PokemonSV_AutoStory_Segment_11.h"
// #include "PokemonSV_AutoStory_Segment_12.h"
// #include "PokemonSV_AutoStory_Segment_13.h"
#include "PokemonSV_AutoStory_Segment_11.h"
#include "PokemonSV_AutoStory_Segment_12.h"
#include "PokemonSV_AutoStory_Segment_13.h"
// #include "PokemonSV_AutoStory_Segment_14.h"
// #include "PokemonSV_AutoStory_Segment_15.h"
#include "PokemonSV_AutoStory.h"
Expand Down Expand Up @@ -61,9 +61,9 @@ std::vector<std::unique_ptr<AutoStory_Segment>> make_autoStory_segment_list(){
segment_list.emplace_back(std::make_unique<AutoStory_Segment_08>());
segment_list.emplace_back(std::make_unique<AutoStory_Segment_09>());
segment_list.emplace_back(std::make_unique<AutoStory_Segment_10>());
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_11>());
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_12>());
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_13>());
segment_list.emplace_back(std::make_unique<AutoStory_Segment_11>());
segment_list.emplace_back(std::make_unique<AutoStory_Segment_12>());
segment_list.emplace_back(std::make_unique<AutoStory_Segment_13>());
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_14>());

return segment_list;
Expand Down Expand Up @@ -483,12 +483,12 @@ void AutoStory::test_checkpoints(
checkpoint_list.push_back([&](){checkpoint_21(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_22(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_23(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_24(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_25(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_26(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_27(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_28(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_29(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_24(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_25(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_26(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_27(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_28(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_29(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_30(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_31(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_32(env, context, notif_status_update);});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/* AutoStory
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/

#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/Exceptions/FatalProgramException.h"
#include "CommonFramework/Exceptions/OperationFailedException.h"
#include "CommonFramework/InferenceInfra/InferenceRoutines.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonFramework/Tools/StatsTracking.h"
#include "CommonFramework/Tools/VideoResolutionCheck.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "Pokemon/Pokemon_Strings.h"
#include "PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h"
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
#include "PokemonSV/Programs/PokemonSV_SaveGame.h"
#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h"
#include "PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h"
#include "PokemonSV/Inference/Overworld/PokemonSV_NoMinimapDetector.h"
#include "PokemonSV_AutoStoryTools.h"
#include "PokemonSV_AutoStory_Segment_12.h"

//#include <iostream>
//using std::cout;
//using std::endl;
//#include <unordered_map>
//#include <algorithm>

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{

using namespace Pokemon;




std::string AutoStory_Segment_12::name() const{
return "10.3: Cortondo Gym - Gym battle";
}

std::string AutoStory_Segment_12::start_text() const{
return "Start: Beat Cortondo Gym challenge.";
}

std::string AutoStory_Segment_12::end_text() const{
return "End: Beat Cortondo Gym battle. At Cortondo West Pokecenter.";
}


void AutoStory_Segment_12::run_segment(SingleSwitchProgramEnvironment& env, BotBaseContext& context, AutoStoryOptions options) const{
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();

context.wait_for_all_requests();
env.console.overlay().add_log("Start Segment 10.3: Cortondo Gym - Gym battle", COLOR_ORANGE);

checkpoint_28(env, context, options.notif_status_update);

context.wait_for_all_requests();
env.console.log("End Segment 10.3: Cortondo Gym - Gym battle", COLOR_GREEN);
stats.m_segment++;
env.update_stats();

}


void checkpoint_28(
SingleSwitchProgramEnvironment& env,
BotBaseContext& context,
EventNotificationOption& notif_status_update
){
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
bool first_attempt = true;
while (true){
try{
if (first_attempt){
checkpoint_save(env, context, notif_status_update);
first_attempt = false;
}
context.wait_for_all_requests();
DirectionDetector direction;
do_action_and_monitor_for_battles(env.program_info(), env.console, context,
[&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
direction.change_direction(env.program_info(), env.console, context, 2.71);
pbf_move_left_joystick(context, 128, 0, 375, 100);
direction.change_direction(env.program_info(), env.console, context, 1.26);
pbf_move_left_joystick(context, 128, 0, 1750, 100);
});

direction.change_direction(env.program_info(), env.console, context, 2.73);

NoMinimapWatcher no_minimap(env.console, COLOR_RED, Milliseconds(2000));
int ret = run_until(
env.console, context,
[&](BotBaseContext& context){
handle_when_stationary_in_overworld(env.program_info(), env.console, context,
[&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
pbf_move_left_joystick(context, 128, 0, 10 * TICKS_PER_SECOND, 100);
},
[&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
pbf_move_left_joystick(context, 0, 0, 100, 20);
},
5, 3
);
},
{no_minimap}
);
if (ret < 0){
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT,
env.logger(),
"Failed to enter Cortondo Gym."
);
}

wait_for_overworld(env.program_info(), env.console, context);

// talk to receptionist
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 10);
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW});

// battle Katy
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::GRADIENT_ARROW}, true);
mash_button_till_overworld(env.console, context, BUTTON_A, 360);

// leave gym building
pbf_move_left_joystick(context, 128, 255, 500, 100);
pbf_wait(context, 3 * TICKS_PER_SECOND);
// wait for overworld after leaving gym
wait_for_overworld(env.program_info(), env.console, context, 30);

pbf_move_left_joystick(context, 128, 0, 450, 100);
direction.change_direction(env.program_info(), env.console, context, 1.26);
pbf_move_left_joystick(context, 128, 0, 1600, 100);
fly_to_overlapping_flypoint(env.program_info(), env.console, context);

break;
}catch (...){
context.wait_for_all_requests();
env.console.log("Resetting from checkpoint.");
reset_game(env.program_info(), env.console, context);
stats.m_reset++;
env.update_stats();
}
}

}




}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Autostory
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/

#ifndef PokemonAutomation_PokemonSV_AutoStory_Segment_12_H
#define PokemonAutomation_PokemonSV_AutoStory_Segment_12_H

#include <functional>
#include "Common/Cpp/Options/EnumDropdownOption.h"
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "CommonFramework/Options/LanguageOCROption.h"
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h"
#include "PokemonSV/Programs/PokemonSV_Navigation.h"
#include "PokemonSV_AutoStoryTools.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{

class AutoStory_Segment_12 : public AutoStory_Segment{
public:
virtual std::string name() const override;
virtual std::string start_text() const override;
virtual std::string end_text() const override;
virtual void run_segment(
SingleSwitchProgramEnvironment& env,
BotBaseContext& context,
AutoStoryOptions options) const override;
};

// start: At Cortondo East Pokecenter.
// end: Beat Cortondo Gym. At Cortondo West Pokecenter.
void checkpoint_28(SingleSwitchProgramEnvironment& env, BotBaseContext& context, EventNotificationOption& notif_status_update);

}
}
}
#endif
Loading

0 comments on commit ae6683b

Please sign in to comment.