From b76d4cba19f318815a1d9519f566279dee3a0996 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 25 Oct 2026 02:04:18 -0700 Subject: [PATCH 01/26] AutoStory: build the start/end select databases with one shared helper SV built six near-identical databases by hand. make_story_select_database() in Pokemon/AutoStory builds a section of a story list with the same labels (name()) and slugs (index in the whole list), so other games can reuse it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/Pokemon_AutoStorySelect.h | 37 ++++++++ .../AutoStory/PokemonSV_AutoStory.cpp | 91 ++++--------------- SerialPrograms/cmake/SourceFiles.cmake | 1 + 3 files changed, 57 insertions(+), 72 deletions(-) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h new file mode 100644 index 0000000000..80b4f94338 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h @@ -0,0 +1,37 @@ +/* AutoStory Select + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_AutoStorySelect_H +#define PokemonAutomation_Pokemon_AutoStorySelect_H + +#include +#include +#include +#include "CommonTools/Options/StringSelectOption.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// A dropdown database of the story segments or checkpoints [begin, end) of +// `list`, labeled by their name() and slugged by their index in the whole +// list, so a slug picks the same entry whichever section it was chosen from. +template +StringSelectDatabase make_story_select_database( + const std::vector>& list, + size_t begin, size_t end +){ + StringSelectDatabase ret; + for (size_t i = begin; i < end && i < list.size(); i++){ + ret.add_entry(StringSelectEntry(std::to_string(i), list[i]->name())); + } + return ret; +} + + +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp index a805a15080..aec8b25ff5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp @@ -28,6 +28,7 @@ #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "VideoGames/PokemonSV/PokemonSV_Settings.h" #include "Pokemon/Pokemon_Strings.h" +#include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h" #include "VideoGames/PokemonSV/Inference/PokemonSV_MainMenuDetector.h" #include "VideoGames/PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h" @@ -149,51 +150,24 @@ const std::vector>& ALL_AUTO_STORY_SEGMENT_LI } -StringSelectDatabase make_all_segments_database(){ - StringSelectDatabase ret; - int index_num = 0; - for (const auto& segment : ALL_AUTO_STORY_SEGMENT_LIST()){ - ret.add_entry(StringSelectEntry(std::to_string(index_num), segment->name())); - index_num++; - } - return ret; -} const StringSelectDatabase& ALL_SEGMENTS_SELECT_DATABASE(){ - static StringSelectDatabase database = make_all_segments_database(); + static StringSelectDatabase database = make_story_select_database( + ALL_AUTO_STORY_SEGMENT_LIST(), 0, ALL_AUTO_STORY_SEGMENT_LIST().size() + ); return database; } -StringSelectDatabase make_tutorial_segments_database(){ - StringSelectDatabase ret; - const StringSelectDatabase& all_segments = ALL_SEGMENTS_SELECT_DATABASE(); - size_t start = 0; - size_t end = INDEX_OF_LAST_TUTORIAL_SEGMENT + 1; - for (size_t i = start; i < end; i++){ - const auto& segment = all_segments[i]; - ret.add_entry(segment); - } - return ret; -} - const StringSelectDatabase& TUTORIAL_SEGMENTS_SELECT_DATABASE(){ - static StringSelectDatabase database = make_tutorial_segments_database(); + static StringSelectDatabase database = make_story_select_database( + ALL_AUTO_STORY_SEGMENT_LIST(), 0, INDEX_OF_LAST_TUTORIAL_SEGMENT + 1 + ); return database; } -StringSelectDatabase make_mainstory_segments_database(){ - StringSelectDatabase ret; - const StringSelectDatabase& all_segments = ALL_SEGMENTS_SELECT_DATABASE(); - size_t start = INDEX_OF_LAST_TUTORIAL_SEGMENT + 1; - size_t end = all_segments.case_list().size(); - for (size_t i = start; i < end; i++){ - const auto& segment = all_segments[i]; - ret.add_entry(segment); - } - return ret; -} - const StringSelectDatabase& MAINSTORY_SEGMENTS_SELECT_DATABASE(){ - static StringSelectDatabase database = make_mainstory_segments_database(); + static StringSelectDatabase database = make_story_select_database( + ALL_AUTO_STORY_SEGMENT_LIST(), INDEX_OF_LAST_TUTORIAL_SEGMENT + 1, ALL_AUTO_STORY_SEGMENT_LIST().size() + ); return database; } @@ -323,51 +297,24 @@ const std::vector>& ALL_AUTO_STORY_CHECKPO return checkpoint_list; } -StringSelectDatabase make_all_checkpoints_database(){ - StringSelectDatabase ret; - int index_num = 0; - for (const auto& segment : ALL_AUTO_STORY_CHECKPOINT_LIST()){ - ret.add_entry(StringSelectEntry(std::to_string(index_num), segment->name())); - index_num++; - } - return ret; -} const StringSelectDatabase& ALL_CHECKPOINTS_SELECT_DATABASE(){ - static StringSelectDatabase database = make_all_checkpoints_database(); + static StringSelectDatabase database = make_story_select_database( + ALL_AUTO_STORY_CHECKPOINT_LIST(), 0, ALL_AUTO_STORY_CHECKPOINT_LIST().size() + ); return database; } -StringSelectDatabase make_tutorial_checkpoints_database(){ - StringSelectDatabase ret; - const StringSelectDatabase& all_checkpoints = ALL_CHECKPOINTS_SELECT_DATABASE(); - size_t start = 0; - size_t end = INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1; - for (size_t i = start; i < end; i++){ - const auto& segment = all_checkpoints[i]; - ret.add_entry(segment); - } - return ret; -} - const StringSelectDatabase& TUTORIAL_CHECKPOINTS_SELECT_DATABASE(){ - static StringSelectDatabase database = make_tutorial_checkpoints_database(); + static StringSelectDatabase database = make_story_select_database( + ALL_AUTO_STORY_CHECKPOINT_LIST(), 0, INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1 + ); return database; } -StringSelectDatabase make_mainstory_checkpoints_database(){ - StringSelectDatabase ret; - const StringSelectDatabase& all_checkpoints = ALL_CHECKPOINTS_SELECT_DATABASE(); - size_t start = INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1; - size_t end = all_checkpoints.case_list().size(); - for (size_t i = start; i < end; i++){ - const auto& segment = all_checkpoints[i]; - ret.add_entry(segment); - } - return ret; -} - const StringSelectDatabase& MAINSTORY_CHECKPOINTS_SELECT_DATABASE(){ - static StringSelectDatabase database = make_mainstory_checkpoints_database(); + static StringSelectDatabase database = make_story_select_database( + ALL_AUTO_STORY_CHECKPOINT_LIST(), INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1, ALL_AUTO_STORY_CHECKPOINT_LIST().size() + ); return database; } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index e04611c3ef..3c444ef3c5 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1435,6 +1435,7 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Options/Pokemon_NameSelectWidget.h Source/Pokemon/Options/Pokemon_StatsHuntFilter.cpp Source/Pokemon/Options/Pokemon_StatsHuntFilter.h + Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h Source/Pokemon/Pokemon_AdvRng.cpp Source/Pokemon/Pokemon_AdvRng.h Source/Pokemon/Pokemon_BdspRng.cpp From 198b2071495b7333422aff373a2a3e66b01f23af Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 25 Oct 2026 02:10:00 -0700 Subject: [PATCH 02/26] AutoStory: compute start/end story indices with one shared function, with tests Depends on the shared select database commit. The six SV index helpers and the two descriptions repeated the same tutorial/main-story offset maths; story_index() does it once and is tested with SV's offsets. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/Pokemon_AutoStorySelect.h | 7 ++ .../VideoGames/PokemonSV/PokemonSV_Tests.cpp | 99 +++++++++++++++++++ .../AutoStory/PokemonSV_AutoStory.cpp | 74 +++++--------- 3 files changed, 132 insertions(+), 48 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h index 80b4f94338..01318b85ce 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h @@ -32,6 +32,13 @@ StringSelectDatabase make_story_select_database( } +// The index in the whole story list of entry `index_in_section` of the +// tutorial or the main story, whose first entry is `first_main_story_index`. +inline size_t story_index(bool main_story, size_t index_in_section, size_t first_main_story_index){ + return main_story ? first_main_story_index + index_in_section : index_in_section; +} + + } } #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp index d966bfe133..de82dd3b2d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp @@ -5,6 +5,7 @@ */ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" #include "Inference/PokemonSV_WhiteButtonDetector.h" #include "Inference/Boxes/PokemonSV_BoxDetection.h" #include "Inference/Boxes/PokemonSV_BoxEggDetector.h" @@ -33,7 +34,105 @@ namespace PokemonSV{ +namespace{ + +// An entry of a story section, its index in the whole story list, and the +// index of the first main story entry. +struct AutoStoryIndexScenario{ + std::string name; + bool main_story; + size_t index_in_section; + size_t first_main_story_index; + size_t expected; +}; + +class Test_AutoStoryIndex : public UnitTest{ +public: + Test_AutoStoryIndex(AutoStoryIndexScenario scenario) + : UnitTest("Pokemon::AutoStoryIndex - " + scenario.name) + , m_scenario(std::move(scenario)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const size_t got = Pokemon::story_index( + m_scenario.main_story, m_scenario.index_in_section, m_scenario.first_main_story_index + ); + if (got != m_scenario.expected){ + return "Expected index " + std::to_string(m_scenario.expected) + ", got " + std::to_string(got); + } + return true; + } + +private: + const AutoStoryIndexScenario m_scenario; +}; + +// A stand-in for a story segment or checkpoint: only its name is read. +struct NamedEntry{ + std::string label; + std::string name() const{ return label; } +}; + +class Test_AutoStorySelectDatabase : public UnitTest{ +public: + Test_AutoStorySelectDatabase() + : UnitTest("Pokemon::AutoStorySelectDatabase - a section keeps whole-list slugs") + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + std::vector> list; + for (const char* label : {"a", "b", "c", "d"}){ + list.emplace_back(std::make_unique(NamedEntry{label})); + } + const StringSelectDatabase database = Pokemon::make_story_select_database(list, 2, 10); + const std::vector& entries = database.case_list(); + if (entries.size() != 2){ + return "Expected 2 entries (the end is clamped to the list), got " + std::to_string(entries.size()); + } + if (entries[0].slug != "2" || entries[0].display_name != "c" || entries[1].slug != "3" || entries[1].display_name != "d"){ + return "Expected slugs 2, 3 labeled c, d; got " + entries[0].slug + " " + entries[0].display_name + + ", " + entries[1].slug + " " + entries[1].display_name; + } + return true; + } +}; + +void add_tests_AutoStory(UnitTestDatabase& database){ + const AutoStoryIndexScenario scenarios[] = { + { + .name = "a tutorial entry is its own index", + .main_story = false, + .index_in_section = 3, + .first_main_story_index = 10, + .expected = 3, + }, + { + // SV: segment 10 is the first of the main story. + .name = "the first main story entry follows the tutorial", + .main_story = true, + .index_in_section = 0, + .first_main_story_index = 10, + .expected = 10, + }, + { + // SV: checkpoint 21 is the first of the main story. + .name = "a later main story checkpoint", + .main_story = true, + .index_in_section = 5, + .first_main_story_index = 21, + .expected = 26, + }, + }; + for (const AutoStoryIndexScenario& scenario : scenarios){ + database.add(scenario); + } + database.add(); +} + +} + void add_tests(UnitTestDatabase& database){ + add_tests_AutoStory(database); add_tests_WhiteButtonDetector(database); add_tests_BoxInfoDetector(database); add_tests_BoxEggDetector(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp index aec8b25ff5..067b6422b9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp @@ -1047,71 +1047,49 @@ std::string AutoStory::end_segment_description(){ } size_t AutoStory::get_start_segment_index(){ - size_t start = 0; - - if (STORY_SECTION == StorySection::TUTORIAL){ - start = STARTPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - start = (INDEX_OF_LAST_TUTORIAL_SEGMENT + 1) + STARTPOINT_MAINSTORY.index(); - } - - return start; + const bool main_story = STORY_SECTION == StorySection::MAIN_STORY; + return story_index( + main_story, + main_story ? STARTPOINT_MAINSTORY.index() : STARTPOINT_TUTORIAL.index(), + INDEX_OF_LAST_TUTORIAL_SEGMENT + 1 + ); } size_t AutoStory::get_end_segment_index(){ - size_t end = 0; - - if (STORY_SECTION == StorySection::TUTORIAL){ - end = ENDPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - end = (INDEX_OF_LAST_TUTORIAL_SEGMENT + 1) + ENDPOINT_MAINSTORY.index(); - } - - return end; + const bool main_story = STORY_SECTION == StorySection::MAIN_STORY; + return story_index( + main_story, + main_story ? ENDPOINT_MAINSTORY.index() : ENDPOINT_TUTORIAL.index(), + INDEX_OF_LAST_TUTORIAL_SEGMENT + 1 + ); } std::string AutoStory::start_checkpoint_description(){ - size_t checkpoint_index = 0; - if (STORY_SECTION == StorySection::TUTORIAL){ - checkpoint_index = START_CHECKPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - checkpoint_index = START_CHECKPOINT_MAINSTORY.index() + (INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1); - } + const size_t checkpoint_index = get_start_checkpoint_index(); return " Start: " + ALL_AUTO_STORY_CHECKPOINT_LIST()[checkpoint_index]->start_text(); } std::string AutoStory::end_checkpoint_description(){ - size_t checkpoint_index = 0; - if (STORY_SECTION == StorySection::TUTORIAL){ - checkpoint_index = END_CHECKPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - checkpoint_index = END_CHECKPOINT_MAINSTORY.index() + (INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1); - } + const size_t checkpoint_index = get_end_checkpoint_index(); return " End: " + ALL_AUTO_STORY_CHECKPOINT_LIST()[checkpoint_index]->end_text(); } size_t AutoStory::get_start_checkpoint_index(){ - size_t start = 0; - - if (STORY_SECTION == StorySection::TUTORIAL){ - start = START_CHECKPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - start = (INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1) + START_CHECKPOINT_MAINSTORY.index(); - } - - return start; + const bool main_story = STORY_SECTION == StorySection::MAIN_STORY; + return story_index( + main_story, + main_story ? START_CHECKPOINT_MAINSTORY.index() : START_CHECKPOINT_TUTORIAL.index(), + INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1 + ); } size_t AutoStory::get_end_checkpoint_index(){ - size_t end = 0; - - if (STORY_SECTION == StorySection::TUTORIAL){ - end = END_CHECKPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - end = (INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1) + END_CHECKPOINT_MAINSTORY.index(); - } - - return end; + const bool main_story = STORY_SECTION == StorySection::MAIN_STORY; + return story_index( + main_story, + main_story ? END_CHECKPOINT_MAINSTORY.index() : END_CHECKPOINT_TUTORIAL.index(), + INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1 + ); } From 17d4034a8b6567277ddb843a05d550e5d4825f26 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 25 Oct 2026 02:11:45 -0700 Subject: [PATCH 03/26] AutoStory: move AutoStoryStats to Pokemon/AutoStory Pure move, so BDSP and FRLG AutoStories can use the same stats; SV keeps the name through an alias. The stat keys are unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/Pokemon_AutoStoryStats.h | 36 +++++++++++++++++++ .../AutoStory/PokemonSV_AutoStoryTools.h | 16 ++------- SerialPrograms/cmake/SourceFiles.cmake | 1 + 3 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h new file mode 100644 index 0000000000..b531e0bb3d --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h @@ -0,0 +1,36 @@ +/* AutoStory Stats + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_AutoStoryStats_H +#define PokemonAutomation_Pokemon_AutoStoryStats_H + +#include "CommonFramework/ProgramStats/StatsTracking.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Saved checkpoints, segments started and game resets of an AutoStory run. +// The names are the keys of the saved stats; do not rename them. +struct AutoStoryStats : public StatsTracker{ + AutoStoryStats() + : m_checkpoint(m_stats["Checkpoint"]) + , m_segment(m_stats["Segment"]) + , m_reset(m_stats["Reset"]) + { + m_display_order.emplace_back("Checkpoint"); + m_display_order.emplace_back("Segment"); + m_display_order.emplace_back("Reset"); + } + std::atomic& m_checkpoint; + std::atomic& m_segment; + std::atomic& m_reset; +}; + + +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h index 0fb5ad799f..dd395dfd5c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h @@ -14,6 +14,7 @@ #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/ProgramStats/StatsTracking.h" #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" #include "VideoGames/PokemonSV/Programs/PokemonSV_WorldNavigation.h" namespace PokemonAutomation{ @@ -24,20 +25,7 @@ using namespace ML; static constexpr bool ENABLE_TEST = false; -struct AutoStoryStats : public StatsTracker{ - AutoStoryStats() - : m_checkpoint(m_stats["Checkpoint"]) - , m_segment(m_stats["Segment"]) - , m_reset(m_stats["Reset"]) - { - m_display_order.emplace_back("Checkpoint"); - m_display_order.emplace_back("Segment"); - m_display_order.emplace_back("Reset"); - } - std::atomic& m_checkpoint; - std::atomic& m_segment; - std::atomic& m_reset; -}; +using AutoStoryStats = Pokemon::AutoStoryStats; diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 3c444ef3c5..accb20e1c9 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1436,6 +1436,7 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Options/Pokemon_StatsHuntFilter.cpp Source/Pokemon/Options/Pokemon_StatsHuntFilter.h Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h + Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h Source/Pokemon/Pokemon_AdvRng.cpp Source/Pokemon/Pokemon_AdvRng.h Source/Pokemon/Pokemon_BdspRng.cpp From 5d23a5601d4cf3be62084b1a4922af816a33bd4f Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 13:12:06 -0800 Subject: [PATCH 04/26] AutoStory: test the shared select database with the helper that builds it Moved here from #44 (user decision): a section of a story list keeps its whole-list slugs and the end is clamped to the list. #44 keeps story_index() and its tests. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../VideoGames/PokemonSV/PokemonSV_Tests.cpp | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp index 80f1d0b6f8..95ea9b1525 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp @@ -5,6 +5,7 @@ */ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" #include "Inference/PokemonSV_WhiteButtonDetector.h" #include "Inference/Boxes/PokemonSV_BoxDetection.h" #include "Inference/Boxes/PokemonSV_BoxEggDetector.h" @@ -148,7 +149,46 @@ class Test_BlueberryPoints : public ImageUnitTest{ } +namespace{ + +// A stand-in for a story segment or checkpoint: only its name is read. +struct NamedEntry{ + std::string label; + std::string name() const{ return label; } +}; + +class Test_AutoStorySelectDatabase : public UnitTest{ +public: + Test_AutoStorySelectDatabase() + : UnitTest("Pokemon::AutoStorySelectDatabase - a section keeps whole-list slugs") + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + std::vector> list; + for (const char* label : {"a", "b", "c", "d"}){ + list.emplace_back(std::make_unique(NamedEntry{label})); + } + const StringSelectDatabase database = Pokemon::make_story_select_database(list, 2, 10); + const std::vector& entries = database.case_list(); + if (entries.size() != 2){ + return "Expected 2 entries (the end is clamped to the list), got " + std::to_string(entries.size()); + } + if (entries[0].slug != "2" || entries[0].display_name != "c" || entries[1].slug != "3" || entries[1].display_name != "d"){ + return "Expected slugs 2, 3 labeled c, d; got " + entries[0].slug + " " + entries[0].display_name + + ", " + entries[1].slug + " " + entries[1].display_name; + } + return true; + } +}; + +void add_tests_AutoStory(UnitTestDatabase& database){ + database.add(); +} + +} + void add_tests(UnitTestDatabase& database){ + add_tests_AutoStory(database); database.add(); // Full-frame references, in the CommandLineTests repo: they exercise the production From 1ea884ba71acfc68d215f4e45c4a632aa37290d4 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 23:05:35 -0800 Subject: [PATCH 05/26] AutoStory: shared start/end select database and story index SV AutoStory built six near-identical start/end dropdown databases by hand and repeated the tutorial/main-story index offset maths in six helpers and two descriptions. make_story_select_database() and story_index() in Pokemon/AutoStory/Pokemon_AutoStorySelect.h do each once, for other games' AutoStory to reuse, with their tests beside them. No behaviour change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../ComputerPrograms_UnitTestRunner.cpp | 2 + .../AutoStory/Pokemon_AutoStorySelect.h | 44 +++++ .../Pokemon_AutoStorySelect_Tests.cpp | 173 ++++++++++++++++++ .../AutoStory/Pokemon_AutoStorySelect_Tests.h | 22 +++ .../AutoStory/PokemonSV_AutoStory.cpp | 165 +++++------------ SerialPrograms/cmake/SourceFiles.cmake | 3 + 6 files changed, 289 insertions(+), 120 deletions(-) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index e34d1cbba1..71a0872070 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -13,6 +13,7 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Common/Qt/QtThreadPool_Tests.h" #include "Kernels/Kernels_Tests.h" +#include "Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h" #include "CommonFramework/AudioPipeline/AudioInfo_Tests.h" #include "CommonFramework/AudioPipeline/Tools/ChannelMixer.h" #include "CommonFramework/AudioPipeline/SinkPipeline_Tests.h" @@ -62,6 +63,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ add_tests_AudioFileLoader(ret); OCR::add_tests(ret); Kernels::add_tests(ret); + Pokemon::add_tests_AutoStorySelect(ret); NintendoSwitch::add_tests_CheckOnlineDetector(ret); NintendoSwitch::add_tests_FailedToConnectDetector(ret); NintendoSwitch::add_tests_UpdatePopupDetector(ret); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h new file mode 100644 index 0000000000..01318b85ce --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h @@ -0,0 +1,44 @@ +/* AutoStory Select + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_AutoStorySelect_H +#define PokemonAutomation_Pokemon_AutoStorySelect_H + +#include +#include +#include +#include "CommonTools/Options/StringSelectOption.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// A dropdown database of the story segments or checkpoints [begin, end) of +// `list`, labeled by their name() and slugged by their index in the whole +// list, so a slug picks the same entry whichever section it was chosen from. +template +StringSelectDatabase make_story_select_database( + const std::vector>& list, + size_t begin, size_t end +){ + StringSelectDatabase ret; + for (size_t i = begin; i < end && i < list.size(); i++){ + ret.add_entry(StringSelectEntry(std::to_string(i), list[i]->name())); + } + return ret; +} + + +// The index in the whole story list of entry `index_in_section` of the +// tutorial or the main story, whose first entry is `first_main_story_index`. +inline size_t story_index(bool main_story, size_t index_in_section, size_t first_main_story_index){ + return main_story ? first_main_story_index + index_in_section : index_in_section; +} + + +} +} +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp new file mode 100644 index 0000000000..efdd49bd8f --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp @@ -0,0 +1,173 @@ +/* AutoStory Select Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Pokemon_AutoStorySelect.h" +#include "Pokemon_AutoStorySelect_Tests.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + +namespace{ + +// An entry of a story section, its index in the whole story list, and the +// index of the first main story entry. +struct AutoStoryIndexScenario{ + std::string name; + bool main_story; + size_t index_in_section; + size_t first_main_story_index; + size_t expected; +}; + +class Test_AutoStoryIndex : public UnitTest{ +public: + Test_AutoStoryIndex(AutoStoryIndexScenario scenario) + : UnitTest("Pokemon::AutoStoryIndex - " + scenario.name) + , m_scenario(std::move(scenario)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const size_t got = story_index( + m_scenario.main_story, m_scenario.index_in_section, m_scenario.first_main_story_index + ); + if (got != m_scenario.expected){ + return "Expected index " + std::to_string(m_scenario.expected) + ", got " + std::to_string(got); + } + return true; + } + +private: + const AutoStoryIndexScenario m_scenario; +}; + +// A stand-in for a story segment or checkpoint: only its name is read. +struct NamedEntry{ + std::string label; + std::string name() const{ return label; } +}; + +// A dropdown built from [begin, end) of a story list of two tutorial entries, +// then two of the main story (which starts at index 2), as SV's lists are +// laid out, and its (slug, label) entries: slugs are indices in the whole +// list, not in the dropdown. +struct AutoStorySelectScenario{ + std::string name; + size_t begin; + size_t end; + std::vector> expected; +}; + +class Test_AutoStorySelectDatabase : public UnitTest{ +public: + Test_AutoStorySelectDatabase(AutoStorySelectScenario scenario) + : UnitTest("Pokemon::AutoStorySelectDatabase - " + scenario.name) + , m_scenario(std::move(scenario)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + // unique_ptr cannot be copied out of a braced list: build it in place. + const std::vector> list = []{ + std::vector> list; + for (const char* label : {"tutorial 0", "tutorial 1", "main story 0", "main story 1"}){ + list.emplace_back(std::make_unique(NamedEntry{label})); + } + return list; + }(); + const StringSelectDatabase database = make_story_select_database(list, m_scenario.begin, m_scenario.end); + std::vector> got; + for (const StringSelectEntry& entry : database.case_list()){ + got.emplace_back(entry.slug, entry.display_name); + } + if (got != m_scenario.expected){ + return "Expected " + describe(m_scenario.expected) + ", got " + describe(got); + } + return true; + } + +private: + static std::string describe(const std::vector>& entries){ + std::string text; + for (const auto& [slug, label] : entries){ + text += (text.empty() ? "" : ", ") + slug + " \"" + label + "\""; + } + return "[" + text + "]"; + } + + const AutoStorySelectScenario m_scenario; +}; + +void add_index_tests(UnitTestDatabase& database){ + const AutoStoryIndexScenario scenarios[] = { + { + .name = "a tutorial entry is its own index", + .main_story = false, + .index_in_section = 3, + .first_main_story_index = 10, + .expected = 3, + }, + { + // SV: segment 10 is the first of the main story. + .name = "the first main story entry follows the tutorial", + .main_story = true, + .index_in_section = 0, + .first_main_story_index = 10, + .expected = 10, + }, + { + // SV: checkpoint 21 is the first of the main story. + .name = "a later main story checkpoint", + .main_story = true, + .index_in_section = 5, + .first_main_story_index = 21, + .expected = 26, + }, + }; + for (const AutoStoryIndexScenario& scenario : scenarios){ + database.add(scenario); + } +} + +void add_select_database_tests(UnitTestDatabase& database){ + const AutoStorySelectScenario select_scenarios[] = { + { + .name = "the tutorial dropdown", + .begin = 0, + .end = 2, + .expected = {{"0", "tutorial 0"}, {"1", "tutorial 1"}}, + }, + { + .name = "the main story dropdown keeps whole-list slugs", + .begin = 2, + .end = 4, + .expected = {{"2", "main story 0"}, {"3", "main story 1"}}, + }, + { + .name = "an end past the list is clamped to it", + .begin = 2, + .end = 10, + .expected = {{"2", "main story 0"}, {"3", "main story 1"}}, + }, + }; + for (const AutoStorySelectScenario& scenario : select_scenarios){ + database.add(scenario); + } +} + +} + +void add_tests_AutoStorySelect(UnitTestDatabase& database){ + add_index_tests(database); + add_select_database_tests(database); +} + + + +} +} diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h new file mode 100644 index 0000000000..5132ce6335 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h @@ -0,0 +1,22 @@ +/* AutoStory Select Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_AutoStorySelect_Tests_H +#define PokemonAutomation_Pokemon_AutoStorySelect_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +void add_tests_AutoStorySelect(UnitTestDatabase& database); + + + +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp index 8167660fcb..9f943f5833 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp @@ -27,6 +27,7 @@ #include "NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManip.h" #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "Pokemon/Pokemon_Strings.h" +#include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h" #include "VideoGames/PokemonSV/PokemonSV_Settings.h" #include "VideoGames/PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h" @@ -150,51 +151,24 @@ const std::vector>& ALL_AUTO_STORY_SEGMENT_LI } -StringSelectDatabase make_all_segments_database(){ - StringSelectDatabase ret; - int index_num = 0; - for (const auto& segment : ALL_AUTO_STORY_SEGMENT_LIST()){ - ret.add_entry(StringSelectEntry(std::to_string(index_num), segment->name())); - index_num++; - } - return ret; -} const StringSelectDatabase& ALL_SEGMENTS_SELECT_DATABASE(){ - static StringSelectDatabase database = make_all_segments_database(); + static StringSelectDatabase database = make_story_select_database( + ALL_AUTO_STORY_SEGMENT_LIST(), 0, ALL_AUTO_STORY_SEGMENT_LIST().size() + ); return database; } -StringSelectDatabase make_tutorial_segments_database(){ - StringSelectDatabase ret; - const StringSelectDatabase& all_segments = ALL_SEGMENTS_SELECT_DATABASE(); - size_t start = 0; - size_t end = INDEX_OF_LAST_TUTORIAL_SEGMENT + 1; - for (size_t i = start; i < end; i++){ - const auto& segment = all_segments[i]; - ret.add_entry(segment); - } - return ret; -} - const StringSelectDatabase& TUTORIAL_SEGMENTS_SELECT_DATABASE(){ - static StringSelectDatabase database = make_tutorial_segments_database(); + static StringSelectDatabase database = make_story_select_database( + ALL_AUTO_STORY_SEGMENT_LIST(), 0, INDEX_OF_LAST_TUTORIAL_SEGMENT + 1 + ); return database; } -StringSelectDatabase make_mainstory_segments_database(){ - StringSelectDatabase ret; - const StringSelectDatabase& all_segments = ALL_SEGMENTS_SELECT_DATABASE(); - size_t start = INDEX_OF_LAST_TUTORIAL_SEGMENT + 1; - size_t end = all_segments.case_list().size(); - for (size_t i = start; i < end; i++){ - const auto& segment = all_segments[i]; - ret.add_entry(segment); - } - return ret; -} - const StringSelectDatabase& MAINSTORY_SEGMENTS_SELECT_DATABASE(){ - static StringSelectDatabase database = make_mainstory_segments_database(); + static StringSelectDatabase database = make_story_select_database( + ALL_AUTO_STORY_SEGMENT_LIST(), INDEX_OF_LAST_TUTORIAL_SEGMENT + 1, ALL_AUTO_STORY_SEGMENT_LIST().size() + ); return database; } @@ -324,51 +298,24 @@ const std::vector>& ALL_AUTO_STORY_CHECKPO return checkpoint_list; } -StringSelectDatabase make_all_checkpoints_database(){ - StringSelectDatabase ret; - int index_num = 0; - for (const auto& segment : ALL_AUTO_STORY_CHECKPOINT_LIST()){ - ret.add_entry(StringSelectEntry(std::to_string(index_num), segment->name())); - index_num++; - } - return ret; -} const StringSelectDatabase& ALL_CHECKPOINTS_SELECT_DATABASE(){ - static StringSelectDatabase database = make_all_checkpoints_database(); + static StringSelectDatabase database = make_story_select_database( + ALL_AUTO_STORY_CHECKPOINT_LIST(), 0, ALL_AUTO_STORY_CHECKPOINT_LIST().size() + ); return database; } -StringSelectDatabase make_tutorial_checkpoints_database(){ - StringSelectDatabase ret; - const StringSelectDatabase& all_checkpoints = ALL_CHECKPOINTS_SELECT_DATABASE(); - size_t start = 0; - size_t end = INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1; - for (size_t i = start; i < end; i++){ - const auto& segment = all_checkpoints[i]; - ret.add_entry(segment); - } - return ret; -} - const StringSelectDatabase& TUTORIAL_CHECKPOINTS_SELECT_DATABASE(){ - static StringSelectDatabase database = make_tutorial_checkpoints_database(); + static StringSelectDatabase database = make_story_select_database( + ALL_AUTO_STORY_CHECKPOINT_LIST(), 0, INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1 + ); return database; } -StringSelectDatabase make_mainstory_checkpoints_database(){ - StringSelectDatabase ret; - const StringSelectDatabase& all_checkpoints = ALL_CHECKPOINTS_SELECT_DATABASE(); - size_t start = INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1; - size_t end = all_checkpoints.case_list().size(); - for (size_t i = start; i < end; i++){ - const auto& segment = all_checkpoints[i]; - ret.add_entry(segment); - } - return ret; -} - const StringSelectDatabase& MAINSTORY_CHECKPOINTS_SELECT_DATABASE(){ - static StringSelectDatabase database = make_mainstory_checkpoints_database(); + static StringSelectDatabase database = make_story_select_database( + ALL_AUTO_STORY_CHECKPOINT_LIST(), INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1, ALL_AUTO_STORY_CHECKPOINT_LIST().size() + ); return database; } @@ -1101,71 +1048,49 @@ std::string AutoStory::end_segment_description(){ } size_t AutoStory::get_start_segment_index(){ - size_t start = 0; - - if (STORY_SECTION == StorySection::TUTORIAL){ - start = STARTPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - start = (INDEX_OF_LAST_TUTORIAL_SEGMENT + 1) + STARTPOINT_MAINSTORY.index(); - } - - return start; + const bool main_story = STORY_SECTION == StorySection::MAIN_STORY; + return story_index( + main_story, + main_story ? STARTPOINT_MAINSTORY.index() : STARTPOINT_TUTORIAL.index(), + INDEX_OF_LAST_TUTORIAL_SEGMENT + 1 + ); } size_t AutoStory::get_end_segment_index(){ - size_t end = 0; - - if (STORY_SECTION == StorySection::TUTORIAL){ - end = ENDPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - end = (INDEX_OF_LAST_TUTORIAL_SEGMENT + 1) + ENDPOINT_MAINSTORY.index(); - } - - return end; + const bool main_story = STORY_SECTION == StorySection::MAIN_STORY; + return story_index( + main_story, + main_story ? ENDPOINT_MAINSTORY.index() : ENDPOINT_TUTORIAL.index(), + INDEX_OF_LAST_TUTORIAL_SEGMENT + 1 + ); } std::string AutoStory::start_checkpoint_description(){ - size_t checkpoint_index = 0; - if (STORY_SECTION == StorySection::TUTORIAL){ - checkpoint_index = START_CHECKPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - checkpoint_index = START_CHECKPOINT_MAINSTORY.index() + (INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1); - } + const size_t checkpoint_index = get_start_checkpoint_index(); return " Start: " + ALL_AUTO_STORY_CHECKPOINT_LIST()[checkpoint_index]->start_text(); } std::string AutoStory::end_checkpoint_description(){ - size_t checkpoint_index = 0; - if (STORY_SECTION == StorySection::TUTORIAL){ - checkpoint_index = END_CHECKPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - checkpoint_index = END_CHECKPOINT_MAINSTORY.index() + (INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1); - } + const size_t checkpoint_index = get_end_checkpoint_index(); return " End: " + ALL_AUTO_STORY_CHECKPOINT_LIST()[checkpoint_index]->end_text(); } size_t AutoStory::get_start_checkpoint_index(){ - size_t start = 0; - - if (STORY_SECTION == StorySection::TUTORIAL){ - start = START_CHECKPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - start = (INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1) + START_CHECKPOINT_MAINSTORY.index(); - } - - return start; + const bool main_story = STORY_SECTION == StorySection::MAIN_STORY; + return story_index( + main_story, + main_story ? START_CHECKPOINT_MAINSTORY.index() : START_CHECKPOINT_TUTORIAL.index(), + INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1 + ); } size_t AutoStory::get_end_checkpoint_index(){ - size_t end = 0; - - if (STORY_SECTION == StorySection::TUTORIAL){ - end = END_CHECKPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - end = (INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1) + END_CHECKPOINT_MAINSTORY.index(); - } - - return end; + const bool main_story = STORY_SECTION == StorySection::MAIN_STORY; + return story_index( + main_story, + main_story ? END_CHECKPOINT_MAINSTORY.index() : END_CHECKPOINT_TUTORIAL.index(), + INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1 + ); } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index b64c8b92f0..0c79904641 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1465,6 +1465,9 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Options/Pokemon_NameSelectWidget.h Source/Pokemon/Options/Pokemon_StatsHuntFilter.cpp Source/Pokemon/Options/Pokemon_StatsHuntFilter.h + Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h + Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp + Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h Source/Pokemon/Pokemon_AdvRng.cpp Source/Pokemon/Pokemon_AdvRng.h Source/Pokemon/Pokemon_BdspRng.cpp From 2b03556251d699fb7f0f9ff85ac6ee28e031b147 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 11:00:49 -0800 Subject: [PATCH 06/26] AutoStory: segment descriptions use the shared index getters start_segment_description() and end_segment_description() computed the tutorial/main-story segment offset inline. They now call get_start_segment_index() / get_end_segment_index(), like the checkpoint descriptions, which removes the last two inline copies of that offset (pa-devbot review on PokemonAutomation/Arduino-Source#1828). No behavior change: both getters return the same index for tutorial and main story. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonSV_AutoStory.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp index 9f943f5833..130271139b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp @@ -1028,23 +1028,11 @@ void AutoStory::test_checkpoints( } std::string AutoStory::start_segment_description(){ - size_t segment_index = 0; - if (STORY_SECTION == StorySection::TUTORIAL){ - segment_index = STARTPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - segment_index = STARTPOINT_MAINSTORY.index() + (INDEX_OF_LAST_TUTORIAL_SEGMENT + 1); - } - return " " + ALL_AUTO_STORY_SEGMENT_LIST()[segment_index]->start_text(); + return " " + ALL_AUTO_STORY_SEGMENT_LIST()[get_start_segment_index()]->start_text(); } std::string AutoStory::end_segment_description(){ - size_t segment_index = 0; - if (STORY_SECTION == StorySection::TUTORIAL){ - segment_index = ENDPOINT_TUTORIAL.index(); - }else if (STORY_SECTION == StorySection::MAIN_STORY){ - segment_index = ENDPOINT_MAINSTORY.index() + (INDEX_OF_LAST_TUTORIAL_SEGMENT + 1); - } - return " " + ALL_AUTO_STORY_SEGMENT_LIST()[segment_index]->end_text(); + return " " + ALL_AUTO_STORY_SEGMENT_LIST()[get_end_segment_index()]->end_text(); } size_t AutoStory::get_start_segment_index(){ From 057306ff58dfa0c11f88f6ec676356b6fb338739 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 11:39:20 -0800 Subject: [PATCH 07/26] AutoStory: note story_index's two-section assumption story_index() maps a tutorial or main-story position to the flat story list. Note that this assumes two consecutive sections, which is all SV AutoStory covers, and that a branching postgame or DLC needs another model. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h index 01318b85ce..44657e26c3 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h @@ -34,6 +34,9 @@ StringSelectDatabase make_story_select_database( // The index in the whole story list of entry `index_in_section` of the // tutorial or the main story, whose first entry is `first_main_story_index`. +// NOTE: assumes two consecutive sections (tutorial, then the main story), +// which is all SV AutoStory covers. A postgame or DLC that branches off +// the main story will need a different model than one global index. inline size_t story_index(bool main_story, size_t index_in_section, size_t first_main_story_index){ return main_story ? first_main_story_index + index_in_section : index_in_section; } From 101f5744f9a59d9ee335ec9d40f52fdada70be1a Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 12:00:05 -0800 Subject: [PATCH 08/26] AutoStory: describe sections as break points in story_index's NOTE Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h index 44657e26c3..84276b0b86 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h @@ -34,9 +34,11 @@ StringSelectDatabase make_story_select_database( // The index in the whole story list of entry `index_in_section` of the // tutorial or the main story, whose first entry is `first_main_story_index`. -// NOTE: assumes two consecutive sections (tutorial, then the main story), -// which is all SV AutoStory covers. A postgame or DLC that branches off -// the main story will need a different model than one global index. +// NOTE: a section ends where the user must step in (e.g. level up the +// Pokemon between the tutorial and the main story). SV has two sections. +// Later content (postgame, DLC) appends to the last section, run only after +// the main story; if it needs its own break (e.g. grinding before a DLC), +// it becomes a third section and `main_story` here becomes a section index. inline size_t story_index(bool main_story, size_t index_in_section, size_t first_main_story_index){ return main_story ? first_main_story_index + index_in_section : index_in_section; } From cc6599476e059388ac29bba6c66e457a30652411 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 7 Nov 2026 21:07:03 -0800 Subject: [PATCH 09/26] Document shared stats alias and namespace endings --- .../Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h | 4 ++-- .../PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h index b531e0bb3d..3b29a6ad34 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h @@ -31,6 +31,6 @@ struct AutoStoryStats : public StatsTracker{ }; -} -} +} // namespace Pokemon +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h index 9d0f9c678f..e39d8a47da 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h @@ -25,6 +25,7 @@ using namespace ML; static constexpr bool ENABLE_TEST = false; +// Shared checkpoint, segment and reset counters used by SV AutoStory. using AutoStoryStats = Pokemon::AutoStoryStats; From 8b30e00629a03bfa4c38701a5c5d39e9b4fc4fe0 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 13:25:14 -0800 Subject: [PATCH 10/26] AutoStory: shared run report: log lines and story counts Move the checkpoint log line formatters (Pokemon_StoryLog) and their tests here from #325, and put StoryRunCounts and record_story_counts() with AutoStoryStats, which they add to. StoryLog now holds only log lines. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../ComputerPrograms_UnitTestRunner.cpp | 3 + .../AutoStory/Pokemon_AutoStoryStats.cpp | 22 ++++ .../AutoStory/Pokemon_AutoStoryStats.h | 14 +++ .../Pokemon_AutoStoryStats_Tests.cpp | 91 +++++++++++++++ .../Pokemon/AutoStory/Pokemon_StoryLog.cpp | 66 +++++++++++ .../Pokemon/AutoStory/Pokemon_StoryLog.h | 62 ++++++++++ .../AutoStory/Pokemon_StoryLog_Tests.cpp | 109 ++++++++++++++++++ .../AutoStory/Pokemon_StoryRun_Tests.h | 28 +++++ SerialPrograms/cmake/SourceFiles.cmake | 6 + 9 files changed, 401 insertions(+) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index 43d70b5ecf..b02b4d3e36 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -14,6 +14,7 @@ #include "Common/Qt/QtThreadPool_Tests.h" #include "Kernels/Kernels_Tests.h" #include "Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h" +#include "Pokemon/AutoStory/Pokemon_StoryRun_Tests.h" #include "CommonFramework/AudioPipeline/AudioInfo_Tests.h" #include "CommonFramework/AudioPipeline/Tools/ChannelMixer.h" #include "CommonFramework/AudioPipeline/SinkPipeline_Tests.h" @@ -69,6 +70,8 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ OCR::add_tests(ret); Kernels::add_tests(ret); Pokemon::add_tests_AutoStorySelect(ret); + Pokemon::add_tests_AutoStoryStats(ret); + Pokemon::add_tests_StoryLog(ret); NintendoSwitch::add_tests_CheckOnlineDetector(ret); NintendoSwitch::add_tests_FailedToConnectDetector(ret); NintendoSwitch::add_tests_UpdatePopupDetector(ret); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp new file mode 100644 index 0000000000..5e09fb5fd3 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp @@ -0,0 +1,22 @@ +/* AutoStory Stats + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Pokemon_AutoStoryStats.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +void record_story_counts(AutoStoryStats& stats, const StoryRunCounts& counts){ + stats.m_segment += counts.segments; + stats.m_checkpoint += counts.checkpoints; + stats.m_reset += counts.resets; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h index 3b29a6ad34..aa552ea50c 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h @@ -7,6 +7,7 @@ #ifndef PokemonAutomation_Pokemon_AutoStoryStats_H #define PokemonAutomation_Pokemon_AutoStoryStats_H +#include #include "CommonFramework/ProgramStats/StatsTracking.h" namespace PokemonAutomation{ @@ -31,6 +32,19 @@ struct AutoStoryStats : public StatsTracker{ }; +// What a story run adds to the program's stats. +struct StoryRunCounts{ + size_t segments = 0; + // Checkpoints passed (and saved at). + size_t checkpoints = 0; + // Game resets or reloads after failed attempts. + size_t resets = 0; +}; + +// Adds `counts` to the shared AutoStory stats. +void record_story_counts(AutoStoryStats& stats, const StoryRunCounts& counts); + + } // namespace Pokemon } // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp new file mode 100644 index 0000000000..d7de8bd5c1 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp @@ -0,0 +1,91 @@ +/* AutoStory Stats Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon_StoryRun_Tests.h" +#include "Pokemon_AutoStoryStats.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + +namespace{ + +// Counts added to fresh stats, in order. +struct StoryCountsInput{ + std::string name; + std::vector added; +}; + +// The stats after them: counts add up rather than replace. +struct StoryCountsExpectation{ + uint64_t segments; + uint64_t checkpoints; + uint64_t resets; +}; + +// Counts recorded into the AutoStory stats and the totals they must reach. +struct StoryCountsCase{ + StoryCountsInput input; + StoryCountsExpectation expectation; +}; + +class Test_StoryCounts : public UnitTest{ +public: + Test_StoryCounts(StoryCountsCase test_case) + : UnitTest("Pokemon::AutoStoryStats - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + AutoStoryStats stats; + for (const StoryRunCounts& counts : m_case.input.added){ + record_story_counts(stats, counts); + } + const StoryCountsExpectation& expected = m_case.expectation; + if (stats.m_segment != expected.segments || stats.m_checkpoint != expected.checkpoints || stats.m_reset != expected.resets){ + return "Expected " + std::to_string(expected.segments) + " segments, " + std::to_string(expected.checkpoints) + + " checkpoints and " + std::to_string(expected.resets) + " resets, got " + + std::to_string(stats.m_segment) + ", " + std::to_string(stats.m_checkpoint) + + " and " + std::to_string(stats.m_reset); + } + return true; + } + +private: + const StoryCountsCase m_case; +}; + +const StoryCountsCase STORY_COUNTS_CASES[] = { + { + .input = {.name = "a segment's counts in the stats", .added = {{.segments = 1, .checkpoints = 2, .resets = 3}}}, + .expectation = {.segments = 1, .checkpoints = 2, .resets = 3}, + }, + { + .input = { + .name = "a checkpoint loop's counts add up", + .added = {{.segments = 0, .checkpoints = 1, .resets = 0}, {.segments = 0, .checkpoints = 0, .resets = 1}, {.segments = 0, .checkpoints = 1, .resets = 0}}, + }, + .expectation = {.segments = 0, .checkpoints = 2, .resets = 1}, + }, +}; + +} // namespace + + +void add_tests_AutoStoryStats(UnitTestDatabase& database){ + for (const StoryCountsCase& test_case : STORY_COUNTS_CASES){ + database.add(test_case); + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp new file mode 100644 index 0000000000..f931e3bd51 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp @@ -0,0 +1,66 @@ +/* Story Log + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Pokemon_StoryLog.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +namespace{ + +std::string resets_text(size_t attempt){ + if (attempt <= 1){ + return "one-shot"; + } + return std::format("{} reset{}", attempt - 1, attempt == 2 ? "" : "s"); +} + +} // namespace + + +std::string event_log_line(std::string_view checkpoint, size_t number, std::string_view event, std::string_view status){ + return std::format("[Event] {}/{} {}: {}", checkpoint, number, event, status); +} + +std::string checkpoint_start_line(std::string_view checkpoint, std::optional events){ + if (!events){ + return std::format("[Checkpoint] {}: start", checkpoint); + } + return std::format("[Checkpoint] {}: start, {} events", checkpoint, *events); +} + +std::string checkpoint_attempt_line(std::string_view checkpoint, size_t attempt, std::optional attempts){ + if (!attempts){ + return std::format("[Checkpoint] {}: attempt {}", checkpoint, attempt); + } + return std::format("[Checkpoint] {}: attempt {}/{}", checkpoint, attempt, *attempts); +} + +std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, size_t in_place){ + return std::format( + "[Checkpoint] {}: passed on attempt {} ({}){}", + checkpoint, attempt, resets_text(attempt), + in_place == 0 ? "" : std::format(", {} in place", in_place) + ); +} + +std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attempt){ + return std::format("[Checkpoint] {}: failed, resetting for attempt {}", checkpoint, next_attempt); +} + +std::string segment_reload_line(std::string_view segment, std::string_view checkpoint, size_t next_attempt, size_t attempts){ + return std::format( + "[Segment] {}: {} failed, reloading for attempt {}/{}", + segment, checkpoint, next_attempt, attempts + ); +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h new file mode 100644 index 0000000000..d8fb689788 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h @@ -0,0 +1,62 @@ +/* Story Log + * + * From: https://github.com/PokemonAutomation/ + * + * The log lines an AutoStory program writes around its checkpoints, in + * one format for every game: the story engine (Pokemon_StoryEvents.h, + * Pokemon_StorySegments.h) writes them, and a game with its own checkpoint + * loop (SV's) writes the same lines, so the lab watcher and whoever reads + * a log find each checkpoint's start, attempts, resets and pass the same + * way. Nothing here runs a story. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryLog_H +#define PokemonAutomation_Pokemon_StoryLog_H + +#include +#include +#include +#include + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// One event's line: +// [Event] 00.04/3 talk_mom: start +// [Event] 00.04/3 talk_mom: failed: expect_failed: has_parcel +std::string event_log_line(std::string_view checkpoint, size_t number, std::string_view event, std::string_view status); + +// A checkpoint starts; the story engine also says it has `events` events: +// [Checkpoint] 00.04: start +// [Checkpoint] 00.04: start, 3 events +std::string checkpoint_start_line(std::string_view checkpoint, std::optional events = std::nullopt); + +// An attempt at a checkpoint starts, counting from 1, out of the +// program's limit of `attempts` if it has one: +// [Checkpoint] 00.04: attempt 2 +// [Checkpoint] 00.04: attempt 2/3 +std::string checkpoint_attempt_line( + std::string_view checkpoint, size_t attempt, std::optional attempts = std::nullopt +); + +// A checkpoint passed on attempt `attempt`, after `in_place` recoveries in +// place: +// [Checkpoint] 00.03: passed on attempt 1 (one-shot) +// [Checkpoint] 00.04: passed on attempt 3 (2 resets), 1 in place +std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, size_t in_place = 0); + +// An attempt failed and the game resets to the checkpoint's save for +// attempt `next_attempt`: +// [Checkpoint] 00.04: failed, resetting for attempt 2 +std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attempt); +// The story engine reloads within segment `segment`, out of `attempts`: +// [Segment] 00: 00.02 failed, reloading for attempt 2/3 +std::string segment_reload_line(std::string_view segment, std::string_view checkpoint, size_t next_attempt, size_t attempts); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp new file mode 100644 index 0000000000..580fcb2d4b --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp @@ -0,0 +1,109 @@ +/* Story Log Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon_StoryRun_Tests.h" +#include "Pokemon_StoryLog.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + +namespace{ + +// A formatter's line, made when the table is built. +struct StoryLogInput{ + std::string name; + std::string line; +}; + +// The exact line: the lab watcher and the engine tests read these. +struct StoryLogExpectation{ + std::string line; +}; + +// One formatter call and the line it must make. +struct StoryLogCase{ + StoryLogInput input; + StoryLogExpectation expectation; +}; + +class Test_StoryLog : public UnitTest{ +public: + Test_StoryLog(StoryLogCase test_case) + : UnitTest("Pokemon::StoryLog - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + if (m_case.input.line != m_case.expectation.line){ + return "Expected \"" + m_case.expectation.line + "\", got \"" + m_case.input.line + "\""; + } + return true; + } + +private: + const StoryLogCase m_case; +}; + +const StoryLogCase STORY_LOG_CASES[] = { + { + .input = {.name = "event", .line = event_log_line("00.04", 3, "talk_mom", "start")}, + .expectation = {.line = "[Event] 00.04/3 talk_mom: start"}, + }, + { + .input = {.name = "checkpoint start", .line = checkpoint_start_line("00.04")}, + .expectation = {.line = "[Checkpoint] 00.04: start"}, + }, + { + .input = {.name = "checkpoint start with its events", .line = checkpoint_start_line("00.04", 3)}, + .expectation = {.line = "[Checkpoint] 00.04: start, 3 events"}, + }, + { + .input = {.name = "attempt", .line = checkpoint_attempt_line("00.04", 2)}, + .expectation = {.line = "[Checkpoint] 00.04: attempt 2"}, + }, + { + .input = {.name = "attempt out of a limit", .line = checkpoint_attempt_line("00.04", 2, 3)}, + .expectation = {.line = "[Checkpoint] 00.04: attempt 2/3"}, + }, + { + .input = {.name = "one-shot pass", .line = checkpoint_pass_line("00.03", 1)}, + .expectation = {.line = "[Checkpoint] 00.03: passed on attempt 1 (one-shot)"}, + }, + { + .input = {.name = "pass after one reset", .line = checkpoint_pass_line("00.04", 2)}, + .expectation = {.line = "[Checkpoint] 00.04: passed on attempt 2 (1 reset)"}, + }, + { + .input = {.name = "pass after resets and recoveries in place", .line = checkpoint_pass_line("00.04", 3, 1)}, + .expectation = {.line = "[Checkpoint] 00.04: passed on attempt 3 (2 resets), 1 in place"}, + }, + { + .input = {.name = "reset", .line = checkpoint_reset_line("00.04", 2)}, + .expectation = {.line = "[Checkpoint] 00.04: failed, resetting for attempt 2"}, + }, + { + .input = {.name = "reload within a segment", .line = segment_reload_line("00", "00.02", 2, 3)}, + .expectation = {.line = "[Segment] 00: 00.02 failed, reloading for attempt 2/3"}, + }, +}; + + +} // namespace + + +void add_tests_StoryLog(UnitTestDatabase& database){ + for (const StoryLogCase& test_case : STORY_LOG_CASES){ + database.add(test_case); + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h new file mode 100644 index 0000000000..4a6113aa87 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h @@ -0,0 +1,28 @@ +/* Story Run Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The unit tests of the pieces every AutoStory program shares, story + * engine or not: the checkpoint log lines and the stats counts. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryRun_Tests_H +#define PokemonAutomation_Pokemon_StoryRun_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers unit tests for the shared checkpoint log lines. +void add_tests_StoryLog(UnitTestDatabase& database); +// Registers unit tests for the story counts added to the AutoStory stats. +void add_tests_AutoStoryStats(UnitTestDatabase& database); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 660beed45a..ef3a75445c 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1470,7 +1470,13 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h + Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h + Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp + Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp + Source/Pokemon/AutoStory/Pokemon_StoryLog.h + Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp + Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h Source/Pokemon/Pokemon_AdvRng.cpp Source/Pokemon/Pokemon_AdvRng.h Source/Pokemon/Pokemon_BdspRng.cpp From 08d50fcfd24e78c92d525f4deea504e19a8035ee Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 14:02:00 -0800 Subject: [PATCH 11/26] AutoStory: one test entry point, output parameter last, std::format Review fixes for #45: - Rename Pokemon_StoryRun_Tests.h to Pokemon_AutoStory_Tests.h with add_tests_AutoStory(), which registers every shared AutoStory suite (AutoStorySelect, AutoStoryStats, StoryLog); the runner calls it once. - record_story_counts(counts, stats): the output parameter goes last. - Build test names and failure messages with std::format. - Blank line between the reset and reload formatters. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../ComputerPrograms_UnitTestRunner.cpp | 7 +--- .../AutoStory/Pokemon_AutoStoryStats.cpp | 2 +- .../AutoStory/Pokemon_AutoStoryStats.h | 2 +- .../Pokemon_AutoStoryStats_Tests.cpp | 16 ++++---- .../AutoStory/Pokemon_AutoStory_Tests.h | 37 +++++++++++++++++++ .../Pokemon/AutoStory/Pokemon_StoryLog.h | 1 + .../AutoStory/Pokemon_StoryLog_Tests.cpp | 7 ++-- .../AutoStory/Pokemon_StoryRun_Tests.h | 28 -------------- SerialPrograms/cmake/SourceFiles.cmake | 2 +- 9 files changed, 56 insertions(+), 46 deletions(-) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h delete mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index b02b4d3e36..5b581f449e 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -13,8 +13,7 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Common/Qt/QtThreadPool_Tests.h" #include "Kernels/Kernels_Tests.h" -#include "Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h" -#include "Pokemon/AutoStory/Pokemon_StoryRun_Tests.h" +#include "Pokemon/AutoStory/Pokemon_AutoStory_Tests.h" #include "CommonFramework/AudioPipeline/AudioInfo_Tests.h" #include "CommonFramework/AudioPipeline/Tools/ChannelMixer.h" #include "CommonFramework/AudioPipeline/SinkPipeline_Tests.h" @@ -69,9 +68,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ add_tests_LabControl(ret); OCR::add_tests(ret); Kernels::add_tests(ret); - Pokemon::add_tests_AutoStorySelect(ret); - Pokemon::add_tests_AutoStoryStats(ret); - Pokemon::add_tests_StoryLog(ret); + Pokemon::add_tests_AutoStory(ret); NintendoSwitch::add_tests_CheckOnlineDetector(ret); NintendoSwitch::add_tests_FailedToConnectDetector(ret); NintendoSwitch::add_tests_UpdatePopupDetector(ret); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp index 5e09fb5fd3..42ca1aea91 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp @@ -10,7 +10,7 @@ namespace PokemonAutomation{ namespace Pokemon{ -void record_story_counts(AutoStoryStats& stats, const StoryRunCounts& counts){ +void record_story_counts(const StoryRunCounts& counts, AutoStoryStats& stats){ stats.m_segment += counts.segments; stats.m_checkpoint += counts.checkpoints; stats.m_reset += counts.resets; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h index aa552ea50c..8daa049cf6 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h @@ -42,7 +42,7 @@ struct StoryRunCounts{ }; // Adds `counts` to the shared AutoStory stats. -void record_story_counts(AutoStoryStats& stats, const StoryRunCounts& counts); +void record_story_counts(const StoryRunCounts& counts, AutoStoryStats& stats); } // namespace Pokemon diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp index d7de8bd5c1..80351d65a1 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp @@ -5,11 +5,12 @@ */ #include +#include #include #include #include #include "Common/Cpp/TestRunners/UnitTest.h" -#include "Pokemon_StoryRun_Tests.h" +#include "Pokemon_AutoStory_Tests.h" #include "Pokemon_AutoStoryStats.h" namespace PokemonAutomation{ @@ -39,21 +40,22 @@ struct StoryCountsCase{ class Test_StoryCounts : public UnitTest{ public: Test_StoryCounts(StoryCountsCase test_case) - : UnitTest("Pokemon::AutoStoryStats - " + test_case.input.name) + : UnitTest(std::format("Pokemon::AutoStoryStats - {}", test_case.input.name)) , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ AutoStoryStats stats; for (const StoryRunCounts& counts : m_case.input.added){ - record_story_counts(stats, counts); + record_story_counts(counts, stats); } const StoryCountsExpectation& expected = m_case.expectation; if (stats.m_segment != expected.segments || stats.m_checkpoint != expected.checkpoints || stats.m_reset != expected.resets){ - return "Expected " + std::to_string(expected.segments) + " segments, " + std::to_string(expected.checkpoints) - + " checkpoints and " + std::to_string(expected.resets) + " resets, got " - + std::to_string(stats.m_segment) + ", " + std::to_string(stats.m_checkpoint) - + " and " + std::to_string(stats.m_reset); + return std::format( + "Expected {} segments, {} checkpoints and {} resets, got {}, {} and {}", + expected.segments, expected.checkpoints, expected.resets, + stats.m_segment.load(), stats.m_checkpoint.load(), stats.m_reset.load() + ); } return true; } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h new file mode 100644 index 0000000000..cacea62d97 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h @@ -0,0 +1,37 @@ +/* AutoStory Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The unit tests of the pieces every AutoStory program shares, story + * engine or not. add_tests_AutoStory() is the one entry point the unit + * test runner calls; a new shared AutoStory suite registers there. + * + */ + +#ifndef PokemonAutomation_Pokemon_AutoStory_Tests_H +#define PokemonAutomation_Pokemon_AutoStory_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon_AutoStorySelect_Tests.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers unit tests for the shared checkpoint log lines. +void add_tests_StoryLog(UnitTestDatabase& database); +// Registers unit tests for the story counts added to the AutoStory stats. +void add_tests_AutoStoryStats(UnitTestDatabase& database); + +// Registers every shared AutoStory suite, for the unit test runner. +inline void add_tests_AutoStory(UnitTestDatabase& database){ + add_tests_AutoStorySelect(database); + add_tests_AutoStoryStats(database); + add_tests_StoryLog(database); +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h index d8fb689788..539a3d3424 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h @@ -51,6 +51,7 @@ std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, si // attempt `next_attempt`: // [Checkpoint] 00.04: failed, resetting for attempt 2 std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attempt); + // The story engine reloads within segment `segment`, out of `attempts`: // [Segment] 00: 00.02 failed, reloading for attempt 2/3 std::string segment_reload_line(std::string_view segment, std::string_view checkpoint, size_t next_attempt, size_t attempts); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp index 580fcb2d4b..80554933d1 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp @@ -4,10 +4,11 @@ * */ +#include #include #include #include "Common/Cpp/TestRunners/UnitTest.h" -#include "Pokemon_StoryRun_Tests.h" +#include "Pokemon_AutoStory_Tests.h" #include "Pokemon_StoryLog.h" namespace PokemonAutomation{ @@ -35,13 +36,13 @@ struct StoryLogCase{ class Test_StoryLog : public UnitTest{ public: Test_StoryLog(StoryLogCase test_case) - : UnitTest("Pokemon::StoryLog - " + test_case.input.name) + : UnitTest(std::format("Pokemon::StoryLog - {}", test_case.input.name)) , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ if (m_case.input.line != m_case.expectation.line){ - return "Expected \"" + m_case.expectation.line + "\", got \"" + m_case.input.line + "\""; + return std::format("Expected \"{}\", got \"{}\"", m_case.expectation.line, m_case.input.line); } return true; } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h deleted file mode 100644 index 4a6113aa87..0000000000 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Story Run Tests - * - * From: https://github.com/PokemonAutomation/ - * - * The unit tests of the pieces every AutoStory program shares, story - * engine or not: the checkpoint log lines and the stats counts. - * - */ - -#ifndef PokemonAutomation_Pokemon_StoryRun_Tests_H -#define PokemonAutomation_Pokemon_StoryRun_Tests_H - -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" - -namespace PokemonAutomation{ -namespace Pokemon{ - - -// Registers unit tests for the shared checkpoint log lines. -void add_tests_StoryLog(UnitTestDatabase& database); -// Registers unit tests for the story counts added to the AutoStory stats. -void add_tests_AutoStoryStats(UnitTestDatabase& database); - - - -} // namespace Pokemon -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index ef3a75445c..c56145b0b9 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1473,10 +1473,10 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp + Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp Source/Pokemon/AutoStory/Pokemon_StoryLog.h Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp - Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h Source/Pokemon/Pokemon_AdvRng.cpp Source/Pokemon/Pokemon_AdvRng.h Source/Pokemon/Pokemon_BdspRng.cpp From 1dba5870b5c82d02d11f82243ed9cda3871a0019 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 14:27:49 -0800 Subject: [PATCH 12/26] AutoStory: one test header per suite Pokemon_StoryLog_Tests.h and Pokemon_AutoStoryStats_Tests.h declare their suites' add_tests functions, as Pokemon_AutoStorySelect_Tests.h does. Each *_Tests.cpp includes only its own header, and Pokemon_AutoStory_Tests.h only includes the per-suite headers and calls them from add_tests_AutoStory(). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon_AutoStoryStats_Tests.cpp | 2 +- .../AutoStory/Pokemon_AutoStoryStats_Tests.h | 23 +++++++++++++++++++ .../AutoStory/Pokemon_AutoStory_Tests.h | 7 ++---- .../AutoStory/Pokemon_StoryLog_Tests.cpp | 2 +- .../AutoStory/Pokemon_StoryLog_Tests.h | 23 +++++++++++++++++++ SerialPrograms/cmake/SourceFiles.cmake | 2 ++ 6 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp index 80351d65a1..453a975516 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp @@ -10,8 +10,8 @@ #include #include #include "Common/Cpp/TestRunners/UnitTest.h" -#include "Pokemon_AutoStory_Tests.h" #include "Pokemon_AutoStoryStats.h" +#include "Pokemon_AutoStoryStats_Tests.h" namespace PokemonAutomation{ namespace Pokemon{ diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.h new file mode 100644 index 0000000000..21deca69ec --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.h @@ -0,0 +1,23 @@ +/* AutoStory Stats Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_AutoStoryStats_Tests_H +#define PokemonAutomation_Pokemon_AutoStoryStats_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers unit tests for the story counts added to the AutoStory stats. +void add_tests_AutoStoryStats(UnitTestDatabase& database); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h index cacea62d97..98faaca844 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h @@ -13,16 +13,13 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Pokemon_AutoStorySelect_Tests.h" +#include "Pokemon_AutoStoryStats_Tests.h" +#include "Pokemon_StoryLog_Tests.h" namespace PokemonAutomation{ namespace Pokemon{ -// Registers unit tests for the shared checkpoint log lines. -void add_tests_StoryLog(UnitTestDatabase& database); -// Registers unit tests for the story counts added to the AutoStory stats. -void add_tests_AutoStoryStats(UnitTestDatabase& database); - // Registers every shared AutoStory suite, for the unit test runner. inline void add_tests_AutoStory(UnitTestDatabase& database){ add_tests_AutoStorySelect(database); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp index 80554933d1..1cc32c258b 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp @@ -8,8 +8,8 @@ #include #include #include "Common/Cpp/TestRunners/UnitTest.h" -#include "Pokemon_AutoStory_Tests.h" #include "Pokemon_StoryLog.h" +#include "Pokemon_StoryLog_Tests.h" namespace PokemonAutomation{ namespace Pokemon{ diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.h new file mode 100644 index 0000000000..822a222b31 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.h @@ -0,0 +1,23 @@ +/* Story Log Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryLog_Tests_H +#define PokemonAutomation_Pokemon_StoryLog_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers unit tests for the shared checkpoint log lines. +void add_tests_StoryLog(UnitTestDatabase& database); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index c56145b0b9..c2bd8aefc3 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1473,10 +1473,12 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp + Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.h Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp Source/Pokemon/AutoStory/Pokemon_StoryLog.h Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp + Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.h Source/Pokemon/Pokemon_AdvRng.cpp Source/Pokemon/Pokemon_AdvRng.h Source/Pokemon/Pokemon_BdspRng.cpp From 1e49c4f46cbbebc798bd41b6c19b87ab7a18fa94 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 12:30:58 -0800 Subject: [PATCH 13/26] SV AutoStory: write the shared checkpoint log lines SV's checkpoint loops and its start line use Pokemon_StoryLog's format (moved here from #325, as asked in review). The log header is included from the .cpp files, not AutoStoryTools.h. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp | 3 ++- .../Programs/AutoStory/PokemonSV_AutoStoryTools.cpp | 9 +++++---- .../Programs/AutoStory/PokemonSV_AutoStoryTools.h | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp index 130271139b..6895a9e8b3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp @@ -28,6 +28,7 @@ #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "Pokemon/Pokemon_Strings.h" #include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" +#include "Pokemon/AutoStory/Pokemon_StoryLog.h" #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h" #include "VideoGames/PokemonSV/PokemonSV_Settings.h" #include "VideoGames/PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h" @@ -1230,7 +1231,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex require_player(env.console, context, BUTTON_L); if (ENABLE_ADVANCED_MODE){ - env.console.log("Start Checkpoint " + ALL_AUTO_STORY_CHECKPOINT_LIST()[get_start_checkpoint_index()]->name(), COLOR_ORANGE); + env.console.log(Pokemon::checkpoint_start_line(ALL_AUTO_STORY_CHECKPOINT_LIST()[get_start_checkpoint_index()]->name()), COLOR_ORANGE); }else{ env.console.log("Start Segment " + ALL_AUTO_STORY_SEGMENT_LIST()[get_start_segment_index()]->name(), COLOR_ORANGE); } diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp index c2d61152df..b87996958d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp @@ -14,6 +14,7 @@ #include "CommonTools/Async/InferenceRoutines.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" +#include "Pokemon/AutoStory/Pokemon_StoryLog.h" #include "VideoGames/PokemonSV/Inference/Battles/PokemonSV_NormalBattleMenus.h" #include "VideoGames/PokemonSV/Inference/Dialogs/PokemonSV_DialogDetector.h" #include "VideoGames/PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.h" @@ -1445,7 +1446,7 @@ void checkpoint_reattempt_loop( save_game_from_overworld(env.program_info(), env.console, context); } - env.console.log(checkpoint_text + " Num attempts: " + std::to_string(i)); + env.console.log(Pokemon::checkpoint_attempt_line(checkpoint_text, i + 1)); context.wait_for_all_requests(); action(i); @@ -1479,7 +1480,7 @@ void checkpoint_reattempt_loop( ); } context.wait_for_all_requests(); - env.console.log("Resetting from checkpoint."); + env.console.log(Pokemon::checkpoint_reset_line(checkpoint_text, i + 2)); reset_game(env.program_info(), env.console, context); stats.m_reset++; env.update_stats(); @@ -1507,7 +1508,7 @@ void checkpoint_reattempt_loop_tutorial( send_program_status_notification(env, notif_status_update, "Saved at checkpoint."); } - env.console.log(checkpoint_text + " Num attempts: " + std::to_string(i)); + env.console.log(Pokemon::checkpoint_attempt_line(checkpoint_text, i + 1)); context.wait_for_all_requests(); action(i); @@ -1538,7 +1539,7 @@ void checkpoint_reattempt_loop_tutorial( ); } context.wait_for_all_requests(); - env.console.log("Resetting from checkpoint."); + env.console.log(Pokemon::checkpoint_reset_line(checkpoint_text, i + 2)); reset_game(env.program_info(), env.console, context); stats.m_reset++; env.update_stats(); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h index e39d8a47da..8583c68c42 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h @@ -7,6 +7,7 @@ #ifndef PokemonAutomation_PokemonSV_AutoStoryTools_H #define PokemonAutomation_PokemonSV_AutoStoryTools_H +#include #include #include "CommonFramework/Language.h" #include "CommonFramework/ImageTools/ImageBoxes.h" @@ -108,7 +109,7 @@ class AutoStory_Checkpoint { AutoStoryStats& stats) const = 0; std::string checkpoint_text() const { - return "Checkpoint:: " + name() + ". Start point: " + start_text(); + return std::format("{}. Start point: {}", name(), start_text()); } }; From 1b5aaf01d0aadf3f9d33572effbea030058af9c2 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 12:32:12 -0800 Subject: [PATCH 14/26] SV AutoStory: keep the legacy file line counts (code health) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp | 1 - .../PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp index 6895a9e8b3..9aca6582cc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp @@ -5,7 +5,6 @@ */ - #if 0 #include "CommonFramework/Exceptions/UnexpectedBattleException.h" #include "CommonTools/Async/InferenceRoutines.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp index b87996958d..63a8e80523 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp @@ -44,7 +44,6 @@ namespace PokemonSV{ - void clear_tutorial(VideoStream& stream, ProControllerContext& context, uint16_t seconds_timeout){ bool seen_tutorial = false; while (true){ From 7cdde2d723cc33b13a3897900007a4502e1aa408 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 13:03:49 -0800 Subject: [PATCH 15/26] AutoStory: review fixes for the shared log lines SV keeps its checkpoint_text() and its own attempt/reset lines: they only know the full "Checkpoint:: name. Start point: ..." text, which does not fit the shared "[Checkpoint] : ..." lines. SV writes only the shared start line, from name(). Drop checkpoint_pass_line()'s unused in_place count, nest the test case's Input and Expectation in StoryLogTestCase, and say who reads the lines in the header comment. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon/AutoStory/Pokemon_StoryLog.cpp | 8 +--- .../Pokemon/AutoStory/Pokemon_StoryLog.h | 16 ++++---- .../AutoStory/Pokemon_StoryLog_Tests.cpp | 40 +++++++++---------- .../AutoStory/PokemonSV_AutoStoryTools.cpp | 10 ++--- .../AutoStory/PokemonSV_AutoStoryTools.h | 3 +- 5 files changed, 36 insertions(+), 41 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp index f931e3bd51..63684e54f8 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp @@ -41,12 +41,8 @@ std::string checkpoint_attempt_line(std::string_view checkpoint, size_t attempt, return std::format("[Checkpoint] {}: attempt {}/{}", checkpoint, attempt, *attempts); } -std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, size_t in_place){ - return std::format( - "[Checkpoint] {}: passed on attempt {} ({}){}", - checkpoint, attempt, resets_text(attempt), - in_place == 0 ? "" : std::format(", {} in place", in_place) - ); +std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt){ + return std::format("[Checkpoint] {}: passed on attempt {} ({})", checkpoint, attempt, resets_text(attempt)); } std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attempt){ diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h index 539a3d3424..7d1d5b5edc 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h @@ -4,10 +4,10 @@ * * The log lines an AutoStory program writes around its checkpoints, in * one format for every game: the story engine (Pokemon_StoryEvents.h, - * Pokemon_StorySegments.h) writes them, and a game with its own checkpoint - * loop (SV's) writes the same lines, so the lab watcher and whoever reads - * a log find each checkpoint's start, attempts, resets and pass the same - * way. Nothing here runs a story. + * Pokemon_StorySegments.h) writes them, and SV's AutoStory writes the same + * checkpoint start line, so the program developer and user find each + * checkpoint's start, attempts, resets and pass the same way in any game's + * log. Nothing here runs a story. * */ @@ -41,11 +41,11 @@ std::string checkpoint_attempt_line( std::string_view checkpoint, size_t attempt, std::optional attempts = std::nullopt ); -// A checkpoint passed on attempt `attempt`, after `in_place` recoveries in -// place: +// A checkpoint passed on attempt `attempt`, counting from 1; every attempt +// before it ended in a reset: // [Checkpoint] 00.03: passed on attempt 1 (one-shot) -// [Checkpoint] 00.04: passed on attempt 3 (2 resets), 1 in place -std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, size_t in_place = 0); +// [Checkpoint] 00.04: passed on attempt 3 (2 resets) +std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt); // An attempt failed and the game resets to the checkpoint's save for // attempt `next_attempt`: diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp index 1cc32c258b..7c705d7d74 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp @@ -16,26 +16,26 @@ namespace Pokemon{ namespace{ -// A formatter's line, made when the table is built. -struct StoryLogInput{ - std::string name; - std::string line; -}; - -// The exact line: the lab watcher and the engine tests read these. -struct StoryLogExpectation{ - std::string line; -}; - // One formatter call and the line it must make. -struct StoryLogCase{ - StoryLogInput input; - StoryLogExpectation expectation; +struct StoryLogTestCase{ + // A formatter's line, made when the table is built. + struct Input{ + std::string name; + std::string line; + }; + + // The exact line: the lab watcher and the engine tests read these. + struct Expectation{ + std::string line; + }; + + Input input; + Expectation expectation; }; class Test_StoryLog : public UnitTest{ public: - Test_StoryLog(StoryLogCase test_case) + Test_StoryLog(StoryLogTestCase test_case) : UnitTest(std::format("Pokemon::StoryLog - {}", test_case.input.name)) , m_case(std::move(test_case)) {} @@ -48,10 +48,10 @@ class Test_StoryLog : public UnitTest{ } private: - const StoryLogCase m_case; + const StoryLogTestCase m_case; }; -const StoryLogCase STORY_LOG_CASES[] = { +const StoryLogTestCase STORY_LOG_CASES[] = { { .input = {.name = "event", .line = event_log_line("00.04", 3, "talk_mom", "start")}, .expectation = {.line = "[Event] 00.04/3 talk_mom: start"}, @@ -81,8 +81,8 @@ const StoryLogCase STORY_LOG_CASES[] = { .expectation = {.line = "[Checkpoint] 00.04: passed on attempt 2 (1 reset)"}, }, { - .input = {.name = "pass after resets and recoveries in place", .line = checkpoint_pass_line("00.04", 3, 1)}, - .expectation = {.line = "[Checkpoint] 00.04: passed on attempt 3 (2 resets), 1 in place"}, + .input = {.name = "pass after resets", .line = checkpoint_pass_line("00.04", 3)}, + .expectation = {.line = "[Checkpoint] 00.04: passed on attempt 3 (2 resets)"}, }, { .input = {.name = "reset", .line = checkpoint_reset_line("00.04", 2)}, @@ -99,7 +99,7 @@ const StoryLogCase STORY_LOG_CASES[] = { void add_tests_StoryLog(UnitTestDatabase& database){ - for (const StoryLogCase& test_case : STORY_LOG_CASES){ + for (const StoryLogTestCase& test_case : STORY_LOG_CASES){ database.add(test_case); } } diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp index 63a8e80523..c2d61152df 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp @@ -14,7 +14,6 @@ #include "CommonTools/Async/InferenceRoutines.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" -#include "Pokemon/AutoStory/Pokemon_StoryLog.h" #include "VideoGames/PokemonSV/Inference/Battles/PokemonSV_NormalBattleMenus.h" #include "VideoGames/PokemonSV/Inference/Dialogs/PokemonSV_DialogDetector.h" #include "VideoGames/PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.h" @@ -44,6 +43,7 @@ namespace PokemonSV{ + void clear_tutorial(VideoStream& stream, ProControllerContext& context, uint16_t seconds_timeout){ bool seen_tutorial = false; while (true){ @@ -1445,7 +1445,7 @@ void checkpoint_reattempt_loop( save_game_from_overworld(env.program_info(), env.console, context); } - env.console.log(Pokemon::checkpoint_attempt_line(checkpoint_text, i + 1)); + env.console.log(checkpoint_text + " Num attempts: " + std::to_string(i)); context.wait_for_all_requests(); action(i); @@ -1479,7 +1479,7 @@ void checkpoint_reattempt_loop( ); } context.wait_for_all_requests(); - env.console.log(Pokemon::checkpoint_reset_line(checkpoint_text, i + 2)); + env.console.log("Resetting from checkpoint."); reset_game(env.program_info(), env.console, context); stats.m_reset++; env.update_stats(); @@ -1507,7 +1507,7 @@ void checkpoint_reattempt_loop_tutorial( send_program_status_notification(env, notif_status_update, "Saved at checkpoint."); } - env.console.log(Pokemon::checkpoint_attempt_line(checkpoint_text, i + 1)); + env.console.log(checkpoint_text + " Num attempts: " + std::to_string(i)); context.wait_for_all_requests(); action(i); @@ -1538,7 +1538,7 @@ void checkpoint_reattempt_loop_tutorial( ); } context.wait_for_all_requests(); - env.console.log(Pokemon::checkpoint_reset_line(checkpoint_text, i + 2)); + env.console.log("Resetting from checkpoint."); reset_game(env.program_info(), env.console, context); stats.m_reset++; env.update_stats(); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h index 8583c68c42..e39d8a47da 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h @@ -7,7 +7,6 @@ #ifndef PokemonAutomation_PokemonSV_AutoStoryTools_H #define PokemonAutomation_PokemonSV_AutoStoryTools_H -#include #include #include "CommonFramework/Language.h" #include "CommonFramework/ImageTools/ImageBoxes.h" @@ -109,7 +108,7 @@ class AutoStory_Checkpoint { AutoStoryStats& stats) const = 0; std::string checkpoint_text() const { - return std::format("{}. Start point: {}", name(), start_text()); + return "Checkpoint:: " + name() + ". Start point: " + start_text(); } }; From 7b7ef1dc17f3ab5e58e4d1a77a2779e94d124042 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 13:37:25 -0800 Subject: [PATCH 16/26] AutoStory: nest the stats test case's Input and Expectation Same test style as StoryLogTestCase: StoryCountsCase becomes StoryCountsTestCase with nested Input and Expectation. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon_AutoStoryStats_Tests.cpp | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp index 453a975516..b427cd6d22 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp @@ -18,28 +18,28 @@ namespace Pokemon{ namespace{ -// Counts added to fresh stats, in order. -struct StoryCountsInput{ - std::string name; - std::vector added; -}; - -// The stats after them: counts add up rather than replace. -struct StoryCountsExpectation{ - uint64_t segments; - uint64_t checkpoints; - uint64_t resets; -}; - // Counts recorded into the AutoStory stats and the totals they must reach. -struct StoryCountsCase{ - StoryCountsInput input; - StoryCountsExpectation expectation; +struct StoryCountsTestCase{ + // Counts added to fresh stats, in order. + struct Input{ + std::string name; + std::vector added; + }; + + // The stats after them: counts add up rather than replace. + struct Expectation{ + uint64_t segments; + uint64_t checkpoints; + uint64_t resets; + }; + + Input input; + Expectation expectation; }; class Test_StoryCounts : public UnitTest{ public: - Test_StoryCounts(StoryCountsCase test_case) + Test_StoryCounts(StoryCountsTestCase test_case) : UnitTest(std::format("Pokemon::AutoStoryStats - {}", test_case.input.name)) , m_case(std::move(test_case)) {} @@ -49,7 +49,7 @@ class Test_StoryCounts : public UnitTest{ for (const StoryRunCounts& counts : m_case.input.added){ record_story_counts(counts, stats); } - const StoryCountsExpectation& expected = m_case.expectation; + const StoryCountsTestCase::Expectation& expected = m_case.expectation; if (stats.m_segment != expected.segments || stats.m_checkpoint != expected.checkpoints || stats.m_reset != expected.resets){ return std::format( "Expected {} segments, {} checkpoints and {} resets, got {}, {} and {}", @@ -61,10 +61,10 @@ class Test_StoryCounts : public UnitTest{ } private: - const StoryCountsCase m_case; + const StoryCountsTestCase m_case; }; -const StoryCountsCase STORY_COUNTS_CASES[] = { +const StoryCountsTestCase STORY_COUNTS_CASES[] = { { .input = {.name = "a segment's counts in the stats", .added = {{.segments = 1, .checkpoints = 2, .resets = 3}}}, .expectation = {.segments = 1, .checkpoints = 2, .resets = 3}, @@ -82,7 +82,7 @@ const StoryCountsCase STORY_COUNTS_CASES[] = { void add_tests_AutoStoryStats(UnitTestDatabase& database){ - for (const StoryCountsCase& test_case : STORY_COUNTS_CASES){ + for (const StoryCountsTestCase& test_case : STORY_COUNTS_CASES){ database.add(test_case); } } From 9ad520ea43a8820f1be03d968df47937678c32e8 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 13:55:05 -0800 Subject: [PATCH 17/26] AutoStory: [Checkpoint] lines take an optional display text A game whose checkpoints carry their own text that already says it is a checkpoint (SV's "Checkpoint:: 004 - 02 ...") passes it as display_text, and the line starts with it in place of "[Checkpoint] ", so the word is not doubled. The default, empty, keeps the current lines. StoryLog cases for both forms. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon/AutoStory/Pokemon_StoryLog.cpp | 38 ++++++++++++++----- .../Pokemon/AutoStory/Pokemon_StoryLog.h | 17 +++++++-- .../AutoStory/Pokemon_StoryLog_Tests.cpp | 21 ++++++++++ 3 files changed, 62 insertions(+), 14 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp index 63684e54f8..2d002518ff 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp @@ -20,6 +20,14 @@ std::string resets_text(size_t attempt){ return std::format("{} reset{}", attempt - 1, attempt == 2 ? "" : "s"); } +// "[Checkpoint] 00.04", or the game's own display text. +std::string checkpoint_head(std::string_view checkpoint, std::string_view display_text){ + if (!display_text.empty()){ + return std::string(display_text); + } + return std::format("[Checkpoint] {}", checkpoint); +} + } // namespace @@ -27,26 +35,36 @@ std::string event_log_line(std::string_view checkpoint, size_t number, std::stri return std::format("[Event] {}/{} {}: {}", checkpoint, number, event, status); } -std::string checkpoint_start_line(std::string_view checkpoint, std::optional events){ +std::string checkpoint_start_line( + std::string_view checkpoint, std::optional events, std::string_view display_text +){ + const std::string head = checkpoint_head(checkpoint, display_text); if (!events){ - return std::format("[Checkpoint] {}: start", checkpoint); + return std::format("{}: start", head); } - return std::format("[Checkpoint] {}: start, {} events", checkpoint, *events); + return std::format("{}: start, {} events", head, *events); } -std::string checkpoint_attempt_line(std::string_view checkpoint, size_t attempt, std::optional attempts){ +std::string checkpoint_attempt_line( + std::string_view checkpoint, size_t attempt, std::optional attempts, std::string_view display_text +){ + const std::string head = checkpoint_head(checkpoint, display_text); if (!attempts){ - return std::format("[Checkpoint] {}: attempt {}", checkpoint, attempt); + return std::format("{}: attempt {}", head, attempt); } - return std::format("[Checkpoint] {}: attempt {}/{}", checkpoint, attempt, *attempts); + return std::format("{}: attempt {}/{}", head, attempt, *attempts); } -std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt){ - return std::format("[Checkpoint] {}: passed on attempt {} ({})", checkpoint, attempt, resets_text(attempt)); +std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, std::string_view display_text){ + return std::format( + "{}: passed on attempt {} ({})", checkpoint_head(checkpoint, display_text), attempt, resets_text(attempt) + ); } -std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attempt){ - return std::format("[Checkpoint] {}: failed, resetting for attempt {}", checkpoint, next_attempt); +std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attempt, std::string_view display_text){ + return std::format( + "{}: failed, resetting for attempt {}", checkpoint_head(checkpoint, display_text), next_attempt + ); } std::string segment_reload_line(std::string_view segment, std::string_view checkpoint, size_t next_attempt, size_t attempts){ diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h index 7d1d5b5edc..9b0f368a18 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h @@ -28,29 +28,38 @@ namespace Pokemon{ // [Event] 00.04/3 talk_mom: failed: expect_failed: has_parcel std::string event_log_line(std::string_view checkpoint, size_t number, std::string_view event, std::string_view status); +// The [Checkpoint] lines below name a checkpoint by its id. A game whose +// checkpoints have their own text that already says it is a checkpoint +// (SV's "Checkpoint:: 004 - 02 ...") passes that as `display_text`, and +// the line starts with it in place of "[Checkpoint] ": +// Checkpoint:: 004 - 02 ...: start + // A checkpoint starts; the story engine also says it has `events` events: // [Checkpoint] 00.04: start // [Checkpoint] 00.04: start, 3 events -std::string checkpoint_start_line(std::string_view checkpoint, std::optional events = std::nullopt); +std::string checkpoint_start_line( + std::string_view checkpoint, std::optional events = std::nullopt, std::string_view display_text = "" +); // An attempt at a checkpoint starts, counting from 1, out of the // program's limit of `attempts` if it has one: // [Checkpoint] 00.04: attempt 2 // [Checkpoint] 00.04: attempt 2/3 std::string checkpoint_attempt_line( - std::string_view checkpoint, size_t attempt, std::optional attempts = std::nullopt + std::string_view checkpoint, size_t attempt, std::optional attempts = std::nullopt, + std::string_view display_text = "" ); // A checkpoint passed on attempt `attempt`, counting from 1; every attempt // before it ended in a reset: // [Checkpoint] 00.03: passed on attempt 1 (one-shot) // [Checkpoint] 00.04: passed on attempt 3 (2 resets) -std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt); +std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, std::string_view display_text = ""); // An attempt failed and the game resets to the checkpoint's save for // attempt `next_attempt`: // [Checkpoint] 00.04: failed, resetting for attempt 2 -std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attempt); +std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attempt, std::string_view display_text = ""); // The story engine reloads within segment `segment`, out of `attempts`: // [Segment] 00: 00.02 failed, reloading for attempt 2/3 diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp index 7c705d7d74..f8063b7a2f 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp @@ -5,7 +5,9 @@ */ #include +#include #include +#include #include #include "Common/Cpp/TestRunners/UnitTest.h" #include "Pokemon_StoryLog.h" @@ -51,6 +53,9 @@ class Test_StoryLog : public UnitTest{ const StoryLogTestCase m_case; }; +// SV's display text for a checkpoint, which already says "Checkpoint::". +constexpr std::string_view SV_TEXT = "Checkpoint:: 004 - 02. Start point: X"; + const StoryLogTestCase STORY_LOG_CASES[] = { { .input = {.name = "event", .line = event_log_line("00.04", 3, "talk_mom", "start")}, @@ -88,6 +93,22 @@ const StoryLogTestCase STORY_LOG_CASES[] = { .input = {.name = "reset", .line = checkpoint_reset_line("00.04", 2)}, .expectation = {.line = "[Checkpoint] 00.04: failed, resetting for attempt 2"}, }, + { + .input = {.name = "start with display text", .line = checkpoint_start_line("004", std::nullopt, SV_TEXT)}, + .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: start"}, + }, + { + .input = {.name = "attempt with display text", .line = checkpoint_attempt_line("004", 2, 100, SV_TEXT)}, + .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: attempt 2/100"}, + }, + { + .input = {.name = "pass with display text", .line = checkpoint_pass_line("004", 2, SV_TEXT)}, + .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: passed on attempt 2 (1 reset)"}, + }, + { + .input = {.name = "reset with display text", .line = checkpoint_reset_line("004", 2, SV_TEXT)}, + .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: failed, resetting for attempt 2"}, + }, { .input = {.name = "reload within a segment", .line = segment_reload_line("00", "00.02", 2, 3)}, .expectation = {.line = "[Segment] 00: 00.02 failed, reloading for attempt 2/3"}, From 687023e5d873bfdd0778cea21377c9a2fd95d1ce Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 15:07:58 -0800 Subject: [PATCH 18/26] AutoStory: checkpoint_head -> checkpoint_prefix The text a [Checkpoint] line starts with is its prefix; the local is named prefix to match. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon/AutoStory/Pokemon_StoryLog.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp index 2d002518ff..c151907331 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp @@ -21,7 +21,7 @@ std::string resets_text(size_t attempt){ } // "[Checkpoint] 00.04", or the game's own display text. -std::string checkpoint_head(std::string_view checkpoint, std::string_view display_text){ +std::string checkpoint_prefix(std::string_view checkpoint, std::string_view display_text){ if (!display_text.empty()){ return std::string(display_text); } @@ -38,32 +38,32 @@ std::string event_log_line(std::string_view checkpoint, size_t number, std::stri std::string checkpoint_start_line( std::string_view checkpoint, std::optional events, std::string_view display_text ){ - const std::string head = checkpoint_head(checkpoint, display_text); + const std::string prefix = checkpoint_prefix(checkpoint, display_text); if (!events){ - return std::format("{}: start", head); + return std::format("{}: start", prefix); } - return std::format("{}: start, {} events", head, *events); + return std::format("{}: start, {} events", prefix, *events); } std::string checkpoint_attempt_line( std::string_view checkpoint, size_t attempt, std::optional attempts, std::string_view display_text ){ - const std::string head = checkpoint_head(checkpoint, display_text); + const std::string prefix = checkpoint_prefix(checkpoint, display_text); if (!attempts){ - return std::format("{}: attempt {}", head, attempt); + return std::format("{}: attempt {}", prefix, attempt); } - return std::format("{}: attempt {}/{}", head, attempt, *attempts); + return std::format("{}: attempt {}/{}", prefix, attempt, *attempts); } std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, std::string_view display_text){ return std::format( - "{}: passed on attempt {} ({})", checkpoint_head(checkpoint, display_text), attempt, resets_text(attempt) + "{}: passed on attempt {} ({})", checkpoint_prefix(checkpoint, display_text), attempt, resets_text(attempt) ); } std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attempt, std::string_view display_text){ return std::format( - "{}: failed, resetting for attempt {}", checkpoint_head(checkpoint, display_text), next_attempt + "{}: failed, resetting for attempt {}", checkpoint_prefix(checkpoint, display_text), next_attempt ); } From 2a33aa5d58ddd457992ce48b85cc787f756a694f Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 15:07:58 -0800 Subject: [PATCH 19/26] SV AutoStory: checkpoint attempt, reset and pass lines use StoryLog checkpoint_reattempt_loop and its tutorial variant write the shared attempt and reset lines, plus a new pass line, with checkpoint_text() as the display text, so SV users still see "Checkpoint:: . Start point: ..." at the start of each line. Attempts now count from 1. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon/AutoStory/Pokemon_StoryLog.h | 6 +++--- .../AutoStory/PokemonSV_AutoStoryTools.cpp | 20 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h index 9b0f368a18..dc0fdebb5a 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h @@ -5,9 +5,9 @@ * The log lines an AutoStory program writes around its checkpoints, in * one format for every game: the story engine (Pokemon_StoryEvents.h, * Pokemon_StorySegments.h) writes them, and SV's AutoStory writes the same - * checkpoint start line, so the program developer and user find each - * checkpoint's start, attempts, resets and pass the same way in any game's - * log. Nothing here runs a story. + * checkpoint start, attempt, reset and pass lines, so the program developer + * and user find each checkpoint's start, attempts, resets and pass the same + * way in any game's log. Nothing here runs a story. * */ diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp index c2d61152df..79231cab83 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp @@ -14,6 +14,7 @@ #include "CommonTools/Async/InferenceRoutines.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" +#include "Pokemon/AutoStory/Pokemon_StoryLog.h" #include "VideoGames/PokemonSV/Inference/Battles/PokemonSV_NormalBattleMenus.h" #include "VideoGames/PokemonSV/Inference/Dialogs/PokemonSV_DialogDetector.h" #include "VideoGames/PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.h" @@ -1420,9 +1421,10 @@ void check_num_sunflora_found(SingleSwitchProgramEnvironment& env, ProController ); } - } +constexpr std::string_view NO_CHECKPOINT_ID = ""; // SV's checkpoint_text() names the checkpoint. + void checkpoint_reattempt_loop( SingleSwitchProgramEnvironment& env, ProControllerContext& context, @@ -1445,13 +1447,13 @@ void checkpoint_reattempt_loop( save_game_from_overworld(env.program_info(), env.console, context); } - env.console.log(checkpoint_text + " Num attempts: " + std::to_string(i)); + env.console.log(Pokemon::checkpoint_attempt_line(NO_CHECKPOINT_ID, i + 1, std::nullopt, checkpoint_text)); context.wait_for_all_requests(); action(i); enter_menu_from_overworld(env.program_info(), env.console, context, -1); - + env.console.log(Pokemon::checkpoint_pass_line(NO_CHECKPOINT_ID, i + 1, checkpoint_text)); break; }catch (OperationFailedException& e){ if (i == 10){ // send an error report for debugging if 10 failed attempts for a given checkpoint. @@ -1479,13 +1481,12 @@ void checkpoint_reattempt_loop( ); } context.wait_for_all_requests(); - env.console.log("Resetting from checkpoint."); + env.console.log(Pokemon::checkpoint_reset_line(NO_CHECKPOINT_ID, i + 2, checkpoint_text)); reset_game(env.program_info(), env.console, context); stats.m_reset++; env.update_stats(); } } - } void checkpoint_reattempt_loop_tutorial( @@ -1506,13 +1507,12 @@ void checkpoint_reattempt_loop_tutorial( env.update_stats(); send_program_status_notification(env, notif_status_update, "Saved at checkpoint."); } - - env.console.log(checkpoint_text + " Num attempts: " + std::to_string(i)); + env.console.log(Pokemon::checkpoint_attempt_line(NO_CHECKPOINT_ID, i + 1, std::nullopt, checkpoint_text)); context.wait_for_all_requests(); action(i); - - break; + env.console.log(Pokemon::checkpoint_pass_line(NO_CHECKPOINT_ID, i + 1, checkpoint_text)); + break; }catch (OperationFailedException& e){ if (i == 10){ // send an error report for debugging if 10 failed attempts for a given checkpoint. auto snapshot = env.console.video().snapshot().frame; @@ -1538,7 +1538,7 @@ void checkpoint_reattempt_loop_tutorial( ); } context.wait_for_all_requests(); - env.console.log("Resetting from checkpoint."); + env.console.log(Pokemon::checkpoint_reset_line(NO_CHECKPOINT_ID, i + 2, checkpoint_text)); reset_game(env.program_info(), env.console, context); stats.m_reset++; env.update_stats(); From 8310a2afbb302e974f4ec87851be9621e181cbdb Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 15:31:59 -0800 Subject: [PATCH 20/26] AutoStory: move StoryRunCounts to the segment report, its first user StoryRunCounts and record_story_counts() have no caller in this PR; their first user is SegmentReport::story_counts() in #114, so they move there. AutoStoryStats and the log lines stay. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/Pokemon_AutoStoryStats.cpp | 22 ----- .../AutoStory/Pokemon_AutoStoryStats.h | 16 +--- .../Pokemon_AutoStoryStats_Tests.cpp | 93 ------------------- .../AutoStory/Pokemon_AutoStoryStats_Tests.h | 23 ----- .../AutoStory/Pokemon_AutoStory_Tests.h | 2 - SerialPrograms/cmake/SourceFiles.cmake | 3 - 6 files changed, 2 insertions(+), 157 deletions(-) delete mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp delete mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp delete mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp deleted file mode 100644 index 42ca1aea91..0000000000 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* AutoStory Stats - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "Pokemon_AutoStoryStats.h" - -namespace PokemonAutomation{ -namespace Pokemon{ - - -void record_story_counts(const StoryRunCounts& counts, AutoStoryStats& stats){ - stats.m_segment += counts.segments; - stats.m_checkpoint += counts.checkpoints; - stats.m_reset += counts.resets; -} - - - -} // namespace Pokemon -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h index 8daa049cf6..47951b2635 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h @@ -7,7 +7,8 @@ #ifndef PokemonAutomation_Pokemon_AutoStoryStats_H #define PokemonAutomation_Pokemon_AutoStoryStats_H -#include +#include +#include #include "CommonFramework/ProgramStats/StatsTracking.h" namespace PokemonAutomation{ @@ -32,19 +33,6 @@ struct AutoStoryStats : public StatsTracker{ }; -// What a story run adds to the program's stats. -struct StoryRunCounts{ - size_t segments = 0; - // Checkpoints passed (and saved at). - size_t checkpoints = 0; - // Game resets or reloads after failed attempts. - size_t resets = 0; -}; - -// Adds `counts` to the shared AutoStory stats. -void record_story_counts(const StoryRunCounts& counts, AutoStoryStats& stats); - - } // namespace Pokemon } // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp deleted file mode 100644 index b427cd6d22..0000000000 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* AutoStory Stats Tests - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include -#include -#include -#include "Common/Cpp/TestRunners/UnitTest.h" -#include "Pokemon_AutoStoryStats.h" -#include "Pokemon_AutoStoryStats_Tests.h" - -namespace PokemonAutomation{ -namespace Pokemon{ - -namespace{ - -// Counts recorded into the AutoStory stats and the totals they must reach. -struct StoryCountsTestCase{ - // Counts added to fresh stats, in order. - struct Input{ - std::string name; - std::vector added; - }; - - // The stats after them: counts add up rather than replace. - struct Expectation{ - uint64_t segments; - uint64_t checkpoints; - uint64_t resets; - }; - - Input input; - Expectation expectation; -}; - -class Test_StoryCounts : public UnitTest{ -public: - Test_StoryCounts(StoryCountsTestCase test_case) - : UnitTest(std::format("Pokemon::AutoStoryStats - {}", test_case.input.name)) - , m_case(std::move(test_case)) - {} - - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - AutoStoryStats stats; - for (const StoryRunCounts& counts : m_case.input.added){ - record_story_counts(counts, stats); - } - const StoryCountsTestCase::Expectation& expected = m_case.expectation; - if (stats.m_segment != expected.segments || stats.m_checkpoint != expected.checkpoints || stats.m_reset != expected.resets){ - return std::format( - "Expected {} segments, {} checkpoints and {} resets, got {}, {} and {}", - expected.segments, expected.checkpoints, expected.resets, - stats.m_segment.load(), stats.m_checkpoint.load(), stats.m_reset.load() - ); - } - return true; - } - -private: - const StoryCountsTestCase m_case; -}; - -const StoryCountsTestCase STORY_COUNTS_CASES[] = { - { - .input = {.name = "a segment's counts in the stats", .added = {{.segments = 1, .checkpoints = 2, .resets = 3}}}, - .expectation = {.segments = 1, .checkpoints = 2, .resets = 3}, - }, - { - .input = { - .name = "a checkpoint loop's counts add up", - .added = {{.segments = 0, .checkpoints = 1, .resets = 0}, {.segments = 0, .checkpoints = 0, .resets = 1}, {.segments = 0, .checkpoints = 1, .resets = 0}}, - }, - .expectation = {.segments = 0, .checkpoints = 2, .resets = 1}, - }, -}; - -} // namespace - - -void add_tests_AutoStoryStats(UnitTestDatabase& database){ - for (const StoryCountsTestCase& test_case : STORY_COUNTS_CASES){ - database.add(test_case); - } -} - - - -} // namespace Pokemon -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.h deleted file mode 100644 index 21deca69ec..0000000000 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.h +++ /dev/null @@ -1,23 +0,0 @@ -/* AutoStory Stats Tests - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_Pokemon_AutoStoryStats_Tests_H -#define PokemonAutomation_Pokemon_AutoStoryStats_Tests_H - -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" - -namespace PokemonAutomation{ -namespace Pokemon{ - - -// Registers unit tests for the story counts added to the AutoStory stats. -void add_tests_AutoStoryStats(UnitTestDatabase& database); - - - -} // namespace Pokemon -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h index 98faaca844..3a5b133c8f 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h @@ -13,7 +13,6 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Pokemon_AutoStorySelect_Tests.h" -#include "Pokemon_AutoStoryStats_Tests.h" #include "Pokemon_StoryLog_Tests.h" namespace PokemonAutomation{ @@ -23,7 +22,6 @@ namespace Pokemon{ // Registers every shared AutoStory suite, for the unit test runner. inline void add_tests_AutoStory(UnitTestDatabase& database){ add_tests_AutoStorySelect(database); - add_tests_AutoStoryStats(database); add_tests_StoryLog(database); } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 9c777c006c..c98679c93f 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1483,10 +1483,7 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h - Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h - Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp - Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.h Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp Source/Pokemon/AutoStory/Pokemon_StoryLog.h From ea12373c25585eb420d938421166778d5db041dc Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 17:04:57 -0800 Subject: [PATCH 21/26] AutoStory: story_short_line, the overlay form of a log line Full lines go to the log; the video overlay shows each without its leading "[Tag] ". Table tests in Pokemon_StoryLog_Tests.cpp. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon/AutoStory/Pokemon_StoryLog.cpp | 11 +++++++++ .../Pokemon/AutoStory/Pokemon_StoryLog.h | 7 ++++++ .../AutoStory/Pokemon_StoryLog_Tests.cpp | 24 +++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp index c151907331..c1102718a0 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp @@ -74,6 +74,17 @@ std::string segment_reload_line(std::string_view segment, std::string_view check ); } +std::string story_short_line(std::string_view line){ + if (!line.starts_with('[')){ + return std::string(line); + } + const size_t end = line.find("] "); + if (end == std::string_view::npos){ + return std::string(line); + } + return std::string(line.substr(end + 2)); +} + } // namespace Pokemon diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h index dc0fdebb5a..7e185c5754 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h @@ -65,6 +65,13 @@ std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attem // [Segment] 00: 00.02 failed, reloading for attempt 2/3 std::string segment_reload_line(std::string_view segment, std::string_view checkpoint, size_t next_attempt, size_t attempts); +// The full lines above go to the log. The video overlay, which wraps its +// lines, shows each one short, without its leading "[Tag] ": +// [Event] 12.03/3 fly_pallet: start -> 12.03/3 fly_pallet: start +// [Checkpoint] 12.03: start, 18 events -> 12.03: start, 18 events +// A line without a tag, like SV's display text, is returned unchanged. +std::string story_short_line(std::string_view line); + } // namespace Pokemon diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp index f8063b7a2f..7626c4eeef 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp @@ -113,6 +113,30 @@ const StoryLogTestCase STORY_LOG_CASES[] = { .input = {.name = "reload within a segment", .line = segment_reload_line("00", "00.02", 2, 3)}, .expectation = {.line = "[Segment] 00: 00.02 failed, reloading for attempt 2/3"}, }, + { + .input = {.name = "short event", .line = story_short_line("[Event] 12.03/3 fly_pallet: start")}, + .expectation = {.line = "12.03/3 fly_pallet: start"}, + }, + { + .input = {.name = "short checkpoint start", .line = story_short_line("[Checkpoint] 12.03: start, 18 events")}, + .expectation = {.line = "12.03: start, 18 events"}, + }, + { + .input = {.name = "short segment line", .line = story_short_line("[Segment] 00: 00.02 failed, reloading for attempt 2/3")}, + .expectation = {.line = "00: 00.02 failed, reloading for attempt 2/3"}, + }, + { + .input = {.name = "short line without a tag", .line = story_short_line("Checkpoint:: 004 - 02. Start point: X: start")}, + .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: start"}, + }, + { + .input = {.name = "short line with an unclosed tag", .line = story_short_line("[Event 12.03")}, + .expectation = {.line = "[Event 12.03"}, + }, + { + .input = {.name = "short empty line", .line = story_short_line("")}, + .expectation = {.line = ""}, + }, }; From 752ad35aa1bba166ca3903d5373151209121bc99 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 20:49:19 -0800 Subject: [PATCH 22/26] StoryLog: checkpoint lines only; reset line takes the attempt limit The event line moves to the story engine that writes it, and the segment reload line goes: a reload is a checkpoint reset, written by checkpoint_reset_line with the attempt limit. The header says what a segment, a checkpoint and an event are. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon/AutoStory/Pokemon_StoryLog.cpp | 23 +++++-------- .../Pokemon/AutoStory/Pokemon_StoryLog.h | 34 ++++++++----------- .../AutoStory/Pokemon_StoryLog_Tests.cpp | 26 +++++--------- 3 files changed, 32 insertions(+), 51 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp index c1102718a0..1e7059baee 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp @@ -31,10 +31,6 @@ std::string checkpoint_prefix(std::string_view checkpoint, std::string_view disp } // namespace -std::string event_log_line(std::string_view checkpoint, size_t number, std::string_view event, std::string_view status){ - return std::format("[Event] {}/{} {}: {}", checkpoint, number, event, status); -} - std::string checkpoint_start_line( std::string_view checkpoint, std::optional events, std::string_view display_text ){ @@ -61,17 +57,14 @@ std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, st ); } -std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attempt, std::string_view display_text){ - return std::format( - "{}: failed, resetting for attempt {}", checkpoint_prefix(checkpoint, display_text), next_attempt - ); -} - -std::string segment_reload_line(std::string_view segment, std::string_view checkpoint, size_t next_attempt, size_t attempts){ - return std::format( - "[Segment] {}: {} failed, reloading for attempt {}/{}", - segment, checkpoint, next_attempt, attempts - ); +std::string checkpoint_reset_line( + std::string_view checkpoint, size_t next_attempt, std::optional attempts, std::string_view display_text +){ + const std::string prefix = checkpoint_prefix(checkpoint, display_text); + if (!attempts){ + return std::format("{}: failed, resetting for attempt {}", prefix, next_attempt); + } + return std::format("{}: failed, resetting for attempt {}/{}", prefix, next_attempt, *attempts); } std::string story_short_line(std::string_view line){ diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h index 7e185c5754..4d68d72915 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h @@ -2,12 +2,13 @@ * * From: https://github.com/PokemonAutomation/ * - * The log lines an AutoStory program writes around its checkpoints, in - * one format for every game: the story engine (Pokemon_StoryEvents.h, - * Pokemon_StorySegments.h) writes them, and SV's AutoStory writes the same - * checkpoint start, attempt, reset and pass lines, so the program developer - * and user find each checkpoint's start, attempts, resets and pass the same - * way in any game's log. Nothing here runs a story. + * A story is split at three levels: a segment is a chapter of + * checkpoints, a checkpoint is the stretch between two saves and the unit + * a run retries, and an event is one step inside a checkpoint. This file + * writes the checkpoint lines: start, attempt, reset and pass, in one + * format for every game, so the program developer and user find each + * checkpoint's attempts the same way in any game's log. Nothing here runs + * a story. * */ @@ -23,11 +24,6 @@ namespace PokemonAutomation{ namespace Pokemon{ -// One event's line: -// [Event] 00.04/3 talk_mom: start -// [Event] 00.04/3 talk_mom: failed: expect_failed: has_parcel -std::string event_log_line(std::string_view checkpoint, size_t number, std::string_view event, std::string_view status); - // The [Checkpoint] lines below name a checkpoint by its id. A game whose // checkpoints have their own text that already says it is a checkpoint // (SV's "Checkpoint:: 004 - 02 ...") passes that as `display_text`, and @@ -57,19 +53,19 @@ std::string checkpoint_attempt_line( std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, std::string_view display_text = ""); // An attempt failed and the game resets to the checkpoint's save for -// attempt `next_attempt`: +// attempt `next_attempt`, out of the limit of `attempts` if it has one: // [Checkpoint] 00.04: failed, resetting for attempt 2 -std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attempt, std::string_view display_text = ""); - -// The story engine reloads within segment `segment`, out of `attempts`: -// [Segment] 00: 00.02 failed, reloading for attempt 2/3 -std::string segment_reload_line(std::string_view segment, std::string_view checkpoint, size_t next_attempt, size_t attempts); +// [Checkpoint] 00.04: failed, resetting for attempt 2/3 +std::string checkpoint_reset_line( + std::string_view checkpoint, size_t next_attempt, std::optional attempts = std::nullopt, + std::string_view display_text = "" +); // The full lines above go to the log. The video overlay, which wraps its // lines, shows each one short, without its leading "[Tag] ": -// [Event] 12.03/3 fly_pallet: start -> 12.03/3 fly_pallet: start // [Checkpoint] 12.03: start, 18 events -> 12.03: start, 18 events -// A line without a tag, like SV's display text, is returned unchanged. +// Any line with a leading "[Tag] " is shortened the same way. A line +// without a tag, like SV's display text, is returned unchanged. std::string story_short_line(std::string_view line); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp index 7626c4eeef..7a948cd89d 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp @@ -57,10 +57,6 @@ class Test_StoryLog : public UnitTest{ constexpr std::string_view SV_TEXT = "Checkpoint:: 004 - 02. Start point: X"; const StoryLogTestCase STORY_LOG_CASES[] = { - { - .input = {.name = "event", .line = event_log_line("00.04", 3, "talk_mom", "start")}, - .expectation = {.line = "[Event] 00.04/3 talk_mom: start"}, - }, { .input = {.name = "checkpoint start", .line = checkpoint_start_line("00.04")}, .expectation = {.line = "[Checkpoint] 00.04: start"}, @@ -93,6 +89,10 @@ const StoryLogTestCase STORY_LOG_CASES[] = { .input = {.name = "reset", .line = checkpoint_reset_line("00.04", 2)}, .expectation = {.line = "[Checkpoint] 00.04: failed, resetting for attempt 2"}, }, + { + .input = {.name = "reset out of a limit", .line = checkpoint_reset_line("00.04", 2, 3)}, + .expectation = {.line = "[Checkpoint] 00.04: failed, resetting for attempt 2/3"}, + }, { .input = {.name = "start with display text", .line = checkpoint_start_line("004", std::nullopt, SV_TEXT)}, .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: start"}, @@ -106,32 +106,24 @@ const StoryLogTestCase STORY_LOG_CASES[] = { .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: passed on attempt 2 (1 reset)"}, }, { - .input = {.name = "reset with display text", .line = checkpoint_reset_line("004", 2, SV_TEXT)}, + .input = {.name = "reset with display text", .line = checkpoint_reset_line("004", 2, std::nullopt, SV_TEXT)}, .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: failed, resetting for attempt 2"}, }, - { - .input = {.name = "reload within a segment", .line = segment_reload_line("00", "00.02", 2, 3)}, - .expectation = {.line = "[Segment] 00: 00.02 failed, reloading for attempt 2/3"}, - }, - { - .input = {.name = "short event", .line = story_short_line("[Event] 12.03/3 fly_pallet: start")}, - .expectation = {.line = "12.03/3 fly_pallet: start"}, - }, { .input = {.name = "short checkpoint start", .line = story_short_line("[Checkpoint] 12.03: start, 18 events")}, .expectation = {.line = "12.03: start, 18 events"}, }, { - .input = {.name = "short segment line", .line = story_short_line("[Segment] 00: 00.02 failed, reloading for attempt 2/3")}, - .expectation = {.line = "00: 00.02 failed, reloading for attempt 2/3"}, + .input = {.name = "short line with another tag", .line = story_short_line("[Tag] 12.03: some text")}, + .expectation = {.line = "12.03: some text"}, }, { .input = {.name = "short line without a tag", .line = story_short_line("Checkpoint:: 004 - 02. Start point: X: start")}, .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: start"}, }, { - .input = {.name = "short line with an unclosed tag", .line = story_short_line("[Event 12.03")}, - .expectation = {.line = "[Event 12.03"}, + .input = {.name = "short line with an unclosed tag", .line = story_short_line("[Tag 12.03")}, + .expectation = {.line = "[Tag 12.03"}, }, { .input = {.name = "short empty line", .line = story_short_line("")}, From 2eca3ab66640a3901edb6d30d805826082cec259 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 20:49:47 -0800 Subject: [PATCH 23/26] StoryLog tests: the case name sits outside its input Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/Pokemon_StoryLog_Tests.cpp | 58 ++++++++++++------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp index 7a948cd89d..cdd375ed78 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp @@ -22,7 +22,6 @@ namespace{ struct StoryLogTestCase{ // A formatter's line, made when the table is built. struct Input{ - std::string name; std::string line; }; @@ -31,6 +30,7 @@ struct StoryLogTestCase{ std::string line; }; + std::string name; Input input; Expectation expectation; }; @@ -38,7 +38,7 @@ struct StoryLogTestCase{ class Test_StoryLog : public UnitTest{ public: Test_StoryLog(StoryLogTestCase test_case) - : UnitTest(std::format("Pokemon::StoryLog - {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::StoryLog - {}", test_case.name)) , m_case(std::move(test_case)) {} @@ -58,75 +58,93 @@ constexpr std::string_view SV_TEXT = "Checkpoint:: 004 - 02. Start point: X"; const StoryLogTestCase STORY_LOG_CASES[] = { { - .input = {.name = "checkpoint start", .line = checkpoint_start_line("00.04")}, + .name = "checkpoint start", + .input = {.line = checkpoint_start_line("00.04")}, .expectation = {.line = "[Checkpoint] 00.04: start"}, }, { - .input = {.name = "checkpoint start with its events", .line = checkpoint_start_line("00.04", 3)}, + .name = "checkpoint start with its events", + .input = {.line = checkpoint_start_line("00.04", 3)}, .expectation = {.line = "[Checkpoint] 00.04: start, 3 events"}, }, { - .input = {.name = "attempt", .line = checkpoint_attempt_line("00.04", 2)}, + .name = "attempt", + .input = {.line = checkpoint_attempt_line("00.04", 2)}, .expectation = {.line = "[Checkpoint] 00.04: attempt 2"}, }, { - .input = {.name = "attempt out of a limit", .line = checkpoint_attempt_line("00.04", 2, 3)}, + .name = "attempt out of a limit", + .input = {.line = checkpoint_attempt_line("00.04", 2, 3)}, .expectation = {.line = "[Checkpoint] 00.04: attempt 2/3"}, }, { - .input = {.name = "one-shot pass", .line = checkpoint_pass_line("00.03", 1)}, + .name = "one-shot pass", + .input = {.line = checkpoint_pass_line("00.03", 1)}, .expectation = {.line = "[Checkpoint] 00.03: passed on attempt 1 (one-shot)"}, }, { - .input = {.name = "pass after one reset", .line = checkpoint_pass_line("00.04", 2)}, + .name = "pass after one reset", + .input = {.line = checkpoint_pass_line("00.04", 2)}, .expectation = {.line = "[Checkpoint] 00.04: passed on attempt 2 (1 reset)"}, }, { - .input = {.name = "pass after resets", .line = checkpoint_pass_line("00.04", 3)}, + .name = "pass after resets", + .input = {.line = checkpoint_pass_line("00.04", 3)}, .expectation = {.line = "[Checkpoint] 00.04: passed on attempt 3 (2 resets)"}, }, { - .input = {.name = "reset", .line = checkpoint_reset_line("00.04", 2)}, + .name = "reset", + .input = {.line = checkpoint_reset_line("00.04", 2)}, .expectation = {.line = "[Checkpoint] 00.04: failed, resetting for attempt 2"}, }, { - .input = {.name = "reset out of a limit", .line = checkpoint_reset_line("00.04", 2, 3)}, + .name = "reset out of a limit", + .input = {.line = checkpoint_reset_line("00.04", 2, 3)}, .expectation = {.line = "[Checkpoint] 00.04: failed, resetting for attempt 2/3"}, }, { - .input = {.name = "start with display text", .line = checkpoint_start_line("004", std::nullopt, SV_TEXT)}, + .name = "start with display text", + .input = {.line = checkpoint_start_line("004", std::nullopt, SV_TEXT)}, .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: start"}, }, { - .input = {.name = "attempt with display text", .line = checkpoint_attempt_line("004", 2, 100, SV_TEXT)}, + .name = "attempt with display text", + .input = {.line = checkpoint_attempt_line("004", 2, 100, SV_TEXT)}, .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: attempt 2/100"}, }, { - .input = {.name = "pass with display text", .line = checkpoint_pass_line("004", 2, SV_TEXT)}, + .name = "pass with display text", + .input = {.line = checkpoint_pass_line("004", 2, SV_TEXT)}, .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: passed on attempt 2 (1 reset)"}, }, { - .input = {.name = "reset with display text", .line = checkpoint_reset_line("004", 2, std::nullopt, SV_TEXT)}, + .name = "reset with display text", + .input = {.line = checkpoint_reset_line("004", 2, std::nullopt, SV_TEXT)}, .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: failed, resetting for attempt 2"}, }, { - .input = {.name = "short checkpoint start", .line = story_short_line("[Checkpoint] 12.03: start, 18 events")}, + .name = "short checkpoint start", + .input = {.line = story_short_line("[Checkpoint] 12.03: start, 18 events")}, .expectation = {.line = "12.03: start, 18 events"}, }, { - .input = {.name = "short line with another tag", .line = story_short_line("[Tag] 12.03: some text")}, + .name = "short line with another tag", + .input = {.line = story_short_line("[Tag] 12.03: some text")}, .expectation = {.line = "12.03: some text"}, }, { - .input = {.name = "short line without a tag", .line = story_short_line("Checkpoint:: 004 - 02. Start point: X: start")}, + .name = "short line without a tag", + .input = {.line = story_short_line("Checkpoint:: 004 - 02. Start point: X: start")}, .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: start"}, }, { - .input = {.name = "short line with an unclosed tag", .line = story_short_line("[Tag 12.03")}, + .name = "short line with an unclosed tag", + .input = {.line = story_short_line("[Tag 12.03")}, .expectation = {.line = "[Tag 12.03"}, }, { - .input = {.name = "short empty line", .line = story_short_line("")}, + .name = "short empty line", + .input = {.line = story_short_line("")}, .expectation = {.line = ""}, }, }; From ec6e5e2bfc44f339c2a81d72dea817f7bff3fcae Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 21:50:28 -0800 Subject: [PATCH 24/26] StoryLog: add_checkpoint_prefix replaces display_text The checkpoint lines take `bool add_checkpoint_prefix = true` in place of `display_text`. SV passes its checkpoint text as `checkpoint` with the prefix off, so NO_CHECKPOINT_ID goes. Literal positional arguments carry a parameter-name comment. SV's reset lines now pass the attempt limit slot explicitly (they passed the text into it before). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon/AutoStory/Pokemon_StoryLog.cpp | 25 ++++++++------- .../Pokemon/AutoStory/Pokemon_StoryLog.h | 32 ++++++++++++------- .../AutoStory/Pokemon_StoryLog_Tests.cpp | 30 +++++++++-------- .../AutoStory/PokemonSV_AutoStoryTools.cpp | 14 ++++---- 4 files changed, 56 insertions(+), 45 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp index 1e7059baee..5fed3725bf 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp @@ -20,10 +20,10 @@ std::string resets_text(size_t attempt){ return std::format("{} reset{}", attempt - 1, attempt == 2 ? "" : "s"); } -// "[Checkpoint] 00.04", or the game's own display text. -std::string checkpoint_prefix(std::string_view checkpoint, std::string_view display_text){ - if (!display_text.empty()){ - return std::string(display_text); +// "[Checkpoint] 00.04", or the game's own checkpoint text unchanged. +std::string checkpoint_prefix(std::string_view checkpoint, bool add_checkpoint_prefix){ + if (!add_checkpoint_prefix){ + return std::string(checkpoint); } return std::format("[Checkpoint] {}", checkpoint); } @@ -32,9 +32,9 @@ std::string checkpoint_prefix(std::string_view checkpoint, std::string_view disp std::string checkpoint_start_line( - std::string_view checkpoint, std::optional events, std::string_view display_text + std::string_view checkpoint, std::optional events, bool add_checkpoint_prefix ){ - const std::string prefix = checkpoint_prefix(checkpoint, display_text); + const std::string prefix = checkpoint_prefix(checkpoint, add_checkpoint_prefix); if (!events){ return std::format("{}: start", prefix); } @@ -42,25 +42,26 @@ std::string checkpoint_start_line( } std::string checkpoint_attempt_line( - std::string_view checkpoint, size_t attempt, std::optional attempts, std::string_view display_text + std::string_view checkpoint, size_t attempt, std::optional attempts, bool add_checkpoint_prefix ){ - const std::string prefix = checkpoint_prefix(checkpoint, display_text); + const std::string prefix = checkpoint_prefix(checkpoint, add_checkpoint_prefix); if (!attempts){ return std::format("{}: attempt {}", prefix, attempt); } return std::format("{}: attempt {}/{}", prefix, attempt, *attempts); } -std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, std::string_view display_text){ +std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, bool add_checkpoint_prefix){ return std::format( - "{}: passed on attempt {} ({})", checkpoint_prefix(checkpoint, display_text), attempt, resets_text(attempt) + "{}: passed on attempt {} ({})", + checkpoint_prefix(checkpoint, add_checkpoint_prefix), attempt, resets_text(attempt) ); } std::string checkpoint_reset_line( - std::string_view checkpoint, size_t next_attempt, std::optional attempts, std::string_view display_text + std::string_view checkpoint, size_t next_attempt, std::optional attempts, bool add_checkpoint_prefix ){ - const std::string prefix = checkpoint_prefix(checkpoint, display_text); + const std::string prefix = checkpoint_prefix(checkpoint, add_checkpoint_prefix); if (!attempts){ return std::format("{}: failed, resetting for attempt {}", prefix, next_attempt); } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h index 4d68d72915..11bfb009d2 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h @@ -24,17 +24,19 @@ namespace PokemonAutomation{ namespace Pokemon{ -// The [Checkpoint] lines below name a checkpoint by its id. A game whose -// checkpoints have their own text that already says it is a checkpoint -// (SV's "Checkpoint:: 004 - 02 ...") passes that as `display_text`, and -// the line starts with it in place of "[Checkpoint] ": +// The lines below start with "[Checkpoint] " and then `checkpoint`. A game +// whose checkpoint text already says it is a checkpoint (SV's +// "Checkpoint:: 004 - 02 ...") passes that text as `checkpoint` and +// `add_checkpoint_prefix` false, and the line starts with the text alone: // Checkpoint:: 004 - 02 ...: start // A checkpoint starts; the story engine also says it has `events` events: // [Checkpoint] 00.04: start // [Checkpoint] 00.04: start, 3 events std::string checkpoint_start_line( - std::string_view checkpoint, std::optional events = std::nullopt, std::string_view display_text = "" + std::string_view checkpoint, + std::optional events = std::nullopt, + bool add_checkpoint_prefix = true ); // An attempt at a checkpoint starts, counting from 1, out of the @@ -42,30 +44,38 @@ std::string checkpoint_start_line( // [Checkpoint] 00.04: attempt 2 // [Checkpoint] 00.04: attempt 2/3 std::string checkpoint_attempt_line( - std::string_view checkpoint, size_t attempt, std::optional attempts = std::nullopt, - std::string_view display_text = "" + std::string_view checkpoint, + size_t attempt, + std::optional attempts = std::nullopt, + bool add_checkpoint_prefix = true ); // A checkpoint passed on attempt `attempt`, counting from 1; every attempt // before it ended in a reset: // [Checkpoint] 00.03: passed on attempt 1 (one-shot) // [Checkpoint] 00.04: passed on attempt 3 (2 resets) -std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, std::string_view display_text = ""); +std::string checkpoint_pass_line( + std::string_view checkpoint, + size_t attempt, + bool add_checkpoint_prefix = true +); // An attempt failed and the game resets to the checkpoint's save for // attempt `next_attempt`, out of the limit of `attempts` if it has one: // [Checkpoint] 00.04: failed, resetting for attempt 2 // [Checkpoint] 00.04: failed, resetting for attempt 2/3 std::string checkpoint_reset_line( - std::string_view checkpoint, size_t next_attempt, std::optional attempts = std::nullopt, - std::string_view display_text = "" + std::string_view checkpoint, + size_t next_attempt, + std::optional attempts = std::nullopt, + bool add_checkpoint_prefix = true ); // The full lines above go to the log. The video overlay, which wraps its // lines, shows each one short, without its leading "[Tag] ": // [Checkpoint] 12.03: start, 18 events -> 12.03: start, 18 events // Any line with a leading "[Tag] " is shortened the same way. A line -// without a tag, like SV's display text, is returned unchanged. +// without a tag, like SV's checkpoint text, is returned unchanged. std::string story_short_line(std::string_view line); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp index cdd375ed78..759ed9b3d7 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp @@ -53,7 +53,7 @@ class Test_StoryLog : public UnitTest{ const StoryLogTestCase m_case; }; -// SV's display text for a checkpoint, which already says "Checkpoint::". +// SV's text for a checkpoint, which already says "Checkpoint::". constexpr std::string_view SV_TEXT = "Checkpoint:: 004 - 02. Start point: X"; const StoryLogTestCase STORY_LOG_CASES[] = { @@ -64,7 +64,7 @@ const StoryLogTestCase STORY_LOG_CASES[] = { }, { .name = "checkpoint start with its events", - .input = {.line = checkpoint_start_line("00.04", 3)}, + .input = {.line = checkpoint_start_line("00.04", /*events=*/3)}, .expectation = {.line = "[Checkpoint] 00.04: start, 3 events"}, }, { @@ -74,7 +74,7 @@ const StoryLogTestCase STORY_LOG_CASES[] = { }, { .name = "attempt out of a limit", - .input = {.line = checkpoint_attempt_line("00.04", 2, 3)}, + .input = {.line = checkpoint_attempt_line("00.04", 2, /*attempts=*/3)}, .expectation = {.line = "[Checkpoint] 00.04: attempt 2/3"}, }, { @@ -99,27 +99,27 @@ const StoryLogTestCase STORY_LOG_CASES[] = { }, { .name = "reset out of a limit", - .input = {.line = checkpoint_reset_line("00.04", 2, 3)}, + .input = {.line = checkpoint_reset_line("00.04", 2, /*attempts=*/3)}, .expectation = {.line = "[Checkpoint] 00.04: failed, resetting for attempt 2/3"}, }, { - .name = "start with display text", - .input = {.line = checkpoint_start_line("004", std::nullopt, SV_TEXT)}, + .name = "start without the checkpoint prefix", + .input = {.line = checkpoint_start_line(SV_TEXT, /*events=*/std::nullopt, /*add_checkpoint_prefix=*/false)}, .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: start"}, }, { - .name = "attempt with display text", - .input = {.line = checkpoint_attempt_line("004", 2, 100, SV_TEXT)}, + .name = "attempt without the checkpoint prefix", + .input = {.line = checkpoint_attempt_line(SV_TEXT, 2, /*attempts=*/100, /*add_checkpoint_prefix=*/false)}, .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: attempt 2/100"}, }, { - .name = "pass with display text", - .input = {.line = checkpoint_pass_line("004", 2, SV_TEXT)}, + .name = "pass without the checkpoint prefix", + .input = {.line = checkpoint_pass_line(SV_TEXT, 2, /*add_checkpoint_prefix=*/false)}, .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: passed on attempt 2 (1 reset)"}, }, { - .name = "reset with display text", - .input = {.line = checkpoint_reset_line("004", 2, std::nullopt, SV_TEXT)}, + .name = "reset without the checkpoint prefix", + .input = {.line = checkpoint_reset_line(SV_TEXT, 2, /*attempts=*/std::nullopt, /*add_checkpoint_prefix=*/false)}, .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: failed, resetting for attempt 2"}, }, { @@ -133,8 +133,10 @@ const StoryLogTestCase STORY_LOG_CASES[] = { .expectation = {.line = "12.03: some text"}, }, { - .name = "short line without a tag", - .input = {.line = story_short_line("Checkpoint:: 004 - 02. Start point: X: start")}, + .name = "short line without the checkpoint prefix", + .input = {.line = story_short_line( + checkpoint_start_line(SV_TEXT, /*events=*/std::nullopt, /*add_checkpoint_prefix=*/false) + )}, .expectation = {.line = "Checkpoint:: 004 - 02. Start point: X: start"}, }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp index 79231cab83..cd90e4f630 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp @@ -1423,8 +1423,6 @@ void check_num_sunflora_found(SingleSwitchProgramEnvironment& env, ProController } -constexpr std::string_view NO_CHECKPOINT_ID = ""; // SV's checkpoint_text() names the checkpoint. - void checkpoint_reattempt_loop( SingleSwitchProgramEnvironment& env, ProControllerContext& context, @@ -1447,13 +1445,13 @@ void checkpoint_reattempt_loop( save_game_from_overworld(env.program_info(), env.console, context); } - env.console.log(Pokemon::checkpoint_attempt_line(NO_CHECKPOINT_ID, i + 1, std::nullopt, checkpoint_text)); + env.console.log(Pokemon::checkpoint_attempt_line(checkpoint_text, i + 1, /*attempts=*/std::nullopt, /*add_checkpoint_prefix=*/false)); context.wait_for_all_requests(); action(i); enter_menu_from_overworld(env.program_info(), env.console, context, -1); - env.console.log(Pokemon::checkpoint_pass_line(NO_CHECKPOINT_ID, i + 1, checkpoint_text)); + env.console.log(Pokemon::checkpoint_pass_line(checkpoint_text, i + 1, /*add_checkpoint_prefix=*/false)); break; }catch (OperationFailedException& e){ if (i == 10){ // send an error report for debugging if 10 failed attempts for a given checkpoint. @@ -1481,7 +1479,7 @@ void checkpoint_reattempt_loop( ); } context.wait_for_all_requests(); - env.console.log(Pokemon::checkpoint_reset_line(NO_CHECKPOINT_ID, i + 2, checkpoint_text)); + env.console.log(Pokemon::checkpoint_reset_line(checkpoint_text, i + 2, /*attempts=*/std::nullopt, /*add_checkpoint_prefix=*/false)); reset_game(env.program_info(), env.console, context); stats.m_reset++; env.update_stats(); @@ -1507,11 +1505,11 @@ void checkpoint_reattempt_loop_tutorial( env.update_stats(); send_program_status_notification(env, notif_status_update, "Saved at checkpoint."); } - env.console.log(Pokemon::checkpoint_attempt_line(NO_CHECKPOINT_ID, i + 1, std::nullopt, checkpoint_text)); + env.console.log(Pokemon::checkpoint_attempt_line(checkpoint_text, i + 1, /*attempts=*/std::nullopt, /*add_checkpoint_prefix=*/false)); context.wait_for_all_requests(); action(i); - env.console.log(Pokemon::checkpoint_pass_line(NO_CHECKPOINT_ID, i + 1, checkpoint_text)); + env.console.log(Pokemon::checkpoint_pass_line(checkpoint_text, i + 1, /*add_checkpoint_prefix=*/false)); break; }catch (OperationFailedException& e){ if (i == 10){ // send an error report for debugging if 10 failed attempts for a given checkpoint. @@ -1538,7 +1536,7 @@ void checkpoint_reattempt_loop_tutorial( ); } context.wait_for_all_requests(); - env.console.log(Pokemon::checkpoint_reset_line(NO_CHECKPOINT_ID, i + 2, checkpoint_text)); + env.console.log(Pokemon::checkpoint_reset_line(checkpoint_text, i + 2, /*attempts=*/std::nullopt, /*add_checkpoint_prefix=*/false)); reset_game(env.program_info(), env.console, context); stats.m_reset++; env.update_stats(); From e81d3bb5f0ae5fced369f76239832db25f0d8b05 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 22:03:10 -0800 Subject: [PATCH 25/26] AutoStory: StoryRunStats for the story engines (Runs, Checkpoints Passed, Resets) SV keeps AutoStoryStats and its saved keys (Checkpoint, Segment, Reset); the story engines get their own stats type whose names say what they count. --- .../AutoStory/Pokemon_AutoStoryStats.h | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h index 47951b2635..962f1d404e 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h @@ -15,8 +15,9 @@ namespace PokemonAutomation{ namespace Pokemon{ -// Saved checkpoints, segments started and game resets of an AutoStory run. -// The names are the keys of the saved stats; do not rename them. +// Scarlet/Violet's AutoStory stats: saved checkpoints, segments (story +// chapters) started and game resets. The names are the keys of the saved +// stats; do not rename them. struct AutoStoryStats : public StatsTracker{ AutoStoryStats() : m_checkpoint(m_stats["Checkpoint"]) @@ -32,6 +33,23 @@ struct AutoStoryStats : public StatsTracker{ std::atomic& m_reset; }; +// The stats of a story engine's AutoStory: program runs, checkpoints passed +// and game resets to a checkpoint's save. +struct StoryRunStats : public StatsTracker{ + StoryRunStats() + : m_runs(m_stats["Runs"]) + , m_checkpoints_passed(m_stats["Checkpoints Passed"]) + , m_resets(m_stats["Resets"]) + { + m_display_order.emplace_back("Runs"); + m_display_order.emplace_back("Checkpoints Passed"); + m_display_order.emplace_back("Resets"); + } + std::atomic& m_runs; + std::atomic& m_checkpoints_passed; + std::atomic& m_resets; +}; + } // namespace Pokemon } // namespace PokemonAutomation From 740530bcc39291fcf06e03832a6ba241881ffc9e Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 22:59:41 -0800 Subject: [PATCH 26/26] AutoStory: SV's AutoStoryStats stays in SV; the shared header keeps StoryRunStats --- .../Pokemon/AutoStory/Pokemon_AutoStoryStats.h | 18 ------------------ .../Programs/AutoStory/PokemonSV_AutoStory.cpp | 4 ++-- .../AutoStory/PokemonSV_AutoStoryTools.cpp | 18 ++++++++++-------- .../AutoStory/PokemonSV_AutoStoryTools.h | 17 ++++++++++++++--- 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h index 962f1d404e..bf54f786df 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h @@ -15,24 +15,6 @@ namespace PokemonAutomation{ namespace Pokemon{ -// Scarlet/Violet's AutoStory stats: saved checkpoints, segments (story -// chapters) started and game resets. The names are the keys of the saved -// stats; do not rename them. -struct AutoStoryStats : public StatsTracker{ - AutoStoryStats() - : m_checkpoint(m_stats["Checkpoint"]) - , m_segment(m_stats["Segment"]) - , m_reset(m_stats["Reset"]) - { - m_display_order.emplace_back("Checkpoint"); - m_display_order.emplace_back("Segment"); - m_display_order.emplace_back("Reset"); - } - std::atomic& m_checkpoint; - std::atomic& m_segment; - std::atomic& m_reset; -}; - // The stats of a story engine's AutoStory: program runs, checkpoints passed // and game resets to a checkpoint's save. struct StoryRunStats : public StatsTracker{ diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp index 9aca6582cc..130271139b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp @@ -5,6 +5,7 @@ */ + #if 0 #include "CommonFramework/Exceptions/UnexpectedBattleException.h" #include "CommonTools/Async/InferenceRoutines.h" @@ -27,7 +28,6 @@ #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "Pokemon/Pokemon_Strings.h" #include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" -#include "Pokemon/AutoStory/Pokemon_StoryLog.h" #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h" #include "VideoGames/PokemonSV/PokemonSV_Settings.h" #include "VideoGames/PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h" @@ -1230,7 +1230,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex require_player(env.console, context, BUTTON_L); if (ENABLE_ADVANCED_MODE){ - env.console.log(Pokemon::checkpoint_start_line(ALL_AUTO_STORY_CHECKPOINT_LIST()[get_start_checkpoint_index()]->name()), COLOR_ORANGE); + env.console.log("Start Checkpoint " + ALL_AUTO_STORY_CHECKPOINT_LIST()[get_start_checkpoint_index()]->name(), COLOR_ORANGE); }else{ env.console.log("Start Segment " + ALL_AUTO_STORY_SEGMENT_LIST()[get_start_segment_index()]->name(), COLOR_ORANGE); } diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp index cd90e4f630..c2d61152df 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp @@ -14,7 +14,6 @@ #include "CommonTools/Async/InferenceRoutines.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" -#include "Pokemon/AutoStory/Pokemon_StoryLog.h" #include "VideoGames/PokemonSV/Inference/Battles/PokemonSV_NormalBattleMenus.h" #include "VideoGames/PokemonSV/Inference/Dialogs/PokemonSV_DialogDetector.h" #include "VideoGames/PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.h" @@ -1421,6 +1420,7 @@ void check_num_sunflora_found(SingleSwitchProgramEnvironment& env, ProController ); } + } void checkpoint_reattempt_loop( @@ -1445,13 +1445,13 @@ void checkpoint_reattempt_loop( save_game_from_overworld(env.program_info(), env.console, context); } - env.console.log(Pokemon::checkpoint_attempt_line(checkpoint_text, i + 1, /*attempts=*/std::nullopt, /*add_checkpoint_prefix=*/false)); + env.console.log(checkpoint_text + " Num attempts: " + std::to_string(i)); context.wait_for_all_requests(); action(i); enter_menu_from_overworld(env.program_info(), env.console, context, -1); - env.console.log(Pokemon::checkpoint_pass_line(checkpoint_text, i + 1, /*add_checkpoint_prefix=*/false)); + break; }catch (OperationFailedException& e){ if (i == 10){ // send an error report for debugging if 10 failed attempts for a given checkpoint. @@ -1479,12 +1479,13 @@ void checkpoint_reattempt_loop( ); } context.wait_for_all_requests(); - env.console.log(Pokemon::checkpoint_reset_line(checkpoint_text, i + 2, /*attempts=*/std::nullopt, /*add_checkpoint_prefix=*/false)); + env.console.log("Resetting from checkpoint."); reset_game(env.program_info(), env.console, context); stats.m_reset++; env.update_stats(); } } + } void checkpoint_reattempt_loop_tutorial( @@ -1505,12 +1506,13 @@ void checkpoint_reattempt_loop_tutorial( env.update_stats(); send_program_status_notification(env, notif_status_update, "Saved at checkpoint."); } - env.console.log(Pokemon::checkpoint_attempt_line(checkpoint_text, i + 1, /*attempts=*/std::nullopt, /*add_checkpoint_prefix=*/false)); + + env.console.log(checkpoint_text + " Num attempts: " + std::to_string(i)); context.wait_for_all_requests(); action(i); - env.console.log(Pokemon::checkpoint_pass_line(checkpoint_text, i + 1, /*add_checkpoint_prefix=*/false)); - break; + + break; }catch (OperationFailedException& e){ if (i == 10){ // send an error report for debugging if 10 failed attempts for a given checkpoint. auto snapshot = env.console.video().snapshot().frame; @@ -1536,7 +1538,7 @@ void checkpoint_reattempt_loop_tutorial( ); } context.wait_for_all_requests(); - env.console.log(Pokemon::checkpoint_reset_line(checkpoint_text, i + 2, /*attempts=*/std::nullopt, /*add_checkpoint_prefix=*/false)); + env.console.log("Resetting from checkpoint."); reset_game(env.program_info(), env.console, context); stats.m_reset++; env.update_stats(); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h index e39d8a47da..3aa6be74be 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h @@ -14,7 +14,6 @@ #include "ML/Inference/ML_YOLOv5Detector.h" #include "ML/Inference/ML_YOLONavigation.h" #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" -#include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" #include "VideoGames/PokemonSV/Programs/PokemonSV_WorldNavigation.h" namespace PokemonAutomation{ @@ -25,8 +24,20 @@ using namespace ML; static constexpr bool ENABLE_TEST = false; -// Shared checkpoint, segment and reset counters used by SV AutoStory. -using AutoStoryStats = Pokemon::AutoStoryStats; +struct AutoStoryStats : public StatsTracker{ + AutoStoryStats() + : m_checkpoint(m_stats["Checkpoint"]) + , m_segment(m_stats["Segment"]) + , m_reset(m_stats["Reset"]) + { + m_display_order.emplace_back("Checkpoint"); + m_display_order.emplace_back("Segment"); + m_display_order.emplace_back("Reset"); + } + std::atomic& m_checkpoint; + std::atomic& m_segment; + std::atomic& m_reset; +};