From ff8ef13709f3e9449296f2eae608906745732a87 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 01:27:36 -0800 Subject: [PATCH 01/75] FRLG: AutoStory, FireRed from a new game to the Boulder Badge Checkpoints 00.01 to 00.08 from the by-hand run on console B (2026-11-01) as a table of story steps on the shared story engine: routes planned from the pose the run carries, talks, text read with B until START opens the menu, YES/NO answers, battles, the nurse, the Viridian Mart, saving with the START cursor read, and the new game's intro with default names. Routes walk with story interrupts that fight trainers (and wild Pokemon in the forest) instead of stopping. A failed checkpoint reloads its save. Unit tests plan every route of the table on the map files and check that checkpoints chain. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG/PokemonFRLG_Panels.cpp | 5 +- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 + .../AutoStory/PokemonFRLG_AutoStory.cpp | 131 ++++++ .../AutoStory/PokemonFRLG_AutoStory.h | 53 +++ .../PokemonFRLG_AutoStoryActions.cpp | 444 ++++++++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryActions.h | 99 ++++ .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 390 +++++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 74 +++ .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 248 ++++++++++ .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 124 +++++ .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 177 +++++++ .../AutoStory/PokemonFRLG_AutoStoryTable.h | 34 ++ .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 198 ++++++++ SerialPrograms/cmake/SourceFiles.cmake | 11 + 14 files changed, 1989 insertions(+), 1 deletion(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp index 430858dd9d..4321d038f4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp @@ -18,6 +18,8 @@ #include "Programs/Farming/PokemonFRLG_PickupFarmer.h" #include "Programs/Farming/PokemonFRLG_EvTrainer.h" +#include "Programs/AutoStory/PokemonFRLG_AutoStory.h" + #include "Programs/ShinyHunting/PokemonFRLG_GiftReset.h" #include "Programs/ShinyHunting/PokemonFRLG_LegendaryReset.h" #include "Programs/ShinyHunting/PokemonFRLG_LegendaryRunAway.h" @@ -69,7 +71,8 @@ std::vector PanelListFactory::make_panels() const{ ret.emplace_back(make_SingleSwitchProgram()); ret.emplace_back(make_SingleSwitchProgram()); - //ret.emplace_back("---- General ----"); + ret.emplace_back("---- General ----"); + ret.emplace_back(make_SingleSwitchProgram()); ret.emplace_back("---- Shiny Hunting ----"); ret.emplace_back(make_SingleSwitchProgram()); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index ed095a6f35..1d1a740ce5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -30,6 +30,7 @@ #include "Overworld/PokemonFRLG_OverworldRoute.h" #include "Overworld/PokemonFRLG_PlayerFacingReader.h" #include "PokemonFRLG_Navigation.h" +#include "Programs/AutoStory/PokemonFRLG_AutoStoryTable.h" #include "Tests/TestUtils.h" #include "PokemonFRLG_Tests.h" @@ -292,6 +293,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_OverworldMaps(database); add_tests_OverworldRoute(database); add_tests_PlayerFacingReader(database); + add_tests_AutoStory(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp new file mode 100644 index 0000000000..56aab77af0 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -0,0 +1,131 @@ +/* AutoStory + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/Notifications/ProgramNotifications.h" +#include "Pokemon/Pokemon_Strings.h" +#include "Pokemon/Navigation/Pokemon_StorySegments.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" +#include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStoryTable.h" +#include "PokemonFRLG_AutoStory.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +AutoStory_Descriptor::AutoStory_Descriptor() + : SingleSwitchProgramDescriptor( + "PokemonFRLG:AutoStory", + Pokemon::STRING_POKEMON + " FRLG", "AutoStory", + "", + "Play FireRed (English) from a new game to the Boulder Badge.", + PanelQualityStanding::OFFICIAL_BETA, + ProgramControllerClass::StandardController_NoRestrictions, + FeedbackType::REQUIRED, + AllowCommandsWhenRunning::DISABLE_COMMANDS + ) +{} + +AutoStory::AutoStory() + : START_CHECKPOINT( + "Start at checkpoint 00.0N:
1: new game, 2: bedroom, 3: Pallet Town, 4: Oak's Lab, " + "5: after the rival's battle, 6: Viridian Mart, 7: Pokedex, 8: Pewter Center.", + LockMode::LOCK_WHILE_RUNNING, + 1, 8, 1, 1 + ) + , END_CHECKPOINT( + "End after checkpoint 00.0N:
8 ends with the Boulder Badge.", + LockMode::LOCK_WHILE_RUNNING, + 1, 8, 8, 8 + ) + , NEW_GAME_FROM_TITLE( + "New game from the title screen:
The game is on its title screen with no save data. " + "Needed to start at 1. Otherwise the program loads the save, which must be the one the start checkpoint begins from.", + LockMode::LOCK_WHILE_RUNNING, + true + ) + , ATTEMPTS_PER_CHECKPOINT( + "Attempts per checkpoint:
A failed checkpoint reloads its save and runs again, up to this many times in all.", + LockMode::LOCK_WHILE_RUNNING, + 1, 5, 2, 2 + ) + , NOTIFICATIONS({ + &NOTIFICATION_PROGRAM_FINISH, + &NOTIFICATION_ERROR_FATAL, + }) +{ + PA_ADD_OPTION(START_CHECKPOINT); + PA_ADD_OPTION(END_CHECKPOINT); + PA_ADD_OPTION(NEW_GAME_FROM_TITLE); + PA_ADD_OPTION(ATTEMPTS_PER_CHECKPOINT); + PA_ADD_OPTION(NOTIFICATIONS); +} + + +void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ + const std::vector& checkpoints = story_checkpoints(); + const size_t first = START_CHECKPOINT - 1; + const size_t last = END_CHECKPOINT - 1; + if (first > last || last >= checkpoints.size()){ + throw UserSetupError(env.console, "The start checkpoint must not come after the end checkpoint."); + } + if (first == 0 && !NEW_GAME_FROM_TITLE){ + throw UserSetupError(env.console, "Checkpoint 00.01 starts a new game: start on the title screen with no save."); + } + + StoryEnv story{env.console, context, checkpoints[first].supplies, checkpoints[first].supplies, false}; + if (!(first == 0 && NEW_GAME_FROM_TITLE)){ + env.console.log("Loading the save for " + checkpoints[first].id + "."); + soft_reset(env.console, context); + story.has_save = true; + } + + Pokemon::Segment segment = make_story_segment(checkpoints, story); + Pokemon::SegmentHooks hooks; + hooks.reload = [&story](Pokemon::RunState&){ + if (!story.has_save){ + return Pokemon::outcome_failed("no_save", "nothing saved yet"); + } + try{ + soft_reset(story.console, story.context); + }catch (OperationFailedException& e){ + return Pokemon::outcome_failed("reload_failed", e.message()); + } + story.supplies = story.saved_supplies; + return Pokemon::outcome_ok(); + }; + hooks.log = [&env](const std::string& line){ + env.console.log(line); + }; + Pokemon::SegmentPolicy policy; + policy.attempts_per_checkpoint = ATTEMPTS_PER_CHECKPOINT; + + Pokemon::RunState state; + const Pokemon::SegmentReport report = run_segment( + state, segment, Pokemon::SegmentRange{checkpoints[first].id, checkpoints[last].id}, policy, hooks + ); + if (!report.completed){ + throw OperationFailedException( + ErrorReportMode::NO_ERROR_REPORT, + std::format( + "AutoStory stopped at {} {}: {}", + report.failed_checkpoint, report.failed_event, Pokemon::to_string(report.failure) + ) + ); + } + env.console.log("AutoStory: done through " + checkpoints[last].id + "."); + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h new file mode 100644 index 0000000000..a71a842818 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h @@ -0,0 +1,53 @@ +/* AutoStory + * + * From: https://github.com/PokemonAutomation/ + * + * Plays FireRed from a new game to the Boulder Badge, as the story + * checkpoints of PokemonFRLG_AutoStoryTable.h run by the shared story + * engine. Each checkpoint saves at its end; one that fails is retried from + * that save. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStory_H +#define PokemonAutomation_PokemonFRLG_AutoStory_H + +#include "Common/Cpp/Options/BooleanCheckBoxOption.h" +#include "Common/Cpp/Options/SimpleIntegerOption.h" +#include "CommonFramework/Notifications/EventNotificationsTable.h" +#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +class AutoStory_Descriptor : public SingleSwitchProgramDescriptor{ +public: + AutoStory_Descriptor(); +}; + +class AutoStory : public SingleSwitchProgramInstance{ +public: + using Descriptor = AutoStory_Descriptor; + AutoStory(); + virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override; + virtual void start_program_border_check( + VideoStream& stream, + FeedbackType feedback_type + ) override{} + +private: + SimpleIntegerOption START_CHECKPOINT; + SimpleIntegerOption END_CHECKPOINT; + BooleanCheckBoxOption NEW_GAME_FROM_TITLE; + SimpleIntegerOption ATTEMPTS_PER_CHECKPOINT; + EventNotificationsOption NOTIFICATIONS; +}; + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp new file mode 100644 index 0000000000..33280fc4fc --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -0,0 +1,444 @@ +/* AutoStory Actions + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "CommonTools/Images/SolidColorTest.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_SelectionArrowDetector.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "VideoGames/PokemonFRLG/Programs/PokemonFRLG_StartMenuNavigation.h" +#include "PokemonFRLG_AutoStoryActions.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace std::chrono_literals; +using Pokemon::Direction; + + +namespace{ + +constexpr Milliseconds POLL = 300ms; +// Text without an arrow or a prompt this long: press anyway, for a last +// line that waits without an arrow (Oak's "Here, come with me!"). +constexpr Milliseconds TEXT_STILL = 4000ms; +// Once a dialog closes in the intro, this long without one is a keyboard. +constexpr Milliseconds INTRO_QUIET = 3000ms; +constexpr Milliseconds INTRO_TIMEOUT = 600000ms; +// "Wait about 8 s" after YES at the nurse (console B, 2026-11-01): 1.5 s +// between presses did not heal. +constexpr Milliseconds HEAL_TIME = 8000ms; +// FRLG takes a tap this short as a turn, without a step. +constexpr Milliseconds TURN_TAP = 40ms; +constexpr Milliseconds TURN_SETTLE = 300ms; + +DpadPosition dpad(Direction direction){ + switch (direction){ + case Direction::NORTH: + return DPAD_UP; + case Direction::EAST: + return DPAD_RIGHT; + case Direction::SOUTH: + return DPAD_DOWN; + case Direction::WEST: + return DPAD_LEFT; + } + return DPAD_NONE; +} + +void press(ProControllerContext& context, Button button, Milliseconds after = 340ms){ + pbf_press_button(context, button, 160ms, after); +} + +void tap(ProControllerContext& context, DpadPosition position, Milliseconds after = 400ms){ + pbf_press_dpad(context, position, 160ms, after); +} + +// START opens the menu only on the overworld, with no scene running. If +// it opened, it is closed again. +bool overworld_shows(ConsoleHandle& console, ProControllerContext& context){ + press(context, BUTTON_PLUS, 1200ms); + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + if (!screen || !StartMenuDetector(COLOR_RED).detect(screen)){ + return false; + } + press(context, BUTTON_B, 600ms); + context.wait_for_all_requests(); + return true; +} + +// Which of the standard YES/NO box's rows the arrow is on, if it shows. +std::optional yes_no_cursor(const ImageViewRGB32& screen){ + if (SelectionArrowDetector(COLOR_RED, nullptr, SelectionArrowPositionConfirmationMenu::YES).detect(screen)){ + return true; + } + if (SelectionArrowDetector(COLOR_RED, nullptr, SelectionArrowPositionConfirmationMenu::NO).detect(screen)){ + return false; + } + return std::nullopt; +} + +bool wait_for_yes_no(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout){ + SelectionArrowWatcher yes(COLOR_RED, &console.overlay(), SelectionArrowPositionConfirmationMenu::YES); + context.wait_for_all_requests(); + return wait_until(console, context, timeout, {yes}) >= 0; +} + +// The START menu's cursor onto `row`, read from the arrow. As +// move_cursor_to_position(), for a menu of any length. +bool move_start_cursor(ConsoleHandle& console, ProControllerContext& context, int rows, int row){ + SelectionArrowWatcher arrow(COLOR_RED, &console.overlay(), MENU_ARROW_BOX); + context.wait_for_all_requests(); + if (wait_until(console, context, 2000ms, {arrow}) < 0){ + return false; + } + const double arrow_y = arrow.last_detected().y + arrow.last_detected().height / 2; + int current = 0; + double closest = std::numeric_limits::max(); + for (int c = 0; c < rows; c++){ + const ImageFloatBox box = SelectionArrowDetector::arrow_box_for_position(static_cast(c)); + const double distance = std::abs(arrow_y - (box.y + box.height / 2)); + if (distance < closest){ + closest = distance; + current = c; + } + } + console.log(std::format("START menu: cursor on row {}, moving to row {}.", current + 1, row + 1)); + const int down = (row - current + rows) % rows; + const int up = (current - row + rows) % rows; + for (int c = 0; c < std::min(down, up); c++){ + tap(context, down <= up ? DPAD_DOWN : DPAD_UP); + } + context.wait_for_all_requests(); + return true; +} + +void open_start_menu_row(ConsoleHandle& console, ProControllerContext& context, StartMenu menu, int row){ + open_start_menu(console, context); + if (!move_start_cursor(console, context, start_menu_rows(menu), row)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "START menu: no cursor.", console + ); + } + press(context, BUTTON_A, 1500ms); +} + + +// The new game's intro, from the title screen. Text is advanced with A +// (B may go back a question); a keyboard is told by the dialog box being +// gone for a while, and given an empty name: B deletes whatever a stray A +// typed, START jumps to OK. +class NewGameIntro{ +public: + NewGameIntro(ConsoleHandle& console, ProControllerContext& context) + : m_console(console) + , m_context(context) + {} + + void run(){ + press_a_until_dialog(); + const WallClock deadline = current_time() + INTRO_TIMEOUT; + m_last_dialog = current_time(); + m_last_press = m_last_dialog; + while (current_time() < deadline){ + if (step()){ + m_console.log("New game: the bedroom."); + return; + } + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "play_new_game_intro(): still in the intro after 10 minutes.", m_console + ); + } + +private: + // The title, then the controls pages, which A turns, up to Oak's first box. + void press_a_until_dialog(){ + WhiteDialogWatcher dialog(COLOR_RED); + m_context.wait_for_all_requests(); + const int ret = run_until( + m_console, m_context, + [](ProControllerContext& context){ + for (int c = 0; c < 80; c++){ + pbf_press_button(context, BUTTON_A, 160ms, 1340ms); + } + }, + {dialog} + ); + if (ret < 0){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "play_new_game_intro(): no message after the title screen.", m_console + ); + } + } + + // True once the bedroom shows. + bool step(){ + m_context.wait_for_all_requests(); + const WallClock now = current_time(); + VideoSnapshot screen = m_console.video().snapshot(); + if (!screen){ + pbf_wait(m_context, POLL); + return false; + } + if (yes_no_cursor(screen)){ + // "...Er, was it GREEN?" YES. + m_console.log("New game: YES."); + press_a(now, 1000ms); + return false; + } + if (WhiteDialogDetector(COLOR_RED).detect(screen)){ + m_dialog_seen = true; + m_last_dialog = now; + if (AdvanceWhiteDialogDetector(COLOR_RED).detect(screen)){ + m_still_presses = 0; + press_a(now, 400ms); + }else if (now - m_last_press > TEXT_STILL){ + still_dialog(now); + }else{ + pbf_wait(m_context, POLL); + } + return false; + } + m_still_presses = 0; + return quiet(screen, now); + } + + // A box with no arrow that A doesn't move on (BOY/GIRL takes one A): + // if the keyboard's frame reads as a message box, it is this. + void still_dialog(WallClock now){ + if (m_still_presses < 2){ + m_still_presses++; + press_a(now, 400ms); + return; + } + m_still_presses = 0; + enter_empty_name(); + m_last_press = current_time(); + } + + void enter_empty_name(){ + m_console.log("New game: a keyboard, confirming an empty name."); + for (int c = 0; c < 8; c++){ + press(m_context, BUTTON_B, 340ms); + } + press(m_context, BUTTON_PLUS, 500ms); + press(m_context, BUTTON_A, 1500ms); + } + + // No message box: a fade, a pause in the speech, a keyboard, or the bedroom. + bool quiet(const ImageViewRGB32& screen, WallClock now){ + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + if (is_black(game) || !m_dialog_seen || now - m_last_dialog < INTRO_QUIET){ + pbf_wait(m_context, POLL); + return false; + } + if (overworld_shows(m_console, m_context)){ + return true; + } + enter_empty_name(); + m_dialog_seen = false; + m_last_dialog = current_time(); + return false; + } + + void press_a(WallClock now, Milliseconds after){ + press(m_context, BUTTON_A, after); + m_last_press = now; + } + + ConsoleHandle& m_console; + ProControllerContext& m_context; + WallClock m_last_dialog; + WallClock m_last_press; + bool m_dialog_seen = false; + int m_still_presses = 0; +}; + +} + + +int start_menu_rows(StartMenu menu){ + switch (menu){ + case StartMenu::BEFORE_POKEMON: + return 5; + case StartMenu::BEFORE_POKEDEX: + return 6; + case StartMenu::FULL: + return 7; + } + return 7; +} +int start_menu_save_row(StartMenu menu){ + return start_menu_rows(menu) - 3; +} +int start_menu_option_row(StartMenu menu){ + return start_menu_rows(menu) - 2; +} + + +TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout, bool stop_at_battle){ + const WallClock deadline = current_time() + timeout; + while (current_time() < deadline){ + BattleDialogWatcher battle(COLOR_RED); + BattleMenuWatcher battle_menu(COLOR_RED); + context.wait_for_all_requests(); + const int ret = run_until( + console, context, + [](ProControllerContext& context){ + for (int c = 0; c < 5; c++){ + pbf_press_button(context, BUTTON_B, 160ms, 340ms); + } + }, + {battle, battle_menu} + ); + if (ret >= 0 && stop_at_battle){ + return TextEnd::BATTLE; + } + if (ret < 0 && overworld_shows(console, context)){ + return TextEnd::OVERWORLD; + } + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("advance_text(): the overworld didn't come back within {} s.", timeout.count() / 1000), + console + ); +} + +void mash_until_overworld(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout){ + advance_text(console, context, timeout, false); +} + +void answer_yes_no(ConsoleHandle& console, ProControllerContext& context, bool yes, Button advance, Milliseconds timeout){ + const WallClock deadline = current_time() + timeout; + WallClock last_press = current_time(); + while (current_time() < deadline){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + const std::optional on_yes = screen ? yes_no_cursor(screen) : std::nullopt; + if (on_yes){ + console.log(yes ? "Answering YES." : "Answering NO."); + if (yes && !*on_yes){ + tap(context, DPAD_UP); + } + press(context, yes ? BUTTON_A : BUTTON_B, 800ms); + context.wait_for_all_requests(); + return; + } + const WallClock now = current_time(); + if ((screen && AdvanceWhiteDialogDetector(COLOR_RED).detect(screen)) || now - last_press > TEXT_STILL){ + press(context, advance, 300ms); + last_press = now; + } + pbf_wait(context, POLL); + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "answer_yes_no(): no YES/NO.", console + ); +} + +void step_once(ProControllerContext& context, Direction direction, std::optional facing){ + if (facing != direction){ + pbf_press_dpad(context, dpad(direction), TURN_TAP, TURN_SETTLE); + } + // A step, once started, finishes on its own. + pbf_press_dpad(context, dpad(direction), 120ms, 500ms); + context.wait_for_all_requests(); +} + +void face_wall(ProControllerContext& context, Direction direction){ + pbf_press_dpad(context, dpad(direction), TURN_TAP, TURN_SETTLE); + context.wait_for_all_requests(); +} + +void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu menu){ + console.log("Saving the game."); + open_start_menu_row(console, context, menu, start_menu_save_row(menu)); + // The save card and "Would you like to save the game?" + if (!wait_for_yes_no(console, context, 5000ms)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "save_game(): no YES/NO to save.", console + ); + } + press(context, BUTTON_A, 1500ms); + // "There is already a saved file. Is it okay to overwrite it?", except + // for the first save. + if (wait_for_yes_no(console, context, 3000ms)){ + press(context, BUTTON_A, 1500ms); + } + pbf_wait(context, 4000ms); + mash_until_overworld(console, context, 30000ms); + console.log("Saved."); +} + +void set_options(ConsoleHandle& console, ProControllerContext& context, StartMenu menu){ + console.log("Options: text speed FAST, battle style SET."); + open_start_menu_row(console, context, menu, start_menu_option_row(menu)); + // TEXT SPEED (MID), BATTLE SCENE, BATTLE STYLE (SHIFT), ... + tap(context, DPAD_RIGHT); + tap(context, DPAD_DOWN); + tap(context, DPAD_DOWN); + tap(context, DPAD_RIGHT); + press(context, BUTTON_B, 1500ms); + mash_until_overworld(console, context, 20000ms); +} + +void heal_at_center(ConsoleHandle& console, ProControllerContext& context){ + console.log("Healing at the Pokemon Center."); + press(context, BUTTON_A, 1000ms); + answer_yes_no(console, context, true, BUTTON_A, 20000ms); + pbf_wait(context, HEAL_TIME); + mash_until_overworld(console, context, 30000ms); +} + +void buy_items(ConsoleHandle& console, ProControllerContext& context, const std::vector& orders){ + // "May I help you?" with BUY on top, then the list, cursor on its top. + press(context, BUTTON_A, 2000ms); + press(context, BUTTON_A, 2000ms); + for (const MartOrder& order : orders){ + console.log(std::format("Mart: buying {} of row {}.", order.quantity, order.row + 1)); + for (int c = 0; c < order.row; c++){ + tap(context, DPAD_DOWN, 300ms); + } + // "How many?" drops presses while its text prints. + press(context, BUTTON_A, 2500ms); + for (int c = 1; c < order.quantity; c++){ + tap(context, DPAD_UP, 340ms); + } + // "That will be..." YES/NO, YES, "Here you are!"; the cursor + // goes back to the top. + press(context, BUTTON_A, 3500ms); + press(context, BUTTON_A, 2000ms); + press(context, BUTTON_A, 1500ms); + } + press(context, BUTTON_B, 1500ms); + press(context, BUTTON_B, 1500ms); + mash_until_overworld(console, context, 20000ms); +} + +void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context){ + console.log("New game: from the title screen."); + NewGameIntro(console, context).run(); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h new file mode 100644 index 0000000000..68330aa7a2 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -0,0 +1,99 @@ +/* AutoStory Actions + * + * From: https://github.com/PokemonAutomation/ + * + * The console steps the FRLG story is made of, as a by-hand run from a new + * game to Brock found them (console B, 2026-11-01): reading text to its end, + * YES/NO prompts, saving from the START menu, the nurse, the Viridian Mart, + * and the new game's intro. Story text is advanced with B, which never + * starts a talk; the overworld is back once START opens the menu, which it + * doesn't while a scene runs. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryActions_H +#define PokemonAutomation_PokemonFRLG_AutoStoryActions_H + +#include +#include +#include "Common/Cpp/Time.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/Navigation/Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The START menu as the story grows it. Before the starter: BAG, the +// player, SAVE, OPTION, EXIT; the starter adds POKEMON on top, the Pokedex +// POKEDEX above that. +enum class StartMenu{ + BEFORE_POKEMON, + BEFORE_POKEDEX, + FULL, +}; +int start_menu_rows(StartMenu menu); +int start_menu_save_row(StartMenu menu); +int start_menu_option_row(StartMenu menu); + + +enum class TextEnd{ + OVERWORLD, + BATTLE, +}; + +// Presses B until the overworld is back or, if `stop_at_battle`, a battle +// shows. Throws OperationFailedException after `timeout`. +TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout, bool stop_at_battle); + +// advance_text() to the overworld. +void mash_until_overworld(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout); + +// Advances text with `advance` until a YES/NO shows, then answers it. B +// answers NO. Throws OperationFailedException after `timeout`. +void answer_yes_no(ConsoleHandle& console, ProControllerContext& context, bool yes, Button advance, Milliseconds timeout); + +// From the overworld: one step `direction`, onto a trigger or into a door. +// `facing` is the way the player faces, if known; a player facing another +// way is turned first. +void step_once(ProControllerContext& context, Pokemon::Direction direction, std::optional facing); + +// From the overworld, turns to face `direction` without stepping: the +// player must have a wall that way. +void face_wall(ProControllerContext& context, Pokemon::Direction direction); + +// From the overworld: SAVE, YES, and YES again to overwrite an older save. +// The menu's cursor is read, since the game remembers it and the menu +// grows. Returns to the overworld. +void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu menu); + +// From the overworld: OPTION, text speed FAST, battle style SET (no +// "Will you switch?" between a trainer's Pokemon). Returns to the +// overworld. +void set_options(ConsoleHandle& console, ProControllerContext& context, StartMenu menu); + +// Facing the nurse: A, YES, the heal, and the text to its end. +void heal_at_center(ConsoleHandle& console, ProControllerContext& context); + +// One line of a Mart's BUY list: the row (from 0) and how many. +struct MartOrder{ + int row = 0; + int quantity = 1; +}; + +// Facing a Mart clerk: BUY each order, then out to the overworld. +void buy_items(ConsoleHandle& console, ProControllerContext& context, const std::vector& orders); + +// From the title screen of a game with no save, to the bedroom: the +// controls pages, Oak's speech, BOY, and the default names for the player +// and the rival (an empty name confirmed). Returns on the overworld. +void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp new file mode 100644 index 0000000000..0b913d8791 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -0,0 +1,390 @@ +/* AutoStory Battle + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace std::chrono_literals; + + +namespace{ + +constexpr Milliseconds POLL = 300ms; +constexpr Milliseconds BATTLE_TIMEOUT = 600000ms; +// To see the battle at all, from its first flash. +constexpr Milliseconds BATTLE_START_TIMEOUT = 20000ms; +// No battle screen for this long: the battle is over. +constexpr Milliseconds BATTLE_GONE = 4000ms; +// A battle screen with neither an arrow nor a menu for this long: B, for +// a prompt the detectors miss. +constexpr Milliseconds STUCK = 8000ms; +// Seen this many polls in a row: the starter fainted. +constexpr int FAINT_POLLS = 3; +// Text and the move learn prompts after a battle, on the overworld. +constexpr Milliseconds AFTER_BATTLE_TEXT = 60000ms; + +// Inside the player's status box (name, level, HP bar, status), which +// BattlePokemonDetector frames. Not calibrated on the console yet. +const ImageFloatBox PLAYER_STATUS_BOX(0.600, 0.500, 0.340, 0.165); + + +struct ColorCounts{ + size_t green = 0; + size_t yellow = 0; + size_t red = 0; + size_t purple = 0; + size_t total = 0; +}; + +// The HP bar's three colors and the PSN badge's purple. Guessed from the +// game's palette, not measured. +ColorCounts count_colors(const ImageViewRGB32& image){ + ColorCounts counts; + for (size_t y = 0; y < image.height(); y++){ + for (size_t x = 0; x < image.width(); x++){ + const uint32_t pixel = image.pixel(x, y); + const int r = (pixel >> 16) & 0xff; + const int g = (pixel >> 8) & 0xff; + const int b = pixel & 0xff; + counts.total++; + if (g > 180 && r < 150 && b > 90 && b < 210){ + counts.green++; + }else if (r > 190 && g > 160 && b < 90){ + counts.yellow++; + }else if (r > 190 && g < 110 && b < 90){ + counts.red++; + }else if (r > 140 && b > 140 && g < 110){ + counts.purple++; + } + } + } + return counts; +} + + +enum class BattleScreen{ + MENU, // "What will do?" with FIGHT/BAG/POKEMON/RUN + LEARN, // a YES/NO about a move to learn + ADVANCE, // battle text waiting for a button + OTHER, // the battle, busy + NONE, // no battle on screen +}; + +BattleScreen read_battle_screen(const ImageViewRGB32& screen){ + if (BattleMenuDetector(COLOR_RED).detect(screen)){ + return BattleScreen::MENU; + } + if (BattleLearnDialogDetector(COLOR_RED).detect(screen)){ + return BattleScreen::LEARN; + } + if (AdvanceBattleDialogDetector(COLOR_RED).detect(screen)){ + return BattleScreen::ADVANCE; + } + if (BattleDialogDetector(COLOR_RED).detect(screen)){ + return BattleScreen::OTHER; + } + return BattleScreen::NONE; +} + +// The player's Pokemon gone while the opponent's is still there. +bool starter_fainted(const ImageViewRGB32& screen){ + return !BattlePokemonDetector(COLOR_RED).detect(screen) && BattleOpponentDetector(COLOR_RED).detect(screen); +} + +void tap(ProControllerContext& context, DpadPosition position){ + pbf_press_dpad(context, position, 160ms, 240ms); +} + +// From the battle menu: the item in `row` (from 0) of the Items pocket, on +// the starter. The bag opens on the pocket used last; Items is the first. +// Not run on the console yet. +void use_item(ConsoleHandle& console, ProControllerContext& context, int row){ + console.log(std::format("Battle: using the item in row {} of the Items pocket.", row + 1)); + tap(context, DPAD_LEFT); + tap(context, DPAD_UP); + tap(context, DPAD_RIGHT); + pbf_press_button(context, BUTTON_A, 160ms, 1500ms); + for (int c = 0; c < 2; c++){ + pbf_press_dpad(context, DPAD_LEFT, 160ms, 500ms); + } + for (int c = 0; c < 12; c++){ + pbf_press_dpad(context, DPAD_UP, 100ms, 150ms); + } + for (int c = 0; c < row; c++){ + tap(context, DPAD_DOWN); + } + // The item, USE, then the starter in the party list. + pbf_press_button(context, BUTTON_A, 160ms, 800ms); + pbf_press_button(context, BUTTON_A, 160ms, 1500ms); + pbf_press_button(context, BUTTON_A, 160ms, 1000ms); +} + +// FIGHT, then the bottom left move (Bubble), or Tackle while that slot is +// empty: the cursor doesn't move onto an empty slot. +void use_move(ProControllerContext& context){ + tap(context, DPAD_LEFT); + tap(context, DPAD_UP); + pbf_press_button(context, BUTTON_A, 160ms, 1000ms); + tap(context, DPAD_LEFT); + tap(context, DPAD_UP); + tap(context, DPAD_DOWN); + pbf_press_button(context, BUTTON_A, 160ms, 500ms); +} + + +class BattleLoop{ +public: + BattleLoop(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, bool trainer) + : m_console(console) + , m_context(context) + , m_supplies(supplies) + , m_trainer(trainer) + , m_start(current_time()) + , m_last_battle(m_start) + , m_last_press(m_start) + {} + + BattleEnd run(){ + m_console.log(m_trainer ? "Battle: fighting a trainer." : "Battle: fighting a wild Pokemon."); + while (!step()){} + m_console.log(std::format("Battle: over after {} turns{}.", m_turns, m_lost ? ", the starter fainted" : "")); + return m_lost ? BattleEnd::LOST : BattleEnd::WON; + } + +private: + // One look at the screen and what it asks for. True once the battle is over. + bool step(){ + m_context.wait_for_all_requests(); + const WallClock now = current_time(); + check_time(now); + VideoSnapshot screen = m_console.video().snapshot(); + if (!screen){ + pbf_wait(m_context, POLL); + return false; + } + const BattleScreen seen = read_battle_screen(screen); + if (seen == BattleScreen::NONE){ + if (m_seen_battle && now - m_last_battle > BATTLE_GONE){ + return true; + } + pbf_wait(m_context, POLL); + return false; + } + m_seen_battle = true; + m_last_battle = now; + act(seen, screen, now); + return false; + } + + void check_time(WallClock now){ + if (!m_seen_battle && now - m_start > BATTLE_START_TIMEOUT){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "fight_battle(): no battle on screen.", m_console + ); + } + if (now - m_start > BATTLE_TIMEOUT){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "fight_battle(): the battle took over 10 minutes.", m_console + ); + } + } + + void act(BattleScreen seen, const ImageViewRGB32& screen, WallClock now){ + switch (seen){ + case BattleScreen::MENU: + take_turn(screen); + m_last_press = now; + return; + case BattleScreen::LEARN: + // "Delete a move to make room?" NO, then "Stop learning?" YES. + m_console.log(m_learn_prompts % 2 == 0 ? "Battle: not deleting a move." : "Battle: stop learning."); + pbf_press_button(m_context, m_learn_prompts % 2 == 0 ? BUTTON_B : BUTTON_A, 160ms, 1500ms); + m_learn_prompts++; + m_last_press = now; + return; + case BattleScreen::ADVANCE: + pbf_press_button(m_context, BUTTON_B, 160ms, 200ms); + m_last_press = now; + return; + default: + break; + } + watch_for_faint(screen); + if (now - m_last_press > STUCK){ + pbf_press_button(m_context, BUTTON_B, 160ms, 200ms); + m_last_press = now; + } + pbf_wait(m_context, POLL); + } + + void take_turn(const ImageViewRGB32& screen){ + m_turns++; + m_faint_polls = 0; + const PartyStatus status = read_party_status(screen); + const bool hurt = status.hp_red || (m_trainer && status.hp_yellow); + if (hurt && m_supplies.potions > 0){ + m_supplies.potions--; + use_item(m_console, m_context, 0); + }else if (status.poisoned && m_supplies.antidotes > 0){ + m_supplies.antidotes--; + use_item(m_console, m_context, m_supplies.potions > 0 ? 1 : 0); + }else{ + use_move(m_context); + } + } + + void watch_for_faint(const ImageViewRGB32& screen){ + if (m_turns == 0 || m_lost){ + return; + } + m_faint_polls = starter_fainted(screen) ? m_faint_polls + 1 : 0; + if (m_faint_polls >= FAINT_POLLS){ + m_console.log("Battle: the starter fainted.", COLOR_RED); + m_lost = true; + } + } + + ConsoleHandle& m_console; + ProControllerContext& m_context; + Supplies& m_supplies; + const bool m_trainer; + const WallClock m_start; + WallClock m_last_battle; + WallClock m_last_press; + bool m_seen_battle = false; + bool m_lost = false; + size_t m_turns = 0; + size_t m_learn_prompts = 0; + int m_faint_polls = 0; +}; + + +void fail_on_blackout(ConsoleHandle& console, BattleEnd end){ + if (end == BattleEnd::LOST){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::NO_ERROR_REPORT, "Story: blackout: the starter fainted in a battle on the way.", console + ); + } +} + + +// A wild battle, seen by its flashes or, when they were missed, by "Wild +// appeared!". +class StoryWildBattle : public OverworldInterrupt{ +public: + StoryWildBattle(Supplies& supplies, bool fight, bool late) + : m_supplies(supplies) + , m_fight(fight) + , m_late(late) + {} + virtual std::string name() const override{ + return m_late ? "a wild battle (seen late)" : "a wild battle"; + } + virtual std::unique_ptr make_watcher() const override{ + if (m_late){ + return std::make_unique(COLOR_RED); + } + return std::make_unique(COLOR_RED); + } + // As the walker's own wild battle interrupts. + virtual Milliseconds detection_delay() const override{ + return m_late ? 2000ms : 300ms; + } + virtual void clear(ConsoleHandle& console, ProControllerContext& context) const override{ + if (!m_fight){ + flee_battle(console, context); + return; + } + fail_on_blackout(console, fight_battle(console, context, m_supplies, false)); + pbf_wait(context, 1000ms); + context.wait_for_all_requests(); + } + +private: + Supplies& m_supplies; + const bool m_fight; + const bool m_late; +}; + +// A message: read to its end, then a trainer's battle if one starts. +class StoryMessage : public OverworldInterrupt{ +public: + explicit StoryMessage(Supplies& supplies) + : m_supplies(supplies) + {} + virtual std::string name() const override{ + return "a message"; + } + virtual std::unique_ptr make_watcher() const override{ + return std::make_unique(COLOR_RED); + } + virtual Milliseconds detection_delay() const override{ + return 400ms; + } + virtual void clear(ConsoleHandle& console, ProControllerContext& context) const override{ + if (advance_text(console, context, AFTER_BATTLE_TEXT, true) == TextEnd::OVERWORLD){ + return; + } + console.log("Story: a trainer's battle after a message on the overworld."); + fail_on_blackout(console, fight_battle(console, context, m_supplies, true)); + mash_until_overworld(console, context, AFTER_BATTLE_TEXT); + } + +private: + Supplies& m_supplies; +}; + +} + + +PartyStatus read_party_status(const ImageViewRGB32& screen){ + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + const ColorCounts counts = count_colors(extract_box_reference(game, PLAYER_STATUS_BOX)); + // A full bar fills a few percent of the box; a sliver of one, much less. + const size_t seen = counts.total / 1000 + 1; + PartyStatus status; + const bool green = counts.green > seen; + status.hp_yellow = !green && counts.yellow > seen; + status.hp_red = !green && !status.hp_yellow && counts.red > seen; + status.poisoned = counts.purple > seen; + return status; +} + +BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, bool trainer){ + return BattleLoop(console, context, supplies, trainer).run(); +} + +OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild){ + // Battles first: their screens are checked before the message box's. + OverworldInterruptSet ret; + ret.wild.emplace_back(std::make_unique(supplies, fight_wild, false)); + ret.wild.emplace_back(std::make_unique(supplies, fight_wild, true)); + ret.wild.emplace_back(std::make_unique(supplies)); + ret.other.emplace_back(std::make_unique(supplies)); + return ret; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h new file mode 100644 index 0000000000..4379939200 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -0,0 +1,74 @@ +/* AutoStory Battle + * + * From: https://github.com/PokemonAutomation/ + * + * The battle loop of the FRLG story, for a party of one (the starter), as + * the by-hand run to Brock played it (console B, 2026-11-01): at each turn + * the cursor is put back on FIGHT and the move list's top left, since the + * game remembers both; the move is the bottom left one (Bubble), which the + * cursor can't reach while that slot is empty, so before Bubble it stays on + * Tackle. A Potion is used when the HP bar turns red (or yellow, against a + * trainer), an Antidote when the status shows PSN. "Delete a move to make + * room?" is answered NO and "Stop learning?" YES. + * + * Also the overworld interrupts the story walks routes with: wild battles + * run from (or fought, for EXP), and messages, after which a trainer's + * battle is fought instead of stopping the route. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattle_H +#define PokemonAutomation_PokemonFRLG_AutoStoryBattle_H + +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The healing items in the Items pocket, in the order they were bought: +// Potions first, then Antidotes. +struct Supplies{ + int potions = 0; + int antidotes = 0; +}; + +enum class BattleEnd{ + WON, + // The starter fainted: a blackout, except in the lab's rival battle, + // which the story goes on from. + LOST, +}; + +// What the HP bar and the status of the player's Pokemon show. +struct PartyStatus{ + bool hp_yellow = false; + bool hp_red = false; + bool poisoned = false; +}; +PartyStatus read_party_status(const ImageViewRGB32& screen); + +// From anywhere in a battle (or its opening), fights it to the end, using +// `supplies` as needed. `trainer` uses a Potion earlier. Returns once the +// battle's screens are gone; text after it (a gym leader's speech) is left +// for the caller. Throws OperationFailedException if it runs over +// 10 minutes. +BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, bool trainer); + + +// The interrupts for walking story routes. Wild battles are run from, or +// fought if `fight_wild`. A message is advanced until the overworld is +// back; a battle that starts after it (a trainer who saw the player) is +// fought. A battle lost (a blackout) throws OperationFailedException. +OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp new file mode 100644 index 0000000000..39700cdd90 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -0,0 +1,248 @@ +/* AutoStory Events + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "Pokemon/Navigation/Pokemon_TilePose.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryEvents.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace std::chrono_literals; +using Pokemon::Outcome; +using Pokemon::RunState; + + +namespace{ + +// The longest scenes: the old man's tutorial (about 60 lines and his +// catching demo), the lab's Pokedex scene (about 75 lines). +constexpr Milliseconds SCENE_TIMEOUT = 300000ms; +constexpr Milliseconds YES_NO_TIMEOUT = 60000ms; +constexpr Milliseconds BATTLE_TEXT_TIMEOUT = 90000ms; + +// The engine knows nothing of consoles: a failed console step is a failed +// Outcome, which the segment answers by reloading the save. +template +Outcome guarded(Body&& body){ + try{ + return body(); + }catch (OperationFailedException& e){ + return Pokemon::outcome_failed("operation_failed", e.message()); + } +} + +std::optional facing_of(const Pokemon::Pose& pose){ + const Pokemon::TilePose* tile_pose = dynamic_cast(pose.where.get()); + return tile_pose ? tile_pose->facing : std::nullopt; +} + +const MapData* find_story_map(const std::string& name){ + for (const MapData& map : story_maps()){ + if (map.name == name){ + return ↦ + } + } + return nullptr; +} + +// Turns the player to a wall next to `position`, which turns without a +// step whichever way the player faced. Nothing if no wall is next to it. +std::optional face_a_wall(StoryEnv& env, const MapPosition& position){ + const MapData* map = find_story_map(position.map); + if (map == nullptr){ + return std::nullopt; + } + const std::optional wall = wall_beside(*map, position.point); + if (wall){ + env.console.log(std::string("Story: facing unknown, turning to the wall ") + direction_name(*wall) + "."); + face_wall(env.context, *wall); + } + return wall; +} + +Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ + const std::vector tiles = Pokemon::tiles_of(state.pose); + if (tiles.size() != 1 || state.pose.certainty != Pokemon::PoseCertainty::TILE){ + return Pokemon::outcome_failed("no_pose", Pokemon::to_string(state.pose)); + } + const MapPosition start{state.pose.map, tiles[0]}; + std::optional facing = facing_of(state.pose); + if (!facing){ + facing = face_a_wall(env, start); + } + if (!facing){ + return Pokemon::outcome_failed("unknown_facing", to_string(start)); + } + const RouteGoal goal{{step.target.map, step.target.tile}, step.target.facing}; + const std::optional> route = plan_overworld_route( + story_maps(), start, goal, default_route_costs(), facing + ); + if (!route){ + return Pokemon::outcome_failed("no_route", to_string(start) + " to " + to_string(goal.position)); + } + const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild); + walk_overworld_route(env.console, env.context, *route, facing, interrupts); + const std::optional end_facing = route->empty() ? facing : std::optional(route->back().facing_after); + return Pokemon::outcome_ok(to_pose(StoryPose{step.target.map, step.target.tile, end_facing})); +} + +Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ + step_once(env.context, step.direction, facing_of(state.pose)); + const std::vector tiles = Pokemon::tiles_of(state.pose); + if (tiles.size() != 1){ + return Pokemon::outcome_ok(); + } + return Pokemon::outcome_ok(to_pose(StoryPose{state.pose.map, tiles[0].next(step.direction), step.direction})); +} + +Outcome battle(StoryEnv& env, const StoryStep& step){ + if (advance_text(env.console, env.context, BATTLE_TEXT_TIMEOUT, true) != TextEnd::BATTLE){ + return Pokemon::outcome_failed("no_battle"); + } + const BattleEnd end = fight_battle(env.console, env.context, env.supplies, true); + if (end == BattleEnd::LOST && !step.may_lose){ + return Pokemon::outcome_failed("blackout"); + } + mash_until_overworld(env.console, env.context, SCENE_TIMEOUT); + return Pokemon::outcome_ok(); +} + +Outcome shop(StoryEnv& env){ + // Viridian Mart before the Boulder Badge: POKE BALL, POTION, ANTIDOTE, PARLYZ HEAL. + buy_items(env.console, env.context, {{1, 4}, {2, 2}}); + env.supplies.potions += 4; + env.supplies.antidotes += 2; + return Pokemon::outcome_ok(); +} + +Outcome run_step(StoryEnv& env, RunState& state, const StoryStep& step, StartMenu menu){ + switch (step.kind){ + case StoryStepKind::NEW_GAME: + play_new_game_intro(env.console, env.context); + return Pokemon::outcome_ok(); + case StoryStepKind::SET_OPTIONS: + set_options(env.console, env.context, menu); + return Pokemon::outcome_ok(); + case StoryStepKind::ROUTE: + return walk_route(env, state, step); + case StoryStepKind::STEP: + return take_step(env, state, step); + case StoryStepKind::TALK: + pbf_press_button(env.context, BUTTON_A, 160ms, 800ms); + return Pokemon::outcome_ok(); + case StoryStepKind::ANSWER: + answer_yes_no(env.console, env.context, step.yes, BUTTON_B, YES_NO_TIMEOUT); + return Pokemon::outcome_ok(); + case StoryStepKind::MASH: + mash_until_overworld(env.console, env.context, SCENE_TIMEOUT); + return Pokemon::outcome_ok(); + case StoryStepKind::BATTLE: + return battle(env, step); + case StoryStepKind::HEAL: + heal_at_center(env.console, env.context); + return Pokemon::outcome_ok(); + case StoryStepKind::SHOP: + return shop(env); + } + return Pokemon::outcome_failed("unknown_step"); +} + +Pokemon::Event make_event(const StoryStep& step, StoryEnv& env, StartMenu menu){ + Pokemon::Event event; + event.name = step.name; + event.why = step.why; + event.act = [&env, &step, menu](RunState& state){ + return guarded([&]{ return run_step(env, state, step, menu); }); + }; + if (step.pose_after){ + event.pose_learned = to_pose(*step.pose_after); + } + return event; +} + +// The first event of a checkpoint that starts from a save: where the save +// leaves the player, for a run that reloaded it. +Pokemon::Event from_save_event(const StoryPose& start){ + Pokemon::Event event; + event.name = "from_save"; + event.why = "where the checkpoint's save leaves the player"; + event.act = [](RunState&){ return Pokemon::outcome_ok(); }; + event.pose_learned = to_pose(start); + return event; +} + +} + + +const std::vector& story_maps(){ + static const std::vector maps = overworld_maps(map_flag_set(overworld_maps(), "after_hall_of_fame")); + return maps; +} + +Pokemon::Pose to_pose(const StoryPose& pose){ + Pokemon::Pose ret; + ret.map = pose.map; + ret.certainty = Pokemon::PoseCertainty::TILE; + ret.where = std::make_shared(std::vector{pose.tile}, pose.facing); + return ret; +} + +std::optional wall_beside(const MapData& map, const TilePos& tile){ + for (Direction direction : {Direction::WEST, Direction::EAST, Direction::NORTH, Direction::SOUTH}){ + const TilePos next = tile.next(direction); + if (in_bounds(map, next) && tile_at(map, next) == Tile::WALL && object_at(map, next) == nullptr){ + return direction; + } + } + return std::nullopt; +} + +Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryEnv& env){ + Pokemon::Checkpoint checkpoint; + checkpoint.id = data.id; + if (data.start){ + checkpoint.events.push_back(from_save_event(*data.start)); + } + for (const StoryStep& step : data.steps){ + checkpoint.events.push_back(make_event(step, env, data.menu)); + } + const StartMenu menu = data.menu; + checkpoint.save = [&env, menu](RunState&){ + return guarded([&]{ + save_game(env.console, env.context, menu); + env.has_save = true; + env.saved_supplies = env.supplies; + return Pokemon::outcome_ok(); + }); + }; + return checkpoint; +} + +Pokemon::Segment make_story_segment(const std::vector& checkpoints, StoryEnv& env){ + Pokemon::Segment segment; + segment.id = "00"; + for (const StoryCheckpoint& data : checkpoints){ + segment.checkpoints.push_back(Pokemon::CheckpointSpec{ + data.id, data.title, false, + [&data, &env]{ return build_checkpoint(data, env); } + }); + } + return segment; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h new file mode 100644 index 0000000000..7ba4f6a14e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -0,0 +1,124 @@ +/* AutoStory Events + * + * From: https://github.com/PokemonAutomation/ + * + * The FRLG story as data for the shared story engine + * (Pokemon/Navigation/Pokemon_StoryEvents.h, Pokemon_StorySegments.h). + * A checkpoint is a list of StorySteps, each one kind of FRLG event (a + * route, a talk, text read to its end, a YES/NO, a battle, the nurse, the + * Mart); make_story_segment() turns the table into engine checkpoints whose + * events run them on the console. Routes plan from the pose the run + * carries and return where they leave the player; scenes that move the + * player say where in the table. + * + * The table itself is in PokemonFRLG_AutoStoryTable.h; it is plain data, + * so its routes are planned in unit tests without a console. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryEvents_H +#define PokemonAutomation_PokemonFRLG_AutoStoryEvents_H + +#include +#include +#include +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/Navigation/Pokemon_StoryEvents.h" +#include "Pokemon/Navigation/Pokemon_StorySegments.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Where the player stands and faces. An unknown facing (after a scene that +// turns the player) is set before the next route by turning to a wall. +struct StoryPose{ + std::string map; + TilePos tile; + std::optional facing; +}; + +enum class StoryStepKind{ + NEW_GAME, // title screen (no save) to the bedroom + SET_OPTIONS, // text speed FAST, battle style SET + ROUTE, // plan and walk to `target` + STEP, // one step `direction`: onto a trigger, into a door + TALK, // A at what the player faces + ANSWER, // text with B to a YES/NO, then `yes` + MASH, // text with B until the overworld is back + BATTLE, // text with B into a battle, fight it, text to the overworld + HEAL, // facing the nurse + SHOP, // facing the Viridian Mart clerk: Potions and Antidotes +}; + +struct StoryStep{ + StoryStepKind kind = StoryStepKind::TALK; + std::string name; + std::string why; + // ROUTE: the goal, and the way to face there if set. + StoryPose target; + // STEP + Direction direction = Direction::NORTH; + // ROUTE: fight wild battles for EXP instead of running. + bool fight_wild = false; + // ANSWER + bool yes = true; + // BATTLE: the starter may faint without a blackout (the lab's rival). + bool may_lose = false; + // Where a scene leaves the player. + std::optional pose_after; +}; + +struct StoryCheckpoint{ + std::string id; + std::string title; + // Where its starting save leaves the player; none for the new game. + std::optional start; + // The healing items at its start, for a run that loads its save. + Supplies supplies; + // The START menu at its end, when it saves. + StartMenu menu = StartMenu::FULL; + std::vector steps; +}; + + +// The maps the story plans on: every map to Brock, with the objects the +// game hides after the Hall of Fame removed, as the lab's frlg_route does. +const std::vector& story_maps(); + +Pokemon::Pose to_pose(const StoryPose& pose); + +// A way the player at `tile` can turn to without stepping: a wall there, +// with no one standing in it. West and east first: walking north or south +// into a sign would read it. +std::optional wall_beside(const MapData& map, const TilePos& tile); + + +// What the story's events act on. `supplies` are what the bag holds now, +// `saved_supplies` what the last save holds. +struct StoryEnv{ + ConsoleHandle& console; + ProControllerContext& context; + Supplies supplies; + Supplies saved_supplies; + // Whether the game has a save to reload. + bool has_save = false; +}; + +// The checkpoint `data` as events, saving at its end. +Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryEnv& env); + +// `checkpoints` (kept alive by the caller) as a segment for run_segment(). +Pokemon::Segment make_story_segment(const std::vector& checkpoints, StoryEnv& env); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp new file mode 100644 index 0000000000..e7766d089a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -0,0 +1,177 @@ +/* AutoStory Table + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +constexpr Direction NORTH = Direction::NORTH; +constexpr Direction SOUTH = Direction::SOUTH; +constexpr Direction EAST = Direction::EAST; +constexpr Direction WEST = Direction::WEST; + +const char* const BEDROOM = "PalletTown_PlayersHouse_2F"; +const char* const PALLET = "PalletTown"; +const char* const LAB = "PalletTown_ProfessorOaksLab"; +const char* const VIRIDIAN = "ViridianCity"; +const char* const VIRIDIAN_MART = "ViridianCity_Mart"; +const char* const VIRIDIAN_CENTER = "ViridianCity_PokemonCenter_1F"; +const char* const FOREST = "ViridianForest"; +const char* const PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; +const char* const GYM = "PewterCity_Gym"; + +StoryPose at(const char* map, int x, int y, std::optional facing = std::nullopt){ + return StoryPose{map, {x, y}, facing}; +} + +StoryStep make(StoryStepKind kind, std::string name, std::string why){ + StoryStep step; + step.kind = kind; + step.name = std::move(name); + step.why = std::move(why); + return step; +} + +StoryStep route(std::string name, StoryPose target, std::string why, bool fight_wild = false){ + StoryStep step = make(StoryStepKind::ROUTE, std::move(name), std::move(why)); + step.target = std::move(target); + step.fight_wild = fight_wild; + return step; +} + +StoryStep step_into(std::string name, Direction direction, std::string why){ + StoryStep step = make(StoryStepKind::STEP, std::move(name), std::move(why)); + step.direction = direction; + return step; +} + +StoryStep answer(std::string name, bool yes, std::string why){ + StoryStep step = make(StoryStepKind::ANSWER, std::move(name), std::move(why)); + step.yes = yes; + return step; +} + +StoryStep scene(std::string name, std::optional pose_after, std::string why){ + StoryStep step = make(StoryStepKind::MASH, std::move(name), std::move(why)); + step.pose_after = std::move(pose_after); + return step; +} + +StoryStep battle(std::string name, StoryPose pose_after, bool may_lose, std::string why){ + StoryStep step = make(StoryStepKind::BATTLE, std::move(name), std::move(why)); + step.pose_after = std::move(pose_after); + step.may_lose = may_lose; + return step; +} + + +StoryCheckpoint new_game(){ + StoryCheckpoint cp{"00.01", "new game to the bedroom", std::nullopt, {}, StartMenu::BEFORE_POKEMON, {}}; + StoryStep intro = make(StoryStepKind::NEW_GAME, "intro", "Oak's speech, BOY, default names, rival GREEN"); + intro.pose_after = at(BEDROOM, 6, 6, NORTH); // new_game.c: the bedroom at (6, 6), facing the TV + cp.steps.push_back(intro); + cp.steps.push_back(make(StoryStepKind::SET_OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon")); + return cp; +} + +StoryCheckpoint leave_house(){ + StoryCheckpoint cp{"00.02", "bedroom to Pallet Town", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, {}}; + cp.steps.push_back(route("front_door", at(PALLET, 6, 8), "down the stairs and out of the house")); + return cp; +} + +StoryCheckpoint oaks_trigger(){ + StoryCheckpoint cp{"00.03", "Oak stops the player and walks them to the lab", at(PALLET, 6, 8, SOUTH), {}, StartMenu::BEFORE_POKEMON, {}}; + cp.steps.push_back(route("below_oaks_trigger", at(PALLET, 12, 2, NORTH), "below the north exit, short of Oak's trigger at (12, 1)")); + cp.steps.push_back(step_into("oaks_trigger", NORTH, "the trigger: \"Don't go out!\"")); + // PlayerEnter walks the player up 8 tiles from the lab's door. + cp.steps.push_back(scene("to_the_lab", at(LAB, 6, 4, NORTH), "Oak walks the player into the lab; the scene ends at the table")); + return cp; +} + +StoryCheckpoint starter(){ + StoryCheckpoint cp{"00.04", "Squirtle, then the rival's battle", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEDEX, {}}; + cp.steps.push_back(route("below_squirtle", at(LAB, 9, 5, NORTH), "under Squirtle's ball (9, 4)")); + cp.steps.push_back(make(StoryStepKind::TALK, "squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\"")); + cp.steps.push_back(answer("choose_squirtle", true, "take Squirtle")); + cp.steps.push_back(answer("no_nickname", false, "\"give a nickname?\" NO")); + cp.steps.push_back(scene("rival_takes_bulbasaur", at(LAB, 9, 5), "the rival picks his ball; he may turn the player")); + cp.steps.push_back(route("above_rival_trigger", at(LAB, 7, 7, SOUTH), "short of the rival's trigger row 8")); + cp.steps.push_back(step_into("rival_trigger", SOUTH, "\"Wait, let's check out our POKEMON!\"")); + // The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down. + cp.steps.push_back(battle("rival_battle", at(LAB, 7, 8, SOUTH), true, "the tutorial battle; losing goes on too")); + return cp; +} + +StoryCheckpoint parcel(){ + StoryCheckpoint cp{"00.05", "Route 1 to Viridian Mart: Oak's Parcel", at(LAB, 7, 8, SOUTH), {}, StartMenu::BEFORE_POKEDEX, {}}; + cp.steps.push_back(route("below_mart_door", at(VIRIDIAN, 36, 20, NORTH), "Route 1, running from wild battles")); + cp.steps.push_back(step_into("mart_door", NORTH, "the clerk's scene starts on entering")); + // ApproachCounter: up 4 from the mat, then faces the clerk. + cp.steps.push_back(scene("parcel_from_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "the clerk gives OAK'S PARCEL")); + return cp; +} + +StoryCheckpoint pokedex(){ + StoryCheckpoint cp{"00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, {}}; + cp.steps.push_back(route("below_oak", at(LAB, 6, 4, NORTH), "back down Route 1 to Oak")); + cp.steps.push_back(make(StoryStepKind::TALK, "give_parcel", "Oak takes the parcel")); + cp.steps.push_back(scene("pokedex_scene", at(LAB, 6, 4), "the rival comes in, Pokedexes from the desk; turns the player")); + return cp; +} + +StoryCheckpoint forest(){ + StoryCheckpoint cp{"00.07", "Viridian shopping to Pewter Center", at(LAB, 6, 4), {}, StartMenu::FULL, {}}; + cp.steps.push_back(route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again")); + cp.steps.push_back(make(StoryStepKind::SHOP, "potions_and_antidotes", "4 Potions, 2 Antidotes")); + cp.steps.push_back(route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest")); + cp.steps.push_back(make(StoryStepKind::HEAL, "heal_viridian", "full HP")); + cp.steps.push_back(route("below_old_man_trigger", at(VIRIDIAN, 20, 9, NORTH), "short of the tutorial trigger (20, 8)")); + cp.steps.push_back(step_into("old_man_trigger", NORTH, "the old man's catching tutorial can't be walked around")); + // TutorialTriggerLeft turns the player right, to the old man. + cp.steps.push_back(scene("old_man_tutorial", at(VIRIDIAN, 20, 8, EAST), "about 60 lines and his demo battle; TEACHY TV")); + cp.steps.push_back(route("forest_entrance", at(FOREST, 29, 61), "Route 2, running from wild battles")); + // The forest legs walked by hand; wild battles are fought for EXP. + cp.steps.push_back(route("forest_west", at(FOREST, 13, 46), "west side of the forest", true)); + cp.steps.push_back(route("forest_east", at(FOREST, 42, 44), "east path, past a Bug Catcher", true)); + cp.steps.push_back(route("forest_north", at(FOREST, 39, 25), "north part", true)); + cp.steps.push_back(route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "out of the forest to Pewter's Center", true)); + cp.steps.push_back(make(StoryStepKind::HEAL, "heal_pewter", "full HP")); + return cp; +} + +StoryCheckpoint brock(){ + // The by-hand save: 2 Potions and 1 Antidote left after the forest. + StoryCheckpoint cp{"00.08", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, {}}; + cp.steps.push_back(route("past_camper_liam", at(GYM, 6, 6, NORTH), "Liam (3, 8) stops the player at (6, 8): fought on the way")); + cp.steps.push_back(route("back_to_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "heal after Liam")); + cp.steps.push_back(make(StoryStepKind::HEAL, "heal_before_brock", "full HP")); + cp.steps.push_back(route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5)")); + cp.steps.push_back(make(StoryStepKind::TALK, "challenge_brock", "Brock's speech")); + cp.steps.push_back(battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39")); + return cp; +} + +} + + +const std::vector& story_checkpoints(){ + static const std::vector checkpoints{ + new_game(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), forest(), brock(), + }; + return checkpoints; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h new file mode 100644 index 0000000000..4c107c9874 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -0,0 +1,34 @@ +/* AutoStory Table + * + * From: https://github.com/PokemonAutomation/ + * + * FireRed from a new game to the Boulder Badge, as story checkpoints + * 00.01 to 00.08, each saved at its end. Taken from a by-hand run on + * console B (2026-11-01) and the pokefirered map scripts. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryTable_H +#define PokemonAutomation_PokemonFRLG_AutoStoryTable_H + +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_AutoStoryEvents.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Checkpoints 00.01 to 00.08, in order. +const std::vector& story_checkpoints(); + + +void add_tests_AutoStory(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp new file mode 100644 index 0000000000..de3ed12d28 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -0,0 +1,198 @@ +/* AutoStory Tests + * + * From: https://github.com/PokemonAutomation/ + * + * Plans every route of the story table on the map files, from where the + * table says the player stands, and checks that each checkpoint starts + * where the one before it ends. + * + */ + +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +class Test_AutoStory : public UnitTest{ +public: + Test_AutoStory(std::string name, std::function body) + : UnitTest("PokemonFRLG::AutoStory - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (FileException& e){ + // CI runs with upstream Packages, which may not have the maps yet. + return UnitTestResult(UnitTestResult::SKIPPED, "Map files not found: " + e.message()); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + +const MapData* find_map_named(const std::string& name){ + for (const MapData& map : story_maps()){ + if (map.name == name){ + return ↦ + } + } + return nullptr; +} + +std::string describe(const std::vector& route){ + std::string text; + for (const RouteStep& step : route){ + text += "\n " + to_string(step); + } + return text; +} + +std::string describe(const StoryPose& pose){ + return to_string(MapPosition{pose.map, pose.tile}) + + (pose.facing ? std::string(" facing ") + direction_name(*pose.facing) : ""); +} + +Direction reverse(Direction direction){ + switch (direction){ + case Direction::NORTH: + return Direction::SOUTH; + case Direction::EAST: + return Direction::WEST; + case Direction::SOUTH: + return Direction::NORTH; + case Direction::WEST: + return Direction::EAST; + } + return direction; +} + +// The tiles a route's walking legs pass over on `map`. +std::vector tiles_walked_on(const std::vector& route, const std::string& map){ + std::vector tiles; + for (const RouteStep& step : route){ + if (step.action != RouteAction::WALK || step.end.map != map){ + continue; + } + TilePos tile = step.end.point; + for (int c = 0; c < step.tiles; c++){ + tiles.push_back(tile); + tile = tile.next(reverse(step.direction)); + } + } + return tiles; +} + +// Plans `step` from `pose` and moves `pose` to its end. +UnitTestResult check_route(StoryPose& pose, const StoryStep& step){ + const MapPosition start{pose.map, pose.tile}; + std::optional facing = pose.facing; + if (!facing){ + const MapData* map = find_map_named(pose.map); + facing = map ? wall_beside(*map, pose.tile) : std::nullopt; + if (!facing){ + return step.name + ": the facing is unknown at " + describe(pose) + " and no wall is beside it."; + } + } + const RouteGoal goal{{step.target.map, step.target.tile}, step.target.facing}; + const std::optional> route = plan_overworld_route(story_maps(), start, goal, default_route_costs(), facing); + if (!route){ + return step.name + ": no route from " + to_string(start) + " to " + to_string(goal.position) + "."; + } + const MapPosition end = follow_overworld_route(story_maps(), start, *route); + if (!(end == goal.position)){ + return step.name + ": the route ends at " + to_string(end) + ":" + describe(*route); + } + if (goal.facing && !route->empty() && route->back().facing_after != *goal.facing){ + return step.name + ": the route doesn't end facing " + direction_name(*goal.facing) + ":" + describe(*route); + } + if (step.name == "below_old_man_trigger"){ + for (const TilePos& tile : tiles_walked_on(*route, "ViridianCity")){ + if (tile == TilePos{20, 8} || tile == TilePos{22, 8}){ + return step.name + ": walks over the old man's trigger " + to_string(tile) + ":" + describe(*route); + } + } + } + pose = StoryPose{step.target.map, step.target.tile, route->empty() ? facing : route->back().facing_after}; + return true; +} + +// Follows `checkpoint` from its start; `pose` ends where it leaves the player. +UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& pose){ + for (const StoryStep& step : checkpoint.steps){ + if (step.kind == StoryStepKind::ROUTE){ + UnitTestResult result = check_route(pose, step); + if (result.result != UnitTestResult::PASSED){ + return checkpoint.id + " " + result.message; + } + }else if (step.kind == StoryStepKind::STEP){ + pose = StoryPose{pose.map, pose.tile.next(step.direction), step.direction}; + } + if (step.pose_after){ + pose = *step.pose_after; + } + } + return true; +} + +UnitTestResult test_routes_and_chain(){ + const std::vector& checkpoints = story_checkpoints(); + if (checkpoints.size() != 8 || checkpoints[0].start){ + return "Expected 8 checkpoints, the first from a new game."; + } + StoryPose pose; + for (size_t c = 0; c < checkpoints.size(); c++){ + const StoryCheckpoint& checkpoint = checkpoints[c]; + if (c > 0){ + const StoryPose& start = *checkpoint.start; + const bool same_facing = !start.facing || start.facing == pose.facing; + if (start.map != pose.map || !(start.tile == pose.tile) || !same_facing){ + return checkpoint.id + " starts at " + describe(start) + ", but " + checkpoints[c - 1].id + " ends at " + describe(pose) + "."; + } + pose = start; + } + UnitTestResult result = check_checkpoint(checkpoint, pose); + if (result.result != UnitTestResult::PASSED){ + return result; + } + } + return true; +} + +UnitTestResult test_unique_names(){ + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + for (size_t i = 0; i < checkpoint.steps.size(); i++){ + for (size_t j = i + 1; j < checkpoint.steps.size(); j++){ + if (checkpoint.steps[i].name == checkpoint.steps[j].name){ + return checkpoint.id + " has two steps named " + checkpoint.steps[i].name + "."; + } + } + } + } + return true; +} + +} + + +void add_tests_AutoStory(UnitTestDatabase& database){ + database.add("every route plans, and checkpoints chain", test_routes_and_chain); + database.add("step names are unique per checkpoint", test_unique_names); +} + + + +} +} +} diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 00cc9806ae..e27db01b33 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1781,6 +1781,17 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EliteFourFarmer.cpp Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EliteFourFarmer.h Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EvTrainer.cpp From 42a6513244fc7f10c04cb7668b8c4d250de13429 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 02:02:55 -0800 Subject: [PATCH 02/75] FRLG AutoStory: press only A in the new game's intro, B only on the keyboard The first console run went back to the controls pages: they read as a message box without an arrow, so after two presses the intro took them for the keyboard and pressed B, which in the intro goes back a page. Now a message box gets A every 1.5 s whatever it shows, and the empty name is entered only when the naming screen is detected. The naming screen detector is the one from frlg/naming-screen (fork #81), unchanged; on the lab's 331 captures it fires on the five keyboard shots and nothing else. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG_NamingScreenDetector.cpp | 65 ++++++++++++++ .../Menus/PokemonFRLG_NamingScreenDetector.h | 57 ++++++++++++ .../PokemonFRLG_AutoStoryActions.cpp | 86 +++++++++---------- SerialPrograms/cmake/SourceFiles.cmake | 2 + 4 files changed, 163 insertions(+), 47 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp new file mode 100644 index 0000000000..c92e0d883e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp @@ -0,0 +1,65 @@ +/* Naming Screen Detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "CommonFramework/ImageTools/FloatPixel.h" +#include "CommonTools/Images/SolidColorTest.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_NamingScreenDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// Keyboard fill colors by page (keyboard.pal 13, 14, 15) as channel ratios: +// (123, 172, 197), (213, 156, 115), (148, 189, 106). +const FloatPixel KEYBOARD_COLORS[] = { + {0.250, 0.350, 0.400}, // upper case + {0.440, 0.322, 0.238}, // lower case + {0.334, 0.427, 0.239}, // symbols +}; + +bool is_keyboard_color(const ImageViewRGB32& image, const FloatPixel& color){ + return is_solid(image, color, 0.08, 30); +} + +} + + +// Boxes are fractions of the 240x160 GBA screen inside the game box. +NamingScreenDetector::NamingScreenDetector(Color color) + : m_color(color) + , m_keyboard_left_box(25.0 / 240, 82.0 / 160, 4.0 / 240, 60.0 / 160) // x 25-29, y 82-142 + , m_keyboard_right_box(170.0 / 240, 82.0 / 160, 5.0 / 240, 60.0 / 160) // x 170-175, y 82-142 + , m_entry_box(168.0 / 240, 50.0 / 160, 6.0 / 240, 12.0 / 160) // x 168-174, y 50-62 +{} +void NamingScreenDetector::make_overlays(VideoOverlaySet& items) const{ + const BoxOption& GAME_BOX = GameSettings::instance().GAME_BOX; + items.add(m_color, GAME_BOX.inner_to_outer(m_keyboard_left_box)); + items.add(m_color, GAME_BOX.inner_to_outer(m_keyboard_right_box)); + items.add(m_color, GAME_BOX.inner_to_outer(m_entry_box)); +} +bool NamingScreenDetector::detect(const ImageViewRGB32& screen){ + ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + ImageViewRGB32 left = extract_box_reference(game_screen, m_keyboard_left_box); + ImageViewRGB32 right = extract_box_reference(game_screen, m_keyboard_right_box); + if (!is_white(extract_box_reference(game_screen, m_entry_box))){ + return false; + } + for (const FloatPixel& color : KEYBOARD_COLORS){ + if (is_keyboard_color(left, color) && is_keyboard_color(right, color)){ + return true; + } + } + return false; +} + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h new file mode 100644 index 0000000000..c486fbf9bf --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h @@ -0,0 +1,57 @@ +/* Naming Screen Detector + * + * From: https://github.com/PokemonAutomation/ + * + * Detects the in-game keyboard used to name the player, the rival, boxes and Pokemon. + * + * The boxes and colors come from pret/pokefirered src/naming_screen.c (commit + * ce6406d8c2eaf46d543c8a2606de0c3cb1951982), not from screenshots: the keyboard window + * covers tiles (3, 10)-(22, 18) and is filled with keyboard.pal color 13, 14 or 15 by page, + * and the text entry window at tiles (8, 6)-(22, 8) is white. + * Not yet checked against a capture. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_NamingScreenDetector_H +#define PokemonAutomation_PokemonFRLG_NamingScreenDetector_H + +#include +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "CommonTools/VisualDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +class NamingScreenDetector : public StaticScreenDetector{ +public: + NamingScreenDetector(Color color = COLOR_RED); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + +private: + Color m_color; + // The keyboard's margins left and right of the keys, clear of the cursor. + ImageFloatBox m_keyboard_left_box; + ImageFloatBox m_keyboard_right_box; + // The text entry window, right of the last character. + ImageFloatBox m_entry_box; +}; +class NamingScreenWatcher : public DetectorToFinder{ +public: + NamingScreenWatcher(Color color = COLOR_RED) + : DetectorToFinder("NamingScreenWatcher", std::chrono::milliseconds(250), color) + {} +}; + + +} +} +} + +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index 33280fc4fc..878a2c0c30 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -16,6 +16,7 @@ #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_SelectionArrowDetector.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" @@ -36,8 +37,12 @@ constexpr Milliseconds POLL = 300ms; // Text without an arrow or a prompt this long: press anyway, for a last // line that waits without an arrow (Oak's "Here, come with me!"). constexpr Milliseconds TEXT_STILL = 4000ms; -// Once a dialog closes in the intro, this long without one is a keyboard. +// In the intro: A this often on a message box; how long with no box +// before checking for the bedroom; and before pressing A on a screen +// nothing reads. +constexpr Milliseconds INTRO_A_EVERY = 1500ms; constexpr Milliseconds INTRO_QUIET = 3000ms; +constexpr Milliseconds INTRO_STUCK = 15000ms; constexpr Milliseconds INTRO_TIMEOUT = 600000ms; // "Wait about 8 s" after YES at the nurse (console B, 2026-11-01): 1.5 s // between presses did not heal. @@ -139,10 +144,14 @@ void open_start_menu_row(ConsoleHandle& console, ProControllerContext& context, } -// The new game's intro, from the title screen. Text is advanced with A -// (B may go back a question); a keyboard is told by the dialog box being -// gone for a while, and given an empty name: B deletes whatever a stray A -// typed, START jumps to OK. +// The new game's intro, from the title screen. Everything but the keyboard +// is advanced with A, which never hurts there (BOY is the default, YES to +// GREEN); B is never pressed outside the keyboard, since in the intro it +// goes back to the controls pages (console B, 2026-11-01). The controls +// pages read as a message box without an arrow, and the arrow at the end +// of Oak's lines may be missed, so a message box gets A every 1.5 s +// whatever it shows. On the keyboard, B deletes whatever a stray A typed +// and START jumps to OK, which confirms the empty name as the default. class NewGameIntro{ public: NewGameIntro(ConsoleHandle& console, ProControllerContext& context) @@ -167,7 +176,7 @@ class NewGameIntro{ } private: - // The title, then the controls pages, which A turns, up to Oak's first box. + // The title, then the controls pages, which A turns, up to a message box. void press_a_until_dialog(){ WhiteDialogWatcher dialog(COLOR_RED); m_context.wait_for_all_requests(); @@ -196,70 +205,54 @@ class NewGameIntro{ pbf_wait(m_context, POLL); return false; } - if (yes_no_cursor(screen)){ - // "...Er, was it GREEN?" YES. - m_console.log("New game: YES."); - press_a(now, 1000ms); + if (NamingScreenDetector(COLOR_RED).detect(screen)){ + enter_empty_name(); + m_last_dialog = current_time(); return false; } - if (WhiteDialogDetector(COLOR_RED).detect(screen)){ + if (yes_no_cursor(screen) || WhiteDialogDetector(COLOR_RED).detect(screen)){ m_dialog_seen = true; m_last_dialog = now; - if (AdvanceWhiteDialogDetector(COLOR_RED).detect(screen)){ - m_still_presses = 0; - press_a(now, 400ms); - }else if (now - m_last_press > TEXT_STILL){ - still_dialog(now); + if (now - m_last_press >= INTRO_A_EVERY){ + press(m_context, BUTTON_A, 200ms); + m_last_press = now; }else{ pbf_wait(m_context, POLL); } return false; } - m_still_presses = 0; return quiet(screen, now); } - // A box with no arrow that A doesn't move on (BOY/GIRL takes one A): - // if the keyboard's frame reads as a message box, it is this. - void still_dialog(WallClock now){ - if (m_still_presses < 2){ - m_still_presses++; - press_a(now, 400ms); - return; - } - m_still_presses = 0; - enter_empty_name(); - m_last_press = current_time(); - } - - void enter_empty_name(){ - m_console.log("New game: a keyboard, confirming an empty name."); - for (int c = 0; c < 8; c++){ - press(m_context, BUTTON_B, 340ms); - } - press(m_context, BUTTON_PLUS, 500ms); - press(m_context, BUTTON_A, 1500ms); - } - - // No message box: a fade, a pause in the speech, a keyboard, or the bedroom. + // No message box and no keyboard: a fade, a pause in the speech, or + // the bedroom. bool quiet(const ImageViewRGB32& screen, WallClock now){ const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); if (is_black(game) || !m_dialog_seen || now - m_last_dialog < INTRO_QUIET){ pbf_wait(m_context, POLL); return false; } + // START does nothing in the intro. if (overworld_shows(m_console, m_context)){ return true; } - enter_empty_name(); - m_dialog_seen = false; - m_last_dialog = current_time(); + // A screen still waiting for A that none of the detectors knows. + if (now - m_last_press > INTRO_STUCK){ + m_console.log("New game: nothing known on screen, pressing A."); + press(m_context, BUTTON_A, 200ms); + m_last_press = current_time(); + } return false; } - void press_a(WallClock now, Milliseconds after){ - press(m_context, BUTTON_A, after); - m_last_press = now; + void enter_empty_name(){ + m_console.log("New game: the keyboard, confirming an empty name."); + for (int c = 0; c < 8; c++){ + press(m_context, BUTTON_B, 340ms); + } + press(m_context, BUTTON_PLUS, 500ms); + press(m_context, BUTTON_A, 2000ms); + m_context.wait_for_all_requests(); } ConsoleHandle& m_console; @@ -267,7 +260,6 @@ class NewGameIntro{ WallClock m_last_dialog; WallClock m_last_press; bool m_dialog_seen = false; - int m_still_presses = 0; }; } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index e27db01b33..7512dc4f42 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1715,6 +1715,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_BagDetector.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_LoadMenuDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_LoadMenuDetector.h + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyEmptySlotDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyEmptySlotDetector.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyHeldItemDetector.cpp From 7f1ae1a519cd0f8cbdef87c427a50f5612e85f8a Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 02:29:59 -0800 Subject: [PATCH 03/75] FRLG AutoStory: the player still faces north after the rival takes his ball Measured on console B: after Squirtle and the rival's pick the player stands at (9, 5) facing the table, so the walk to the rival's trigger can start without a facing check. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index e7766d089a..3219142378 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -103,7 +103,7 @@ StoryCheckpoint starter(){ cp.steps.push_back(make(StoryStepKind::TALK, "squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\"")); cp.steps.push_back(answer("choose_squirtle", true, "take Squirtle")); cp.steps.push_back(answer("no_nickname", false, "\"give a nickname?\" NO")); - cp.steps.push_back(scene("rival_takes_bulbasaur", at(LAB, 9, 5), "the rival picks his ball; he may turn the player")); + cp.steps.push_back(scene("rival_takes_bulbasaur", at(LAB, 9, 5, NORTH), "the rival picks his ball; the player still faces the table (console B, 2026-11-01)")); cp.steps.push_back(route("above_rival_trigger", at(LAB, 7, 7, SOUTH), "short of the rival's trigger row 8")); cp.steps.push_back(step_into("rival_trigger", SOUTH, "\"Wait, let's check out our POKEMON!\"")); // The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down. From 7772ed0008645b1e3c1b5e5de42db7838d5cba09 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 02:43:53 -0800 Subject: [PATCH 04/75] FRLG AutoStory: a battle is not over, nor at a move prompt, before its first turn On console B the rival's battle logged a learn prompt and "over after 0 turns" during the opening slide-in, then waited 300 s for the overworld with the FIGHT menu up. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 0b913d8791..b8fbdb0843 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -183,7 +183,9 @@ class BattleLoop{ } const BattleScreen seen = read_battle_screen(screen); if (seen == BattleScreen::NONE){ - if (m_seen_battle && now - m_last_battle > BATTLE_GONE){ + // Not before the first turn: the opening slide-in shows none of the battle + // screens for a while (console B: "over after 0 turns" at the rival). + if (m_seen_battle && m_turns > 0 && now - m_last_battle > BATTLE_GONE){ return true; } pbf_wait(m_context, POLL); @@ -215,6 +217,10 @@ class BattleLoop{ m_last_press = now; return; case BattleScreen::LEARN: + if (m_turns == 0){ + // The learn prompts come after a turn; before one it is a misread. + break; + } // "Delete a move to make room?" NO, then "Stop learning?" YES. m_console.log(m_learn_prompts % 2 == 0 ? "Battle: not deleting a move." : "Battle: stop learning."); pbf_press_button(m_context, m_learn_prompts % 2 == 0 ? BUTTON_B : BUTTON_A, 160ms, 1500ms); From 4ff8a5377b7fe7b63db4cc8a5df77ae9f4977541 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 03:07:32 -0800 Subject: [PATCH 05/75] FRLG AutoStory: press B through text the battle screens don't know Oak's white text box during the rival's battle reads as no battle screen, so the loop waited 10 minutes on "TOSH." (console B). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index b8fbdb0843..010248b27b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -188,6 +188,13 @@ class BattleLoop{ if (m_seen_battle && m_turns > 0 && now - m_last_battle > BATTLE_GONE){ return true; } + // Oak's white text box in the rival's battle reads as no battle screen: + // B moves it on, and B does nothing on the overworld once the battle is over. + if (m_seen_battle && now - m_last_press > 1500ms){ + pbf_press_button(m_context, BUTTON_B, 160ms, 200ms); + m_last_press = now; + return false; + } pbf_wait(m_context, POLL); return false; } From ce2d77dc459bf8c291cc2058e2050501fd169547 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 04:56:02 -0800 Subject: [PATCH 06/75] FRLG AutoStory: the player faces south after the Pokedex scene Measured on console B after the 00.06 save: Oak's Lab (6, 4), facing south. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 3219142378..dfab9a47ca 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -124,12 +124,12 @@ StoryCheckpoint pokedex(){ StoryCheckpoint cp{"00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, {}}; cp.steps.push_back(route("below_oak", at(LAB, 6, 4, NORTH), "back down Route 1 to Oak")); cp.steps.push_back(make(StoryStepKind::TALK, "give_parcel", "Oak takes the parcel")); - cp.steps.push_back(scene("pokedex_scene", at(LAB, 6, 4), "the rival comes in, Pokedexes from the desk; turns the player")); + cp.steps.push_back(scene("pokedex_scene", at(LAB, 6, 4, SOUTH), "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)")); return cp; } StoryCheckpoint forest(){ - StoryCheckpoint cp{"00.07", "Viridian shopping to Pewter Center", at(LAB, 6, 4), {}, StartMenu::FULL, {}}; + StoryCheckpoint cp{"00.07", "Viridian shopping to Pewter Center", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, {}}; cp.steps.push_back(route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again")); cp.steps.push_back(make(StoryStepKind::SHOP, "potions_and_antidotes", "4 Potions, 2 Antidotes")); cp.steps.push_back(route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest")); From c91d4a3838b09bb5b52793731deac387d379c467 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 05:04:27 -0800 Subject: [PATCH 07/75] FRLG AutoStory: answer the nurse's YES by timed A presses answer_yes_no() didn't see her YES/NO box and failed although the heal had happened (console B). YES is the default there. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index 878a2c0c30..aa144004d8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -393,8 +393,13 @@ void set_options(ConsoleHandle& console, ProControllerContext& context, StartMen void heal_at_center(ConsoleHandle& console, ProControllerContext& context){ console.log("Healing at the Pokemon Center."); + // The nurse's YES/NO isn't seen by the selection detector (console B, + // 2026-11-01); YES is the default, so A after her lines is YES. + // "Welcome ... We heal your POKEMON ... Shall we heal?" is 3 lines. + press(context, BUTTON_A, 1500ms); + press(context, BUTTON_A, 1500ms); + press(context, BUTTON_A, 2500ms); press(context, BUTTON_A, 1000ms); - answer_yes_no(console, context, true, BUTTON_A, 20000ms); pbf_wait(context, HEAL_TIME); mash_until_overworld(console, context, 30000ms); } From 1d44d6f1ab2fc24adc5f4c099a40458ac252a47c Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 05:18:34 -0800 Subject: [PATCH 08/75] FRLG AutoStory: walk north clear of the old man before Route 2 After the tutorial he stands east of the player; the route's first leg east didn't move and the walk north ended under Route 2's ledge (console B). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index dfab9a47ca..31ae7f68a9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -138,6 +138,10 @@ StoryCheckpoint forest(){ cp.steps.push_back(step_into("old_man_trigger", NORTH, "the old man's catching tutorial can't be walked around")); // TutorialTriggerLeft turns the player right, to the old man. cp.steps.push_back(scene("old_man_tutorial", at(VIRIDIAN, 20, 8, EAST), "about 60 lines and his demo battle; TEACHY TV")); + // After his demo the old man stands east of the player, beside (20, 8), where + // the map doesn't have him: "east 2" from there didn't move, and the walk north + // ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first. + cp.steps.push_back(route("past_old_man", at(VIRIDIAN, 20, 5, NORTH), "north along column 20, clear of the old man")); cp.steps.push_back(route("forest_entrance", at(FOREST, 29, 61), "Route 2, running from wild battles")); // The forest legs walked by hand; wild battles are fought for EXP. cp.steps.push_back(route("forest_west", at(FOREST, 13, 46), "west side of the forest", true)); From a423f0eddf594097064c7518eace82396947b71b Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 05:58:17 -0800 Subject: [PATCH 09/75] FRLG AutoStory: Potion on yellow HP, Antidote only on PSN read twice, A/B when no menu shows Console B, 2026-11-01 (run 13, 00.07 pewter_nurse): a wild battle used an Antidote twice and no Potion, then the starter fainted; and a "trainer battle" after a message pressed B on the overworld for 10 minutes, since before the first turn the loop never took the battle to be over. A Potion is now used whenever the HP bar is yellow or red; an Antidote only when PSN is read at two turns in a row, and at most once a battle. The purple taken for PSN is narrower. Before the first turn, the battle is over once START opens the menu. With no battle menu for 60 s, A and B are pressed in turn. Each change of what the loop sees, and each turn's HP and PSN reading, is logged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG_AutoStoryActions.cpp | 25 ++-- .../AutoStory/PokemonFRLG_AutoStoryActions.h | 5 + .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 108 +++++++++++++++--- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 6 +- 4 files changed, 110 insertions(+), 34 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index aa144004d8..90a0ea74c9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -73,19 +73,6 @@ void tap(ProControllerContext& context, DpadPosition position, Milliseconds afte pbf_press_dpad(context, position, 160ms, after); } -// START opens the menu only on the overworld, with no scene running. If -// it opened, it is closed again. -bool overworld_shows(ConsoleHandle& console, ProControllerContext& context){ - press(context, BUTTON_PLUS, 1200ms); - context.wait_for_all_requests(); - VideoSnapshot screen = console.video().snapshot(); - if (!screen || !StartMenuDetector(COLOR_RED).detect(screen)){ - return false; - } - press(context, BUTTON_B, 600ms); - context.wait_for_all_requests(); - return true; -} // Which of the standard YES/NO box's rows the arrow is on, if it shows. std::optional yes_no_cursor(const ImageViewRGB32& screen){ @@ -284,6 +271,18 @@ int start_menu_option_row(StartMenu menu){ } +bool overworld_shows(ConsoleHandle& console, ProControllerContext& context){ + press(context, BUTTON_PLUS, 1200ms); + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + if (!screen || !StartMenuDetector(COLOR_RED).detect(screen)){ + return false; + } + press(context, BUTTON_B, 600ms); + context.wait_for_all_requests(); + return true; +} + TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout, bool stop_at_battle){ const WallClock deadline = current_time() + timeout; while (current_time() < deadline){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index 68330aa7a2..f462bc93af 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -39,6 +39,11 @@ int start_menu_save_row(StartMenu menu); int start_menu_option_row(StartMenu menu); +// Whether the overworld is up: START opens the menu only there, with no +// scene running. If it opened, it is closed again. +bool overworld_shows(ConsoleHandle& console, ProControllerContext& context); + + enum class TextEnd{ OVERWORLD, BATTLE, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 010248b27b..8bea1a61d1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" @@ -39,6 +40,14 @@ constexpr Milliseconds BATTLE_GONE = 4000ms; constexpr Milliseconds STUCK = 8000ms; // Seen this many polls in a row: the starter fainted. constexpr int FAINT_POLLS = 3; +// No battle menu for this long: A and B in turn, for a prompt nothing reads. +constexpr Milliseconds NO_MENU = 60000ms; +// No battle screen yet and no turn taken: whether the overworld is back +// is checked by START this often (a trainer's battle that never started, +// console B, 2026-11-01: 10 minutes of B on the overworld). +constexpr Milliseconds OVERWORLD_CHECK = 5000ms; +// PSN read at this many turns in a row before an Antidote. +constexpr int PSN_READS = 2; // Text and the move learn prompts after a battle, on the overworld. constexpr Milliseconds AFTER_BATTLE_TEXT = 60000ms; @@ -72,7 +81,7 @@ ColorCounts count_colors(const ImageViewRGB32& image){ counts.yellow++; }else if (r > 190 && g < 110 && b < 90){ counts.red++; - }else if (r > 140 && b > 140 && g < 110){ + }else if (r > 150 && b > 150 && g < 100 && std::abs(r - b) < 60){ counts.purple++; } } @@ -82,6 +91,7 @@ ColorCounts count_colors(const ImageViewRGB32& image){ enum class BattleScreen{ + // Keep in step with screen_name(). MENU, // "What will do?" with FIGHT/BAG/POKEMON/RUN LEARN, // a YES/NO about a move to learn ADVANCE, // battle text waiting for a button @@ -89,6 +99,22 @@ enum class BattleScreen{ NONE, // no battle on screen }; +const char* screen_name(BattleScreen screen){ + switch (screen){ + case BattleScreen::MENU: + return "battle menu"; + case BattleScreen::LEARN: + return "move prompt"; + case BattleScreen::ADVANCE: + return "battle text with arrow"; + case BattleScreen::OTHER: + return "battle text box"; + case BattleScreen::NONE: + return "no battle screen"; + } + return "?"; +} + BattleScreen read_battle_screen(const ImageViewRGB32& screen){ if (BattleMenuDetector(COLOR_RED).detect(screen)){ return BattleScreen::MENU; @@ -161,6 +187,8 @@ class BattleLoop{ , m_start(current_time()) , m_last_battle(m_start) , m_last_press(m_start) + , m_last_menu(m_start) + , m_last_overworld_check(m_start) {} BattleEnd run(){ @@ -182,28 +210,60 @@ class BattleLoop{ return false; } const BattleScreen seen = read_battle_screen(screen); - if (seen == BattleScreen::NONE){ - // Not before the first turn: the opening slide-in shows none of the battle - // screens for a while (console B: "over after 0 turns" at the rival). - if (m_seen_battle && m_turns > 0 && now - m_last_battle > BATTLE_GONE){ - return true; - } - // Oak's white text box in the rival's battle reads as no battle screen: - // B moves it on, and B does nothing on the overworld once the battle is over. - if (m_seen_battle && now - m_last_press > 1500ms){ - pbf_press_button(m_context, BUTTON_B, 160ms, 200ms); - m_last_press = now; - return false; - } - pbf_wait(m_context, POLL); + if (seen != m_last_seen){ + m_console.log(std::format("Battle: {} (turn {}).", screen_name(seen), m_turns)); + m_last_seen = seen; + } + if (seen == BattleScreen::MENU){ + m_last_menu = now; + }else if (now - m_last_menu > NO_MENU && now - m_last_press > 1500ms){ + // Something waits that none of the battle screens knows. + m_console.log(std::format("Battle: no battle menu for {} s, pressing {}.", + std::chrono::duration_cast(now - m_last_menu).count(), m_press_a ? "A" : "B")); + pbf_press_button(m_context, m_press_a ? BUTTON_A : BUTTON_B, 160ms, 200ms); + m_press_a = !m_press_a; + m_last_press = now; return false; } + if (seen == BattleScreen::NONE){ + return no_battle_screen(now); + } m_seen_battle = true; m_last_battle = now; act(seen, screen, now); return false; } + // True once the battle is over. + bool no_battle_screen(WallClock now){ + if (!m_seen_battle || now - m_last_battle <= BATTLE_GONE){ + pbf_wait(m_context, POLL); + return false; + } + // After a turn, the battle screens gone for a while is the end. Before + // one, the opening slide-in shows none for a while (console B: "over + // after 0 turns" at the rival), so only START opening is. + if (m_turns > 0){ + return true; + } + if (now - m_last_overworld_check > OVERWORLD_CHECK){ + m_last_overworld_check = now; + if (overworld_shows(m_console, m_context)){ + m_console.log("Battle: the overworld is back before any turn.", COLOR_ORANGE); + return true; + } + } + // Oak's white text box in the rival's battle reads as no battle screen: + // B moves it on, and B does nothing on the overworld once the battle is over. + if (now - m_last_press > 1500ms){ + pbf_press_button(m_context, BUTTON_B, 160ms, 200ms); + m_last_press = now; + return false; + } + pbf_wait(m_context, POLL); + return false; + } + void check_time(WallClock now){ if (!m_seen_battle && now - m_start > BATTLE_START_TIMEOUT){ OperationFailedExceptionWithScreenshot::fire( @@ -253,11 +313,17 @@ class BattleLoop{ m_turns++; m_faint_polls = 0; const PartyStatus status = read_party_status(screen); - const bool hurt = status.hp_red || (m_trainer && status.hp_yellow); - if (hurt && m_supplies.potions > 0){ + m_psn_reads = status.poisoned ? m_psn_reads + 1 : 0; + m_console.log(std::format( + "Battle: turn {}, HP {}{}, {} Potions, {} Antidotes.", + m_turns, status.hp_red ? "red" : status.hp_yellow ? "yellow" : "green", + status.poisoned ? ", PSN read" : "", m_supplies.potions, m_supplies.antidotes + )); + if ((status.hp_red || status.hp_yellow) && m_supplies.potions > 0){ m_supplies.potions--; use_item(m_console, m_context, 0); - }else if (status.poisoned && m_supplies.antidotes > 0){ + }else if (m_psn_reads >= PSN_READS && !m_antidote_used && m_supplies.antidotes > 0){ + m_antidote_used = true; m_supplies.antidotes--; use_item(m_console, m_context, m_supplies.potions > 0 ? 1 : 0); }else{ @@ -283,8 +349,14 @@ class BattleLoop{ const WallClock m_start; WallClock m_last_battle; WallClock m_last_press; + WallClock m_last_menu; + WallClock m_last_overworld_check; + BattleScreen m_last_seen = BattleScreen::NONE; bool m_seen_battle = false; bool m_lost = false; + bool m_press_a = true; + bool m_antidote_used = false; + int m_psn_reads = 0; size_t m_turns = 0; size_t m_learn_prompts = 0; int m_faint_polls = 0; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index 4379939200..047484c209 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -7,9 +7,9 @@ * the cursor is put back on FIGHT and the move list's top left, since the * game remembers both; the move is the bottom left one (Bubble), which the * cursor can't reach while that slot is empty, so before Bubble it stays on - * Tackle. A Potion is used when the HP bar turns red (or yellow, against a - * trainer), an Antidote when the status shows PSN. "Delete a move to make - * room?" is answered NO and "Stop learning?" YES. + * Tackle. A Potion is used when the HP bar turns yellow or red, an Antidote + * (once a battle) when the status reads PSN at two turns in a row. + * "Delete a move to make room?" is answered NO and "Stop learning?" YES. * * Also the overworld interrupts the story walks routes with: wild battles * run from (or fought, for EXP), and messages, after which a trainer's From 95d92d6353ef18f07e06b0efd9e47c587f18f315 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 05:58:17 -0800 Subject: [PATCH 10/75] FRLG AutoStory: fight wild Pokemon only inside Viridian Forest The forest's last leg now ends in its north gate; from there to Pewter's Center wild battles are run from, and trainers still fought. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 31ae7f68a9..47a7c3de60 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -25,6 +25,7 @@ const char* const VIRIDIAN = "ViridianCity"; const char* const VIRIDIAN_MART = "ViridianCity_Mart"; const char* const VIRIDIAN_CENTER = "ViridianCity_PokemonCenter_1F"; const char* const FOREST = "ViridianForest"; +const char* const FOREST_GATE = "Route2_ViridianForest_NorthEntrance"; const char* const PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; const char* const GYM = "PewterCity_Gym"; @@ -147,7 +148,9 @@ StoryCheckpoint forest(){ cp.steps.push_back(route("forest_west", at(FOREST, 13, 46), "west side of the forest", true)); cp.steps.push_back(route("forest_east", at(FOREST, 42, 44), "east path, past a Bug Catcher", true)); cp.steps.push_back(route("forest_north", at(FOREST, 39, 25), "north part", true)); - cp.steps.push_back(route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "out of the forest to Pewter's Center", true)); + cp.steps.push_back(route("forest_exit", at(FOREST_GATE, 7, 8, NORTH), "into the north gate, fighting in the forest", true)); + // Out of the forest, wild battles are run from; trainers are still fought. + cp.steps.push_back(route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center")); cp.steps.push_back(make(StoryStepKind::HEAL, "heal_pewter", "full HP")); return cp; } From 08db4938643dd6794e760696efdc326288506c0e Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 06:18:40 -0800 Subject: [PATCH 11/75] FRLG AutoStory: a battle is over only once START opens; run from wild battles in the battle loop Console B, 2026-11-01 (run 14): - A forest battle was called over 4 s after its last battle screen while the move prompt's YES/NO was up; the message interrupt then pressed B through "Delete a move?" and "Stop learning?" for 60 s. - Running from a Route 1 battle with flee_battle() failed ("Can't escape!" outlasted its watch), and its fallback opened START inside the battle: "Failed to open Start menu 5 times in a row". The battle loop now ends a battle only when START opens the menu, after 2 s without a battle screen; a YES/NO under no battle screen is answered as a move prompt (NO, then YES). Wild battles that the story runs from go through the same loop, with RUN for the turn, up to 4 tries before fighting. advance_text() answers a YES/NO the same way instead of pressing B through it. The A/B presses after 60 s without a battle menu are kept to within 10 s of a battle screen, so they don't talk to a gym leader again after the speech. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG_AutoStoryActions.cpp | 36 ++++--- .../AutoStory/PokemonFRLG_AutoStoryActions.h | 6 ++ .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 95 ++++++++++++------- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 17 ++-- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 2 +- 5 files changed, 104 insertions(+), 52 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index 90a0ea74c9..9379b3e845 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -74,16 +74,6 @@ void tap(ProControllerContext& context, DpadPosition position, Milliseconds afte } -// Which of the standard YES/NO box's rows the arrow is on, if it shows. -std::optional yes_no_cursor(const ImageViewRGB32& screen){ - if (SelectionArrowDetector(COLOR_RED, nullptr, SelectionArrowPositionConfirmationMenu::YES).detect(screen)){ - return true; - } - if (SelectionArrowDetector(COLOR_RED, nullptr, SelectionArrowPositionConfirmationMenu::NO).detect(screen)){ - return false; - } - return std::nullopt; -} bool wait_for_yes_no(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout){ SelectionArrowWatcher yes(COLOR_RED, &console.overlay(), SelectionArrowPositionConfirmationMenu::YES); @@ -271,6 +261,16 @@ int start_menu_option_row(StartMenu menu){ } +std::optional yes_no_cursor(const ImageViewRGB32& screen){ + if (SelectionArrowDetector(COLOR_RED, nullptr, SelectionArrowPositionConfirmationMenu::YES).detect(screen)){ + return true; + } + if (SelectionArrowDetector(COLOR_RED, nullptr, SelectionArrowPositionConfirmationMenu::NO).detect(screen)){ + return false; + } + return std::nullopt; +} + bool overworld_shows(ConsoleHandle& console, ProControllerContext& context){ press(context, BUTTON_PLUS, 1200ms); context.wait_for_all_requests(); @@ -285,9 +285,16 @@ bool overworld_shows(ConsoleHandle& console, ProControllerContext& context){ TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout, bool stop_at_battle){ const WallClock deadline = current_time() + timeout; + // A YES/NO here is a move to learn: "Delete a move to make room?" NO, + // then, right after, "Stop learning?" YES. B to "Stop learning?" goes + // back to the first, for good (console B, 2026-11-01). + WallClock last_no = WallClock::min(); while (current_time() < deadline){ BattleDialogWatcher battle(COLOR_RED); BattleMenuWatcher battle_menu(COLOR_RED); + SelectionArrowWatcher yes(COLOR_RED, &console.overlay(), SelectionArrowPositionConfirmationMenu::YES); + SelectionArrowWatcher no(COLOR_RED, &console.overlay(), SelectionArrowPositionConfirmationMenu::NO); + BattleLearnDialogWatcher learn(COLOR_RED); context.wait_for_all_requests(); const int ret = run_until( console, context, @@ -296,8 +303,15 @@ TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Mill pbf_press_button(context, BUTTON_B, 160ms, 340ms); } }, - {battle, battle_menu} + {battle, battle_menu, yes, no, learn} ); + if (ret >= 2){ + const bool stop_learning = current_time() - last_no < 10000ms; + console.log(stop_learning ? "Text: YES/NO, YES (stop learning)." : "Text: YES/NO, NO."); + press(context, stop_learning ? BUTTON_A : BUTTON_B, 1500ms); + last_no = stop_learning ? WallClock::min() : current_time(); + continue; + } if (ret >= 0 && stop_at_battle){ return TextEnd::BATTLE; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index f462bc93af..230139d159 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -17,6 +17,7 @@ #include #include #include "Common/Cpp/Time.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "Pokemon/Navigation/Pokemon_Grid.h" @@ -44,6 +45,11 @@ int start_menu_option_row(StartMenu menu); bool overworld_shows(ConsoleHandle& console, ProControllerContext& context); +// Which row of the standard YES/NO box the arrow is on (true: YES), if +// one shows. +std::optional yes_no_cursor(const ImageViewRGB32& screen); + + enum class TextEnd{ OVERWORLD, BATTLE, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 8bea1a61d1..10a7841c59 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -33,19 +33,24 @@ constexpr Milliseconds POLL = 300ms; constexpr Milliseconds BATTLE_TIMEOUT = 600000ms; // To see the battle at all, from its first flash. constexpr Milliseconds BATTLE_START_TIMEOUT = 20000ms; -// No battle screen for this long: the battle is over. -constexpr Milliseconds BATTLE_GONE = 4000ms; +// No battle screen for this long: check for the overworld with START. +constexpr Milliseconds BATTLE_GONE = 2000ms; // A battle screen with neither an arrow nor a menu for this long: B, for // a prompt the detectors miss. constexpr Milliseconds STUCK = 8000ms; // Seen this many polls in a row: the starter fainted. constexpr int FAINT_POLLS = 3; // No battle menu for this long: A and B in turn, for a prompt nothing reads. +// Only near battle screens: A on the overworld after a gym leader's speech +// would talk to them again. constexpr Milliseconds NO_MENU = 60000ms; +constexpr Milliseconds NO_MENU_NEAR = 10000ms; // No battle screen yet and no turn taken: whether the overworld is back // is checked by START this often (a trainer's battle that never started, // console B, 2026-11-01: 10 minutes of B on the overworld). -constexpr Milliseconds OVERWORLD_CHECK = 5000ms; +constexpr Milliseconds OVERWORLD_CHECK = 3000ms; +// RUN this many times ("Can't escape!") before fighting instead. +constexpr int RUN_TRIES = 4; // PSN read at this many turns in a row before an Antidote. constexpr int PSN_READS = 2; // Text and the move learn prompts after a battle, on the overworld. @@ -164,6 +169,15 @@ void use_item(ConsoleHandle& console, ProControllerContext& context, int row){ pbf_press_button(context, BUTTON_A, 160ms, 1000ms); } +// RUN, bottom right of the battle menu. +void run_away(ProControllerContext& context){ + tap(context, DPAD_LEFT); + tap(context, DPAD_UP); + tap(context, DPAD_RIGHT); + tap(context, DPAD_DOWN); + pbf_press_button(context, BUTTON_A, 160ms, 500ms); +} + // FIGHT, then the bottom left move (Bubble), or Tackle while that slot is // empty: the cursor doesn't move onto an empty slot. void use_move(ProControllerContext& context){ @@ -179,11 +193,11 @@ void use_move(ProControllerContext& context){ class BattleLoop{ public: - BattleLoop(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, bool trainer) + BattleLoop(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind) : m_console(console) , m_context(context) , m_supplies(supplies) - , m_trainer(trainer) + , m_kind(kind) , m_start(current_time()) , m_last_battle(m_start) , m_last_press(m_start) @@ -192,7 +206,10 @@ class BattleLoop{ {} BattleEnd run(){ - m_console.log(m_trainer ? "Battle: fighting a trainer." : "Battle: fighting a wild Pokemon."); + m_console.log( + m_kind == BattleKind::TRAINER ? "Battle: fighting a trainer." : + m_kind == BattleKind::WILD_FIGHT ? "Battle: fighting a wild Pokemon." : "Battle: running from a wild Pokemon." + ); while (!step()){} m_console.log(std::format("Battle: over after {} turns{}.", m_turns, m_lost ? ", the starter fainted" : "")); return m_lost ? BattleEnd::LOST : BattleEnd::WON; @@ -216,7 +233,7 @@ class BattleLoop{ } if (seen == BattleScreen::MENU){ m_last_menu = now; - }else if (now - m_last_menu > NO_MENU && now - m_last_press > 1500ms){ + }else if (now - m_last_menu > NO_MENU && now - m_last_battle < NO_MENU_NEAR && now - m_last_press > 1500ms){ // Something waits that none of the battle screens knows. m_console.log(std::format("Battle: no battle menu for {} s, pressing {}.", std::chrono::duration_cast(now - m_last_menu).count(), m_press_a ? "A" : "B")); @@ -226,7 +243,7 @@ class BattleLoop{ return false; } if (seen == BattleScreen::NONE){ - return no_battle_screen(now); + return no_battle_screen(screen, now); } m_seen_battle = true; m_last_battle = now; @@ -234,22 +251,23 @@ class BattleLoop{ return false; } - // True once the battle is over. - bool no_battle_screen(WallClock now){ - if (!m_seen_battle || now - m_last_battle <= BATTLE_GONE){ + // True once the battle is over: only when START opens the menu. The + // battle screens are gone during the opening slide-in (console B: "over + // after 0 turns" at the rival) and under a move prompt's YES/NO (console + // B, 2026-11-01, Viridian Forest: called over, then stuck at "Stop + // learning?"). + bool no_battle_screen(const ImageViewRGB32& screen, WallClock now){ + if (!m_seen_battle){ pbf_wait(m_context, POLL); return false; } - // After a turn, the battle screens gone for a while is the end. Before - // one, the opening slide-in shows none for a while (console B: "over - // after 0 turns" at the rival), so only START opening is. - if (m_turns > 0){ - return true; + if (m_turns > 0 && yes_no_cursor(screen)){ + answer_learn_prompt(now); + return false; } - if (now - m_last_overworld_check > OVERWORLD_CHECK){ + if (now - m_last_battle > BATTLE_GONE && now - m_last_overworld_check > OVERWORLD_CHECK){ m_last_overworld_check = now; if (overworld_shows(m_console, m_context)){ - m_console.log("Battle: the overworld is back before any turn.", COLOR_ORANGE); return true; } } @@ -288,11 +306,7 @@ class BattleLoop{ // The learn prompts come after a turn; before one it is a misread. break; } - // "Delete a move to make room?" NO, then "Stop learning?" YES. - m_console.log(m_learn_prompts % 2 == 0 ? "Battle: not deleting a move." : "Battle: stop learning."); - pbf_press_button(m_context, m_learn_prompts % 2 == 0 ? BUTTON_B : BUTTON_A, 160ms, 1500ms); - m_learn_prompts++; - m_last_press = now; + answer_learn_prompt(now); return; case BattleScreen::ADVANCE: pbf_press_button(m_context, BUTTON_B, 160ms, 200ms); @@ -309,9 +323,23 @@ class BattleLoop{ pbf_wait(m_context, POLL); } + // "Delete a move to make room?" NO, then "Stop learning?" YES. + void answer_learn_prompt(WallClock now){ + m_console.log(m_learn_prompts % 2 == 0 ? "Battle: not deleting a move." : "Battle: stop learning."); + pbf_press_button(m_context, m_learn_prompts % 2 == 0 ? BUTTON_B : BUTTON_A, 160ms, 1500ms); + m_learn_prompts++; + m_last_press = now; + } + void take_turn(const ImageViewRGB32& screen){ m_turns++; m_faint_polls = 0; + if (m_kind == BattleKind::WILD_RUN && m_run_tries < RUN_TRIES){ + m_run_tries++; + m_console.log(std::format("Battle: RUN (try {}).", m_run_tries)); + run_away(m_context); + return; + } const PartyStatus status = read_party_status(screen); m_psn_reads = status.poisoned ? m_psn_reads + 1 : 0; m_console.log(std::format( @@ -345,7 +373,7 @@ class BattleLoop{ ConsoleHandle& m_console; ProControllerContext& m_context; Supplies& m_supplies; - const bool m_trainer; + const BattleKind m_kind; const WallClock m_start; WallClock m_last_battle; WallClock m_last_press; @@ -357,6 +385,7 @@ class BattleLoop{ bool m_press_a = true; bool m_antidote_used = false; int m_psn_reads = 0; + int m_run_tries = 0; size_t m_turns = 0; size_t m_learn_prompts = 0; int m_faint_polls = 0; @@ -394,14 +423,12 @@ class StoryWildBattle : public OverworldInterrupt{ virtual Milliseconds detection_delay() const override{ return m_late ? 2000ms : 300ms; } + // Run from or fought by the battle loop, which returns only once START + // opens on the overworld, so nothing of the battle is left before the + // next leg. virtual void clear(ConsoleHandle& console, ProControllerContext& context) const override{ - if (!m_fight){ - flee_battle(console, context); - return; - } - fail_on_blackout(console, fight_battle(console, context, m_supplies, false)); - pbf_wait(context, 1000ms); - context.wait_for_all_requests(); + const BattleKind kind = m_fight ? BattleKind::WILD_FIGHT : BattleKind::WILD_RUN; + fail_on_blackout(console, fight_battle(console, context, m_supplies, kind)); } private: @@ -430,7 +457,7 @@ class StoryMessage : public OverworldInterrupt{ return; } console.log("Story: a trainer's battle after a message on the overworld."); - fail_on_blackout(console, fight_battle(console, context, m_supplies, true)); + fail_on_blackout(console, fight_battle(console, context, m_supplies, BattleKind::TRAINER)); mash_until_overworld(console, context, AFTER_BATTLE_TEXT); } @@ -454,8 +481,8 @@ PartyStatus read_party_status(const ImageViewRGB32& screen){ return status; } -BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, bool trainer){ - return BattleLoop(console, context, supplies, trainer).run(); +BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind){ + return BattleLoop(console, context, supplies, kind).run(); } OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index 047484c209..e1d47fcec6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -37,6 +37,12 @@ struct Supplies{ int antidotes = 0; }; +enum class BattleKind{ + WILD_RUN, // RUN, or fight after a few "Can't escape!" + WILD_FIGHT, // fight for EXP + TRAINER, +}; + enum class BattleEnd{ WON, // The starter fainted: a blackout, except in the lab's rival battle, @@ -52,12 +58,11 @@ struct PartyStatus{ }; PartyStatus read_party_status(const ImageViewRGB32& screen); -// From anywhere in a battle (or its opening), fights it to the end, using -// `supplies` as needed. `trainer` uses a Potion earlier. Returns once the -// battle's screens are gone; text after it (a gym leader's speech) is left -// for the caller. Throws OperationFailedException if it runs over -// 10 minutes. -BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, bool trainer); +// From anywhere in a battle (or its opening), plays it to the end as +// `kind` says, using `supplies` as needed. Returns once START opens the +// menu on the overworld: text after the battle (a gym leader's speech) is +// read with B on the way. Throws OperationFailedException if it runs over 10 minutes. +BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind); // The interrupts for walking story routes. Wild battles are run from, or diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 39700cdd90..2cad928ada 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -110,7 +110,7 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ if (advance_text(env.console, env.context, BATTLE_TEXT_TIMEOUT, true) != TextEnd::BATTLE){ return Pokemon::outcome_failed("no_battle"); } - const BattleEnd end = fight_battle(env.console, env.context, env.supplies, true); + const BattleEnd end = fight_battle(env.console, env.context, env.supplies, BattleKind::TRAINER); if (end == BattleEnd::LOST && !step.may_lose){ return Pokemon::outcome_failed("blackout"); } From ac1873bb7d27a50b405cb5f400fb44ddd87b5364 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 06:50:59 -0800 Subject: [PATCH 12/75] FRLG: a battle needs an HP box or the battle menu, not the text box alone BattleDialogDetector also fires on the black below a small indoor map (console B, 2026-11-01: Oak's Lab's mat, and Viridian Forest's north gate, where a "wild battle (seen late)" ended a route and no battle came). The new BattleScreenDetector wants the battle menu, or the battle text box with the opponent's or the player's HP box. The walker's late wild battle watch and its trainer-battle check use it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG_BattleScreenDetector.cpp | 36 +++++++++++++ .../PokemonFRLG_BattleScreenDetector.h | 54 +++++++++++++++++++ .../Overworld/PokemonFRLG_OverworldWalk.cpp | 5 +- SerialPrograms/cmake/SourceFiles.cmake | 2 + 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp new file mode 100644 index 0000000000..a3ac1c9106 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp @@ -0,0 +1,36 @@ +/* Battle Screen Detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonFRLG_BattleScreenDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +BattleScreenDetector::BattleScreenDetector(Color color) + : m_dialog(color) + , m_menu(color) + , m_opponent(color) + , m_player(color) +{} +void BattleScreenDetector::make_overlays(VideoOverlaySet& items) const{ + m_dialog.make_overlays(items); + m_opponent.make_overlays(items); + m_player.make_overlays(items); +} +bool BattleScreenDetector::detect(const ImageViewRGB32& screen){ + if (m_menu.detect(screen)){ + return true; + } + return m_dialog.detect(screen) && (m_opponent.detect(screen) || m_player.detect(screen)); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h new file mode 100644 index 0000000000..ac4257c707 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h @@ -0,0 +1,54 @@ +/* Battle Screen Detector + * + * From: https://github.com/PokemonAutomation/ + * + * A battle on screen: the battle text box, and with it the opponent's HP + * box, the player's or the battle menu. The text box alone also reads on + * the black below a small indoor map (console B, 2026-11-01: Oak's Lab's + * mat, Viridian Forest's north gate). + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_BattleScreenDetector_H +#define PokemonAutomation_PokemonFRLG_BattleScreenDetector_H + +#include +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "CommonTools/VisualDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +class BattleScreenDetector : public StaticScreenDetector{ +public: + BattleScreenDetector(Color color = COLOR_RED); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + +private: + BattleDialogDetector m_dialog; + BattleMenuDetector m_menu; + BattleOpponentDetector m_opponent; + BattlePokemonDetector m_player; +}; + +class BattleScreenWatcher : public DetectorToFinder{ +public: + BattleScreenWatcher(Color color = COLOR_RED) + : DetectorToFinder("BattleScreenWatcher", std::chrono::milliseconds(250), color) + {} +}; + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp index 44d12de076..09a675a261 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp @@ -14,6 +14,7 @@ #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "PokemonFRLG_OverworldMaps.h" @@ -92,7 +93,7 @@ class LateWildBattleInterrupt : public WildBattleInterrupt{ return "a wild battle (seen late)"; } virtual std::unique_ptr make_watcher() const override{ - return std::make_unique(COLOR_RED); + return std::make_unique(COLOR_RED); } // The flashes, the wipe and the opening animation: 3.7s after the step's // press, twice on Route 1 (console B, 2026-11-01). Other maps open @@ -141,7 +142,7 @@ class MessageInterrupt : public OverworldInterrupt{ // A trainer's battle can't be fled, and the walker must not try (console // B, 2026-11-01, Viridian Forest): it stops here for the caller. static void check_no_trainer_battle(ConsoleHandle& console, ProControllerContext& context){ - BattleDialogWatcher battle(COLOR_RED); + BattleScreenWatcher battle(COLOR_RED); context.wait_for_all_requests(); if (wait_until(console, context, TRAINER_BATTLE_WATCH, {battle}) >= 0){ OperationFailedExceptionWithScreenshot::fire( diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 905b633306..e28ef07f41 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1736,6 +1736,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.cpp Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.h + Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp + Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleSelectionArrowDetector.cpp Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleSelectionArrowDetector.h Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_DaycareManDetector.cpp From 35cb587567ebeddd7710c11bd25d689d3fb76e11 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 06:51:00 -0800 Subject: [PATCH 13/75] FRLG AutoStory: no battle without an HP box or the battle menu The story's late wild battle watch and advance_text() take a battle only from BattleScreenDetector. In the battle loop the text box alone counts only once the battle menu or an HP box has shown; with neither in 15 s the loop returns, taking it for no battle, and the route's overworld check goes on from there. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG_AutoStoryActions.cpp | 3 ++- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 24 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index 9379b3e845..07012f38a9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -18,6 +18,7 @@ #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_SelectionArrowDetector.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "VideoGames/PokemonFRLG/Programs/PokemonFRLG_StartMenuNavigation.h" @@ -290,7 +291,7 @@ TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Mill // back to the first, for good (console B, 2026-11-01). WallClock last_no = WallClock::min(); while (current_time() < deadline){ - BattleDialogWatcher battle(COLOR_RED); + BattleScreenWatcher battle(COLOR_RED); BattleMenuWatcher battle_menu(COLOR_RED); SelectionArrowWatcher yes(COLOR_RED, &console.overlay(), SelectionArrowPositionConfirmationMenu::YES); SelectionArrowWatcher no(COLOR_RED, &console.overlay(), SelectionArrowPositionConfirmationMenu::NO); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 10a7841c59..a16e5d67bd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -15,6 +15,7 @@ #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_AutoStoryActions.h" @@ -51,6 +52,9 @@ constexpr Milliseconds NO_MENU_NEAR = 10000ms; constexpr Milliseconds OVERWORLD_CHECK = 3000ms; // RUN this many times ("Can't escape!") before fighting instead. constexpr int RUN_TRIES = 4; +// No battle menu or HP box this long after a battle was seen: there was +// none (console B, 2026-11-01, Viridian Forest's north gate mat). +constexpr Milliseconds NOT_A_BATTLE = 15000ms; // PSN read at this many turns in a row before an Antidote. constexpr int PSN_READS = 2; // Text and the move learn prompts after a battle, on the overworld. @@ -120,13 +124,18 @@ const char* screen_name(BattleScreen screen){ return "?"; } -BattleScreen read_battle_screen(const ImageViewRGB32& screen){ +// Until `confirmed`, the battle text box alone counts for nothing: it also +// reads on the black below a small indoor map. +BattleScreen read_battle_screen(const ImageViewRGB32& screen, bool confirmed){ if (BattleMenuDetector(COLOR_RED).detect(screen)){ return BattleScreen::MENU; } if (BattleLearnDialogDetector(COLOR_RED).detect(screen)){ return BattleScreen::LEARN; } + if (!confirmed && !BattleScreenDetector(COLOR_RED).detect(screen)){ + return BattleScreen::NONE; + } if (AdvanceBattleDialogDetector(COLOR_RED).detect(screen)){ return BattleScreen::ADVANCE; } @@ -226,7 +235,15 @@ class BattleLoop{ pbf_wait(m_context, POLL); return false; } - const BattleScreen seen = read_battle_screen(screen); + if (!m_confirmed && BattleScreenDetector(COLOR_RED).detect(screen)){ + m_console.log("Battle: the battle menu or an HP box shows."); + m_confirmed = true; + } + if (!m_confirmed && now - m_start > NOT_A_BATTLE){ + m_console.log("Battle: no battle menu or HP box in 15 s: not a battle.", COLOR_ORANGE); + return true; + } + const BattleScreen seen = read_battle_screen(screen, m_confirmed); if (seen != m_last_seen){ m_console.log(std::format("Battle: {} (turn {}).", screen_name(seen), m_turns)); m_last_seen = seen; @@ -381,6 +398,7 @@ class BattleLoop{ WallClock m_last_overworld_check; BattleScreen m_last_seen = BattleScreen::NONE; bool m_seen_battle = false; + bool m_confirmed = false; bool m_lost = false; bool m_press_a = true; bool m_antidote_used = false; @@ -415,7 +433,7 @@ class StoryWildBattle : public OverworldInterrupt{ } virtual std::unique_ptr make_watcher() const override{ if (m_late){ - return std::make_unique(COLOR_RED); + return std::make_unique(COLOR_RED); } return std::make_unique(COLOR_RED); } From 50b0dad92afa776103f25566d1c75dac16658fc6 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 08:22:35 -0800 Subject: [PATCH 14/75] FRLG AutoStory: forest fights only at full strength; leave the forest by legs that end on walls Console B, 2026-11-01 (run 17): - Fighting every wild Pokemon in Viridian Forest used up all 4 Potions, and the starter then fainted in a battle begun at yellow HP. A wild Pokemon is now fought only with green HP and at least 2 Potions; else the turn is RUN. After a battle on the way, a Potion is used from the bag on the overworld when the last HP read wasn't green. - forest_exit's planned route had open legs; after a battle the player was lost (the failure screenshot puts them at (21, 5), under the north edge, 5 tiles east of the Bug Catcher at (16, 5)), and the last leg's warp never came. The forest is now left by a fixed list of legs (new LEGS step), each ending on a wall except two single steps, then north onto the exit. The route test checks that every leg of forest_exit and forest_gate ends on a wall or a warp, or is one step. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 58 ++++++++++++++++--- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 5 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 56 ++++++++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 19 +++++- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 13 ++++- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 40 ++++++++++++- 6 files changed, 179 insertions(+), 12 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index a16e5d67bd..3c90e50735 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -50,6 +50,9 @@ constexpr Milliseconds NO_MENU_NEAR = 10000ms; // is checked by START this often (a trainer's battle that never started, // console B, 2026-11-01: 10 minutes of B on the overworld). constexpr Milliseconds OVERWORLD_CHECK = 3000ms; +// A wild Pokemon is fought (WILD_FIGHT) only with green HP and this many +// Potions left; otherwise it is run from. +constexpr int MIN_POTIONS_TO_FIGHT = 2; // RUN this many times ("Can't escape!") before fighting instead. constexpr int RUN_TRIES = 4; // No battle menu or HP box this long after a battle was seen: there was @@ -351,21 +354,29 @@ class BattleLoop{ void take_turn(const ImageViewRGB32& screen){ m_turns++; m_faint_polls = 0; - if (m_kind == BattleKind::WILD_RUN && m_run_tries < RUN_TRIES){ - m_run_tries++; - m_console.log(std::format("Battle: RUN (try {}).", m_run_tries)); - run_away(m_context); - return; - } const PartyStatus status = read_party_status(screen); + const bool hurt = status.hp_red || status.hp_yellow; + m_supplies.hurt = hurt; m_psn_reads = status.poisoned ? m_psn_reads + 1 : 0; m_console.log(std::format( "Battle: turn {}, HP {}{}, {} Potions, {} Antidotes.", m_turns, status.hp_red ? "red" : status.hp_yellow ? "yellow" : "green", status.poisoned ? ", PSN read" : "", m_supplies.potions, m_supplies.antidotes )); - if ((status.hp_red || status.hp_yellow) && m_supplies.potions > 0){ + // A wild Pokemon is fought for EXP only at full strength: fighting + // every one in Viridian Forest used up all 4 Potions and then the + // starter (console B, 2026-11-01). + const bool run = m_kind == BattleKind::WILD_RUN + || (m_kind == BattleKind::WILD_FIGHT && (hurt || m_supplies.potions < MIN_POTIONS_TO_FIGHT)); + if (run && m_run_tries < RUN_TRIES){ + m_run_tries++; + m_console.log(std::format("Battle: RUN (try {}).", m_run_tries)); + run_away(m_context); + return; + } + if (hurt && m_supplies.potions > 0){ m_supplies.potions--; + m_supplies.hurt = false; use_item(m_console, m_context, 0); }else if (m_psn_reads >= PSN_READS && !m_antidote_used && m_supplies.antidotes > 0){ m_antidote_used = true; @@ -410,6 +421,37 @@ class BattleLoop{ }; +// From the overworld: a Potion from the Items pocket, top row, on the +// starter. Not run on the console yet. +void use_potion_on_overworld(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies){ + console.log(std::format("Story: HP below green after the battle, using a Potion ({} left).", supplies.potions)); + open_bag_from_overworld(console, context); + // The bag ignores presses while it slides in. + pbf_wait(context, 1000ms); + for (int c = 0; c < 3; c++){ + pbf_press_dpad(context, DPAD_LEFT, 100ms, 500ms); + } + for (int c = 0; c < 20; c++){ + pbf_press_dpad(context, DPAD_UP, 100ms, 100ms); + } + // The Potion, USE, the starter, then "...HP was restored". + pbf_press_button(context, BUTTON_A, 160ms, 800ms); + pbf_press_button(context, BUTTON_A, 160ms, 1500ms); + pbf_press_button(context, BUTTON_A, 160ms, 2500ms); + pbf_press_button(context, BUTTON_B, 160ms, 1500ms); + supplies.potions--; + supplies.hurt = false; + mash_until_overworld(console, context, AFTER_BATTLE_TEXT); +} + +// After a battle on the way: heal between battles if the last HP read +// wasn't green. +void heal_if_hurt(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies){ + if (supplies.hurt && supplies.potions > 0){ + use_potion_on_overworld(console, context, supplies); + } +} + void fail_on_blackout(ConsoleHandle& console, BattleEnd end){ if (end == BattleEnd::LOST){ OperationFailedExceptionWithScreenshot::fire( @@ -447,6 +489,7 @@ class StoryWildBattle : public OverworldInterrupt{ virtual void clear(ConsoleHandle& console, ProControllerContext& context) const override{ const BattleKind kind = m_fight ? BattleKind::WILD_FIGHT : BattleKind::WILD_RUN; fail_on_blackout(console, fight_battle(console, context, m_supplies, kind)); + heal_if_hurt(console, context, m_supplies); } private: @@ -477,6 +520,7 @@ class StoryMessage : public OverworldInterrupt{ console.log("Story: a trainer's battle after a message on the overworld."); fail_on_blackout(console, fight_battle(console, context, m_supplies, BattleKind::TRAINER)); mash_until_overworld(console, context, AFTER_BATTLE_TEXT); + heal_if_hurt(console, context, m_supplies); } private: diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index e1d47fcec6..bc1250c76e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -35,11 +35,14 @@ namespace PokemonFRLG{ struct Supplies{ int potions = 0; int antidotes = 0; + // The starter's HP bar wasn't green at the last battle turn, and no + // Potion was used since. + bool hurt = false; }; enum class BattleKind{ WILD_RUN, // RUN, or fight after a few "Can't escape!" - WILD_FIGHT, // fight for EXP + WILD_FIGHT, // fight for EXP with green HP and 2 Potions, else RUN TRAINER, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 2cad928ada..7008fec311 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -97,6 +97,25 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ return Pokemon::outcome_ok(to_pose(StoryPose{step.target.map, step.target.tile, end_facing})); } +Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ + const std::vector tiles = Pokemon::tiles_of(state.pose); + if (tiles.size() != 1 || state.pose.certainty != Pokemon::PoseCertainty::TILE){ + return Pokemon::outcome_failed("no_pose", Pokemon::to_string(state.pose)); + } + const MapPosition start{state.pose.map, tiles[0]}; + std::optional facing = facing_of(state.pose); + if (!facing){ + facing = face_a_wall(env, start); + } + const std::optional> route = fixed_route(story_maps(), start, step.legs); + if (!facing || !route || route->empty()){ + return Pokemon::outcome_failed("bad_legs", to_string(start)); + } + const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild); + walk_overworld_route(env.console, env.context, *route, facing, interrupts); + return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after})); +} + Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ step_once(env.context, step.direction, facing_of(state.pose)); const std::vector tiles = Pokemon::tiles_of(state.pose); @@ -136,6 +155,8 @@ Outcome run_step(StoryEnv& env, RunState& state, const StoryStep& step, StartMen return Pokemon::outcome_ok(); case StoryStepKind::ROUTE: return walk_route(env, state, step); + case StoryStepKind::LEGS: + return walk_legs(env, state, step); case StoryStepKind::STEP: return take_step(env, state, step); case StoryStepKind::TALK: @@ -198,6 +219,41 @@ Pokemon::Pose to_pose(const StoryPose& pose){ return ret; } +std::optional> fixed_route( + const std::vector& maps, const MapPosition& start, const std::vector& legs +){ + const MapData* map = nullptr; + for (const MapData& candidate : maps){ + if (candidate.name == start.map){ + map = &candidate; + } + } + if (map == nullptr || !in_bounds(*map, start.point)){ + return std::nullopt; + } + std::vector route; + PlayerState player{start.point, elevation_at(*map, start.point), false}; + for (const StoryLeg& leg : legs){ + RouteStep step; + step.direction = leg.direction; + step.tiles = leg.tiles; + step.facing_after = leg.direction; + for (int c = 0; c < leg.tiles; c++){ + const StepKind kind = classify_step(*map, player, leg.direction); + const TilePos next = player.position.next(leg.direction); + if (kind != StepKind::WALK || !in_bounds(*map, next) || warps_on_step(*map, next)){ + return std::nullopt; + } + step.wild |= is_tall_grass(*map, next); + player = after_step(*map, player, leg.direction, kind); + } + step.to_wall = classify_step(*map, player, leg.direction) == StepKind::BLOCKED; + step.end = MapPosition{map->name, player.position}; + route.push_back(step); + } + return route; +} + std::optional wall_beside(const MapData& map, const TilePos& tile){ for (Direction direction : {Direction::WEST, Direction::EAST, Direction::NORTH, Direction::SOUTH}){ const TilePos next = tile.next(direction); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 7ba4f6a14e..1f254cd5ca 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -27,6 +27,7 @@ #include "Pokemon/Navigation/Pokemon_StoryEvents.h" #include "Pokemon/Navigation/Pokemon_StorySegments.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattle.h" @@ -47,6 +48,7 @@ enum class StoryStepKind{ NEW_GAME, // title screen (no save) to the bedroom SET_OPTIONS, // text speed FAST, battle style SET ROUTE, // plan and walk to `target` + LEGS, // walk `legs` as given, on one map STEP, // one step `direction`: onto a trigger, into a door TALK, // A at what the player faces ANSWER, // text with B to a YES/NO, then `yes` @@ -56,6 +58,12 @@ enum class StoryStepKind{ SHOP, // facing the Viridian Mart clerk: Potions and Antidotes }; +// A straight leg of a fixed walk. +struct StoryLeg{ + Direction direction = Direction::NORTH; + int tiles = 0; +}; + struct StoryStep{ StoryStepKind kind = StoryStepKind::TALK; std::string name; @@ -64,7 +72,9 @@ struct StoryStep{ StoryPose target; // STEP Direction direction = Direction::NORTH; - // ROUTE: fight wild battles for EXP instead of running. + // LEGS + std::vector legs; + // ROUTE, LEGS: fight wild battles for EXP instead of running. bool fight_wild = false; // ANSWER bool yes = true; @@ -93,6 +103,13 @@ const std::vector& story_maps(); Pokemon::Pose to_pose(const StoryPose& pose); +// `legs` from `start` as route steps for the walker, each checked against +// the map: nothing if a step is blocked or leaves the map. A leg ends "to +// wall" if the next step its way is blocked. +std::optional> fixed_route( + const std::vector& maps, const MapPosition& start, const std::vector& legs +); + // A way the player at `tile` can turn to without stepping: a wall there, // with no one standing in it. West and east first: walking north or south // into a sign would read it. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 47a7c3de60..72561652e7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -148,7 +148,18 @@ StoryCheckpoint forest(){ cp.steps.push_back(route("forest_west", at(FOREST, 13, 46), "west side of the forest", true)); cp.steps.push_back(route("forest_east", at(FOREST, 42, 44), "east path, past a Bug Catcher", true)); cp.steps.push_back(route("forest_north", at(FOREST, 39, 25), "north part", true)); - cp.steps.push_back(route("forest_exit", at(FOREST_GATE, 7, 8, NORTH), "into the north gate, fighting in the forest", true)); + // To the gate by legs that end on walls, which the walker holds again + // after a battle instead of estimating where it stopped: planned + // routes with open legs lost the player in the north of the forest + // (console B, 2026-11-01). The two 1-tile legs are single steps. + StoryStep exit_legs = make(StoryStepKind::LEGS, "forest_exit", "walls all the way to the gate's column"); + exit_legs.legs = { + {NORTH, 10}, {WEST, 12}, {SOUTH, 10}, {WEST, 6}, {NORTH, 20}, + {SOUTH, 1}, {WEST, 10}, {SOUTH, 27}, {WEST, 8}, {NORTH, 20}, {EAST, 1}, + }; + exit_legs.fight_wild = true; + cp.steps.push_back(exit_legs); + cp.steps.push_back(route("forest_gate", at(FOREST_GATE, 7, 10, NORTH), "north onto the exit, arriving on the gate's mat", true)); // Out of the forest, wild battles are run from; trainers are still fought. cp.steps.push_back(route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center")); cp.steps.push_back(make(StoryStepKind::HEAL, "heal_pewter", "full HP")); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index de3ed12d28..c87d49a912 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -94,6 +94,36 @@ std::vector tiles_walked_on(const std::vector& route, const return tiles; } +// Steps that must reach Viridian Forest's gate by legs the walker can hold +// again after a battle: each ends on a wall or a warp, or is one step. +bool held_legs_only(const std::string& name){ + return name == "forest_exit" || name == "forest_gate"; +} +UnitTestResult check_held_legs(const std::string& name, const std::vector& route){ + for (const RouteStep& step : route){ + if (step.action == RouteAction::WALK && !step.to_wall && !step.warps && step.tiles != 1){ + return name + ": an open leg, " + to_string(step) + ":" + describe(route); + } + } + return true; +} + +// Walks `step`'s fixed legs from `pose` and moves `pose` to their end. +UnitTestResult check_legs(StoryPose& pose, const StoryStep& step){ + const std::optional> route = fixed_route(story_maps(), MapPosition{pose.map, pose.tile}, step.legs); + if (!route || route->empty()){ + return step.name + ": the legs can't be walked from " + describe(pose) + "."; + } + if (held_legs_only(step.name)){ + UnitTestResult result = check_held_legs(step.name, *route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + } + pose = StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after}; + return true; +} + // Plans `step` from `pose` and moves `pose` to its end. UnitTestResult check_route(StoryPose& pose, const StoryStep& step){ const MapPosition start{pose.map, pose.tile}; @@ -117,6 +147,12 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step){ if (goal.facing && !route->empty() && route->back().facing_after != *goal.facing){ return step.name + ": the route doesn't end facing " + direction_name(*goal.facing) + ":" + describe(*route); } + if (held_legs_only(step.name)){ + UnitTestResult result = check_held_legs(step.name, *route); + if (result.result != UnitTestResult::PASSED){ + return result; + } + } if (step.name == "below_old_man_trigger"){ for (const TilePos& tile : tiles_walked_on(*route, "ViridianCity")){ if (tile == TilePos{20, 8} || tile == TilePos{22, 8}){ @@ -131,8 +167,8 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step){ // Follows `checkpoint` from its start; `pose` ends where it leaves the player. UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& pose){ for (const StoryStep& step : checkpoint.steps){ - if (step.kind == StoryStepKind::ROUTE){ - UnitTestResult result = check_route(pose, step); + if (step.kind == StoryStepKind::ROUTE || step.kind == StoryStepKind::LEGS){ + UnitTestResult result = step.kind == StoryStepKind::ROUTE ? check_route(pose, step) : check_legs(pose, step); if (result.result != UnitTestResult::PASSED){ return checkpoint.id + " " + result.message; } From 6138b2c0f0c469a418c08c57392a36b4a24546e3 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 09:04:05 -0800 Subject: [PATCH 15/75] FRLG AutoStory: fight Camper Liam on purpose, from beside him Console B, 2026-11-01 (run 18): walking up column 6 through Liam's row, he stopped the player only on the way back, and the walker couldn't find the stopped leg again. In pokefirered Liam (3, 8) always faces east with sight 4, so he sees (4..7, 8). 00.08 now goes up the gym's east side to (10, 9), then by fixed legs along row 6 to (4, 7), and steps south onto (4, 8) beside him: he battles without walking, and FRLG leaves the player facing south there. The route test checks the way to (10, 9) stays off his row. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 15 ++++++++++++++- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 72561652e7..ffa4327d45 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -169,7 +169,20 @@ StoryCheckpoint forest(){ StoryCheckpoint brock(){ // The by-hand save: 2 Potions and 1 Antidote left after the forest. StoryCheckpoint cp{"00.08", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, {}}; - cp.steps.push_back(route("past_camper_liam", at(GYM, 6, 6, NORTH), "Liam (3, 8) stops the player at (6, 8): fought on the way")); + // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight + // 4): he sees (4..7, 8). Walked through, he stopped the player only + // some of the time (console B, 2026-11-01), and the leg he stopped + // couldn't be found again. He is fought on purpose instead, from + // (4, 8) beside him, so he doesn't walk and the player stays put + // (FRLG doesn't turn the player to a trainer). The way there keeps + // off row 8 west of column 8: planned from (10, 9), crossing row 8 at + // column 10 or along it costs the same, so the legs are fixed. + cp.steps.push_back(route("gym_east_side", at(GYM, 10, 9, NORTH), "up the gym's east side, below Liam's row")); + StoryStep to_liam = make(StoryStepKind::LEGS, "above_liam_line", "up column 10, along row 6, then above (4, 8)"); + to_liam.legs = {{NORTH, 3}, {WEST, 6}, {SOUTH, 1}}; + cp.steps.push_back(to_liam); + cp.steps.push_back(step_into("liam_line", SOUTH, "beside Liam, in his line")); + cp.steps.push_back(battle("camper_liam", at(GYM, 4, 8, SOUTH), false, "Geodude and Sandshrew; EXP before Brock")); cp.steps.push_back(route("back_to_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "heal after Liam")); cp.steps.push_back(make(StoryStepKind::HEAL, "heal_before_brock", "full HP")); cp.steps.push_back(route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5)")); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index c87d49a912..d87219e5f4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -153,6 +153,13 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step){ return result; } } + if (step.name == "gym_east_side"){ + for (const TilePos& tile : tiles_walked_on(*route, "PewterCity_Gym")){ + if (tile.y == 8 && 4 <= tile.x && tile.x <= 7){ + return step.name + ": walks into Camper Liam's line at " + to_string(tile) + ":" + describe(*route); + } + } + } if (step.name == "below_old_man_trigger"){ for (const TilePos& tile : tiles_walked_on(*route, "ViridianCity")){ if (tile == TilePos{20, 8} || tile == TilePos{22, 8}){ From 53bf9bef8de8d46c4c929030c7581ef0116a31e8 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 09:08:28 -0800 Subject: [PATCH 16/75] FRLG AutoStory: write each checkpoint as one initializer list Each checkpoint is now one StoryCheckpoint expression with its steps in a braced list, the step comments inline, instead of push_back after push_back. New helpers legs(), new_game_intro(), talk() and heal() build the steps that needed fields set by hand. The table's data is unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 199 ++++++++++-------- 1 file changed, 107 insertions(+), 92 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index ffa4327d45..6fb7c75559 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -73,122 +73,137 @@ StoryStep battle(std::string name, StoryPose pose_after, bool may_lose, std::str return step; } +StoryStep legs(std::string name, std::vector legs, std::string why, bool fight_wild = false){ + StoryStep step = make(StoryStepKind::LEGS, std::move(name), std::move(why)); + step.legs = std::move(legs); + step.fight_wild = fight_wild; + return step; +} + +StoryStep new_game_intro(StoryPose pose_after, std::string why){ + StoryStep step = make(StoryStepKind::NEW_GAME, "intro", std::move(why)); + step.pose_after = std::move(pose_after); + return step; +} + +StoryStep talk(std::string name, std::string why){ + return make(StoryStepKind::TALK, std::move(name), std::move(why)); +} + +StoryStep heal(std::string name){ + return make(StoryStepKind::HEAL, std::move(name), "full HP"); +} + StoryCheckpoint new_game(){ - StoryCheckpoint cp{"00.01", "new game to the bedroom", std::nullopt, {}, StartMenu::BEFORE_POKEMON, {}}; - StoryStep intro = make(StoryStepKind::NEW_GAME, "intro", "Oak's speech, BOY, default names, rival GREEN"); - intro.pose_after = at(BEDROOM, 6, 6, NORTH); // new_game.c: the bedroom at (6, 6), facing the TV - cp.steps.push_back(intro); - cp.steps.push_back(make(StoryStepKind::SET_OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon")); - return cp; + return StoryCheckpoint{"00.01", "new game to the bedroom", std::nullopt, {}, StartMenu::BEFORE_POKEMON, { + // new_game.c: the bedroom at (6, 6), facing the TV. + new_game_intro(at(BEDROOM, 6, 6, NORTH), "Oak's speech, BOY, default names, rival GREEN"), + make(StoryStepKind::SET_OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon"), + }}; } StoryCheckpoint leave_house(){ - StoryCheckpoint cp{"00.02", "bedroom to Pallet Town", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, {}}; - cp.steps.push_back(route("front_door", at(PALLET, 6, 8), "down the stairs and out of the house")); - return cp; + return StoryCheckpoint{"00.02", "bedroom to Pallet Town", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, { + route("front_door", at(PALLET, 6, 8), "down the stairs and out of the house"), + }}; } StoryCheckpoint oaks_trigger(){ - StoryCheckpoint cp{"00.03", "Oak stops the player and walks them to the lab", at(PALLET, 6, 8, SOUTH), {}, StartMenu::BEFORE_POKEMON, {}}; - cp.steps.push_back(route("below_oaks_trigger", at(PALLET, 12, 2, NORTH), "below the north exit, short of Oak's trigger at (12, 1)")); - cp.steps.push_back(step_into("oaks_trigger", NORTH, "the trigger: \"Don't go out!\"")); - // PlayerEnter walks the player up 8 tiles from the lab's door. - cp.steps.push_back(scene("to_the_lab", at(LAB, 6, 4, NORTH), "Oak walks the player into the lab; the scene ends at the table")); - return cp; + return StoryCheckpoint{"00.03", "Oak stops the player and walks them to the lab", at(PALLET, 6, 8, SOUTH), {}, StartMenu::BEFORE_POKEMON, { + route("below_oaks_trigger", at(PALLET, 12, 2, NORTH), "below the north exit, short of Oak's trigger at (12, 1)"), + step_into("oaks_trigger", NORTH, "the trigger: \"Don't go out!\""), + // PlayerEnter walks the player up 8 tiles from the lab's door. + scene("to_the_lab", at(LAB, 6, 4, NORTH), "Oak walks the player into the lab; the scene ends at the table"), + }}; } StoryCheckpoint starter(){ - StoryCheckpoint cp{"00.04", "Squirtle, then the rival's battle", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEDEX, {}}; - cp.steps.push_back(route("below_squirtle", at(LAB, 9, 5, NORTH), "under Squirtle's ball (9, 4)")); - cp.steps.push_back(make(StoryStepKind::TALK, "squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\"")); - cp.steps.push_back(answer("choose_squirtle", true, "take Squirtle")); - cp.steps.push_back(answer("no_nickname", false, "\"give a nickname?\" NO")); - cp.steps.push_back(scene("rival_takes_bulbasaur", at(LAB, 9, 5, NORTH), "the rival picks his ball; the player still faces the table (console B, 2026-11-01)")); - cp.steps.push_back(route("above_rival_trigger", at(LAB, 7, 7, SOUTH), "short of the rival's trigger row 8")); - cp.steps.push_back(step_into("rival_trigger", SOUTH, "\"Wait, let's check out our POKEMON!\"")); - // The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down. - cp.steps.push_back(battle("rival_battle", at(LAB, 7, 8, SOUTH), true, "the tutorial battle; losing goes on too")); - return cp; + return StoryCheckpoint{"00.04", "Squirtle, then the rival's battle", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEDEX, { + route("below_squirtle", at(LAB, 9, 5, NORTH), "under Squirtle's ball (9, 4)"), + talk("squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\""), + answer("choose_squirtle", true, "take Squirtle"), + answer("no_nickname", false, "\"give a nickname?\" NO"), + scene("rival_takes_bulbasaur", at(LAB, 9, 5, NORTH), "the rival picks his ball; the player still faces the table (console B, 2026-11-01)"), + route("above_rival_trigger", at(LAB, 7, 7, SOUTH), "short of the rival's trigger row 8"), + step_into("rival_trigger", SOUTH, "\"Wait, let's check out our POKEMON!\""), + // The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down. + battle("rival_battle", at(LAB, 7, 8, SOUTH), true, "the tutorial battle; losing goes on too"), + }}; } StoryCheckpoint parcel(){ - StoryCheckpoint cp{"00.05", "Route 1 to Viridian Mart: Oak's Parcel", at(LAB, 7, 8, SOUTH), {}, StartMenu::BEFORE_POKEDEX, {}}; - cp.steps.push_back(route("below_mart_door", at(VIRIDIAN, 36, 20, NORTH), "Route 1, running from wild battles")); - cp.steps.push_back(step_into("mart_door", NORTH, "the clerk's scene starts on entering")); - // ApproachCounter: up 4 from the mat, then faces the clerk. - cp.steps.push_back(scene("parcel_from_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "the clerk gives OAK'S PARCEL")); - return cp; + return StoryCheckpoint{"00.05", "Route 1 to Viridian Mart: Oak's Parcel", at(LAB, 7, 8, SOUTH), {}, StartMenu::BEFORE_POKEDEX, { + route("below_mart_door", at(VIRIDIAN, 36, 20, NORTH), "Route 1, running from wild battles"), + step_into("mart_door", NORTH, "the clerk's scene starts on entering"), + // ApproachCounter: up 4 from the mat, then faces the clerk. + scene("parcel_from_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "the clerk gives OAK'S PARCEL"), + }}; } StoryCheckpoint pokedex(){ - StoryCheckpoint cp{"00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, {}}; - cp.steps.push_back(route("below_oak", at(LAB, 6, 4, NORTH), "back down Route 1 to Oak")); - cp.steps.push_back(make(StoryStepKind::TALK, "give_parcel", "Oak takes the parcel")); - cp.steps.push_back(scene("pokedex_scene", at(LAB, 6, 4, SOUTH), "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)")); - return cp; + return StoryCheckpoint{"00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, { + route("below_oak", at(LAB, 6, 4, NORTH), "back down Route 1 to Oak"), + talk("give_parcel", "Oak takes the parcel"), + scene("pokedex_scene", at(LAB, 6, 4, SOUTH), "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)"), + }}; } StoryCheckpoint forest(){ - StoryCheckpoint cp{"00.07", "Viridian shopping to Pewter Center", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, {}}; - cp.steps.push_back(route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again")); - cp.steps.push_back(make(StoryStepKind::SHOP, "potions_and_antidotes", "4 Potions, 2 Antidotes")); - cp.steps.push_back(route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest")); - cp.steps.push_back(make(StoryStepKind::HEAL, "heal_viridian", "full HP")); - cp.steps.push_back(route("below_old_man_trigger", at(VIRIDIAN, 20, 9, NORTH), "short of the tutorial trigger (20, 8)")); - cp.steps.push_back(step_into("old_man_trigger", NORTH, "the old man's catching tutorial can't be walked around")); - // TutorialTriggerLeft turns the player right, to the old man. - cp.steps.push_back(scene("old_man_tutorial", at(VIRIDIAN, 20, 8, EAST), "about 60 lines and his demo battle; TEACHY TV")); - // After his demo the old man stands east of the player, beside (20, 8), where - // the map doesn't have him: "east 2" from there didn't move, and the walk north - // ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first. - cp.steps.push_back(route("past_old_man", at(VIRIDIAN, 20, 5, NORTH), "north along column 20, clear of the old man")); - cp.steps.push_back(route("forest_entrance", at(FOREST, 29, 61), "Route 2, running from wild battles")); - // The forest legs walked by hand; wild battles are fought for EXP. - cp.steps.push_back(route("forest_west", at(FOREST, 13, 46), "west side of the forest", true)); - cp.steps.push_back(route("forest_east", at(FOREST, 42, 44), "east path, past a Bug Catcher", true)); - cp.steps.push_back(route("forest_north", at(FOREST, 39, 25), "north part", true)); - // To the gate by legs that end on walls, which the walker holds again - // after a battle instead of estimating where it stopped: planned - // routes with open legs lost the player in the north of the forest - // (console B, 2026-11-01). The two 1-tile legs are single steps. - StoryStep exit_legs = make(StoryStepKind::LEGS, "forest_exit", "walls all the way to the gate's column"); - exit_legs.legs = { - {NORTH, 10}, {WEST, 12}, {SOUTH, 10}, {WEST, 6}, {NORTH, 20}, - {SOUTH, 1}, {WEST, 10}, {SOUTH, 27}, {WEST, 8}, {NORTH, 20}, {EAST, 1}, - }; - exit_legs.fight_wild = true; - cp.steps.push_back(exit_legs); - cp.steps.push_back(route("forest_gate", at(FOREST_GATE, 7, 10, NORTH), "north onto the exit, arriving on the gate's mat", true)); - // Out of the forest, wild battles are run from; trainers are still fought. - cp.steps.push_back(route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center")); - cp.steps.push_back(make(StoryStepKind::HEAL, "heal_pewter", "full HP")); - return cp; + return StoryCheckpoint{"00.07", "Viridian shopping to Pewter Center", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { + route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again"), + make(StoryStepKind::SHOP, "potions_and_antidotes", "4 Potions, 2 Antidotes"), + route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest"), + heal("heal_viridian"), + route("below_old_man_trigger", at(VIRIDIAN, 20, 9, NORTH), "short of the tutorial trigger (20, 8)"), + step_into("old_man_trigger", NORTH, "the old man's catching tutorial can't be walked around"), + // TutorialTriggerLeft turns the player right, to the old man. + scene("old_man_tutorial", at(VIRIDIAN, 20, 8, EAST), "about 60 lines and his demo battle; TEACHY TV"), + // After his demo the old man stands east of the player, beside (20, 8), where + // the map doesn't have him: "east 2" from there didn't move, and the walk north + // ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first. + route("past_old_man", at(VIRIDIAN, 20, 5, NORTH), "north along column 20, clear of the old man"), + route("forest_entrance", at(FOREST, 29, 61), "Route 2, running from wild battles"), + // The forest legs walked by hand; wild battles are fought for EXP. + route("forest_west", at(FOREST, 13, 46), "west side of the forest", true), + route("forest_east", at(FOREST, 42, 44), "east path, past a Bug Catcher", true), + route("forest_north", at(FOREST, 39, 25), "north part", true), + // To the gate by legs that end on walls, which the walker holds again + // after a battle instead of estimating where it stopped: planned + // routes with open legs lost the player in the north of the forest + // (console B, 2026-11-01). The two 1-tile legs are single steps. + legs("forest_exit", { + {NORTH, 10}, {WEST, 12}, {SOUTH, 10}, {WEST, 6}, {NORTH, 20}, + {SOUTH, 1}, {WEST, 10}, {SOUTH, 27}, {WEST, 8}, {NORTH, 20}, {EAST, 1}, + }, "walls all the way to the gate's column", true), + route("forest_gate", at(FOREST_GATE, 7, 10, NORTH), "north onto the exit, arriving on the gate's mat", true), + // Out of the forest, wild battles are run from; trainers are still fought. + route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center"), + heal("heal_pewter"), + }}; } StoryCheckpoint brock(){ // The by-hand save: 2 Potions and 1 Antidote left after the forest. - StoryCheckpoint cp{"00.08", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, {}}; - // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight - // 4): he sees (4..7, 8). Walked through, he stopped the player only - // some of the time (console B, 2026-11-01), and the leg he stopped - // couldn't be found again. He is fought on purpose instead, from - // (4, 8) beside him, so he doesn't walk and the player stays put - // (FRLG doesn't turn the player to a trainer). The way there keeps - // off row 8 west of column 8: planned from (10, 9), crossing row 8 at - // column 10 or along it costs the same, so the legs are fixed. - cp.steps.push_back(route("gym_east_side", at(GYM, 10, 9, NORTH), "up the gym's east side, below Liam's row")); - StoryStep to_liam = make(StoryStepKind::LEGS, "above_liam_line", "up column 10, along row 6, then above (4, 8)"); - to_liam.legs = {{NORTH, 3}, {WEST, 6}, {SOUTH, 1}}; - cp.steps.push_back(to_liam); - cp.steps.push_back(step_into("liam_line", SOUTH, "beside Liam, in his line")); - cp.steps.push_back(battle("camper_liam", at(GYM, 4, 8, SOUTH), false, "Geodude and Sandshrew; EXP before Brock")); - cp.steps.push_back(route("back_to_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "heal after Liam")); - cp.steps.push_back(make(StoryStepKind::HEAL, "heal_before_brock", "full HP")); - cp.steps.push_back(route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5)")); - cp.steps.push_back(make(StoryStepKind::TALK, "challenge_brock", "Brock's speech")); - cp.steps.push_back(battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39")); - return cp; + return StoryCheckpoint{"00.08", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { + // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight + // 4): he sees (4..7, 8). Walked through, he stopped the player only + // some of the time (console B, 2026-11-01), and the leg he stopped + // couldn't be found again. He is fought on purpose instead, from + // (4, 8) beside him, so he doesn't walk and the player stays put + // (FRLG doesn't turn the player to a trainer). The way there keeps + // off row 8 west of column 8: planned from (10, 9), crossing row 8 at + // column 10 or along it costs the same, so the legs are fixed. + route("gym_east_side", at(GYM, 10, 9, NORTH), "up the gym's east side, below Liam's row"), + legs("above_liam_line", {{NORTH, 3}, {WEST, 6}, {SOUTH, 1}}, "up column 10, along row 6, then above (4, 8)"), + step_into("liam_line", SOUTH, "beside Liam, in his line"), + battle("camper_liam", at(GYM, 4, 8, SOUTH), false, "Geodude and Sandshrew; EXP before Brock"), + route("back_to_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "heal after Liam"), + heal("heal_before_brock"), + route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5)"), + talk("challenge_brock", "Brock's speech"), + battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39"), + }}; } } From c2de4f54b2b577b6112dad4451a4822b724c393e Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 09:10:26 -0800 Subject: [PATCH 17/75] FRLG AutoStory: meet Camper Liam on the way up column 6 The user's call: walk north from the gym's door and fight Liam where he stops the player. The route now ends at (6, 9), below his row; a single step north onto (6, 8), in his line, starts his battle, and the player stays there facing north. The detour by the gym's east side, and the route test that kept it off his row, are dropped. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 18 +++++++----------- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 7 ------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 6fb7c75559..fb97857453 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -187,17 +187,13 @@ StoryCheckpoint brock(){ // The by-hand save: 2 Potions and 1 Antidote left after the forest. return StoryCheckpoint{"00.08", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight - // 4): he sees (4..7, 8). Walked through, he stopped the player only - // some of the time (console B, 2026-11-01), and the leg he stopped - // couldn't be found again. He is fought on purpose instead, from - // (4, 8) beside him, so he doesn't walk and the player stays put - // (FRLG doesn't turn the player to a trainer). The way there keeps - // off row 8 west of column 8: planned from (10, 9), crossing row 8 at - // column 10 or along it costs the same, so the legs are fixed. - route("gym_east_side", at(GYM, 10, 9, NORTH), "up the gym's east side, below Liam's row"), - legs("above_liam_line", {{NORTH, 3}, {WEST, 6}, {SOUTH, 1}}, "up column 10, along row 6, then above (4, 8)"), - step_into("liam_line", SOUTH, "beside Liam, in his line"), - battle("camper_liam", at(GYM, 4, 8, SOUTH), false, "Geodude and Sandshrew; EXP before Brock"), + // 4) and sees (4..7, 8): walking north up column 6 from the door, + // the step onto (6, 8) starts his battle. He walks up to the player, + // who stays put and keeps facing north (FRLG doesn't turn the player + // to a trainer). That step is taken on its own, so no leg is cut. + route("below_liam_line", at(GYM, 6, 9, NORTH), "in by the door, up column 6 to below Liam's row"), + step_into("liam_line", NORTH, "onto (6, 8), in Liam's line"), + battle("camper_liam", at(GYM, 6, 8, NORTH), false, "Geodude and Sandshrew; EXP before Brock"), route("back_to_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "heal after Liam"), heal("heal_before_brock"), route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5)"), diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index d87219e5f4..c87d49a912 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -153,13 +153,6 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step){ return result; } } - if (step.name == "gym_east_side"){ - for (const TilePos& tile : tiles_walked_on(*route, "PewterCity_Gym")){ - if (tile.y == 8 && 4 <= tile.x && tile.x <= 7){ - return step.name + ": walks into Camper Liam's line at " + to_string(tile) + ":" + describe(*route); - } - } - } if (step.name == "below_old_man_trigger"){ for (const TilePos& tile : tiles_walked_on(*route, "ViridianCity")){ if (tile == TilePos{20, 8} || tile == TilePos{22, 8}){ From b7f861767e2e4d85fa2dc5a831e3e301a332b2fd Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 09:11:48 -0800 Subject: [PATCH 18/75] FRLG AutoStory: before a big battle, a Potion if hurt, the nurse only when out The user's call: don't always walk back to the Pokemon Center after Liam. A new READY step decides from the starter's HP and the Potions left: green goes on; yellow or red uses a Potion from the bag on the overworld; red with no Potion walks to the nurse given in the table and heals. The battle loop now reads the HP bar at every battle screen that shows the starter's box, so the reading includes the battle's last hit. 00.08 uses it between Liam and Brock; the route test plans the way to the nurse too. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 18 ++++++++++ .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 10 ++++-- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 35 +++++++++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 3 +- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 12 +++++-- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 9 +++++ 6 files changed, 81 insertions(+), 6 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 3c90e50735..9ccbcd6c10 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -267,6 +267,7 @@ class BattleLoop{ } m_seen_battle = true; m_last_battle = now; + read_hp(screen); act(seen, screen, now); return false; } @@ -343,6 +344,17 @@ class BattleLoop{ pbf_wait(m_context, POLL); } + // The HP bar whenever the starter's box shows, so the last reading + // includes the battle's last hit. + void read_hp(const ImageViewRGB32& screen){ + if (!BattlePokemonDetector(COLOR_RED).detect(screen)){ + return; + } + const PartyStatus status = read_party_status(screen); + m_supplies.hurt = status.hp_red || status.hp_yellow; + m_supplies.hp_red = status.hp_red; + } + // "Delete a move to make room?" NO, then "Stop learning?" YES. void answer_learn_prompt(WallClock now){ m_console.log(m_learn_prompts % 2 == 0 ? "Battle: not deleting a move." : "Battle: stop learning."); @@ -377,6 +389,7 @@ class BattleLoop{ if (hurt && m_supplies.potions > 0){ m_supplies.potions--; m_supplies.hurt = false; + m_supplies.hp_red = false; use_item(m_console, m_context, 0); }else if (m_psn_reads >= PSN_READS && !m_antidote_used && m_supplies.antidotes > 0){ m_antidote_used = true; @@ -441,6 +454,7 @@ void use_potion_on_overworld(ConsoleHandle& console, ProControllerContext& conte pbf_press_button(context, BUTTON_B, 160ms, 1500ms); supplies.potions--; supplies.hurt = false; + supplies.hp_red = false; mash_until_overworld(console, context, AFTER_BATTLE_TEXT); } @@ -543,6 +557,10 @@ PartyStatus read_party_status(const ImageViewRGB32& screen){ return status; } +void use_potion_from_bag(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies){ + use_potion_on_overworld(console, context, supplies); +} + BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind){ return BattleLoop(console, context, supplies, kind).run(); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index bc1250c76e..32edc0a087 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -35,9 +35,10 @@ namespace PokemonFRLG{ struct Supplies{ int potions = 0; int antidotes = 0; - // The starter's HP bar wasn't green at the last battle turn, and no - // Potion was used since. + // The starter's HP bar wasn't green (or was red) at the last battle + // screen that showed it, and no Potion or nurse healed it since. bool hurt = false; + bool hp_red = false; }; enum class BattleKind{ @@ -68,6 +69,11 @@ PartyStatus read_party_status(const ImageViewRGB32& screen); BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind); +// From the overworld: a Potion from the top row of the Items pocket, on +// the starter. The bag's inputs are not checked on the console yet. +void use_potion_from_bag(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies); + + // The interrupts for walking story routes. Wild battles are run from, or // fought if `fight_wild`. A message is advanced until the overworld is // back; a battle that starts after it (a trainer who saw the player) is diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 7008fec311..f5af734e3e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include #include "CommonFramework/Exceptions/OperationFailedException.h" @@ -137,6 +138,36 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ return Pokemon::outcome_ok(); } +// HP is the battle loop's last reading. One Potion (20 HP) takes a starter +// of the levels here (max HP about 30) from red to green, so one is used +// and the bar is taken to be green after it; it can't be read again on the +// overworld. +Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ + Supplies& supplies = env.supplies; + env.console.log(std::format( + "Story: before the battle, HP {}, {} Potions.", + supplies.hp_red ? "red" : supplies.hurt ? "yellow" : "green", supplies.potions + )); + if (!supplies.hurt){ + return Pokemon::outcome_ok(); + } + if (supplies.potions > 0){ + use_potion_from_bag(env.console, env.context, supplies); + return Pokemon::outcome_ok(); + } + if (!supplies.hp_red){ + return Pokemon::outcome_ok(); + } + Outcome walked = walk_route(env, state, step); + if (!walked.succeeded()){ + return walked; + } + heal_at_center(env.console, env.context); + supplies.hurt = false; + supplies.hp_red = false; + return walked; +} + Outcome shop(StoryEnv& env){ // Viridian Mart before the Boulder Badge: POKE BALL, POTION, ANTIDOTE, PARLYZ HEAL. buy_items(env.console, env.context, {{1, 4}, {2, 2}}); @@ -172,7 +203,11 @@ Outcome run_step(StoryEnv& env, RunState& state, const StoryStep& step, StartMen return battle(env, step); case StoryStepKind::HEAL: heal_at_center(env.console, env.context); + env.supplies.hurt = false; + env.supplies.hp_red = false; return Pokemon::outcome_ok(); + case StoryStepKind::READY: + return get_ready(env, state, step); case StoryStepKind::SHOP: return shop(env); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 1f254cd5ca..bc7a70e409 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -56,6 +56,7 @@ enum class StoryStepKind{ BATTLE, // text with B into a battle, fight it, text to the overworld HEAL, // facing the nurse SHOP, // facing the Viridian Mart clerk: Potions and Antidotes + READY, // before a big battle: a Potion if hurt, the nurse at `target` if red with none }; // A straight leg of a fixed walk. @@ -68,7 +69,7 @@ struct StoryStep{ StoryStepKind kind = StoryStepKind::TALK; std::string name; std::string why; - // ROUTE: the goal, and the way to face there if set. + // ROUTE: the goal, and the way to face there if set. READY: the nurse. StoryPose target; // STEP Direction direction = Direction::NORTH; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index fb97857453..1b8d6f3d15 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -90,6 +90,12 @@ StoryStep talk(std::string name, std::string why){ return make(StoryStepKind::TALK, std::move(name), std::move(why)); } +StoryStep ready(std::string name, StoryPose nurse, std::string why){ + StoryStep step = make(StoryStepKind::READY, std::move(name), std::move(why)); + step.target = std::move(nurse); + return step; +} + StoryStep heal(std::string name){ return make(StoryStepKind::HEAL, std::move(name), "full HP"); } @@ -194,9 +200,9 @@ StoryCheckpoint brock(){ route("below_liam_line", at(GYM, 6, 9, NORTH), "in by the door, up column 6 to below Liam's row"), step_into("liam_line", NORTH, "onto (6, 8), in Liam's line"), battle("camper_liam", at(GYM, 6, 8, NORTH), false, "Geodude and Sandshrew; EXP before Brock"), - route("back_to_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "heal after Liam"), - heal("heal_before_brock"), - route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5)"), + // On to Brock unless the starter's HP is red with no Potion left. + ready("ready_for_brock", at(PEWTER_CENTER, 7, 4, NORTH), "a Potion if hurt; the nurse only if red with none"), + route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5); Liam, beaten, stands at (5, 8)"), talk("challenge_brock", "Brock's speech"), battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39"), }}; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index c87d49a912..d15df26559 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -172,6 +172,15 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po if (result.result != UnitTestResult::PASSED){ return checkpoint.id + " " + result.message; } + }else if (step.kind == StoryStepKind::READY){ + // The nurse may be needed: that way must plan too, but the pose + // goes on from where the player stands. + StoryPose nurse_pose = pose; + StoryStep to_nurse = step; + UnitTestResult result = check_route(nurse_pose, to_nurse); + if (result.result != UnitTestResult::PASSED){ + return checkpoint.id + " " + result.message; + } }else if (step.kind == StoryStepKind::STEP){ pose = StoryPose{pose.map, pose.tile.next(step.direction), step.direction}; } From cfef415403b7d0331f4afef2726a1151b484d49e Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 09:23:21 -0800 Subject: [PATCH 19/75] FRLG AutoStory: plan 00.08's gym walks in CI on embedded maps The route tests skip in CI, which has no map files. Pewter City, its Pokemon Center and its gym are now embedded in the test file as JSON fixtures, and a test plans 00.08 step by step: from the nurse in by the door mat and straight up column 6 to (6, 9) (one leg, north 5); the step onto (6, 8); then (6, 8) to (6, 6), north 2; and the nurse's way back, north 8 from the mat to (6, 6). The gym's legs are checked exactly. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 251 ++++++++++++++++++ 1 file changed, 251 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index d15df26559..31ee37acbe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -11,6 +11,7 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "PokemonFRLG_AutoStoryTable.h" @@ -215,6 +216,255 @@ UnitTestResult test_routes_and_chain(){ return true; } +// Pewter City, its Pokemon Center and its gym, from Packages' +// Resources/PokemonFRLG/Maps (generated by devtools/maps/frlg_maps.py), so +// 00.08's walks are planned in CI, which has no map files. +const char* const PEWTER_CITY_JSON = R"json({ +"name": "PewterCity", "width": 48, "height": 40, +"tiles": [ + "################################################", + "#######################....#####################", + "####........#################.........##########", + "####........#################.........##########", + "####........#############D######......##########", + "####........###########...............##########", + "#######.....#####C#####..#######........########", + "####JJJ..JJJJJJJ...#JJJJJJJJJJJJJJJJJ...########", + "####....................................########", + "####............................#####...########", + "######..........................#####...########", + "######..........................#D###...########", + "######..................................########", + "######...##.#######.##..................########", + "######...#############..................########", + "######...##.#######.##..................########", + "######...###..#D#...##....####..........########", + "######...............#....######........########", + "######...............#....##D###........########", + "######...............#.................#########", + "######################..........................", + "######..........................................", + "######.......#########..........................", + "######.......#########....##########............", + "######.......#########....##########....########", + "######.......####D####....###########...########", + "######....................#.........#...########", + "######....................#.........#...########", + "######..#####.............#.........#...########", + "######..#####.............#.........#...########", + "######..#D###.......#.....#JJJJ.JJJJ#...########", + "######..................................########", + "######..................................########", + "######..................................########", + "######..................................########", + "######..................................########", + "####################....########################", + "####################....########################", + "####################....########################", + "####################....########################" +], +"elevation": [ + "000000000000000000000000000000000000000000000000", + "000000000000000000000003333000000000000000000000", + "000033333333000000000000000003333333330000000000", + "000033333333000000000000000003333333330000000000", + "000033333333000000000000000000003333330000000000", + "000033333333000000000003333333333333330000000000", + "000000033333000003000003300000003333333300000000", + "000000033000000033300000000000000000033300000000", + "000033333333333333333333333333333333333300000000", + "000033333333333333333333333333330000033300000000", + "000000333333333333333333333333330000033300000000", + "000000333333333333333333333333330000033300000000", + "000000333333333333333333333333333333333300000000", + "000000333003000000030033333333333333333300000000", + "000000333000000000000033333333333333333300000000", + "000000333003000000030033333333333333333300000000", + "000000333000330003330033330000333333333300000000", + "000000333333333333333033330000003333333300000000", + "000000333333333333333033330000003333333300000000", + "000000333333333333333033333333333333333000000000", + "000000000000000000000033333333333333333333333333", + "000000333333333333333333333333333333333333333333", + "000000333333300000000033333333333333333333333333", + "000000333333300000000033330000000000333333333333", + "000000333333300000000033330000000000333300000000", + "000000333333300000000033330000000000033300000000", + "000000333333333333333333330333333333033300000000", + "000000333333333333333333330333333333033300000000", + "000000330000033333333333330333333333033300000000", + "000000330000033333333333330333333333033300000000", + "000000330000033333330333330000030000033300000000", + "000000333333333333333333333333333333333300000000", + "000000333333333333333333333333333333333300000000", + "000000333333333333333333333333333333333300000000", + "000000333333333333333333333333333333333300000000", + "000000333333333333333333333333333333333300000000", + "000000000000000000003333000000000000000000000000", + "000000000000000000003333000000000000000000000000", + "000000000000000000003333000000000000000000000000", + "000000000000000000003333000000000000000000000000" +], +"warps": [{"x": 17, "y": 6, "dest_map": "PewterCity_Museum_1F", "dest_warp": 1}, {"x": 25, "y": 4, "dest_map": "PewterCity_Museum_1F", "dest_warp": 3}, {"x": 15, "y": 16, "dest_map": "PewterCity_Gym", "dest_warp": 1}, {"x": 28, "y": 18, "dest_map": "PewterCity_Mart", "dest_warp": 1}, {"x": 33, "y": 11, "dest_map": "", "dest_warp": 1}, {"x": 17, "y": 25, "dest_map": "PewterCity_PokemonCenter_1F", "dest_warp": 1}, {"x": 9, "y": 30, "dest_map": "", "dest_warp": 1}], +"objects": [{"x": 6, "y": 15, "kind": "lass", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 33, "y": 17, "kind": "man", "flag": "FLAG_HIDE_PEWTER_MUSEUM_GUIDE", "wander_x": 0, "wander_y": 0}, {"x": 21, "y": 28, "kind": "fat_man", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 33, "y": 27, "kind": "bug_catcher", "flag": "", "wander_x": 2, "wander_y": 0}, {"x": 42, "y": 20, "kind": "boy", "flag": "FLAG_HIDE_PEWTER_CITY_GYM_GUIDE", "wander_x": 0, "wander_y": 0}, {"x": 30, "y": 5, "kind": "cut_tree", "flag": "FLAG_TEMP_12", "wander_x": 0, "wander_y": 0}, {"x": 46, "y": 20, "kind": "scientist", "flag": "FLAG_HIDE_PEWTER_CITY_RUNNING_SHOES_GUY", "wander_x": 0, "wander_y": 0}], +"connections": [{"direction": "south", "offset": 12, "map": "Route2"}], +"points": [{"name": "gym_front", "x": 15, "y": 17}], +"flag_sets": [] +})json"; + +const char* const PEWTER_GYM_JSON = R"json({ +"name": "PewterCity_Gym", "width": 13, "height": 16, +"tiles": [ + "#############", + "####.....####", + "#############", + "#....#.#....#", + "#...........#", + "#...#...#...#", + "#...........#", + "#..#.#.#.#..#", + "##.........##", + "#...#...#...#", + "##.........##", + "#...........#", + "#...#...#...#", + "#...........#", + "#.....v.....#", + "#############" +], +"elevation": [ + "0000000000000", + "0000333330000", + "0000000000000", + "0333303033330", + "0333333333330", + "0333033303330", + "0333333333330", + "0330303030330", + "0033333333300", + "0333033303330", + "0033333333300", + "0333333333330", + "0333033303330", + "0333333333330", + "0333333333330", + "0000000000000" +], +"warps": [{"x": 5, "y": 14, "dest_map": "PewterCity", "dest_warp": 2}, {"x": 6, "y": 14, "dest_map": "PewterCity", "dest_warp": 2}, {"x": 7, "y": 14, "dest_map": "PewterCity", "dest_warp": 2}], +"objects": [{"x": 6, "y": 5, "kind": "brock", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 3, "y": 8, "kind": "camper", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 7, "y": 12, "kind": "gym_guy", "flag": "", "wander_x": 0, "wander_y": 0}], +"connections": [], +"points": [{"name": "brock_front", "x": 6, "y": 6}], +"flag_sets": [] +})json"; + +const char* const PEWTER_CENTER_JSON = R"json({ +"name": "PewterCity_PokemonCenter_1F", "width": 15, "height": 10, +"tiles": [ + "#.#############", + "###############", + "....###..##....", + "....#######....", + "...............", + "...............", + "#L.........##..", + "...........##..", + ".......v.......", + "###############" +], +"elevation": [ + "030000000000000", + "000000000000000", + "333300033003333", + "333300000003333", + "333333333333333", + "330333333333333", + "044033333330033", + "330333333330033", + "333333333333333", + "000000000000000" +], +"warps": [{"x": 6, "y": 8, "dest_map": "PewterCity", "dest_warp": 5}, {"x": 7, "y": 8, "dest_map": "PewterCity", "dest_warp": 5}, {"x": 8, "y": 8, "dest_map": "PewterCity", "dest_warp": 5}, {"x": 1, "y": 6, "dest_map": "", "dest_warp": 0}], +"objects": [{"x": 2, "y": 2, "kind": "jigglypuff", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 4, "y": 8, "kind": "gentleman", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 7, "y": 2, "kind": "nurse", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 1, "y": 2, "kind": "youngster", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 13, "y": 2, "kind": "woman_1", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 10, "y": 7, "kind": "gba_kid", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 14, "y": 6, "kind": "gba_kid", "flag": "", "wander_x": 0, "wander_y": 0}], +"connections": [], +"points": [{"name": "nurse_front", "x": 7, "y": 4}], +"flag_sets": [] +})json"; + + +const std::vector& pewter_maps(){ + static const std::vector maps{ + parse_map(PEWTER_CITY_JSON, "PewterCity (test fixture)"), + parse_map(PEWTER_GYM_JSON, "PewterCity_Gym (test fixture)"), + parse_map(PEWTER_CENTER_JSON, "PewterCity_PokemonCenter_1F (test fixture)"), + }; + return maps; +} + +struct ExpectedLeg{ + Direction direction; + int tiles; + TilePos end; +}; + +// Plans `start` to `goal` on the Pewter maps and checks the walking legs +// on `map`, except the step that warps onto it, against `expected`. +UnitTestResult check_legs_on( + const MapPosition& start, Direction start_facing, const RouteGoal& goal, + const std::string& map, const std::vector& expected +){ + const std::optional> route = plan_overworld_route( + pewter_maps(), start, goal, default_route_costs(), start_facing + ); + if (!route){ + return "No route from " + to_string(start) + " to " + to_string(goal.position) + "."; + } + std::vector legs; + for (const RouteStep& step : *route){ + if (step.action == RouteAction::WALK && !step.warps && step.end.map == map){ + legs.push_back(step); + } + } + bool same = legs.size() == expected.size(); + for (size_t c = 0; same && c < legs.size(); c++){ + same = legs[c].direction == expected[c].direction && legs[c].tiles == expected[c].tiles && legs[c].end.point == expected[c].end; + } + if (!same){ + return "Unexpected legs on " + map + " from " + to_string(start) + " to " + to_string(goal.position) + ":" + describe(*route); + } + return true; +} + +// 00.08, each walk from where the one before leaves the player. +UnitTestResult test_pewter_gym_walks(){ + const MapPosition nurse{"PewterCity_PokemonCenter_1F", {7, 4}}; + // In by the door's mat (6, 14), straight up column 6 to below Liam's row. + UnitTestResult result = check_legs_on( + nurse, Direction::NORTH, RouteGoal{{"PewterCity_Gym", {6, 9}}, Direction::NORTH}, + "PewterCity_Gym", {{Direction::NORTH, 5, {6, 9}}} + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + // The step onto (6, 8), into Liam's line. + const MapData& gym = pewter_maps()[1]; + if (classify_step(gym, PlayerState{{6, 9}, elevation_at(gym, {6, 9}), false}, Direction::NORTH) != StepKind::WALK){ + return "Can't step north from (6, 9) onto (6, 8)."; + } + // After Liam, on to Brock: two tiles north. + result = check_legs_on( + MapPosition{"PewterCity_Gym", {6, 8}}, Direction::NORTH, RouteGoal{{"PewterCity_Gym", {6, 6}}, Direction::NORTH}, + "PewterCity_Gym", {{Direction::NORTH, 2, {6, 6}}} + ); + if (result.result != UnitTestResult::PASSED){ + return result; + } + // The nurse's way: from her counter back in and up column 6 to Brock. + return check_legs_on( + nurse, Direction::NORTH, RouteGoal{{"PewterCity_Gym", {6, 6}}, Direction::NORTH}, + "PewterCity_Gym", {{Direction::NORTH, 8, {6, 6}}} + ); +} + UnitTestResult test_unique_names(){ for (const StoryCheckpoint& checkpoint : story_checkpoints()){ for (size_t i = 0; i < checkpoint.steps.size(); i++){ @@ -234,6 +484,7 @@ UnitTestResult test_unique_names(){ void add_tests_AutoStory(UnitTestDatabase& database){ database.add("every route plans, and checkpoints chain", test_routes_and_chain); database.add("step names are unique per checkpoint", test_unique_names); + database.add("Pewter Gym walks, on embedded maps", test_pewter_gym_walks); } From efb05fe2651f06154de147fb980b85410fa4a875 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 09:23:21 -0800 Subject: [PATCH 20/75] FRLG AutoStory: read HP and status from measured colors; cure PSN and PAR after battles The HP bar and status badge are now read in small boxes, with colors measured on console B's battle captures (2026-11-01): fill green (100, 251, 171), yellow (255, 228, 23), red (255, 113, 68); the badge's place off-white (255, 255, 217) with no status, (228, 168, 212) for PSN. The old reading, over the whole box, took the female symbol for PSN. On 22 lab captures it reads every HP bar's color and every PSN badge right. After a battle on the way, PSN is cured with an Antidote and PAR with a Parlyz Heal from the bag, then a Potion is used if HP wasn't green. The READY step sends the player to the nurse only for red HP with no Potion, or a status no item cures (SLP, BRN, FRZ). In the forest a wild Pokemon is run from when the starter has any status. Viridian Mart now sells the story 5 Potions, 3 Antidotes and 1 Parlyz Heal (2000 at pokefirered's prices). PAR's badge color is a guess: there is no capture of it yet. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 147 ++++++++++++------ .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 37 ++++- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 34 ++-- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 2 +- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 6 +- 5 files changed, 147 insertions(+), 79 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 9ccbcd6c10..6051f8d21c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -4,11 +4,13 @@ * */ +#include #include #include #include #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" #include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTools/ImageStats.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" @@ -63,23 +65,22 @@ constexpr int PSN_READS = 2; // Text and the move learn prompts after a battle, on the overworld. constexpr Milliseconds AFTER_BATTLE_TEXT = 60000ms; -// Inside the player's status box (name, level, HP bar, status), which -// BattlePokemonDetector frames. Not calibrated on the console yet. -const ImageFloatBox PLAYER_STATUS_BOX(0.600, 0.500, 0.340, 0.165); +// In the player's box, as fractions of the 240x160 screen: the HP bar's +// fill, which grows from its left end, and the status badge left of the +// HP numbers. The box bobs by a pixel; these keep a pixel inside. +const ImageFloatBox HP_BAR_BOX(174.0 / 240, 91.0 / 160, 48.0 / 240, 2.0 / 160); +const ImageFloatBox STATUS_BADGE_BOX(146.0 / 240, 99.0 / 160, 12.0 / 240, 4.0 / 160); -struct ColorCounts{ +struct HpCounts{ size_t green = 0; size_t yellow = 0; size_t red = 0; - size_t purple = 0; size_t total = 0; }; -// The HP bar's three colors and the PSN badge's purple. Guessed from the -// game's palette, not measured. -ColorCounts count_colors(const ImageViewRGB32& image){ - ColorCounts counts; +HpCounts count_hp_colors(const ImageViewRGB32& image){ + HpCounts counts; for (size_t y = 0; y < image.height(); y++){ for (size_t x = 0; x < image.width(); x++){ const uint32_t pixel = image.pixel(x, y); @@ -87,20 +88,37 @@ ColorCounts count_colors(const ImageViewRGB32& image){ const int g = (pixel >> 8) & 0xff; const int b = pixel & 0xff; counts.total++; - if (g > 180 && r < 150 && b > 90 && b < 210){ + if (g > 200 && r < 160 && b > 120 && b < 210){ counts.green++; - }else if (r > 190 && g > 160 && b < 90){ + }else if (r > 220 && g > 180 && b < 80){ counts.yellow++; - }else if (r > 190 && g < 110 && b < 90){ + }else if (r > 220 && g > 80 && g < 150 && b < 110){ counts.red++; - }else if (r > 150 && b > 150 && g < 100 && std::abs(r - b) < 60){ - counts.purple++; } } } return counts; } +StatusCondition read_status_badge(const ImageViewRGB32& badge){ + const ImageStats stats = image_stats(badge); + const double r = stats.average.r; + const double g = stats.average.g; + const double b = stats.average.b; + const double off_white = std::abs(r - 255) + std::abs(g - 255) + std::abs(b - 217); + if (off_white < 60){ + return StatusCondition::NONE; + } + if (r > 200 && g < 200 && b > 180){ + return StatusCondition::POISON; + } + // Not measured yet: PAR's badge is taken to be the yellow one. + if (r > 180 && g > 150 && b < 140){ + return StatusCondition::PARALYSIS; + } + return StatusCondition::OTHER; +} + enum class BattleScreen{ // Keep in step with screen_name(). @@ -351,8 +369,11 @@ class BattleLoop{ return; } const PartyStatus status = read_party_status(screen); - m_supplies.hurt = status.hp_red || status.hp_yellow; - m_supplies.hp_red = status.hp_red; + if (status.hp_seen){ + m_supplies.hurt = status.hp_red || status.hp_yellow; + m_supplies.hp_red = status.hp_red; + } + m_supplies.status = status.status; } // "Delete a move to make room?" NO, then "Stop learning?" YES. @@ -369,17 +390,18 @@ class BattleLoop{ const PartyStatus status = read_party_status(screen); const bool hurt = status.hp_red || status.hp_yellow; m_supplies.hurt = hurt; - m_psn_reads = status.poisoned ? m_psn_reads + 1 : 0; + m_supplies.status = status.status; + m_psn_reads = status.status == StatusCondition::POISON ? m_psn_reads + 1 : 0; m_console.log(std::format( - "Battle: turn {}, HP {}{}, {} Potions, {} Antidotes.", + "Battle: turn {}, HP {}, {}, {} Potions, {} Antidotes, {} Parlyz Heals.", m_turns, status.hp_red ? "red" : status.hp_yellow ? "yellow" : "green", - status.poisoned ? ", PSN read" : "", m_supplies.potions, m_supplies.antidotes + status_name(status.status), m_supplies.potions, m_supplies.antidotes, m_supplies.parlyz_heals )); // A wild Pokemon is fought for EXP only at full strength: fighting // every one in Viridian Forest used up all 4 Potions and then the - // starter (console B, 2026-11-01). - const bool run = m_kind == BattleKind::WILD_RUN - || (m_kind == BattleKind::WILD_FIGHT && (hurt || m_supplies.potions < MIN_POTIONS_TO_FIGHT)); + // starter (console B, 2026-11-01). With a status, it is run from too. + const bool weak = hurt || status.status != StatusCondition::NONE || m_supplies.potions < MIN_POTIONS_TO_FIGHT; + const bool run = m_kind == BattleKind::WILD_RUN || (m_kind == BattleKind::WILD_FIGHT && weak); if (run && m_run_tries < RUN_TRIES){ m_run_tries++; m_console.log(std::format("Battle: RUN (try {}).", m_run_tries)); @@ -434,10 +456,10 @@ class BattleLoop{ }; -// From the overworld: a Potion from the Items pocket, top row, on the -// starter. Not run on the console yet. -void use_potion_on_overworld(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies){ - console.log(std::format("Story: HP below green after the battle, using a Potion ({} left).", supplies.potions)); +// From the overworld: the item in `row` (from 0) of the Items pocket, on +// the starter. Not run on the console yet. +void use_item_on_overworld(ConsoleHandle& console, ProControllerContext& context, int row, const char* item){ + console.log(std::format("Story: using a {} from the bag (Items pocket, row {}).", item, row + 1)); open_bag_from_overworld(console, context); // The bag ignores presses while it slides in. pbf_wait(context, 1000ms); @@ -447,25 +469,17 @@ void use_potion_on_overworld(ConsoleHandle& console, ProControllerContext& conte for (int c = 0; c < 20; c++){ pbf_press_dpad(context, DPAD_UP, 100ms, 100ms); } - // The Potion, USE, the starter, then "...HP was restored". + for (int c = 0; c < row; c++){ + pbf_press_dpad(context, DPAD_DOWN, 100ms, 300ms); + } + // The item, USE, the starter, then its message. pbf_press_button(context, BUTTON_A, 160ms, 800ms); pbf_press_button(context, BUTTON_A, 160ms, 1500ms); pbf_press_button(context, BUTTON_A, 160ms, 2500ms); pbf_press_button(context, BUTTON_B, 160ms, 1500ms); - supplies.potions--; - supplies.hurt = false; - supplies.hp_red = false; mash_until_overworld(console, context, AFTER_BATTLE_TEXT); } -// After a battle on the way: heal between battles if the last HP read -// wasn't green. -void heal_if_hurt(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies){ - if (supplies.hurt && supplies.potions > 0){ - use_potion_on_overworld(console, context, supplies); - } -} - void fail_on_blackout(ConsoleHandle& console, BattleEnd end){ if (end == BattleEnd::LOST){ OperationFailedExceptionWithScreenshot::fire( @@ -503,7 +517,7 @@ class StoryWildBattle : public OverworldInterrupt{ virtual void clear(ConsoleHandle& console, ProControllerContext& context) const override{ const BattleKind kind = m_fight ? BattleKind::WILD_FIGHT : BattleKind::WILD_RUN; fail_on_blackout(console, fight_battle(console, context, m_supplies, kind)); - heal_if_hurt(console, context, m_supplies); + recover_after_battle(console, context, m_supplies); } private: @@ -534,7 +548,7 @@ class StoryMessage : public OverworldInterrupt{ console.log("Story: a trainer's battle after a message on the overworld."); fail_on_blackout(console, fight_battle(console, context, m_supplies, BattleKind::TRAINER)); mash_until_overworld(console, context, AFTER_BATTLE_TEXT); - heal_if_hurt(console, context, m_supplies); + recover_after_battle(console, context, m_supplies); } private: @@ -544,21 +558,56 @@ class StoryMessage : public OverworldInterrupt{ } +const char* status_name(StatusCondition status){ + switch (status){ + case StatusCondition::NONE: + return "no status"; + case StatusCondition::POISON: + return "PSN"; + case StatusCondition::PARALYSIS: + return "PAR"; + case StatusCondition::OTHER: + return "a status"; + } + return "?"; +} + PartyStatus read_party_status(const ImageViewRGB32& screen){ const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); - const ColorCounts counts = count_colors(extract_box_reference(game, PLAYER_STATUS_BOX)); - // A full bar fills a few percent of the box; a sliver of one, much less. - const size_t seen = counts.total / 1000 + 1; + const HpCounts counts = count_hp_colors(extract_box_reference(game, HP_BAR_BOX)); + // At 1 HP the red sliver was 32 of the box's 4000 pixels (console B, + // 2026-11-01, 1/25 HP). + const size_t seen = counts.total / 200 + 1; PartyStatus status; - const bool green = counts.green > seen; - status.hp_yellow = !green && counts.yellow > seen; - status.hp_red = !green && !status.hp_yellow && counts.red > seen; - status.poisoned = counts.purple > seen; + const size_t most = std::max({counts.green, counts.yellow, counts.red}); + status.hp_seen = most >= seen; + status.hp_yellow = status.hp_seen && counts.yellow == most; + status.hp_red = status.hp_seen && !status.hp_yellow && counts.red == most; + status.status = read_status_badge(extract_box_reference(game, STATUS_BADGE_BOX)); return status; } -void use_potion_from_bag(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies){ - use_potion_on_overworld(console, context, supplies); +void recover_after_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies){ + // Rows in the order bought: Potions, Antidotes, Parlyz Heals. + const int antidote_row = supplies.potions > 0 ? 1 : 0; + const int parlyz_row = antidote_row + (supplies.antidotes > 0 ? 1 : 0); + if (supplies.status == StatusCondition::POISON && supplies.antidotes > 0){ + use_item_on_overworld(console, context, antidote_row, "Antidote"); + supplies.antidotes--; + supplies.status = StatusCondition::NONE; + }else if (supplies.status == StatusCondition::PARALYSIS && supplies.parlyz_heals > 0){ + use_item_on_overworld(console, context, parlyz_row, "Parlyz Heal"); + supplies.parlyz_heals--; + supplies.status = StatusCondition::NONE; + } + // One Potion (20 HP) takes a starter of these levels (about 30 HP) + // from red to green; the bar can't be read again on the overworld. + if (supplies.hurt && supplies.potions > 0){ + use_item_on_overworld(console, context, 0, "Potion"); + supplies.potions--; + supplies.hurt = false; + supplies.hp_red = false; + } } BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index 32edc0a087..f9a0c55ddd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -8,7 +8,8 @@ * game remembers both; the move is the bottom left one (Bubble), which the * cursor can't reach while that slot is empty, so before Bubble it stays on * Tackle. A Potion is used when the HP bar turns yellow or red, an Antidote - * (once a battle) when the status reads PSN at two turns in a row. + * (once a battle) when the status reads PSN at two turns in a row; after + * the battle, PSN and PAR are cured from the bag. * "Delete a move to make room?" is answered NO and "Stop learning?" YES. * * Also the overworld interrupts the story walks routes with: wild battles @@ -30,11 +31,25 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ +// A status condition, as far as the story treats them: the two it carries +// items for, and the rest, which only a nurse cures. +enum class StatusCondition{ + NONE, + POISON, + PARALYSIS, + OTHER, // SLP, BRN, FRZ +}; +const char* status_name(StatusCondition status); + // The healing items in the Items pocket, in the order they were bought: -// Potions first, then Antidotes. +// Potions, Antidotes, then Parlyz Heals. struct Supplies{ int potions = 0; int antidotes = 0; + int parlyz_heals = 0; + // The starter's status at the last battle screen that showed it, and + // not cured since. + StatusCondition status = StatusCondition::NONE; // The starter's HP bar wasn't green (or was red) at the last battle // screen that showed it, and no Potion or nurse healed it since. bool hurt = false; @@ -43,7 +58,7 @@ struct Supplies{ enum class BattleKind{ WILD_RUN, // RUN, or fight after a few "Can't escape!" - WILD_FIGHT, // fight for EXP with green HP and 2 Potions, else RUN + WILD_FIGHT, // fight for EXP with green HP, no status and 2 Potions, else RUN TRAINER, }; @@ -54,11 +69,16 @@ enum class BattleEnd{ LOST, }; -// What the HP bar and the status of the player's Pokemon show. +// What the HP bar and the status badge of the player's Pokemon show, on a +// battle screen with its box. Colors measured on console B's captures +// (2026-11-01): the bar's fill green (100, 251, 171), yellow +// (255, 228, 23), red (255, 113, 68); the badge's place off-white +// (255, 255, 217) with no status, (228, 168, 212) for PSN. struct PartyStatus{ + bool hp_seen = false; bool hp_yellow = false; bool hp_red = false; - bool poisoned = false; + StatusCondition status = StatusCondition::NONE; }; PartyStatus read_party_status(const ImageViewRGB32& screen); @@ -69,9 +89,10 @@ PartyStatus read_party_status(const ImageViewRGB32& screen); BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind); -// From the overworld: a Potion from the top row of the Items pocket, on -// the starter. The bag's inputs are not checked on the console yet. -void use_potion_from_bag(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies); +// From the overworld, after a battle: an Antidote for PSN, a Parlyz Heal +// for PAR, then a Potion if the HP bar wasn't green, each if one is left. +// The bag's inputs are not checked on the console yet. +void recover_after_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies); // The interrupts for walking story routes. Wild battles are run from, or diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index f5af734e3e..2f2f9343be 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -138,24 +138,17 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ return Pokemon::outcome_ok(); } -// HP is the battle loop's last reading. One Potion (20 HP) takes a starter -// of the levels here (max HP about 30) from red to green, so one is used -// and the bar is taken to be green after it; it can't be read again on the -// overworld. +// HP and status are the battle loop's last reading. Items first (an +// Antidote, a Parlyz Heal, a Potion); the nurse only for red HP with no +// Potion left, or a status no item here cures. Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ Supplies& supplies = env.supplies; env.console.log(std::format( - "Story: before the battle, HP {}, {} Potions.", - supplies.hp_red ? "red" : supplies.hurt ? "yellow" : "green", supplies.potions + "Story: before the battle, HP {}, {}, {} Potions.", + supplies.hp_red ? "red" : supplies.hurt ? "yellow" : "green", status_name(supplies.status), supplies.potions )); - if (!supplies.hurt){ - return Pokemon::outcome_ok(); - } - if (supplies.potions > 0){ - use_potion_from_bag(env.console, env.context, supplies); - return Pokemon::outcome_ok(); - } - if (!supplies.hp_red){ + recover_after_battle(env.console, env.context, supplies); + if (!supplies.hp_red && supplies.status == StatusCondition::NONE){ return Pokemon::outcome_ok(); } Outcome walked = walk_route(env, state, step); @@ -165,14 +158,18 @@ Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ heal_at_center(env.console, env.context); supplies.hurt = false; supplies.hp_red = false; + supplies.status = StatusCondition::NONE; return walked; } Outcome shop(StoryEnv& env){ - // Viridian Mart before the Boulder Badge: POKE BALL, POTION, ANTIDOTE, PARLYZ HEAL. - buy_items(env.console, env.context, {{1, 4}, {2, 2}}); - env.supplies.potions += 4; - env.supplies.antidotes += 2; + // Viridian Mart before the Boulder Badge (pokefirered ViridianCity_Mart_Items): + // POKE BALL, POTION (300), ANTIDOTE (100), PARLYZ HEAL (200). 2000 of the + // 3000 a new game starts with, plus the rival's prize. + buy_items(env.console, env.context, {{1, 5}, {2, 3}, {3, 1}}); + env.supplies.potions += 5; + env.supplies.antidotes += 3; + env.supplies.parlyz_heals += 1; return Pokemon::outcome_ok(); } @@ -205,6 +202,7 @@ Outcome run_step(StoryEnv& env, RunState& state, const StoryStep& step, StartMen heal_at_center(env.console, env.context); env.supplies.hurt = false; env.supplies.hp_red = false; + env.supplies.status = StatusCondition::NONE; return Pokemon::outcome_ok(); case StoryStepKind::READY: return get_ready(env, state, step); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index bc7a70e409..dcb6084848 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -56,7 +56,7 @@ enum class StoryStepKind{ BATTLE, // text with B into a battle, fight it, text to the overworld HEAL, // facing the nurse SHOP, // facing the Viridian Mart clerk: Potions and Antidotes - READY, // before a big battle: a Potion if hurt, the nurse at `target` if red with none + READY, // before a big battle: items for status and HP, the nurse at `target` if they can't }; // A straight leg of a fixed walk. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 1b8d6f3d15..b8cbbce1e8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -158,7 +158,7 @@ StoryCheckpoint pokedex(){ StoryCheckpoint forest(){ return StoryCheckpoint{"00.07", "Viridian shopping to Pewter Center", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again"), - make(StoryStepKind::SHOP, "potions_and_antidotes", "4 Potions, 2 Antidotes"), + make(StoryStepKind::SHOP, "potions_and_antidotes", "5 Potions, 3 Antidotes, 1 Parlyz Heal"), route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest"), heal("heal_viridian"), route("below_old_man_trigger", at(VIRIDIAN, 20, 9, NORTH), "short of the tutorial trigger (20, 8)"), @@ -200,8 +200,8 @@ StoryCheckpoint brock(){ route("below_liam_line", at(GYM, 6, 9, NORTH), "in by the door, up column 6 to below Liam's row"), step_into("liam_line", NORTH, "onto (6, 8), in Liam's line"), battle("camper_liam", at(GYM, 6, 8, NORTH), false, "Geodude and Sandshrew; EXP before Brock"), - // On to Brock unless the starter's HP is red with no Potion left. - ready("ready_for_brock", at(PEWTER_CENTER, 7, 4, NORTH), "a Potion if hurt; the nurse only if red with none"), + // On to Brock unless red HP or a status is left that no item cures. + ready("ready_for_brock", at(PEWTER_CENTER, 7, 4, NORTH), "items for a status or low HP; the nurse only if they can't"), route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5); Liam, beaten, stands at (5, 8)"), talk("challenge_brock", "Brock's speech"), battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39"), From 77a183d52606d307dee1573b645428f66c8bb590 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 09:32:35 -0800 Subject: [PATCH 21/75] FRLG AutoStory: plan every checkpoint in CI on the compiled-in maps The route and chain tests planned on story_maps(), read from Packages, so CI skipped them; the gym test had its own trimmed copies of three Pewter maps. All of them now plan on test_overworld_maps() (#118) with the Hall of Fame flags story_maps() uses: one copy of each map, the generator's, checked against it by frlg_maps.py --check. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 211 ++---------------- 1 file changed, 16 insertions(+), 195 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 31ee37acbe..0d7ac005ad 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -12,6 +12,7 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMapsTestData.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "PokemonFRLG_AutoStoryTable.h" @@ -31,9 +32,6 @@ class Test_AutoStory : public UnitTest{ virtual UnitTestResult run(Logger&, CancellableScope&) const override{ try{ return m_body(); - }catch (FileException& e){ - // CI runs with upstream Packages, which may not have the maps yet. - return UnitTestResult(UnitTestResult::SKIPPED, "Map files not found: " + e.message()); }catch (Exception& e){ return std::string(e.name()) + ": " + e.message(); } @@ -43,8 +41,15 @@ class Test_AutoStory : public UnitTest{ std::function m_body; }; +// story_maps(), from the maps compiled into the program, so the routes +// are planned in CI, which has no map files. +const std::vector& test_story_maps(){ + static const std::vector maps = test_overworld_maps(map_flag_set(test_overworld_maps(), "after_hall_of_fame")); + return maps; +} + const MapData* find_map_named(const std::string& name){ - for (const MapData& map : story_maps()){ + for (const MapData& map : test_story_maps()){ if (map.name == name){ return ↦ } @@ -111,7 +116,7 @@ UnitTestResult check_held_legs(const std::string& name, const std::vector> route = fixed_route(story_maps(), MapPosition{pose.map, pose.tile}, step.legs); + const std::optional> route = fixed_route(test_story_maps(), MapPosition{pose.map, pose.tile}, step.legs); if (!route || route->empty()){ return step.name + ": the legs can't be walked from " + describe(pose) + "."; } @@ -137,11 +142,11 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step){ } } const RouteGoal goal{{step.target.map, step.target.tile}, step.target.facing}; - const std::optional> route = plan_overworld_route(story_maps(), start, goal, default_route_costs(), facing); + const std::optional> route = plan_overworld_route(test_story_maps(), start, goal, default_route_costs(), facing); if (!route){ return step.name + ": no route from " + to_string(start) + " to " + to_string(goal.position) + "."; } - const MapPosition end = follow_overworld_route(story_maps(), start, *route); + const MapPosition end = follow_overworld_route(test_story_maps(), start, *route); if (!(end == goal.position)){ return step.name + ": the route ends at " + to_string(end) + ":" + describe(*route); } @@ -216,204 +221,20 @@ UnitTestResult test_routes_and_chain(){ return true; } -// Pewter City, its Pokemon Center and its gym, from Packages' -// Resources/PokemonFRLG/Maps (generated by devtools/maps/frlg_maps.py), so -// 00.08's walks are planned in CI, which has no map files. -const char* const PEWTER_CITY_JSON = R"json({ -"name": "PewterCity", "width": 48, "height": 40, -"tiles": [ - "################################################", - "#######################....#####################", - "####........#################.........##########", - "####........#################.........##########", - "####........#############D######......##########", - "####........###########...............##########", - "#######.....#####C#####..#######........########", - "####JJJ..JJJJJJJ...#JJJJJJJJJJJJJJJJJ...########", - "####....................................########", - "####............................#####...########", - "######..........................#####...########", - "######..........................#D###...########", - "######..................................########", - "######...##.#######.##..................########", - "######...#############..................########", - "######...##.#######.##..................########", - "######...###..#D#...##....####..........########", - "######...............#....######........########", - "######...............#....##D###........########", - "######...............#.................#########", - "######################..........................", - "######..........................................", - "######.......#########..........................", - "######.......#########....##########............", - "######.......#########....##########....########", - "######.......####D####....###########...########", - "######....................#.........#...########", - "######....................#.........#...########", - "######..#####.............#.........#...########", - "######..#####.............#.........#...########", - "######..#D###.......#.....#JJJJ.JJJJ#...########", - "######..................................########", - "######..................................########", - "######..................................########", - "######..................................########", - "######..................................########", - "####################....########################", - "####################....########################", - "####################....########################", - "####################....########################" -], -"elevation": [ - "000000000000000000000000000000000000000000000000", - "000000000000000000000003333000000000000000000000", - "000033333333000000000000000003333333330000000000", - "000033333333000000000000000003333333330000000000", - "000033333333000000000000000000003333330000000000", - "000033333333000000000003333333333333330000000000", - "000000033333000003000003300000003333333300000000", - "000000033000000033300000000000000000033300000000", - "000033333333333333333333333333333333333300000000", - "000033333333333333333333333333330000033300000000", - "000000333333333333333333333333330000033300000000", - "000000333333333333333333333333330000033300000000", - "000000333333333333333333333333333333333300000000", - "000000333003000000030033333333333333333300000000", - "000000333000000000000033333333333333333300000000", - "000000333003000000030033333333333333333300000000", - "000000333000330003330033330000333333333300000000", - "000000333333333333333033330000003333333300000000", - "000000333333333333333033330000003333333300000000", - "000000333333333333333033333333333333333000000000", - "000000000000000000000033333333333333333333333333", - "000000333333333333333333333333333333333333333333", - "000000333333300000000033333333333333333333333333", - "000000333333300000000033330000000000333333333333", - "000000333333300000000033330000000000333300000000", - "000000333333300000000033330000000000033300000000", - "000000333333333333333333330333333333033300000000", - "000000333333333333333333330333333333033300000000", - "000000330000033333333333330333333333033300000000", - "000000330000033333333333330333333333033300000000", - "000000330000033333330333330000030000033300000000", - "000000333333333333333333333333333333333300000000", - "000000333333333333333333333333333333333300000000", - "000000333333333333333333333333333333333300000000", - "000000333333333333333333333333333333333300000000", - "000000333333333333333333333333333333333300000000", - "000000000000000000003333000000000000000000000000", - "000000000000000000003333000000000000000000000000", - "000000000000000000003333000000000000000000000000", - "000000000000000000003333000000000000000000000000" -], -"warps": [{"x": 17, "y": 6, "dest_map": "PewterCity_Museum_1F", "dest_warp": 1}, {"x": 25, "y": 4, "dest_map": "PewterCity_Museum_1F", "dest_warp": 3}, {"x": 15, "y": 16, "dest_map": "PewterCity_Gym", "dest_warp": 1}, {"x": 28, "y": 18, "dest_map": "PewterCity_Mart", "dest_warp": 1}, {"x": 33, "y": 11, "dest_map": "", "dest_warp": 1}, {"x": 17, "y": 25, "dest_map": "PewterCity_PokemonCenter_1F", "dest_warp": 1}, {"x": 9, "y": 30, "dest_map": "", "dest_warp": 1}], -"objects": [{"x": 6, "y": 15, "kind": "lass", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 33, "y": 17, "kind": "man", "flag": "FLAG_HIDE_PEWTER_MUSEUM_GUIDE", "wander_x": 0, "wander_y": 0}, {"x": 21, "y": 28, "kind": "fat_man", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 33, "y": 27, "kind": "bug_catcher", "flag": "", "wander_x": 2, "wander_y": 0}, {"x": 42, "y": 20, "kind": "boy", "flag": "FLAG_HIDE_PEWTER_CITY_GYM_GUIDE", "wander_x": 0, "wander_y": 0}, {"x": 30, "y": 5, "kind": "cut_tree", "flag": "FLAG_TEMP_12", "wander_x": 0, "wander_y": 0}, {"x": 46, "y": 20, "kind": "scientist", "flag": "FLAG_HIDE_PEWTER_CITY_RUNNING_SHOES_GUY", "wander_x": 0, "wander_y": 0}], -"connections": [{"direction": "south", "offset": 12, "map": "Route2"}], -"points": [{"name": "gym_front", "x": 15, "y": 17}], -"flag_sets": [] -})json"; - -const char* const PEWTER_GYM_JSON = R"json({ -"name": "PewterCity_Gym", "width": 13, "height": 16, -"tiles": [ - "#############", - "####.....####", - "#############", - "#....#.#....#", - "#...........#", - "#...#...#...#", - "#...........#", - "#..#.#.#.#..#", - "##.........##", - "#...#...#...#", - "##.........##", - "#...........#", - "#...#...#...#", - "#...........#", - "#.....v.....#", - "#############" -], -"elevation": [ - "0000000000000", - "0000333330000", - "0000000000000", - "0333303033330", - "0333333333330", - "0333033303330", - "0333333333330", - "0330303030330", - "0033333333300", - "0333033303330", - "0033333333300", - "0333333333330", - "0333033303330", - "0333333333330", - "0333333333330", - "0000000000000" -], -"warps": [{"x": 5, "y": 14, "dest_map": "PewterCity", "dest_warp": 2}, {"x": 6, "y": 14, "dest_map": "PewterCity", "dest_warp": 2}, {"x": 7, "y": 14, "dest_map": "PewterCity", "dest_warp": 2}], -"objects": [{"x": 6, "y": 5, "kind": "brock", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 3, "y": 8, "kind": "camper", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 7, "y": 12, "kind": "gym_guy", "flag": "", "wander_x": 0, "wander_y": 0}], -"connections": [], -"points": [{"name": "brock_front", "x": 6, "y": 6}], -"flag_sets": [] -})json"; - -const char* const PEWTER_CENTER_JSON = R"json({ -"name": "PewterCity_PokemonCenter_1F", "width": 15, "height": 10, -"tiles": [ - "#.#############", - "###############", - "....###..##....", - "....#######....", - "...............", - "...............", - "#L.........##..", - "...........##..", - ".......v.......", - "###############" -], -"elevation": [ - "030000000000000", - "000000000000000", - "333300033003333", - "333300000003333", - "333333333333333", - "330333333333333", - "044033333330033", - "330333333330033", - "333333333333333", - "000000000000000" -], -"warps": [{"x": 6, "y": 8, "dest_map": "PewterCity", "dest_warp": 5}, {"x": 7, "y": 8, "dest_map": "PewterCity", "dest_warp": 5}, {"x": 8, "y": 8, "dest_map": "PewterCity", "dest_warp": 5}, {"x": 1, "y": 6, "dest_map": "", "dest_warp": 0}], -"objects": [{"x": 2, "y": 2, "kind": "jigglypuff", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 4, "y": 8, "kind": "gentleman", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 7, "y": 2, "kind": "nurse", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 1, "y": 2, "kind": "youngster", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 13, "y": 2, "kind": "woman_1", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 10, "y": 7, "kind": "gba_kid", "flag": "", "wander_x": 0, "wander_y": 0}, {"x": 14, "y": 6, "kind": "gba_kid", "flag": "", "wander_x": 0, "wander_y": 0}], -"connections": [], -"points": [{"name": "nurse_front", "x": 7, "y": 4}], -"flag_sets": [] -})json"; - - -const std::vector& pewter_maps(){ - static const std::vector maps{ - parse_map(PEWTER_CITY_JSON, "PewterCity (test fixture)"), - parse_map(PEWTER_GYM_JSON, "PewterCity_Gym (test fixture)"), - parse_map(PEWTER_CENTER_JSON, "PewterCity_PokemonCenter_1F (test fixture)"), - }; - return maps; -} - struct ExpectedLeg{ Direction direction; int tiles; TilePos end; }; -// Plans `start` to `goal` on the Pewter maps and checks the walking legs +// Plans `start` to `goal` on the story maps and checks the walking legs // on `map`, except the step that warps onto it, against `expected`. UnitTestResult check_legs_on( const MapPosition& start, Direction start_facing, const RouteGoal& goal, const std::string& map, const std::vector& expected ){ const std::optional> route = plan_overworld_route( - pewter_maps(), start, goal, default_route_costs(), start_facing + test_story_maps(), start, goal, default_route_costs(), start_facing ); if (!route){ return "No route from " + to_string(start) + " to " + to_string(goal.position) + "."; @@ -446,7 +267,7 @@ UnitTestResult test_pewter_gym_walks(){ return result; } // The step onto (6, 8), into Liam's line. - const MapData& gym = pewter_maps()[1]; + const MapData& gym = *find_map_named("PewterCity_Gym"); if (classify_step(gym, PlayerState{{6, 9}, elevation_at(gym, {6, 9}), false}, Direction::NORTH) != StepKind::WALK){ return "Can't step north from (6, 9) onto (6, 8)."; } @@ -484,7 +305,7 @@ UnitTestResult test_unique_names(){ void add_tests_AutoStory(UnitTestDatabase& database){ database.add("every route plans, and checkpoints chain", test_routes_and_chain); database.add("step names are unique per checkpoint", test_unique_names); - database.add("Pewter Gym walks, on embedded maps", test_pewter_gym_walks); + database.add("Pewter Gym walks", test_pewter_gym_walks); } From 88d8ffdb62ae573ad9439a813a5e0c01ce1c75c8 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 09:53:08 -0800 Subject: [PATCH 22/75] FRLG AutoStory: let the walker recover stopped legs on story routes walk_overworld_route() now recovers a stopped open leg only when given a RoutePlanning (#119). Both story walks, planned routes and fixed legs, pass one on the story's maps, so a leg stopped part-way is planned back to its end and the rest walked as given, as in run 18. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 2f2f9343be..92c0484045 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -11,6 +11,7 @@ #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "Pokemon/Navigation/Pokemon_TilePose.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_AutoStoryEvents.h" @@ -93,7 +94,10 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ return Pokemon::outcome_failed("no_route", to_string(start) + " to " + to_string(goal.position)); } const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild); - walk_overworld_route(env.console, env.context, *route, facing, interrupts); + // Planning lets the walker recover a stopped open leg: it plans back to + // the leg's end, then walks the rest as given. + const RoutePlanning planning{&story_maps(), default_route_costs()}; + walk_overworld_route(env.console, env.context, *route, facing, interrupts, &planning); const std::optional end_facing = route->empty() ? facing : std::optional(route->back().facing_after); return Pokemon::outcome_ok(to_pose(StoryPose{step.target.map, step.target.tile, end_facing})); } @@ -113,7 +117,10 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ return Pokemon::outcome_failed("bad_legs", to_string(start)); } const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild); - walk_overworld_route(env.console, env.context, *route, facing, interrupts); + // Planning lets the walker recover a stopped open leg: it plans back to + // the leg's end, then walks the rest as given. + const RoutePlanning planning{&story_maps(), default_route_costs()}; + walk_overworld_route(env.console, env.context, *route, facing, interrupts, &planning); return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after})); } From bac9b9f9950bb020dad5c0666228ba41d7b480a4 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 09:56:10 -0800 Subject: [PATCH 23/75] FRLG AutoStory: the story table on the shared story steps The table's StoryStep, StoryStepKind and StoryLeg are now the shared ones (Pokemon/Navigation/Pokemon_StorySteps.h). FRLG's checkpoint adds its supplies and START menu to the shared StoryCheckpoint, and StoryExecutor does each kind on the console with the code run_step() had. The shop's items are in the table and mapped to Viridian Mart rows. Behaviour is unchanged; the route and chain tests read the table's poses back as one-tile StoryPoses, and a new test lints every checkpoint. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStory.cpp | 3 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 216 ++++++++++-------- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 113 ++++----- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 71 ++++-- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 32 ++- 5 files changed, 257 insertions(+), 178 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 56aab77af0..3517ea23c9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -87,7 +87,8 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex story.has_save = true; } - Pokemon::Segment segment = make_story_segment(checkpoints, story); + StoryExecutor executor(story); + Pokemon::Segment segment = make_story_segment(checkpoints, executor); Pokemon::SegmentHooks hooks; hooks.reload = [&story](Pokemon::RunState&){ if (!story.has_save){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 2f2f9343be..9b91cfdc43 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -20,6 +20,7 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ using namespace std::chrono_literals; +using Pokemon::facing_of; using Pokemon::Outcome; using Pokemon::RunState; @@ -43,11 +44,6 @@ Outcome guarded(Body&& body){ } } -std::optional facing_of(const Pokemon::Pose& pose){ - const Pokemon::TilePose* tile_pose = dynamic_cast(pose.where.get()); - return tile_pose ? tile_pose->facing : std::nullopt; -} - const MapData* find_story_map(const std::string& name){ for (const MapData& map : story_maps()){ if (map.name == name){ @@ -85,7 +81,11 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ if (!facing){ return Pokemon::outcome_failed("unknown_facing", to_string(start)); } - const RouteGoal goal{{step.target.map, step.target.tile}, step.target.facing}; + const std::optional target = step.target ? story_pose(*step.target) : std::nullopt; + if (!target){ + return Pokemon::outcome_failed("bad_target", step.target ? Pokemon::to_string(*step.target) : "none"); + } + const RouteGoal goal{{target->map, target->tile}, target->facing}; const std::optional> route = plan_overworld_route( story_maps(), start, goal, default_route_costs(), facing ); @@ -95,7 +95,7 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild); walk_overworld_route(env.console, env.context, *route, facing, interrupts); const std::optional end_facing = route->empty() ? facing : std::optional(route->back().facing_after); - return Pokemon::outcome_ok(to_pose(StoryPose{step.target.map, step.target.tile, end_facing})); + return Pokemon::outcome_ok(to_pose(StoryPose{target->map, target->tile, end_facing})); } Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ @@ -162,78 +162,41 @@ Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ return walked; } -Outcome shop(StoryEnv& env){ - // Viridian Mart before the Boulder Badge (pokefirered ViridianCity_Mart_Items): - // POKE BALL, POTION (300), ANTIDOTE (100), PARLYZ HEAL (200). 2000 of the - // 3000 a new game starts with, plus the rival's prize. - buy_items(env.console, env.context, {{1, 5}, {2, 3}, {3, 1}}); - env.supplies.potions += 5; - env.supplies.antidotes += 3; - env.supplies.parlyz_heals += 1; - return Pokemon::outcome_ok(); -} +// Viridian Mart before the Boulder Badge (pokefirered ViridianCity_Mart_Items): +// POKE BALL, POTION (300), ANTIDOTE (100), PARLYZ HEAL (200). Each item +// the story buys: its row, and where the bag's count is kept. +struct MartItem{ + const char* item; + int row; + int Supplies::* count; +}; +constexpr MartItem VIRIDIAN_MART_ITEMS[] = { + {.item = "potion", .row = 1, .count = &Supplies::potions}, + {.item = "antidote", .row = 2, .count = &Supplies::antidotes}, + {.item = "parlyz_heal", .row = 3, .count = &Supplies::parlyz_heals}, +}; -Outcome run_step(StoryEnv& env, RunState& state, const StoryStep& step, StartMenu menu){ - switch (step.kind){ - case StoryStepKind::NEW_GAME: - play_new_game_intro(env.console, env.context); - return Pokemon::outcome_ok(); - case StoryStepKind::SET_OPTIONS: - set_options(env.console, env.context, menu); - return Pokemon::outcome_ok(); - case StoryStepKind::ROUTE: - return walk_route(env, state, step); - case StoryStepKind::LEGS: - return walk_legs(env, state, step); - case StoryStepKind::STEP: - return take_step(env, state, step); - case StoryStepKind::TALK: - pbf_press_button(env.context, BUTTON_A, 160ms, 800ms); - return Pokemon::outcome_ok(); - case StoryStepKind::ANSWER: - answer_yes_no(env.console, env.context, step.yes, BUTTON_B, YES_NO_TIMEOUT); - return Pokemon::outcome_ok(); - case StoryStepKind::MASH: - mash_until_overworld(env.console, env.context, SCENE_TIMEOUT); - return Pokemon::outcome_ok(); - case StoryStepKind::BATTLE: - return battle(env, step); - case StoryStepKind::HEAL: - heal_at_center(env.console, env.context); - env.supplies.hurt = false; - env.supplies.hp_red = false; - env.supplies.status = StatusCondition::NONE; - return Pokemon::outcome_ok(); - case StoryStepKind::READY: - return get_ready(env, state, step); - case StoryStepKind::SHOP: - return shop(env); +Outcome shop(StoryEnv& env, const StoryStep& step){ + std::vector orders; + std::vector counts; + for (const Pokemon::StoryItem& wanted : step.items){ + const MartItem* found = nullptr; + for (const MartItem& item : VIRIDIAN_MART_ITEMS){ + if (wanted.item == item.item){ + found = &item; + } + } + if (found == nullptr){ + return Pokemon::outcome_failed("unknown_item", wanted.item); + } + orders.push_back(MartOrder{found->row, (int)wanted.quantity}); + counts.push_back(found->count); } - return Pokemon::outcome_failed("unknown_step"); -} - -Pokemon::Event make_event(const StoryStep& step, StoryEnv& env, StartMenu menu){ - Pokemon::Event event; - event.name = step.name; - event.why = step.why; - event.act = [&env, &step, menu](RunState& state){ - return guarded([&]{ return run_step(env, state, step, menu); }); - }; - if (step.pose_after){ - event.pose_learned = to_pose(*step.pose_after); + buy_items(env.console, env.context, orders); + for (size_t c = 0; c < orders.size(); c++){ + env.supplies.*counts[c] += orders[c].quantity; } - return event; -} - -// The first event of a checkpoint that starts from a save: where the save -// leaves the player, for a run that reloaded it. -Pokemon::Event from_save_event(const StoryPose& start){ - Pokemon::Event event; - event.name = "from_save"; - event.why = "where the checkpoint's save leaves the player"; - event.act = [](RunState&){ return Pokemon::outcome_ok(); }; - event.pose_learned = to_pose(start); - return event; + return Pokemon::outcome_ok(); } } @@ -245,11 +208,15 @@ const std::vector& story_maps(){ } Pokemon::Pose to_pose(const StoryPose& pose){ - Pokemon::Pose ret; - ret.map = pose.map; - ret.certainty = Pokemon::PoseCertainty::TILE; - ret.where = std::make_shared(std::vector{pose.tile}, pose.facing); - return ret; + return Pokemon::tile_pose(pose.map, {pose.tile}, pose.facing); +} + +std::optional story_pose(const Pokemon::Pose& pose){ + const std::vector tiles = Pokemon::tiles_of(pose); + if (tiles.size() != 1){ + return std::nullopt; + } + return StoryPose{pose.map, tiles[0], facing_of(pose)}; } std::optional> fixed_route( @@ -297,15 +264,80 @@ std::optional wall_beside(const MapData& map, const TilePos& tile){ return std::nullopt; } -Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryEnv& env){ - Pokemon::Checkpoint checkpoint; - checkpoint.id = data.id; - if (data.start){ - checkpoint.events.push_back(from_save_event(*data.start)); - } - for (const StoryStep& step : data.steps){ - checkpoint.events.push_back(make_event(step, env, data.menu)); - } +StoryExecutor::StoryExecutor(StoryEnv& env) + : m_env(env) +{} + +Outcome StoryExecutor::run(RunState& state, const StoryStep& step){ + return guarded([&]{ return Pokemon::StoryStepExecutor::run(state, step); }); +} + +bool StoryExecutor::holds(const std::string&, RunState&){ + return false; +} + +Outcome StoryExecutor::new_game(RunState&, const StoryStep&){ + play_new_game_intro(m_env.console, m_env.context); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::options(RunState&, const StoryStep&){ + set_options(m_env.console, m_env.context, m_menu); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::route(RunState& state, const StoryStep& step){ + return walk_route(m_env, state, step); +} + +Outcome StoryExecutor::legs(RunState& state, const StoryStep& step){ + return walk_legs(m_env, state, step); +} + +Outcome StoryExecutor::step(RunState& state, const StoryStep& step){ + return take_step(m_env, state, step); +} + +Outcome StoryExecutor::talk(RunState&, const StoryStep&){ + pbf_press_button(m_env.context, BUTTON_A, 160ms, 800ms); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::answer(RunState&, const StoryStep& step){ + answer_yes_no(m_env.console, m_env.context, step.yes, BUTTON_B, YES_NO_TIMEOUT); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::mash(RunState&, const StoryStep&){ + mash_until_overworld(m_env.console, m_env.context, SCENE_TIMEOUT); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::battle(RunState&, const StoryStep& step){ + return PokemonFRLG::battle(m_env, step); +} + +Outcome StoryExecutor::heal(RunState&, const StoryStep&){ + heal_at_center(m_env.console, m_env.context); + m_env.supplies.hurt = false; + m_env.supplies.hp_red = false; + m_env.supplies.status = StatusCondition::NONE; + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::shop(RunState&, const StoryStep& step){ + return PokemonFRLG::shop(m_env, step); +} + +Outcome StoryExecutor::ready(RunState& state, const StoryStep& step){ + return get_ready(m_env, state, step); +} + + +Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& executor){ + executor.set_menu(data.menu); + Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); + StoryEnv& env = executor.env(); const StartMenu menu = data.menu; checkpoint.save = [&env, menu](RunState&){ return guarded([&]{ @@ -318,13 +350,13 @@ Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryEnv& env) return checkpoint; } -Pokemon::Segment make_story_segment(const std::vector& checkpoints, StoryEnv& env){ +Pokemon::Segment make_story_segment(const std::vector& checkpoints, StoryExecutor& executor){ Pokemon::Segment segment; segment.id = "00"; for (const StoryCheckpoint& data : checkpoints){ segment.checkpoints.push_back(Pokemon::CheckpointSpec{ data.id, data.title, false, - [&data, &env]{ return build_checkpoint(data, env); } + [&data, &executor]{ return build_checkpoint(data, executor); } }); } return segment; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index dcb6084848..7f8bccfa60 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -4,12 +4,13 @@ * * The FRLG story as data for the shared story engine * (Pokemon/Navigation/Pokemon_StoryEvents.h, Pokemon_StorySegments.h). - * A checkpoint is a list of StorySteps, each one kind of FRLG event (a + * A checkpoint is a list of the shared StorySteps + * (Pokemon/Navigation/Pokemon_StorySteps.h), each one kind of event (a * route, a talk, text read to its end, a YES/NO, a battle, the nurse, the - * Mart); make_story_segment() turns the table into engine checkpoints whose - * events run them on the console. Routes plan from the pose the run - * carries and return where they leave the player; scenes that move the - * player say where in the table. + * Mart); StoryExecutor does each kind on the console, and + * make_story_segment() turns the table into engine checkpoints. Routes + * plan from the pose the run carries and return where they leave the + * player; scenes that move the player say where in the table. * * The table itself is in PokemonFRLG_AutoStoryTable.h; it is plain data, * so its routes are planned in unit tests without a console. @@ -26,6 +27,7 @@ #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "Pokemon/Navigation/Pokemon_StoryEvents.h" #include "Pokemon/Navigation/Pokemon_StorySegments.h" +#include "Pokemon/Navigation/Pokemon_StorySteps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "PokemonFRLG_AutoStoryActions.h" @@ -36,65 +38,25 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Where the player stands and faces. An unknown facing (after a scene that -// turns the player) is set before the next route by turning to a wall. +using Pokemon::StoryLeg; +using Pokemon::StoryStep; +using Pokemon::StoryStepKind; + +// Where the player stands and faces: the one-tile poses of FRLG's table +// and routes. An unknown facing (after a scene that turns the player) is +// set before the next route by turning to a wall. struct StoryPose{ std::string map; TilePos tile; std::optional facing; }; -enum class StoryStepKind{ - NEW_GAME, // title screen (no save) to the bedroom - SET_OPTIONS, // text speed FAST, battle style SET - ROUTE, // plan and walk to `target` - LEGS, // walk `legs` as given, on one map - STEP, // one step `direction`: onto a trigger, into a door - TALK, // A at what the player faces - ANSWER, // text with B to a YES/NO, then `yes` - MASH, // text with B until the overworld is back - BATTLE, // text with B into a battle, fight it, text to the overworld - HEAL, // facing the nurse - SHOP, // facing the Viridian Mart clerk: Potions and Antidotes - READY, // before a big battle: items for status and HP, the nurse at `target` if they can't -}; - -// A straight leg of a fixed walk. -struct StoryLeg{ - Direction direction = Direction::NORTH; - int tiles = 0; -}; - -struct StoryStep{ - StoryStepKind kind = StoryStepKind::TALK; - std::string name; - std::string why; - // ROUTE: the goal, and the way to face there if set. READY: the nurse. - StoryPose target; - // STEP - Direction direction = Direction::NORTH; - // LEGS - std::vector legs; - // ROUTE, LEGS: fight wild battles for EXP instead of running. - bool fight_wild = false; - // ANSWER - bool yes = true; - // BATTLE: the starter may faint without a blackout (the lab's rival). - bool may_lose = false; - // Where a scene leaves the player. - std::optional pose_after; -}; - -struct StoryCheckpoint{ - std::string id; - std::string title; - // Where its starting save leaves the player; none for the new game. - std::optional start; +// A shared checkpoint with what FRLG adds to it. +struct StoryCheckpoint : public Pokemon::StoryCheckpoint{ // The healing items at its start, for a run that loads its save. Supplies supplies; // The START menu at its end, when it saves. StartMenu menu = StartMenu::FULL; - std::vector steps; }; @@ -103,6 +65,8 @@ struct StoryCheckpoint{ const std::vector& story_maps(); Pokemon::Pose to_pose(const StoryPose& pose); +// `pose` as a StoryPose: nothing unless it is on one tile. +std::optional story_pose(const Pokemon::Pose& pose); // `legs` from `start` as route steps for the walker, each checked against // the map: nothing if a step is blocked or leaves the map. A leg ends "to @@ -128,11 +92,48 @@ struct StoryEnv{ bool has_save = false; }; +// Does FRLG's kinds of story step on the console. A console step that +// fails is a failed Outcome, which the segment answers by reloading. +class StoryExecutor : public Pokemon::StoryStepExecutor{ +public: + explicit StoryExecutor(StoryEnv& env); + + StoryEnv& env(){ + return m_env; + } + // The START menu SET_OPTIONS leaves: the checkpoint's being built. + void set_menu(StartMenu menu){ + m_menu = menu; + } + + virtual Pokemon::Outcome run(Pokemon::RunState& state, const StoryStep& step) override; + // FRLG's table skips nothing. + virtual bool holds(const std::string& condition, Pokemon::RunState& state) override; + + virtual Pokemon::Outcome new_game(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome options(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome route(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome legs(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome step(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome talk(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome answer(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome mash(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome battle(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome heal(Pokemon::RunState& state, const StoryStep& step) override; + // The Viridian Mart, before the Boulder Badge: Potions, Antidotes and Parlyz Heals. + virtual Pokemon::Outcome shop(Pokemon::RunState& state, const StoryStep& step) override; + virtual Pokemon::Outcome ready(Pokemon::RunState& state, const StoryStep& step) override; + +private: + StoryEnv& m_env; + StartMenu m_menu = StartMenu::FULL; +}; + // The checkpoint `data` as events, saving at its end. -Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryEnv& env); +Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& executor); // `checkpoints` (kept alive by the caller) as a segment for run_segment(). -Pokemon::Segment make_story_segment(const std::vector& checkpoints, StoryEnv& env); +Pokemon::Segment make_story_segment(const std::vector& checkpoints, StoryExecutor& executor); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index b8cbbce1e8..72427a3772 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -29,8 +29,22 @@ const char* const FOREST_GATE = "Route2_ViridianForest_NorthEntrance"; const char* const PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; const char* const GYM = "PewterCity_Gym"; -StoryPose at(const char* map, int x, int y, std::optional facing = std::nullopt){ - return StoryPose{map, {x, y}, facing}; +Pokemon::Pose at(const char* map, int x, int y, std::optional facing = std::nullopt){ + return to_pose(StoryPose{map, {x, y}, facing}); +} + +StoryCheckpoint row( + std::string id, std::string title, std::optional start, + Supplies supplies, StartMenu menu, std::vector steps +){ + StoryCheckpoint checkpoint; + checkpoint.id = std::move(id); + checkpoint.title = std::move(title); + checkpoint.start = std::move(start); + checkpoint.steps = std::move(steps); + checkpoint.supplies = supplies; + checkpoint.menu = menu; + return checkpoint; } StoryStep make(StoryStepKind kind, std::string name, std::string why){ @@ -41,7 +55,7 @@ StoryStep make(StoryStepKind kind, std::string name, std::string why){ return step; } -StoryStep route(std::string name, StoryPose target, std::string why, bool fight_wild = false){ +StoryStep route(std::string name, Pokemon::Pose target, std::string why, bool fight_wild = false){ StoryStep step = make(StoryStepKind::ROUTE, std::move(name), std::move(why)); step.target = std::move(target); step.fight_wild = fight_wild; @@ -60,13 +74,13 @@ StoryStep answer(std::string name, bool yes, std::string why){ return step; } -StoryStep scene(std::string name, std::optional pose_after, std::string why){ +StoryStep scene(std::string name, std::optional pose_after, std::string why){ StoryStep step = make(StoryStepKind::MASH, std::move(name), std::move(why)); step.pose_after = std::move(pose_after); return step; } -StoryStep battle(std::string name, StoryPose pose_after, bool may_lose, std::string why){ +StoryStep battle(std::string name, Pokemon::Pose pose_after, bool may_lose, std::string why){ StoryStep step = make(StoryStepKind::BATTLE, std::move(name), std::move(why)); step.pose_after = std::move(pose_after); step.may_lose = may_lose; @@ -80,7 +94,7 @@ StoryStep legs(std::string name, std::vector legs, std::string why, bo return step; } -StoryStep new_game_intro(StoryPose pose_after, std::string why){ +StoryStep new_game_intro(Pokemon::Pose pose_after, std::string why){ StoryStep step = make(StoryStepKind::NEW_GAME, "intro", std::move(why)); step.pose_after = std::move(pose_after); return step; @@ -90,7 +104,7 @@ StoryStep talk(std::string name, std::string why){ return make(StoryStepKind::TALK, std::move(name), std::move(why)); } -StoryStep ready(std::string name, StoryPose nurse, std::string why){ +StoryStep ready(std::string name, Pokemon::Pose nurse, std::string why){ StoryStep step = make(StoryStepKind::READY, std::move(name), std::move(why)); step.target = std::move(nurse); return step; @@ -100,32 +114,38 @@ StoryStep heal(std::string name){ return make(StoryStepKind::HEAL, std::move(name), "full HP"); } +StoryStep shop(std::string name, std::vector items, std::string why){ + StoryStep step = make(StoryStepKind::SHOP, std::move(name), std::move(why)); + step.items = std::move(items); + return step; +} + StoryCheckpoint new_game(){ - return StoryCheckpoint{"00.01", "new game to the bedroom", std::nullopt, {}, StartMenu::BEFORE_POKEMON, { + return row("00.01", "new game to the bedroom", std::nullopt, {}, StartMenu::BEFORE_POKEMON, { // new_game.c: the bedroom at (6, 6), facing the TV. new_game_intro(at(BEDROOM, 6, 6, NORTH), "Oak's speech, BOY, default names, rival GREEN"), - make(StoryStepKind::SET_OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon"), - }}; + make(StoryStepKind::OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon"), + }); } StoryCheckpoint leave_house(){ - return StoryCheckpoint{"00.02", "bedroom to Pallet Town", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, { + return row("00.02", "bedroom to Pallet Town", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, { route("front_door", at(PALLET, 6, 8), "down the stairs and out of the house"), - }}; + }); } StoryCheckpoint oaks_trigger(){ - return StoryCheckpoint{"00.03", "Oak stops the player and walks them to the lab", at(PALLET, 6, 8, SOUTH), {}, StartMenu::BEFORE_POKEMON, { + return row("00.03", "Oak stops the player and walks them to the lab", at(PALLET, 6, 8, SOUTH), {}, StartMenu::BEFORE_POKEMON, { route("below_oaks_trigger", at(PALLET, 12, 2, NORTH), "below the north exit, short of Oak's trigger at (12, 1)"), step_into("oaks_trigger", NORTH, "the trigger: \"Don't go out!\""), // PlayerEnter walks the player up 8 tiles from the lab's door. scene("to_the_lab", at(LAB, 6, 4, NORTH), "Oak walks the player into the lab; the scene ends at the table"), - }}; + }); } StoryCheckpoint starter(){ - return StoryCheckpoint{"00.04", "Squirtle, then the rival's battle", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEDEX, { + return row("00.04", "Squirtle, then the rival's battle", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEDEX, { route("below_squirtle", at(LAB, 9, 5, NORTH), "under Squirtle's ball (9, 4)"), talk("squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\""), answer("choose_squirtle", true, "take Squirtle"), @@ -135,30 +155,31 @@ StoryCheckpoint starter(){ step_into("rival_trigger", SOUTH, "\"Wait, let's check out our POKEMON!\""), // The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down. battle("rival_battle", at(LAB, 7, 8, SOUTH), true, "the tutorial battle; losing goes on too"), - }}; + }); } StoryCheckpoint parcel(){ - return StoryCheckpoint{"00.05", "Route 1 to Viridian Mart: Oak's Parcel", at(LAB, 7, 8, SOUTH), {}, StartMenu::BEFORE_POKEDEX, { + return row("00.05", "Route 1 to Viridian Mart: Oak's Parcel", at(LAB, 7, 8, SOUTH), {}, StartMenu::BEFORE_POKEDEX, { route("below_mart_door", at(VIRIDIAN, 36, 20, NORTH), "Route 1, running from wild battles"), step_into("mart_door", NORTH, "the clerk's scene starts on entering"), // ApproachCounter: up 4 from the mat, then faces the clerk. scene("parcel_from_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "the clerk gives OAK'S PARCEL"), - }}; + }); } StoryCheckpoint pokedex(){ - return StoryCheckpoint{"00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, { + return row("00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, { route("below_oak", at(LAB, 6, 4, NORTH), "back down Route 1 to Oak"), talk("give_parcel", "Oak takes the parcel"), scene("pokedex_scene", at(LAB, 6, 4, SOUTH), "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)"), - }}; + }); } StoryCheckpoint forest(){ - return StoryCheckpoint{"00.07", "Viridian shopping to Pewter Center", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { + return row("00.07", "Viridian shopping to Pewter Center", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again"), - make(StoryStepKind::SHOP, "potions_and_antidotes", "5 Potions, 3 Antidotes, 1 Parlyz Heal"), + // 2000 of the 3000 a new game starts with, plus the rival's prize. + shop("potions_and_antidotes", {{"potion", 5}, {"antidote", 3}, {"parlyz_heal", 1}}, "5 Potions, 3 Antidotes, 1 Parlyz Heal"), route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest"), heal("heal_viridian"), route("below_old_man_trigger", at(VIRIDIAN, 20, 9, NORTH), "short of the tutorial trigger (20, 8)"), @@ -186,12 +207,12 @@ StoryCheckpoint forest(){ // Out of the forest, wild battles are run from; trainers are still fought. route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center"), heal("heal_pewter"), - }}; + }); } StoryCheckpoint brock(){ // The by-hand save: 2 Potions and 1 Antidote left after the forest. - return StoryCheckpoint{"00.08", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { + return row("00.08", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight // 4) and sees (4..7, 8): walking north up column 6 from the door, // the step onto (6, 8) starts his battle. He walks up to the player, @@ -205,7 +226,7 @@ StoryCheckpoint brock(){ route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5); Liam, beaten, stands at (5, 8)"), talk("challenge_brock", "Brock's speech"), battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39"), - }}; + }); } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 0d7ac005ad..e517a2fc31 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -70,6 +70,15 @@ std::string describe(const StoryPose& pose){ + (pose.facing ? std::string(" facing ") + direction_name(*pose.facing) : ""); } +// A table pose as a StoryPose; FRLG's table has one-tile poses only. +StoryPose one_tile(const Pokemon::Pose& pose){ + const std::optional ret = story_pose(pose); + if (!ret){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Not a one-tile pose: " + Pokemon::to_string(pose)); + } + return *ret; +} + Direction reverse(Direction direction){ switch (direction){ case Direction::NORTH: @@ -141,7 +150,11 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step){ return step.name + ": the facing is unknown at " + describe(pose) + " and no wall is beside it."; } } - const RouteGoal goal{{step.target.map, step.target.tile}, step.target.facing}; + if (!step.target){ + return step.name + ": no target."; + } + const StoryPose target = one_tile(*step.target); + const RouteGoal goal{{target.map, target.tile}, target.facing}; const std::optional> route = plan_overworld_route(test_story_maps(), start, goal, default_route_costs(), facing); if (!route){ return step.name + ": no route from " + to_string(start) + " to " + to_string(goal.position) + "."; @@ -166,7 +179,7 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step){ } } } - pose = StoryPose{step.target.map, step.target.tile, route->empty() ? facing : route->back().facing_after}; + pose = StoryPose{target.map, target.tile, route->empty() ? facing : route->back().facing_after}; return true; } @@ -191,7 +204,7 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po pose = StoryPose{pose.map, pose.tile.next(step.direction), step.direction}; } if (step.pose_after){ - pose = *step.pose_after; + pose = one_tile(*step.pose_after); } } return true; @@ -206,7 +219,7 @@ UnitTestResult test_routes_and_chain(){ for (size_t c = 0; c < checkpoints.size(); c++){ const StoryCheckpoint& checkpoint = checkpoints[c]; if (c > 0){ - const StoryPose& start = *checkpoint.start; + const StoryPose start = one_tile(*checkpoint.start); const bool same_facing = !start.facing || start.facing == pose.facing; if (start.map != pose.map || !(start.tile == pose.tile) || !same_facing){ return checkpoint.id + " starts at " + describe(start) + ", but " + checkpoints[c - 1].id + " ends at " + describe(pose) + "."; @@ -286,6 +299,16 @@ UnitTestResult test_pewter_gym_walks(){ ); } +UnitTestResult test_lint(){ + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + const std::vector problems = Pokemon::lint_story_checkpoint(checkpoint); + if (!problems.empty()){ + return problems[0]; + } + } + return true; +} + UnitTestResult test_unique_names(){ for (const StoryCheckpoint& checkpoint : story_checkpoints()){ for (size_t i = 0; i < checkpoint.steps.size(); i++){ @@ -305,6 +328,7 @@ UnitTestResult test_unique_names(){ void add_tests_AutoStory(UnitTestDatabase& database){ database.add("every route plans, and checkpoints chain", test_routes_and_chain); database.add("step names are unique per checkpoint", test_unique_names); + database.add("every checkpoint lints clean", test_lint); database.add("Pewter Gym walks", test_pewter_gym_walks); } From ebe8087468d9bb9074fee52c8561098def0cb9c8 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 10:01:40 -0800 Subject: [PATCH 24/75] FRLG AutoStory: the shared retry options instead of its own attempts ATTEMPTS_PER_CHECKPOINT (default 2) is replaced by the shared StoryRunOptions group: attempts per checkpoint (default 3) and stop at the first failure, read into the segment's policy. The executor's own holds() goes: the table skips nothing, and the shared default reads run flags. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStory.cpp | 10 ++-------- .../Programs/AutoStory/PokemonFRLG_AutoStory.h | 5 +++-- .../Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 4 ---- .../Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h | 2 -- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 3517ea23c9..fe4bec28ba 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -51,11 +51,6 @@ AutoStory::AutoStory() LockMode::LOCK_WHILE_RUNNING, true ) - , ATTEMPTS_PER_CHECKPOINT( - "Attempts per checkpoint:
A failed checkpoint reloads its save and runs again, up to this many times in all.", - LockMode::LOCK_WHILE_RUNNING, - 1, 5, 2, 2 - ) , NOTIFICATIONS({ &NOTIFICATION_PROGRAM_FINISH, &NOTIFICATION_ERROR_FATAL, @@ -64,7 +59,7 @@ AutoStory::AutoStory() PA_ADD_OPTION(START_CHECKPOINT); PA_ADD_OPTION(END_CHECKPOINT); PA_ADD_OPTION(NEW_GAME_FROM_TITLE); - PA_ADD_OPTION(ATTEMPTS_PER_CHECKPOINT); + PA_ADD_OPTION(RETRIES); PA_ADD_OPTION(NOTIFICATIONS); } @@ -105,8 +100,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex hooks.log = [&env](const std::string& line){ env.console.log(line); }; - Pokemon::SegmentPolicy policy; - policy.attempts_per_checkpoint = ATTEMPTS_PER_CHECKPOINT; + const Pokemon::SegmentPolicy policy = RETRIES.policy(); Pokemon::RunState state; const Pokemon::SegmentReport report = run_segment( diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h index a71a842818..2e67904a80 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h @@ -5,7 +5,7 @@ * Plays FireRed from a new game to the Boulder Badge, as the story * checkpoints of PokemonFRLG_AutoStoryTable.h run by the shared story * engine. Each checkpoint saves at its end; one that fails is retried from - * that save. + * that save, as the shared retry options say. * */ @@ -16,6 +16,7 @@ #include "Common/Cpp/Options/SimpleIntegerOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "Pokemon/Options/Pokemon_StoryRunOptions.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -41,7 +42,7 @@ class AutoStory : public SingleSwitchProgramInstance{ SimpleIntegerOption START_CHECKPOINT; SimpleIntegerOption END_CHECKPOINT; BooleanCheckBoxOption NEW_GAME_FROM_TITLE; - SimpleIntegerOption ATTEMPTS_PER_CHECKPOINT; + Pokemon::StoryRunOptions RETRIES; EventNotificationsOption NOTIFICATIONS; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 9b91cfdc43..7c25700099 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -272,10 +272,6 @@ Outcome StoryExecutor::run(RunState& state, const StoryStep& step){ return guarded([&]{ return Pokemon::StoryStepExecutor::run(state, step); }); } -bool StoryExecutor::holds(const std::string&, RunState&){ - return false; -} - Outcome StoryExecutor::new_game(RunState&, const StoryStep&){ play_new_game_intro(m_env.console, m_env.context); return Pokemon::outcome_ok(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 7f8bccfa60..ca3424506d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -107,8 +107,6 @@ class StoryExecutor : public Pokemon::StoryStepExecutor{ } virtual Pokemon::Outcome run(Pokemon::RunState& state, const StoryStep& step) override; - // FRLG's table skips nothing. - virtual bool holds(const std::string& condition, Pokemon::RunState& state) override; virtual Pokemon::Outcome new_game(Pokemon::RunState& state, const StoryStep& step) override; virtual Pokemon::Outcome options(Pokemon::RunState& state, const StoryStep& step) override; From d48c063f92fa6b80090ff8b3a51efb729d7995dc Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 10:18:57 -0800 Subject: [PATCH 25/75] FRLG AutoStory: run the story table end to end against a fake game Test_AutoStorySimulation builds story_checkpoints() into a segment with the shared builder, saving at each end as the program does, and runs it with the shared runner and retry policy against a fake game that plans each route and fixed walk on the story maps (turning to a wall when the facing is unknown), steps onto triggers and passes the rest. It checks: new game to Brock in order, each checkpoint starting where the save before it stood; a start/end range; a failed walk in 00.07 reloading its save and passing on attempt 2; Brock lost every time stopping after 3 attempts. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 1 + .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 324 ++++++++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryTable.h | 2 + SerialPrograms/cmake/SourceFiles.cmake | 1 + 4 files changed, 328 insertions(+) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 87e3252324..40c4df68f7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -298,6 +298,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_OverworldRecovery(database); add_tests_PlayerFacingReader(database); add_tests_AutoStory(database); + add_tests_AutoStorySimulation(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp new file mode 100644 index 0000000000..3a1664ed39 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -0,0 +1,324 @@ +/* AutoStory Simulation Tests + * + * From: https://github.com/PokemonAutomation/ + * + * A run of the whole story table, new game to the Boulder Badge, without + * the console: story_checkpoints() built into engine checkpoints by the + * shared builder, saving at each end as the program does, run by the + * shared runner with the program's retry policy, against a fake game. + * The fake plans each ROUTE on the story maps from where the run's pose + * says we stand (turning to a wall when the facing is unknown, as the + * program does), walks each LEGS on them, steps onto triggers, and passes + * every other step unless told to fail it. + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/Navigation/Pokemon_StorySegments.h" +#include "Pokemon/Navigation/Pokemon_StorySteps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +using Pokemon::Outcome; +using Pokemon::RunState; + +std::string joined(const std::vector& lines){ + std::string text; + for (const std::string& line : lines){ + text += "\n " + line; + } + return text; +} + +const MapData* map_named(const std::string& name){ + for (const MapData& map : story_maps()){ + if (map.name == name){ + return ↦ + } + } + return nullptr; +} + +// Where the run stands, with a facing: a wall beside it when unknown. +struct Standing{ + MapPosition position; + Direction facing = Direction::NORTH; + std::string error; +}; +Standing standing(const Pokemon::Pose& pose){ + const std::optional at = story_pose(pose); + if (!at){ + return {{}, Direction::NORTH, "no one-tile pose: " + Pokemon::to_string(pose)}; + } + std::optional facing = at->facing; + if (!facing){ + const MapData* map = map_named(at->map); + facing = map ? wall_beside(*map, at->tile) : std::nullopt; + } + if (!facing){ + return {{}, Direction::NORTH, "facing unknown and no wall beside " + to_string(MapPosition{at->map, at->tile})}; + } + return {{at->map, at->tile}, *facing, ""}; +} + +class FakeGame : public Pokemon::StoryStepExecutor{ +public: + struct Failure{ + std::string failure; + size_t times = 0; + }; + + std::vector trace; + std::map failures; + + virtual void begin_attempt(const Pokemon::StoryCheckpoint& data) override{ + m_row = data.id; + trace.push_back("begin " + data.id); + } + virtual Outcome run(RunState& state, const StoryStep& step) override{ + const std::string key = m_row + "/" + step.name; + trace.push_back(key); + auto failure = failures.find(key); + if (failure != failures.end() && failure->second.times > 0){ + failure->second.times--; + return Pokemon::outcome_failed(failure->second.failure, key); + } + return Pokemon::StoryStepExecutor::run(state, step); + } + virtual Outcome route(RunState& state, const StoryStep& step) override{ + return walk_to(state.pose, step); + } + virtual Outcome legs(RunState& state, const StoryStep& step) override{ + const Standing at = standing(state.pose); + if (!at.error.empty()){ + return Pokemon::outcome_failed("no_pose", at.error); + } + const std::optional> route = fixed_route(story_maps(), at.position, step.legs); + if (!route || route->empty()){ + return Pokemon::outcome_failed("bad_legs", to_string(at.position)); + } + return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after})); + } + virtual Outcome step(RunState& state, const StoryStep& step) override{ + const std::optional at = story_pose(state.pose); + if (!at){ + return Pokemon::outcome_failed("no_pose", Pokemon::to_string(state.pose)); + } + return Pokemon::outcome_ok(to_pose(StoryPose{at->map, at->tile.next(step.direction), step.direction})); + } + // The nurse's way must plan too, but the run goes on from where it stands. + virtual Outcome ready(RunState& state, const StoryStep& step) override{ + const Outcome to_nurse = walk_to(state.pose, step); + return to_nurse.succeeded() ? Pokemon::outcome_ok() : to_nurse; + } + virtual Outcome new_game(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + virtual Outcome options(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + virtual Outcome talk(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + virtual Outcome answer(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + virtual Outcome mash(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + virtual Outcome battle(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + virtual Outcome heal(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + virtual Outcome shop(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + +private: + Outcome walk_to(const Pokemon::Pose& pose, const StoryStep& step){ + const Standing at = standing(pose); + if (!at.error.empty()){ + return Pokemon::outcome_failed("no_pose", at.error); + } + const std::optional target = story_pose(*step.target); + const RouteGoal goal{{target->map, target->tile}, target->facing}; + const std::optional> route = plan_overworld_route( + story_maps(), at.position, goal, default_route_costs(), at.facing + ); + if (!route){ + return Pokemon::outcome_failed("no_route", to_string(at.position) + " to " + to_string(goal.position)); + } + const MapPosition end = follow_overworld_route(story_maps(), at.position, *route); + if (!(end == goal.position)){ + return Pokemon::outcome_failed("wrong_end", to_string(end)); + } + const Direction facing = route->empty() ? at.facing : route->back().facing_after; + return Pokemon::outcome_ok(to_pose(StoryPose{target->map, target->tile, facing})); + } + + std::string m_row; +}; + + +// One simulated run, segment built as the program builds it: each +// checkpoint saves at its end (hooks.save stands for save_game()). +struct Simulation{ + FakeGame game; + std::vector lines; + // Where each save stood: the end of its checkpoint. + std::vector> saves; + Pokemon::SegmentPolicy policy; + + Pokemon::SegmentReport run(const Pokemon::SegmentRange& range){ + Pokemon::Segment segment; + segment.id = "00"; + for (const StoryCheckpoint& data : story_checkpoints()){ + segment.checkpoints.push_back(Pokemon::CheckpointSpec{ + .id = data.id, .title = data.title, .saves = true, + .build = [this, &data]{ return Pokemon::build_story_checkpoint(data, game); }, + }); + } + Pokemon::SegmentHooks hooks; + hooks.save = [this](RunState& state){ + game.trace.push_back("save"); + saves.emplace_back(last_begun(), state.pose); + return Pokemon::outcome_ok(); + }; + hooks.reload = [this](RunState&){ + game.trace.push_back("reload"); + return Pokemon::outcome_ok(); + }; + hooks.log = [this](const std::string& line){ lines.push_back(line); }; + RunState state; + return Pokemon::run_segment(state, segment, range, policy, hooks); + } + std::string last_begun() const{ + for (auto it = game.trace.rbegin(); it != game.trace.rend(); ++it){ + if (it->starts_with("begin ")){ + return it->substr(6); + } + } + return ""; + } + std::vector begun() const{ + std::vector ids; + for (const std::string& item : game.trace){ + if (item.starts_with("begin ")){ + ids.push_back(item.substr(6)); + } + } + return ids; + } + size_t count(const std::string& item) const{ + return (size_t)std::count(game.trace.begin(), game.trace.end(), item); + } +}; + + +class Test_AutoStorySimulation : public UnitTest{ +public: + Test_AutoStorySimulation(std::string name, std::function body) + : UnitTest("PokemonFRLG::AutoStory - Simulation: " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + + +UnitTestResult test_whole_story(){ + Simulation sim; + const Pokemon::SegmentReport report = sim.run({}); + if (!report.completed){ + return "Expected the whole story through:" + joined(sim.lines); + } + std::vector ids; + for (const StoryCheckpoint& data : story_checkpoints()){ + ids.push_back(data.id); + } + if (sim.begun() != ids || sim.saves.size() != ids.size()){ + return "Expected each checkpoint once, in order, each saving at its end:" + joined(sim.game.trace); + } + // Each checkpoint starts where the save before it stands. + for (size_t c = 1; c < story_checkpoints().size(); c++){ + const StoryCheckpoint& data = story_checkpoints()[c]; + const std::optional start = story_pose(*data.start); + const std::optional saved = story_pose(sim.saves[c - 1].second); + const bool same = start && saved && start->map == saved->map && start->tile == saved->tile + && (!start->facing || start->facing == saved->facing); + if (!same){ + return std::format("{} starts at {}, but {} saved at {}.", data.id, + Pokemon::to_string(*data.start), sim.saves[c - 1].first, Pokemon::to_string(sim.saves[c - 1].second)); + } + } + if (report.one_shot_passes() != report.checkpoints_run){ + return "Expected every checkpoint one-shot:" + joined(sim.lines); + } + return true; +} + +UnitTestResult test_start_and_end(){ + Simulation sim; + const Pokemon::SegmentReport report = sim.run({.from = "00.05", .to = "00.07"}); + if (!report.completed || sim.begun() != std::vector{"00.05", "00.06", "00.07"}){ + return "Expected 00.05 to 00.07 only:" + joined(sim.begun()); + } + return true; +} + +// A walk that fails once (a trainer the walker could not recover from): +// the checkpoint reloads its last save and runs again from its start. +UnitTestResult test_retry_from_save(){ + Simulation sim; + sim.game.failures["00.07/forest_north"] = {.failure = "operation_failed", .times = 1}; + const Pokemon::SegmentReport report = sim.run({.from = "00.07", .to = "00.08"}); + if (!report.completed || report.reloads != 1 || sim.begun() != std::vector{"00.07", "00.07", "00.08"} + || sim.count("00.07/mart_clerk") != 2 + ){ + return "Expected 00.07 reloaded once and run again from its start:" + joined(sim.game.trace); + } + if (std::find(sim.lines.begin(), sim.lines.end(), "[Checkpoint] 00.07: passed on attempt 2 (1 reset)") == sim.lines.end()){ + return "Expected the retried pass logged:" + joined(sim.lines); + } + return true; +} + +// Brock's battle lost every time: three attempts, then the stop. +UnitTestResult test_gives_up_after_attempts(){ + Simulation sim; + sim.game.failures["00.08/brock"] = {.failure = "blackout", .times = 10}; + const Pokemon::SegmentReport report = sim.run({.from = "00.08", .to = std::nullopt}); + if (report.completed || report.reloads != 2 || report.failed_checkpoint != "00.08" || report.failed_event != "brock" + || report.failure.failure != "blackout" || sim.count("00.08/brock") != 3 || !sim.saves.empty() + ){ + return "Expected 00.08 tried 3 times, then a stop on Brock:" + joined(sim.game.trace) + joined(sim.lines); + } + return true; +} + +} + + +void add_tests_AutoStorySimulation(UnitTestDatabase& database){ + const auto add = [&](std::string name, UnitTestResult (*body)()){ + database.add(std::move(name), body); + }; + add("new game to Brock, in order, each start where the last save stood", test_whole_story); + add("start and end checkpoints", test_start_and_end); + add("a failed walk reloads its checkpoint's save", test_retry_from_save); + add("a battle lost every time stops after 3 attempts", test_gives_up_after_attempts); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index 4c107c9874..cbf6fadbc3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -25,6 +25,8 @@ const std::vector& story_checkpoints(); void add_tests_AutoStory(UnitTestDatabase& database); +// The table run end to end against a fake game (PokemonFRLG_AutoStorySimulation_Tests.cpp). +void add_tests_AutoStorySimulation(UnitTestDatabase& database); diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index d96f9459c6..c424877b32 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1806,6 +1806,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EliteFourFarmer.cpp Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EliteFourFarmer.h From ad5d4088514e85dd61c5a5d13e27e992dce65733 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 10:27:21 -0800 Subject: [PATCH 26/75] FRLG AutoStory: Mart cursor stays on the item bought; screenshots at each purchase The cursor stays on the row just bought, so counting each order's rows from the top bought Parlyz Heals instead of Antidotes and sent the third order to CANCEL (console B, 2026-11-01). Move the cursor from where it is, and save the list, the quantity and the result of each purchase to DebugDumps/AutoStory/mart. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG_AutoStoryActions.cpp | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index 07012f38a9..ed79c6e282 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -10,6 +10,7 @@ #include #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" #include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/Tools/DebugDumper.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "CommonTools/Async/InferenceRoutines.h" #include "CommonTools/Images/SolidColorTest.h" @@ -418,25 +419,43 @@ void heal_at_center(ConsoleHandle& console, ProControllerContext& context){ mash_until_overworld(console, context, 30000ms); } +// A picture of the Mart screen for the run's record: the list with the +// cursor, the quantity, the bag after. +static void mart_shot(ConsoleHandle& console, ProControllerContext& context, const std::string& label){ + context.wait_for_all_requests(); + dump_debug_image(console, "AutoStory/mart", label, console.video().snapshot()); +} + void buy_items(ConsoleHandle& console, ProControllerContext& context, const std::vector& orders){ // "May I help you?" with BUY on top, then the list, cursor on its top. press(context, BUTTON_A, 2000ms); press(context, BUTTON_A, 2000ms); + // After a purchase the cursor stays on the item bought (run on console B, + // 2026-11-01: rows {1, 2, 3} counted from the top each time bought + // Parlyz Heals instead of Antidotes, and the third order hit CANCEL). + int cursor = 0; for (const MartOrder& order : orders){ - console.log(std::format("Mart: buying {} of row {}.", order.quantity, order.row + 1)); - for (int c = 0; c < order.row; c++){ + console.log(std::format("Mart: buying {} of row {} (cursor on row {}).", order.quantity, order.row + 1, cursor + 1)); + for (int c = cursor; c < order.row; c++){ tap(context, DPAD_DOWN, 300ms); } + for (int c = order.row; c < cursor; c++){ + tap(context, DPAD_UP, 300ms); + } + cursor = order.row; + mart_shot(console, context, std::format("row{}-list", order.row + 1)); // "How many?" drops presses while its text prints. press(context, BUTTON_A, 2500ms); for (int c = 1; c < order.quantity; c++){ tap(context, DPAD_UP, 340ms); } - // "That will be..." YES/NO, YES, "Here you are!"; the cursor - // goes back to the top. + mart_shot(console, context, std::format("row{}-quantity", order.row + 1)); + // "That will be..." YES/NO, YES, "Here you are!"; the cursor stays + // on the row. press(context, BUTTON_A, 3500ms); press(context, BUTTON_A, 2000ms); press(context, BUTTON_A, 1500ms); + mart_shot(console, context, std::format("row{}-bought", order.row + 1)); } press(context, BUTTON_B, 1500ms); press(context, BUTTON_B, 1500ms); From b60d99391d85db42f904c758bbab254fd770f77e Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 10:28:30 -0800 Subject: [PATCH 27/75] FRLG AutoStory: simulate the Viridian Mart with its cursor staying on the row bought viridian_mart_orders() turns the table's items into Mart rows (shop() uses it). The simulation's Mart keeps its cursor on the row just bought, moves it from there for each order, and fails on CANCEL or a wrong item; the whole-story test checks 00.07 buys 5 Potions, 3 Antidotes, 1 Parlyz Heal. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 44 ++++++++++++------- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 5 +++ .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 36 ++++++++++++++- 3 files changed, 67 insertions(+), 18 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index b50fe33722..5eb43cb531 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -183,25 +183,23 @@ constexpr MartItem VIRIDIAN_MART_ITEMS[] = { {.item = "parlyz_heal", .row = 3, .count = &Supplies::parlyz_heals}, }; -Outcome shop(StoryEnv& env, const StoryStep& step){ - std::vector orders; - std::vector counts; - for (const Pokemon::StoryItem& wanted : step.items){ - const MartItem* found = nullptr; - for (const MartItem& item : VIRIDIAN_MART_ITEMS){ - if (wanted.item == item.item){ - found = &item; - } - } - if (found == nullptr){ - return Pokemon::outcome_failed("unknown_item", wanted.item); +const MartItem* viridian_mart_item(const std::string& name){ + for (const MartItem& item : VIRIDIAN_MART_ITEMS){ + if (name == item.item){ + return &item; } - orders.push_back(MartOrder{found->row, (int)wanted.quantity}); - counts.push_back(found->count); } - buy_items(env.console, env.context, orders); - for (size_t c = 0; c < orders.size(); c++){ - env.supplies.*counts[c] += orders[c].quantity; + return nullptr; +} + +Outcome shop(StoryEnv& env, const StoryStep& step){ + const std::optional> orders = viridian_mart_orders(step.items); + if (!orders){ + return Pokemon::outcome_failed("unknown_item", step.name); + } + buy_items(env.console, env.context, *orders); + for (const Pokemon::StoryItem& item : step.items){ + env.supplies.*viridian_mart_item(item.item)->count += (int)item.quantity; } return Pokemon::outcome_ok(); } @@ -209,6 +207,18 @@ Outcome shop(StoryEnv& env, const StoryStep& step){ } +std::optional> viridian_mart_orders(const std::vector& items){ + std::vector orders; + for (const Pokemon::StoryItem& wanted : items){ + const MartItem* found = viridian_mart_item(wanted.item); + if (found == nullptr){ + return std::nullopt; + } + orders.push_back(MartOrder{found->row, (int)wanted.quantity}); + } + return orders; +} + const std::vector& story_maps(){ static const std::vector maps = overworld_maps(map_flag_set(overworld_maps(), "after_hall_of_fame")); return maps; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index ca3424506d..a0b601f28d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -80,6 +80,11 @@ std::optional> fixed_route( // into a sign would read it. std::optional wall_beside(const MapData& map, const TilePos& tile); +// `items` as orders at the Viridian Mart before the Boulder Badge: the +// rows of POKE BALL, POTION, ANTIDOTE, PARLYZ HEAL. Nothing if it does +// not sell one of them. +std::optional> viridian_mart_orders(const std::vector& items); + // What the story's events act on. `supplies` are what the bag holds now, // `saved_supplies` what the last save holds. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index 3a1664ed39..7dcd139a13 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -84,6 +84,8 @@ class FakeGame : public Pokemon::StoryStepExecutor{ std::vector trace; std::map failures; + // What the Mart sold, by its list's names. + std::map bag; virtual void begin_attempt(const Pokemon::StoryCheckpoint& data) override{ m_row = data.id; @@ -132,7 +134,30 @@ class FakeGame : public Pokemon::StoryStepExecutor{ virtual Outcome mash(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } virtual Outcome battle(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } virtual Outcome heal(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } - virtual Outcome shop(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } + // The Viridian Mart's list as the game shows it. After a purchase the + // cursor stays on the row bought (console B, 2026-11-01), so each + // order moves it from there, as buy_items() does since ad5d40885. + virtual Outcome shop(RunState&, const StoryStep& step) override{ + static const std::vector LIST{"poke_ball", "potion", "antidote", "parlyz_heal", "cancel"}; + const std::optional> orders = viridian_mart_orders(step.items); + if (!orders){ + return Pokemon::outcome_failed("unknown_item", step.name); + } + int cursor = 0; + for (size_t c = 0; c < orders->size(); c++){ + const MartOrder& order = (*orders)[c]; + // The presses: down or up from where the cursor is. + cursor += order.row - cursor; + if (cursor < 0 || cursor >= (int)LIST.size() || LIST[cursor] == "cancel"){ + return Pokemon::outcome_failed("mart_cancel", std::format("order {} ends on row {}", c + 1, cursor + 1)); + } + if (LIST[cursor] != step.items[c].item){ + return Pokemon::outcome_failed("wrong_item", std::format("{} instead of {}", LIST[cursor], step.items[c].item)); + } + bag[LIST[cursor]] += order.quantity; + } + return Pokemon::outcome_ok(); + } private: Outcome walk_to(const Pokemon::Pose& pose, const StoryStep& step){ @@ -262,6 +287,15 @@ UnitTestResult test_whole_story(){ if (report.one_shot_passes() != report.checkpoints_run){ return "Expected every checkpoint one-shot:" + joined(sim.lines); } + // 00.07's shopping, with the cursor staying on each row bought. + const std::map bought{{"potion", 5}, {"antidote", 3}, {"parlyz_heal", 1}}; + if (sim.game.bag != bought){ + std::string text; + for (const auto& item : sim.game.bag){ + text += std::format(" {} {}", item.second, item.first); + } + return "Expected 5 Potions, 3 Antidotes and 1 Parlyz Heal; bought" + text + "."; + } return true; } From 7b074809bf994f21b0b0c504910f23b4d59b1ea4 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 10:33:02 -0800 Subject: [PATCH 28/75] FRLG AutoStory: hand the shared checks option to the story executor Nothing reads it yet; #120's Mart and Bag checks will. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index fe4bec28ba..bbd0778d22 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -83,6 +83,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex } StoryExecutor executor(story); + executor.set_checks(RETRIES.checks()); Pokemon::Segment segment = make_story_segment(checkpoints, executor); Pokemon::SegmentHooks hooks; hooks.reload = [&story](Pokemon::RunState&){ From ac0c9632852f2274b8b50a0a4cc12867d9ab195c Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 10:37:40 -0800 Subject: [PATCH 29/75] FRLG AutoStory: Checks option; read the Mart row, the bag after shopping, and an item before using it A run bought Parlyz Heals instead of Antidotes (ad5d40885) and the story's own counts never noticed. A new option, Checks, sets how much the story looks before and after it acts: - Thorough (the default): reads the item on the Mart's cursor row before buying, and fails with a screenshot if it reads as another item (one it can't read is logged and saved to DebugDumps/AutoStory/mart); reads the bag's Items pocket after shopping and keeps those counts and that order; reads an item's row in the bag before using it, in battle or on the overworld, and doesn't use it if it reads as something else. - Fast: trusts the counts the story keeps and the timings, as before. The reader (Inference/Menus/PokemonFRLG_ItemListReader) OCRs the names of the items met before the Boulder Badge, in English, and the bag's counts; the bag and the Mart lay out their lists alike (pokefirered: a list window at tile (11, 1), names from x 97, rows 16 apart). Its boxes are measured on a capture of the Items pocket; the Mart's are the same by the decomp and not yet checked on a capture. Item rows now come from the pocket's order with empty items dropped. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Menus/PokemonFRLG_ItemListReader.cpp | 109 +++++++++ .../Menus/PokemonFRLG_ItemListReader.h | 54 +++++ .../AutoStory/PokemonFRLG_AutoStory.cpp | 14 +- .../AutoStory/PokemonFRLG_AutoStory.h | 3 + .../PokemonFRLG_AutoStoryActions.cpp | 40 +++- .../AutoStory/PokemonFRLG_AutoStoryActions.h | 21 +- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 207 ++++++++++++++---- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 34 ++- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 21 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 1 + SerialPrograms/cmake/SourceFiles.cmake | 3 + 11 files changed, 447 insertions(+), 60 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp new file mode 100644 index 0000000000..b8b9ad5810 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp @@ -0,0 +1,109 @@ +/* Item List Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/Language.h" +#include "CommonTools/OCR/OCR_NumberReader.h" +#include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_ItemListReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// Measured on a capture of the Items pocket (console B, 2026-11-01): text +// rows from y 13 to 21, 16 apart; names from x 97, "x" at 198, the count +// to 221. +constexpr double ROW_TOP = 11; +constexpr double ROW_STEP = 16; +constexpr double ROW_HEIGHT = 12; + +class ItemNameMatcher : public OCR::SmallDictionaryMatcher{ +public: + static constexpr double MAX_LOG10P = -1.40; + static constexpr double MAX_LOG10P_SPREAD = 0.50; + + static const ItemNameMatcher& instance(){ + static const ItemNameMatcher matcher; + return matcher; + } + + std::string read(Logger& logger, const ImageViewRGB32& image) const{ + const ImageRGB32 ready = preprocess_for_ocr(image); + const OCR::StringMatchResult result = match_substring_from_image_multifiltered( + &logger, Language::English, ready, DARK_TEXT_FILTERS(), + MAX_LOG10P, MAX_LOG10P_SPREAD, 0.01, 0.50 + ); + return result.results.empty() ? "" : result.results.begin()->second.token; + } + +private: + ItemNameMatcher() + : SmallDictionaryMatcher(dictionary()) + {} + + static JsonObject dictionary(){ + JsonObject english; + for (const auto& [slug, name] : { + std::pair{"potion", "Potion"}, + {"antidote", "Antidote"}, + {"parlyz-heal", "Parlyz Heal"}, + {"poke-ball", "Poke Ball"}, + {"cancel", "Cancel"}, + }){ + JsonArray names; + names.push_back(name); + english[slug] = std::move(names); + } + JsonObject json; + json["eng"] = std::move(english); + return json; + } +}; + +ImageViewRGB32 game_box(const ImageViewRGB32& screen){ + return extract_box_reference(screen, GameSettings::instance().GAME_BOX); +} + +} + + +ImageFloatBox item_list_name_box(int row){ + return ImageFloatBox(96.0 / 240, (ROW_TOP + ROW_STEP * row) / 160, 72.0 / 240, ROW_HEIGHT / 160); +} +ImageFloatBox bag_item_count_box(int row){ + return ImageFloatBox(208.0 / 240, (ROW_TOP + ROW_STEP * row) / 160, 15.0 / 240, ROW_HEIGHT / 160); +} + +std::string read_item_list_name(Logger& logger, const ImageViewRGB32& screen, int row){ + return ItemNameMatcher::instance().read(logger, extract_box_reference(game_box(screen), item_list_name_box(row))); +} + +std::vector read_bag_pocket(Logger& logger, const ImageViewRGB32& screen){ + std::vector rows; + for (int row = 0; row < ITEM_LIST_ROWS; row++){ + const std::string item = read_item_list_name(logger, screen, row); + if (item.empty() || item == "cancel"){ + break; + } + const ImageViewRGB32 count = extract_box_reference(game_box(screen), bag_item_count_box(row)); + rows.push_back(BagRow{item, OCR::read_number_waterfill(logger, count, 0xff000000, 0xff808080)}); + } + return rows; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h new file mode 100644 index 0000000000..936f2cfaa8 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h @@ -0,0 +1,54 @@ +/* Item List Reader + * + * From: https://github.com/PokemonAutomation/ + * + * Reads the item lists of the bag's pockets and of a Mart's BUY menu, + * which the game draws alike: rows 16 pixels apart from y 13, names from + * x 97 (pokefirered: the list window at tile (11, 1), item_X 9). English + * only, and only the items a new game meets before the Boulder Badge. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_ItemListReader_H +#define PokemonAutomation_PokemonFRLG_ItemListReader_H + +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Rows a list shows at once. +constexpr int ITEM_LIST_ROWS = 6; + +// Where row `row` (from 0) of a list shows its item's name, and in the bag +// its count, as fractions of the game screen. +ImageFloatBox item_list_name_box(int row); +ImageFloatBox bag_item_count_box(int row); + +// The item named in row `row`: a slug such as "potion", "antidote", +// "parlyz-heal", "poke-ball", or "cancel" for the list's last row; empty +// if it can't be read. +std::string read_item_list_name(Logger& logger, const ImageViewRGB32& screen, int row); + +struct BagRow{ + std::string item; + int count = 0; +}; + +// The rows of the bag's open pocket from the top, up to its CANCEL (not +// included). Stops at a row it can't read. The pocket must be scrolled to +// its top. +std::vector read_bag_pocket(Logger& logger, const ImageViewRGB32& screen); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 56aab77af0..3946f96427 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -56,6 +56,17 @@ AutoStory::AutoStory() LockMode::LOCK_WHILE_RUNNING, 1, 5, 2, 2 ) + , CHECKS( + "Checks:
Thorough reads the screen before acting and confirms after: the item on a Mart row " + "before buying it, the bag's Items pocket after shopping (its counts are the ones kept), and an item's name " + "in the bag before using it. Fast trusts the counts it keeps and the timings.", + { + {StoryChecks::THOROUGH, "thorough", "Thorough"}, + {StoryChecks::FAST, "fast", "Fast"}, + }, + LockMode::LOCK_WHILE_RUNNING, + StoryChecks::THOROUGH + ) , NOTIFICATIONS({ &NOTIFICATION_PROGRAM_FINISH, &NOTIFICATION_ERROR_FATAL, @@ -65,6 +76,7 @@ AutoStory::AutoStory() PA_ADD_OPTION(END_CHECKPOINT); PA_ADD_OPTION(NEW_GAME_FROM_TITLE); PA_ADD_OPTION(ATTEMPTS_PER_CHECKPOINT); + PA_ADD_OPTION(CHECKS); PA_ADD_OPTION(NOTIFICATIONS); } @@ -80,7 +92,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex throw UserSetupError(env.console, "Checkpoint 00.01 starts a new game: start on the title screen with no save."); } - StoryEnv story{env.console, context, checkpoints[first].supplies, checkpoints[first].supplies, false}; + StoryEnv story{env.console, context, checkpoints[first].supplies, checkpoints[first].supplies, false, CHECKS}; if (!(first == 0 && NEW_GAME_FROM_TITLE)){ env.console.log("Loading the save for " + checkpoints[first].id + "."); soft_reset(env.console, context); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h index a71a842818..eed050ea88 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h @@ -13,9 +13,11 @@ #define PokemonAutomation_PokemonFRLG_AutoStory_H #include "Common/Cpp/Options/BooleanCheckBoxOption.h" +#include "Common/Cpp/Options/EnumDropdownOption.h" #include "Common/Cpp/Options/SimpleIntegerOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "PokemonFRLG_AutoStoryActions.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -42,6 +44,7 @@ class AutoStory : public SingleSwitchProgramInstance{ SimpleIntegerOption END_CHECKPOINT; BooleanCheckBoxOption NEW_GAME_FROM_TITLE; SimpleIntegerOption ATTEMPTS_PER_CHECKPOINT; + EnumDropdownOption CHECKS; EventNotificationsOption NOTIFICATIONS; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index ed79c6e282..c4d5b17c51 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" @@ -17,6 +18,7 @@ #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" @@ -426,7 +428,32 @@ static void mart_shot(ConsoleHandle& console, ProControllerContext& context, con dump_debug_image(console, "AutoStory/mart", label, console.video().snapshot()); } -void buy_items(ConsoleHandle& console, ProControllerContext& context, const std::vector& orders){ +int mart_cursor_moves(int cursor, int row){ + return row - cursor; +} + +// THOROUGH: the item on the cursor's row is `order.item`. +static void check_mart_row(ConsoleHandle& console, ProControllerContext& context, const MartOrder& order){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + const std::string item = screen ? read_item_list_name(console, screen, order.row) : ""; + if (item == order.item){ + console.log(std::format("Mart: row {} is {}.", order.row + 1, item)); + return; + } + if (item.empty()){ + console.log(std::format("Mart: couldn't read row {}, expected {}; buying anyway.", order.row + 1, order.item), COLOR_ORANGE); + dump_debug_image(console, "AutoStory/mart", std::format("row{}-unread", order.row + 1), screen); + return; + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("buy_items(): row {} is {}, not {}.", order.row + 1, item, order.item), + console + ); +} + +void buy_items(ConsoleHandle& console, ProControllerContext& context, const std::vector& orders, StoryChecks checks){ // "May I help you?" with BUY on top, then the list, cursor on its top. press(context, BUTTON_A, 2000ms); press(context, BUTTON_A, 2000ms); @@ -436,14 +463,15 @@ void buy_items(ConsoleHandle& console, ProControllerContext& context, const std: int cursor = 0; for (const MartOrder& order : orders){ console.log(std::format("Mart: buying {} of row {} (cursor on row {}).", order.quantity, order.row + 1, cursor + 1)); - for (int c = cursor; c < order.row; c++){ - tap(context, DPAD_DOWN, 300ms); - } - for (int c = order.row; c < cursor; c++){ - tap(context, DPAD_UP, 300ms); + const int moves = mart_cursor_moves(cursor, order.row); + for (int c = 0; c < std::abs(moves); c++){ + tap(context, moves > 0 ? DPAD_DOWN : DPAD_UP, 300ms); } cursor = order.row; mart_shot(console, context, std::format("row{}-list", order.row + 1)); + if (checks == StoryChecks::THOROUGH){ + check_mart_row(console, context, order); + } // "How many?" drops presses while its text prints. press(context, BUTTON_A, 2500ms); for (int c = 1; c < order.quantity; c++){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index 230139d159..ec2f5fa80a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -27,6 +27,16 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ +// How much the story checks the screen before and after it acts. +// THOROUGH: reads a Mart row's item before buying it, the bag's Items +// pocket after shopping (the counts the story then keeps), and an item's +// name in the bag before using it. FAST trusts the counts it keeps and the +// timings. +enum class StoryChecks{ + THOROUGH, + FAST, +}; + // The START menu as the story grows it. Before the starter: BAG, the // player, SAVE, OPTION, EXIT; the starter adds POKEMON on top, the Pokedex // POKEDEX above that. @@ -92,10 +102,19 @@ void heal_at_center(ConsoleHandle& console, ProControllerContext& context); struct MartOrder{ int row = 0; int quantity = 1; + // The item's slug for the check (see read_item_list_name()). + const char* item = ""; }; +// Down (positive) or up (negative) presses to move a Mart list's cursor +// from `cursor` to `row`. After a purchase the cursor stays on its row. +int mart_cursor_moves(int cursor, int row); + // Facing a Mart clerk: BUY each order, then out to the overworld. -void buy_items(ConsoleHandle& console, ProControllerContext& context, const std::vector& orders); +// THOROUGH: each row's item is read before buying; one that reads as +// another item fails with a screenshot, one that can't be read is only +// logged. +void buy_items(ConsoleHandle& console, ProControllerContext& context, const std::vector& orders, StoryChecks checks); // From the title screen of a game with no save, to the bedroom: the // controls pages, Oak's speech, BOY, and the default names for the player diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 6051f8d21c..dbc69db487 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -11,6 +11,7 @@ #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/ImageTools/ImageStats.h" +#include "CommonFramework/Tools/DebugDumper.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" @@ -175,11 +176,29 @@ void tap(ProControllerContext& context, DpadPosition position){ pbf_press_dpad(context, position, 160ms, 240ms); } -// From the battle menu: the item in `row` (from 0) of the Items pocket, on +// In the bag, with the cursor on `row`: whether that row is `item`. FAST +// doesn't look. One that can't be read counts as a mismatch. +bool bag_row_is(ConsoleHandle& console, ProControllerContext& context, int row, const std::string& item, StoryChecks checks){ + if (checks == StoryChecks::FAST){ + return true; + } + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + const std::string read = screen ? read_item_list_name(console, screen, row) : ""; + if (read == item){ + return true; + } + console.log(std::format("Bag: row {} reads \"{}\", not {}: not using it.", row + 1, read, item), COLOR_RED); + dump_debug_image(console, "AutoStory/bag", std::format("row{}-not-{}", row + 1, item), screen); + return false; +} + +// From the battle menu: `item`, in `row` (from 0) of the Items pocket, on // the starter. The bag opens on the pocket used last; Items is the first. -// Not run on the console yet. -void use_item(ConsoleHandle& console, ProControllerContext& context, int row){ - console.log(std::format("Battle: using the item in row {} of the Items pocket.", row + 1)); +// Returns whether it was used; if the row holds something else (THOROUGH), +// backs out to the battle menu. Not run on the console yet. +bool use_item(ConsoleHandle& console, ProControllerContext& context, int row, const std::string& item, StoryChecks checks){ + console.log(std::format("Battle: using the {} in row {} of the Items pocket.", item, row + 1)); tap(context, DPAD_LEFT); tap(context, DPAD_UP); tap(context, DPAD_RIGHT); @@ -193,10 +212,15 @@ void use_item(ConsoleHandle& console, ProControllerContext& context, int row){ for (int c = 0; c < row; c++){ tap(context, DPAD_DOWN); } + if (!bag_row_is(console, context, row, item, checks)){ + pbf_press_button(context, BUTTON_B, 160ms, 1500ms); + return false; + } // The item, USE, then the starter in the party list. pbf_press_button(context, BUTTON_A, 160ms, 800ms); pbf_press_button(context, BUTTON_A, 160ms, 1500ms); pbf_press_button(context, BUTTON_A, 160ms, 1000ms); + return true; } // RUN, bottom right of the battle menu. @@ -223,11 +247,12 @@ void use_move(ProControllerContext& context){ class BattleLoop{ public: - BattleLoop(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind) + BattleLoop(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind, StoryChecks checks) : m_console(console) , m_context(context) , m_supplies(supplies) , m_kind(kind) + , m_checks(checks) , m_start(current_time()) , m_last_battle(m_start) , m_last_press(m_start) @@ -408,15 +433,21 @@ class BattleLoop{ run_away(m_context); return; } - if (hurt && m_supplies.potions > 0){ - m_supplies.potions--; - m_supplies.hurt = false; - m_supplies.hp_red = false; - use_item(m_console, m_context, 0); - }else if (m_psn_reads >= PSN_READS && !m_antidote_used && m_supplies.antidotes > 0){ + if (!m_items_off && hurt && m_supplies.potions > 0){ + if (use_item(m_console, m_context, item_row(m_supplies, "potion"), "potion", m_checks)){ + m_supplies.potions--; + m_supplies.hurt = false; + m_supplies.hp_red = false; + }else{ + m_items_off = true; + } + }else if (!m_items_off && m_psn_reads >= PSN_READS && !m_antidote_used && m_supplies.antidotes > 0){ m_antidote_used = true; - m_supplies.antidotes--; - use_item(m_console, m_context, m_supplies.potions > 0 ? 1 : 0); + if (use_item(m_console, m_context, item_row(m_supplies, "antidote"), "antidote", m_checks)){ + m_supplies.antidotes--; + }else{ + m_items_off = true; + } }else{ use_move(m_context); } @@ -437,6 +468,9 @@ class BattleLoop{ ProControllerContext& m_context; Supplies& m_supplies; const BattleKind m_kind; + const StoryChecks m_checks; + // An item read as another in the bag: none is used again this battle. + bool m_items_off = false; const WallClock m_start; WallClock m_last_battle; WallClock m_last_press; @@ -456,10 +490,8 @@ class BattleLoop{ }; -// From the overworld: the item in `row` (from 0) of the Items pocket, on -// the starter. Not run on the console yet. -void use_item_on_overworld(ConsoleHandle& console, ProControllerContext& context, int row, const char* item){ - console.log(std::format("Story: using a {} from the bag (Items pocket, row {}).", item, row + 1)); +// From the overworld: the bag open on the Items pocket, cursor on its top. +void open_items_pocket(ConsoleHandle& console, ProControllerContext& context){ open_bag_from_overworld(console, context); // The bag ignores presses while it slides in. pbf_wait(context, 1000ms); @@ -469,15 +501,28 @@ void use_item_on_overworld(ConsoleHandle& console, ProControllerContext& context for (int c = 0; c < 20; c++){ pbf_press_dpad(context, DPAD_UP, 100ms, 100ms); } +} + +// From the overworld: `item`, in `row` (from 0) of the Items pocket, on +// the starter. Returns whether it was used (THOROUGH reads the row first). +// Not run on the console yet. +bool use_item_on_overworld(ConsoleHandle& console, ProControllerContext& context, int row, const std::string& item, StoryChecks checks){ + console.log(std::format("Story: using a {} from the bag (Items pocket, row {}).", item, row + 1)); + open_items_pocket(console, context); for (int c = 0; c < row; c++){ pbf_press_dpad(context, DPAD_DOWN, 100ms, 300ms); } + if (!bag_row_is(console, context, row, item, checks)){ + mash_until_overworld(console, context, AFTER_BATTLE_TEXT); + return false; + } // The item, USE, the starter, then its message. pbf_press_button(context, BUTTON_A, 160ms, 800ms); pbf_press_button(context, BUTTON_A, 160ms, 1500ms); pbf_press_button(context, BUTTON_A, 160ms, 2500ms); pbf_press_button(context, BUTTON_B, 160ms, 1500ms); mash_until_overworld(console, context, AFTER_BATTLE_TEXT); + return true; } void fail_on_blackout(ConsoleHandle& console, BattleEnd end){ @@ -493,8 +538,9 @@ void fail_on_blackout(ConsoleHandle& console, BattleEnd end){ // appeared!". class StoryWildBattle : public OverworldInterrupt{ public: - StoryWildBattle(Supplies& supplies, bool fight, bool late) + StoryWildBattle(Supplies& supplies, bool fight, bool late, StoryChecks checks) : m_supplies(supplies) + , m_checks(checks) , m_fight(fight) , m_late(late) {} @@ -516,12 +562,13 @@ class StoryWildBattle : public OverworldInterrupt{ // next leg. virtual void clear(ConsoleHandle& console, ProControllerContext& context) const override{ const BattleKind kind = m_fight ? BattleKind::WILD_FIGHT : BattleKind::WILD_RUN; - fail_on_blackout(console, fight_battle(console, context, m_supplies, kind)); - recover_after_battle(console, context, m_supplies); + fail_on_blackout(console, fight_battle(console, context, m_supplies, kind, m_checks)); + recover_after_battle(console, context, m_supplies, m_checks); } private: Supplies& m_supplies; + const StoryChecks m_checks; const bool m_fight; const bool m_late; }; @@ -529,8 +576,9 @@ class StoryWildBattle : public OverworldInterrupt{ // A message: read to its end, then a trainer's battle if one starts. class StoryMessage : public OverworldInterrupt{ public: - explicit StoryMessage(Supplies& supplies) + StoryMessage(Supplies& supplies, StoryChecks checks) : m_supplies(supplies) + , m_checks(checks) {} virtual std::string name() const override{ return "a message"; @@ -546,13 +594,14 @@ class StoryMessage : public OverworldInterrupt{ return; } console.log("Story: a trainer's battle after a message on the overworld."); - fail_on_blackout(console, fight_battle(console, context, m_supplies, BattleKind::TRAINER)); + fail_on_blackout(console, fight_battle(console, context, m_supplies, BattleKind::TRAINER, m_checks)); mash_until_overworld(console, context, AFTER_BATTLE_TEXT); - recover_after_battle(console, context, m_supplies); + recover_after_battle(console, context, m_supplies, m_checks); } private: Supplies& m_supplies; + const StoryChecks m_checks; }; } @@ -587,40 +636,110 @@ PartyStatus read_party_status(const ImageViewRGB32& screen){ return status; } -void recover_after_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies){ - // Rows in the order bought: Potions, Antidotes, Parlyz Heals. - const int antidote_row = supplies.potions > 0 ? 1 : 0; - const int parlyz_row = antidote_row + (supplies.antidotes > 0 ? 1 : 0); +// The count the story keeps for `item`, or null for an item it doesn't count. +static int* count_slot(Supplies& supplies, const std::string& item){ + if (item == "potion"){ + return &supplies.potions; + } + if (item == "antidote"){ + return &supplies.antidotes; + } + if (item == "parlyz-heal"){ + return &supplies.parlyz_heals; + } + return nullptr; +} + +int item_count(const Supplies& supplies, const std::string& item){ + if (item == "potion"){ + return supplies.potions; + } + if (item == "antidote"){ + return supplies.antidotes; + } + if (item == "parlyz-heal"){ + return supplies.parlyz_heals; + } + return 0; +} + +int item_row(const Supplies& supplies, const std::string& item){ + int row = 0; + for (const std::string& slot : supplies.pocket){ + if (item_count(supplies, slot) <= 0){ + continue; + } + if (slot == item){ + return row; + } + row++; + } + return -1; +} + +void set_from_bag(Supplies& supplies, const std::vector& rows){ + supplies.potions = 0; + supplies.antidotes = 0; + supplies.parlyz_heals = 0; + supplies.pocket.clear(); + for (const BagRow& row : rows){ + supplies.pocket.push_back(row.item); + int* slot = count_slot(supplies, row.item); + if (slot != nullptr){ + *slot = std::max(row.count, 0); + } + } +} + +std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context){ + open_items_pocket(console, context); + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + dump_debug_image(console, "AutoStory/bag", "items-pocket", screen); + std::vector rows = screen ? read_bag_pocket(console, screen) : std::vector{}; + std::string text; + for (const BagRow& row : rows){ + text += std::format(" {} x{};", row.item, row.count); + } + console.log("Bag: Items pocket:" + (text.empty() ? std::string(" nothing read.") : text)); + mash_until_overworld(console, context, AFTER_BATTLE_TEXT); + return rows; +} + +void recover_after_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, StoryChecks checks){ if (supplies.status == StatusCondition::POISON && supplies.antidotes > 0){ - use_item_on_overworld(console, context, antidote_row, "Antidote"); - supplies.antidotes--; - supplies.status = StatusCondition::NONE; + if (use_item_on_overworld(console, context, item_row(supplies, "antidote"), "antidote", checks)){ + supplies.antidotes--; + supplies.status = StatusCondition::NONE; + } }else if (supplies.status == StatusCondition::PARALYSIS && supplies.parlyz_heals > 0){ - use_item_on_overworld(console, context, parlyz_row, "Parlyz Heal"); - supplies.parlyz_heals--; - supplies.status = StatusCondition::NONE; + if (use_item_on_overworld(console, context, item_row(supplies, "parlyz-heal"), "parlyz-heal", checks)){ + supplies.parlyz_heals--; + supplies.status = StatusCondition::NONE; + } } // One Potion (20 HP) takes a starter of these levels (about 30 HP) // from red to green; the bar can't be read again on the overworld. if (supplies.hurt && supplies.potions > 0){ - use_item_on_overworld(console, context, 0, "Potion"); - supplies.potions--; - supplies.hurt = false; - supplies.hp_red = false; + if (use_item_on_overworld(console, context, item_row(supplies, "potion"), "potion", checks)){ + supplies.potions--; + supplies.hurt = false; + supplies.hp_red = false; + } } } -BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind){ - return BattleLoop(console, context, supplies, kind).run(); +BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind, StoryChecks checks){ + return BattleLoop(console, context, supplies, kind, checks).run(); } -OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild){ +OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks){ // Battles first: their screens are checked before the message box's. OverworldInterruptSet ret; - ret.wild.emplace_back(std::make_unique(supplies, fight_wild, false)); - ret.wild.emplace_back(std::make_unique(supplies, fight_wild, true)); - ret.wild.emplace_back(std::make_unique(supplies)); - ret.other.emplace_back(std::make_unique(supplies)); + ret.wild.emplace_back(std::make_unique(supplies, fight_wild, false, checks)); + ret.wild.emplace_back(std::make_unique(supplies, fight_wild, true, checks)); + ret.wild.emplace_back(std::make_unique(supplies, checks)); + ret.other.emplace_back(std::make_unique(supplies, checks)); return ret; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index f9a0c55ddd..adeda47ce5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -21,10 +21,15 @@ #ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattle_H #define PokemonAutomation_PokemonFRLG_AutoStoryBattle_H +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryActions.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -47,6 +52,10 @@ struct Supplies{ int potions = 0; int antidotes = 0; int parlyz_heals = 0; + // The Items pocket's order, by slug (see read_item_list_name()): the + // order bought, or as read from the bag. An item with none left takes + // no row. + std::vector pocket = {"potion", "antidote", "parlyz-heal"}; // The starter's status at the last battle screen that showed it, and // not cured since. StatusCondition status = StatusCondition::NONE; @@ -69,6 +78,20 @@ enum class BattleEnd{ LOST, }; +// How many of `item` (a slug) the bag holds, as far as known. +int item_count(const Supplies& supplies, const std::string& item); + +// The row (from 0) of `item` in the Items pocket, or -1 if none is left. +int item_row(const Supplies& supplies, const std::string& item); + +// Sets the counts and the pocket's order from the Items pocket as read. +void set_from_bag(Supplies& supplies, const std::vector& rows); + +// From the overworld: opens the Items pocket, reads it, and closes the +// bag again. Empty if nothing could be read. +std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context); + + // What the HP bar and the status badge of the player's Pokemon show, on a // battle screen with its box. Colors measured on console B's captures // (2026-11-01): the bar's fill green (100, 251, 171), yellow @@ -86,20 +109,25 @@ PartyStatus read_party_status(const ImageViewRGB32& screen); // `kind` says, using `supplies` as needed. Returns once START opens the // menu on the overworld: text after the battle (a gym leader's speech) is // read with B on the way. Throws OperationFailedException if it runs over 10 minutes. -BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind); +// THOROUGH: an item's name is read in the bag before it is used, and a +// different one isn't used. +BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind, StoryChecks checks); // From the overworld, after a battle: an Antidote for PSN, a Parlyz Heal // for PAR, then a Potion if the HP bar wasn't green, each if one is left. // The bag's inputs are not checked on the console yet. -void recover_after_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies); +void recover_after_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, StoryChecks checks); // The interrupts for walking story routes. Wild battles are run from, or // fought if `fight_wild`. A message is advanced until the overworld is // back; a battle that starts after it (a trainer who saw the player) is // fought. A battle lost (a blackout) throws OperationFailedException. -OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild); +OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks); + + +void add_tests_AutoStoryItems(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 92c0484045..bcdb5e82b7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -93,7 +93,7 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ if (!route){ return Pokemon::outcome_failed("no_route", to_string(start) + " to " + to_string(goal.position)); } - const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild); + const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks); // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. const RoutePlanning planning{&story_maps(), default_route_costs()}; @@ -116,7 +116,7 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ if (!facing || !route || route->empty()){ return Pokemon::outcome_failed("bad_legs", to_string(start)); } - const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild); + const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks); // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. const RoutePlanning planning{&story_maps(), default_route_costs()}; @@ -137,7 +137,7 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ if (advance_text(env.console, env.context, BATTLE_TEXT_TIMEOUT, true) != TextEnd::BATTLE){ return Pokemon::outcome_failed("no_battle"); } - const BattleEnd end = fight_battle(env.console, env.context, env.supplies, BattleKind::TRAINER); + const BattleEnd end = fight_battle(env.console, env.context, env.supplies, BattleKind::TRAINER, env.checks); if (end == BattleEnd::LOST && !step.may_lose){ return Pokemon::outcome_failed("blackout"); } @@ -154,7 +154,7 @@ Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ "Story: before the battle, HP {}, {}, {} Potions.", supplies.hp_red ? "red" : supplies.hurt ? "yellow" : "green", status_name(supplies.status), supplies.potions )); - recover_after_battle(env.console, env.context, supplies); + recover_after_battle(env.console, env.context, supplies, env.checks); if (!supplies.hp_red && supplies.status == StatusCondition::NONE){ return Pokemon::outcome_ok(); } @@ -173,10 +173,21 @@ Outcome shop(StoryEnv& env){ // Viridian Mart before the Boulder Badge (pokefirered ViridianCity_Mart_Items): // POKE BALL, POTION (300), ANTIDOTE (100), PARLYZ HEAL (200). 2000 of the // 3000 a new game starts with, plus the rival's prize. - buy_items(env.console, env.context, {{1, 5}, {2, 3}, {3, 1}}); + buy_items(env.console, env.context, {{1, 5, "potion"}, {2, 3, "antidote"}, {3, 1, "parlyz-heal"}}, env.checks); env.supplies.potions += 5; env.supplies.antidotes += 3; env.supplies.parlyz_heals += 1; + if (env.checks == StoryChecks::FAST){ + return Pokemon::outcome_ok(); + } + // The counts from the bag, not from the orders: a wrong row once bought + // Parlyz Heals for Antidotes unnoticed (console B, 2026-11-01). + const std::vector rows = read_items_pocket(env.console, env.context); + if (rows.empty()){ + env.console.log("Story: couldn't read the Items pocket; keeping the counts ordered.", COLOR_ORANGE); + return Pokemon::outcome_ok(); + } + set_from_bag(env.supplies, rows); return Pokemon::outcome_ok(); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index dcb6084848..8a4245561d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -126,6 +126,7 @@ struct StoryEnv{ Supplies saved_supplies; // Whether the game has a save to reload. bool has_save = false; + StoryChecks checks = StoryChecks::THOROUGH; }; // The checkpoint `data` as events, saving at its end. diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 433946d598..8ddec70b10 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1713,6 +1713,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Inference/Map/PokemonFRLG_PokemonLeagueDetectors.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_BagDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_BagDetector.h + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_LoadMenuDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_LoadMenuDetector.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp @@ -1799,6 +1801,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp From 99d0d760be9413292b8f9941d5480349c254106e Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 10:37:41 -0800 Subject: [PATCH 30/75] FRLG AutoStory: tests for the Mart cursor, the pocket's rows and the bag capture - The Mart cursor's moves for the story's orders (rows 1, 2, 3 with the cursor staying on the row bought). - Item rows from the pocket's order, skipping items with none left, and counts and order taken from a bag read. - The Items pocket read off the run's capture (POTION x4, PARLYZ HEAL x3): names and counts, row 1 passes the check as a Potion, row 2 fails it as an Antidote, row 3 is CANCEL. The capture is on the fork's CommandLineTests branch frlg/autostory-bag-capture; the test skips until it is in the CommandLineTests repo CI checks out. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 + .../PokemonFRLG_AutoStoryItems_Tests.cpp | 139 ++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 87e3252324..ddec042740 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -32,6 +32,7 @@ #include "Overworld/PokemonFRLG_OverworldRoute.h" #include "Overworld/PokemonFRLG_PlayerFacingReader.h" #include "PokemonFRLG_Navigation.h" +#include "Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryTable.h" #include "Tests/TestUtils.h" @@ -298,6 +299,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_OverworldRecovery(database); add_tests_PlayerFacingReader(database); add_tests_AutoStory(database); + add_tests_AutoStoryItems(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp new file mode 100644 index 0000000000..6de1a18c90 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -0,0 +1,139 @@ +/* AutoStory Items Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The Mart cursor's moves, the bag's rows as the story counts them, and + * the bag read off a capture: the one that showed the Mart had bought + * Parlyz Heals instead of Antidotes (console B, 2026-11-01). + * + */ + +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +class Test_AutoStoryItems : public UnitTest{ +public: + Test_AutoStoryItems(std::string name, std::function body) + : UnitTest("PokemonFRLG::AutoStoryItems - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_body(logger); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + + +// The orders the story gives the Viridian Mart: rows 1, 2, 3 in turn. The +// cursor stays on the row bought, so each is one row down from the last. +UnitTestResult test_mart_cursor(Logger&){ + if (mart_cursor_moves(0, 1) != 1 || mart_cursor_moves(1, 2) != 1 || mart_cursor_moves(2, 3) != 1){ + return "Expected one press down between the story's orders."; + } + if (mart_cursor_moves(3, 1) != -2 || mart_cursor_moves(2, 2) != 0){ + return "Expected presses up to a row above, none to the same row."; + } + int cursor = 0; + std::vector bought; + for (int row : {1, 2, 3}){ + cursor += mart_cursor_moves(cursor, row); + bought.push_back(cursor); + } + if (bought != std::vector{1, 2, 3}){ + return "The cursor didn't land on rows 1, 2, 3."; + } + return true; +} + +// Rows skip items with none left; the order read from the bag replaces +// the order bought. +UnitTestResult test_pocket_rows(Logger&){ + Supplies supplies; + supplies.potions = 5; + supplies.antidotes = 3; + supplies.parlyz_heals = 1; + if (item_row(supplies, "potion") != 0 || item_row(supplies, "antidote") != 1 || item_row(supplies, "parlyz-heal") != 2){ + return "Wrong rows for the order bought."; + } + supplies.potions = 0; + if (item_row(supplies, "potion") != -1 || item_row(supplies, "antidote") != 0){ + return "An item with none left still takes a row."; + } + set_from_bag(supplies, {{"potion", 4}, {"parlyz-heal", 3}}); + if (supplies.potions != 4 || supplies.antidotes != 0 || supplies.parlyz_heals != 3){ + return "Counts not taken from the bag."; + } + if (item_row(supplies, "parlyz-heal") != 1 || item_row(supplies, "antidote") != -1){ + return "Rows not taken from the bag."; + } + return true; +} + + +// In the CommandLineTests repo, like the other image tests. Skipped while +// it isn't there. +const char* const BAG_CAPTURE = "PokemonFRLG/AutoStory/BagItems_Potion4_ParlyzHeal3.png"; + +UnitTestResult test_bag_capture(Logger& logger){ + const std::string path = UNIT_TEST_RESOURCE_PATH() + BAG_CAPTURE; + if (!std::filesystem::exists(path)){ + return UnitTestResult(UnitTestResult::SKIPPED, "Capture not found: " + path); + } + const ImageRGB32 screen(path); + const std::vector rows = read_bag_pocket(logger, screen); + if (rows.size() != 2 || rows[0].item != "potion" || rows[0].count != 4 || rows[1].item != "parlyz-heal" || rows[1].count != 3){ + std::string text; + for (const BagRow& row : rows){ + text += std::format(" {} x{};", row.item, row.count); + } + return "Expected potion x4; parlyz-heal x3, read:" + text; + } + // The name check before using an item: row 1 passes as a Potion, row 2 + // fails as an Antidote. + if (read_item_list_name(logger, screen, 0) != "potion"){ + return "Row 1 doesn't read as a Potion."; + } + if (read_item_list_name(logger, screen, 1) == "antidote"){ + return "Row 2 reads as an Antidote."; + } + if (read_item_list_name(logger, screen, 2) != "cancel"){ + return "Row 3 doesn't read as CANCEL."; + } + return true; +} + +} + + +void add_tests_AutoStoryItems(UnitTestDatabase& database){ + database.add("Mart cursor stays on the row bought", test_mart_cursor); + database.add("Items pocket rows", test_pocket_rows); + database.add("Items pocket read off a capture", test_bag_capture); +} + + + +} +} +} From 44742ac63567afbc1873303f0ea3dd9876380c98 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 10:43:18 -0800 Subject: [PATCH 31/75] FRLG AutoStory: drop the bag capture test The user's call: the test that read the Items pocket off a capture needed the image in CommandLineTests, which isn't going upstream. The Mart cursor and pocket-row tests stay. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG_AutoStoryItems_Tests.cpp | 41 +------------------ 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index 6de1a18c90..0713ead5c8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -2,20 +2,14 @@ * * From: https://github.com/PokemonAutomation/ * - * The Mart cursor's moves, the bag's rows as the story counts them, and - * the bag read off a capture: the one that showed the Mart had bought - * Parlyz Heals instead of Antidotes (console B, 2026-11-01). + * The Mart cursor's moves, and the bag's rows as the story counts them. * */ -#include -#include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Logging/AbstractLogger.h" #include "Common/Cpp/TestRunners/UnitTest.h" -#include "CommonFramework/GlobalAutoPaths.h" -#include "CommonFramework/ImageTypes/ImageRGB32.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattle.h" @@ -91,45 +85,12 @@ UnitTestResult test_pocket_rows(Logger&){ } -// In the CommandLineTests repo, like the other image tests. Skipped while -// it isn't there. -const char* const BAG_CAPTURE = "PokemonFRLG/AutoStory/BagItems_Potion4_ParlyzHeal3.png"; - -UnitTestResult test_bag_capture(Logger& logger){ - const std::string path = UNIT_TEST_RESOURCE_PATH() + BAG_CAPTURE; - if (!std::filesystem::exists(path)){ - return UnitTestResult(UnitTestResult::SKIPPED, "Capture not found: " + path); - } - const ImageRGB32 screen(path); - const std::vector rows = read_bag_pocket(logger, screen); - if (rows.size() != 2 || rows[0].item != "potion" || rows[0].count != 4 || rows[1].item != "parlyz-heal" || rows[1].count != 3){ - std::string text; - for (const BagRow& row : rows){ - text += std::format(" {} x{};", row.item, row.count); - } - return "Expected potion x4; parlyz-heal x3, read:" + text; - } - // The name check before using an item: row 1 passes as a Potion, row 2 - // fails as an Antidote. - if (read_item_list_name(logger, screen, 0) != "potion"){ - return "Row 1 doesn't read as a Potion."; - } - if (read_item_list_name(logger, screen, 1) == "antidote"){ - return "Row 2 reads as an Antidote."; - } - if (read_item_list_name(logger, screen, 2) != "cancel"){ - return "Row 3 doesn't read as CANCEL."; - } - return true; -} - } void add_tests_AutoStoryItems(UnitTestDatabase& database){ database.add("Mart cursor stays on the row bought", test_mart_cursor); database.add("Items pocket rows", test_pocket_rows); - database.add("Items pocket read off a capture", test_bag_capture); } From 8e0eabed42a78633a6d7c8e165302e0e0b9b0c39 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 11:11:25 -0800 Subject: [PATCH 32/75] FRLG AutoStory: name the route log after the story step, from its start The story runner passes the step's name and its start tile to the walker (RoutePlanning), so FRLG's route log lines read like BDSP's: the plan "from" where the player stands, under the step's name, and an "arrived at" line once the route is walked. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index bcdb5e82b7..3cf48547e3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -9,6 +9,7 @@ #include #include "CommonFramework/Exceptions/OperationFailedException.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "Pokemon/Navigation/Pokemon_RouteLog.h" #include "Pokemon/Navigation/Pokemon_TilePose.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h" @@ -73,6 +74,12 @@ std::optional face_a_wall(StoryEnv& env, const MapPosition& position) return wall; } +// The shared route log's arrival line (Pokemon_RouteLog.h), as BDSP's walker +// writes it: where the route was walked to. +void log_arrival(StoryEnv& env, const std::string& label, const std::string& map, const TilePos& tile){ + env.console.log(Pokemon::ROUTE_LOG_TAG + Pokemon::route_arrived_line(label, {{map, tile}})); +} + Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ const std::vector tiles = Pokemon::tiles_of(state.pose); if (tiles.size() != 1 || state.pose.certainty != Pokemon::PoseCertainty::TILE){ @@ -96,8 +103,9 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks); // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. - const RoutePlanning planning{&story_maps(), default_route_costs()}; + const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name}; walk_overworld_route(env.console, env.context, *route, facing, interrupts, &planning); + log_arrival(env, step.name, step.target.map, step.target.tile); const std::optional end_facing = route->empty() ? facing : std::optional(route->back().facing_after); return Pokemon::outcome_ok(to_pose(StoryPose{step.target.map, step.target.tile, end_facing})); } @@ -119,8 +127,9 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks); // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. - const RoutePlanning planning{&story_maps(), default_route_costs()}; + const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name}; walk_overworld_route(env.console, env.context, *route, facing, interrupts, &planning); + log_arrival(env, step.name, route->back().end.map, route->back().end.point); return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after})); } From 530a5be33a138e6489b7c8a0c08af0a80e757cc3 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 11:12:26 -0800 Subject: [PATCH 33/75] FRLG AutoStory: the game's language from the shared options; simulate in Japanese The executor takes StoryRunOptions' language. No FRLG story step reads dialogue or menu text; the only text reads are #120's item names (read_item_list_name()), still English. The simulation runs its executor in Japanese, which no reader supports. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp | 3 +++ .../AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 1d5945d2e4..544dcb6e39 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -84,6 +84,9 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex StoryExecutor executor(story); executor.set_checks(RETRIES.checks()); + // For #120's item-name reads (read_item_list_name()), which still read + // English; no other step reads text. + executor.set_language(RETRIES.language()); Pokemon::Segment segment = make_story_segment(checkpoints, executor); Pokemon::SegmentHooks hooks; hooks.reload = [&story](Pokemon::RunState&){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index 7dcd139a13..0534dcee3c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -194,7 +194,9 @@ struct Simulation{ std::vector> saves; Pokemon::SegmentPolicy policy; + // A language no reader supports, so a step that needed text would show. Pokemon::SegmentReport run(const Pokemon::SegmentRange& range){ + game.set_language(Language::Japanese); Pokemon::Segment segment; segment.id = "00"; for (const StoryCheckpoint& data : story_checkpoints()){ From 6253aaf7944b7c6d9e8f71857462d003c97df30c Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 11:13:28 -0800 Subject: [PATCH 34/75] FRLG AutoStory: save on entering Viridian Forest (new 00.08); Brock is 00.09 Three runs failed at forest_gate after drifting in the forest's battles, and each retry reloaded the save in Oak's Lab: 15 minutes back through Route 1, the Mart and Route 2. 00.07 now ends on the forest's exit mat (29, 62), where the south gate's north warp lands, facing north, and saves there. The new 00.08 starts from that save with the supplies 00.07 bought (5 Potions, 3 Antidotes, 1 Parlyz Heal) and walks the forest to Pewter's Center. Brock's checkpoint is now 00.09, and the start and end options run to 9. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStory.cpp | 8 ++++---- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 18 +++++++++++++----- .../AutoStory/PokemonFRLG_AutoStoryTable.h | 4 ++-- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 6 +++--- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 3946f96427..6c63d0a04d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -36,14 +36,14 @@ AutoStory_Descriptor::AutoStory_Descriptor() AutoStory::AutoStory() : START_CHECKPOINT( "Start at checkpoint 00.0N:
1: new game, 2: bedroom, 3: Pallet Town, 4: Oak's Lab, " - "5: after the rival's battle, 6: Viridian Mart, 7: Pokedex, 8: Pewter Center.", + "5: after the rival's battle, 6: Viridian Mart, 7: Pokedex, 8: Viridian Forest's entrance, 9: Pewter Center.", LockMode::LOCK_WHILE_RUNNING, - 1, 8, 1, 1 + 1, 9, 1, 1 ) , END_CHECKPOINT( - "End after checkpoint 00.0N:
8 ends with the Boulder Badge.", + "End after checkpoint 00.0N:
9 ends with the Boulder Badge.", LockMode::LOCK_WHILE_RUNNING, - 1, 8, 8, 8 + 1, 9, 9, 9 ) , NEW_GAME_FROM_TITLE( "New game from the title screen:
The game is on its title screen with no save data. " diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index b8cbbce1e8..f3f9f07f95 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -155,8 +155,8 @@ StoryCheckpoint pokedex(){ }}; } -StoryCheckpoint forest(){ - return StoryCheckpoint{"00.07", "Viridian shopping to Pewter Center", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { +StoryCheckpoint shopping(){ + return StoryCheckpoint{"00.07", "Viridian shopping, then into Viridian Forest", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again"), make(StoryStepKind::SHOP, "potions_and_antidotes", "5 Potions, 3 Antidotes, 1 Parlyz Heal"), route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest"), @@ -169,7 +169,15 @@ StoryCheckpoint forest(){ // the map doesn't have him: "east 2" from there didn't move, and the walk north // ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first. route("past_old_man", at(VIRIDIAN, 20, 5, NORTH), "north along column 20, clear of the old man"), - route("forest_entrance", at(FOREST, 29, 61), "Route 2, running from wild battles"), + // The gate's north warp lands on the forest's exit mat (29, 62), facing + // north. The save there keeps a forest failure from going back to Pallet. + route("forest_entrance", at(FOREST, 29, 62, NORTH), "Route 2 and the south gate, running from wild battles"), + }}; +} + +StoryCheckpoint forest(){ + // The supplies bought in 00.07. + return StoryCheckpoint{"00.08", "Viridian Forest to Pewter Center", at(FOREST, 29, 62, NORTH), {5, 3, 1}, StartMenu::FULL, { // The forest legs walked by hand; wild battles are fought for EXP. route("forest_west", at(FOREST, 13, 46), "west side of the forest", true), route("forest_east", at(FOREST, 42, 44), "east path, past a Bug Catcher", true), @@ -191,7 +199,7 @@ StoryCheckpoint forest(){ StoryCheckpoint brock(){ // The by-hand save: 2 Potions and 1 Antidote left after the forest. - return StoryCheckpoint{"00.08", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { + return StoryCheckpoint{"00.09", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight // 4) and sees (4..7, 8): walking north up column 6 from the door, // the step onto (6, 8) starts his battle. He walks up to the player, @@ -213,7 +221,7 @@ StoryCheckpoint brock(){ const std::vector& story_checkpoints(){ static const std::vector checkpoints{ - new_game(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), forest(), brock(), + new_game(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), }; return checkpoints; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index 4c107c9874..505fb242ff 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -3,7 +3,7 @@ * From: https://github.com/PokemonAutomation/ * * FireRed from a new game to the Boulder Badge, as story checkpoints - * 00.01 to 00.08, each saved at its end. Taken from a by-hand run on + * 00.01 to 00.09, each saved at its end. Taken from a by-hand run on * console B (2026-11-01) and the pokefirered map scripts. * */ @@ -20,7 +20,7 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Checkpoints 00.01 to 00.08, in order. +// Checkpoints 00.01 to 00.09, in order. const std::vector& story_checkpoints(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 6fcced4acc..398f90e1df 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -191,8 +191,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po UnitTestResult test_routes_and_chain(){ const std::vector& checkpoints = story_checkpoints(); - if (checkpoints.size() != 8 || checkpoints[0].start){ - return "Expected 8 checkpoints, the first from a new game."; + if (checkpoints.size() != 9 || checkpoints[0].start){ + return "Expected 9 checkpoints, the first from a new game."; } StoryPose pose; for (size_t c = 0; c < checkpoints.size(); c++){ @@ -247,7 +247,7 @@ UnitTestResult check_legs_on( return true; } -// 00.08, each walk from where the one before leaves the player. +// 00.09, each walk from where the one before leaves the player. UnitTestResult test_pewter_gym_walks(){ const MapPosition nurse{"PewterCity_PokemonCenter_1F", {7, 4}}; // In by the door's mat (6, 14), straight up column 6 to below Liam's row. From f694e4db43b833fce7111c609332e4927880d5ca Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 11:37:24 -0800 Subject: [PATCH 35/75] FRLG AutoStory: Viridian Forest straight up the east side, without the west detour 00.08 went from the entrance west to (13, 46) and back south before heading east: two open legs through grass, walked in the by-hand run only. forest_east now starts at the entrance (29, 62) and goes by legs that end on walls: east 1, north 4, east 14 (stopped by the Boy at (45, 58)), north 15 to (44, 43). Rick (47, 45) sees (42..46, 45), so the last leg meets his battle and is held on to its wall after it. forest_north plans on from (44, 43). The route test checks forest_east's legs end on walls like forest_exit's. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp | 9 ++++++--- .../Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index f3f9f07f95..b8124594ff 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -178,9 +178,12 @@ StoryCheckpoint shopping(){ StoryCheckpoint forest(){ // The supplies bought in 00.07. return StoryCheckpoint{"00.08", "Viridian Forest to Pewter Center", at(FOREST, 29, 62, NORTH), {5, 3, 1}, StartMenu::FULL, { - // The forest legs walked by hand; wild battles are fought for EXP. - route("forest_west", at(FOREST, 13, 46), "west side of the forest", true), - route("forest_east", at(FOREST, 42, 44), "east path, past a Bug Catcher", true), + // Wild battles are fought for EXP. Straight up the east side from the + // entrance, each leg ending on a wall (the Boy at (45, 58) stops the + // east one). Rick (47, 45) sees (42..46, 45), so the last leg meets + // his battle and is held on to its wall after it. The by-hand run's + // detour west to (13, 46) and back is dropped. + legs("forest_east", {{EAST, 1}, {NORTH, 4}, {EAST, 14}, {NORTH, 15}}, "up the east side to (44, 43)", true), route("forest_north", at(FOREST, 39, 25), "north part", true), // To the gate by legs that end on walls, which the walker holds again // after a battle instead of estimating where it stopped: planned diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 398f90e1df..ea1c53e378 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -95,7 +95,7 @@ std::vector tiles_walked_on(const std::vector& route, const // Steps that must reach Viridian Forest's gate by legs the walker can hold // again after a battle: each ends on a wall or a warp, or is one step. bool held_legs_only(const std::string& name){ - return name == "forest_exit" || name == "forest_gate"; + return name == "forest_east" || name == "forest_exit" || name == "forest_gate"; } UnitTestResult check_held_legs(const std::string& name, const std::vector& route){ for (const RouteStep& step : route){ From bc95fe36b811b3d1e09d90260e1ab09736fbbfff Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 11:43:40 -0800 Subject: [PATCH 36/75] FRLG AutoStory: read item names in the game's language; unread means fall back The item list reader took English for granted. It now takes the game's language, from StoryEnv (English by default; the shared options set it on frlg/story-steps), and reads nothing in a language it has no names for, never a match. Thorough then falls back instead of failing: a Mart row is bought by its position, the bag read keeps the counts ordered, and an item's row in the bag is taken by its position. Only another item's name stops a purchase or an item's use. A test checks that nothing is read in Japanese. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Menus/PokemonFRLG_ItemListReader.cpp | 15 ++-- .../Menus/PokemonFRLG_ItemListReader.h | 19 ++-- .../PokemonFRLG_AutoStoryActions.cpp | 11 ++- .../AutoStory/PokemonFRLG_AutoStoryActions.h | 8 +- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 87 ++++++++++++------- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 14 ++- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 12 +-- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 3 + .../PokemonFRLG_AutoStoryItems_Tests.cpp | 16 ++++ 9 files changed, 127 insertions(+), 58 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp index b8b9ad5810..cf63b79a6a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp @@ -38,10 +38,13 @@ class ItemNameMatcher : public OCR::SmallDictionaryMatcher{ return matcher; } - std::string read(Logger& logger, const ImageViewRGB32& image) const{ + std::string read(Logger& logger, Language language, const ImageViewRGB32& image) const{ + if (!languages()[language]){ + return ""; + } const ImageRGB32 ready = preprocess_for_ocr(image); const OCR::StringMatchResult result = match_substring_from_image_multifiltered( - &logger, Language::English, ready, DARK_TEXT_FILTERS(), + &logger, language, ready, DARK_TEXT_FILTERS(), MAX_LOG10P, MAX_LOG10P_SPREAD, 0.01, 0.50 ); return result.results.empty() ? "" : result.results.begin()->second.token; @@ -85,14 +88,14 @@ ImageFloatBox bag_item_count_box(int row){ return ImageFloatBox(208.0 / 240, (ROW_TOP + ROW_STEP * row) / 160, 15.0 / 240, ROW_HEIGHT / 160); } -std::string read_item_list_name(Logger& logger, const ImageViewRGB32& screen, int row){ - return ItemNameMatcher::instance().read(logger, extract_box_reference(game_box(screen), item_list_name_box(row))); +std::string read_item_list_name(Logger& logger, Language language, const ImageViewRGB32& screen, int row){ + return ItemNameMatcher::instance().read(logger, language, extract_box_reference(game_box(screen), item_list_name_box(row))); } -std::vector read_bag_pocket(Logger& logger, const ImageViewRGB32& screen){ +std::vector read_bag_pocket(Logger& logger, Language language, const ImageViewRGB32& screen){ std::vector rows; for (int row = 0; row < ITEM_LIST_ROWS; row++){ - const std::string item = read_item_list_name(logger, screen, row); + const std::string item = read_item_list_name(logger, language, screen, row); if (item.empty() || item == "cancel"){ break; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h index 936f2cfaa8..e8d536e565 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h @@ -4,8 +4,9 @@ * * Reads the item lists of the bag's pockets and of a Mart's BUY menu, * which the game draws alike: rows 16 pixels apart from y 13, names from - * x 97 (pokefirered: the list window at tile (11, 1), item_X 9). English - * only, and only the items a new game meets before the Boulder Badge. + * x 97 (pokefirered: the list window at tile (11, 1), item_X 9). It knows + * the names of the items a new game meets before the Boulder Badge, in + * English only so far: in another language a name is never read. * */ @@ -17,6 +18,7 @@ #include "Common/Cpp/Logging/AbstractLogger.h" #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -32,9 +34,10 @@ ImageFloatBox item_list_name_box(int row); ImageFloatBox bag_item_count_box(int row); // The item named in row `row`: a slug such as "potion", "antidote", -// "parlyz-heal", "poke-ball", or "cancel" for the list's last row; empty -// if it can't be read. -std::string read_item_list_name(Logger& logger, const ImageViewRGB32& screen, int row); +// "parlyz-heal", "poke-ball", or "cancel" for the list's last row, in a +// game in `language`; empty if it can't be read, as in a language the +// reader has no names for. +std::string read_item_list_name(Logger& logger, Language language, const ImageViewRGB32& screen, int row); struct BagRow{ std::string item; @@ -42,9 +45,9 @@ struct BagRow{ }; // The rows of the bag's open pocket from the top, up to its CANCEL (not -// included). Stops at a row it can't read. The pocket must be scrolled to -// its top. -std::vector read_bag_pocket(Logger& logger, const ImageViewRGB32& screen); +// included). Stops at a row it can't read, so it is empty in a language +// the reader has no names for. The pocket must be scrolled to its top. +std::vector read_bag_pocket(Logger& logger, Language language, const ImageViewRGB32& screen); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index c4d5b17c51..6f18982f1a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -433,10 +433,10 @@ int mart_cursor_moves(int cursor, int row){ } // THOROUGH: the item on the cursor's row is `order.item`. -static void check_mart_row(ConsoleHandle& console, ProControllerContext& context, const MartOrder& order){ +static void check_mart_row(ConsoleHandle& console, ProControllerContext& context, const MartOrder& order, Language language){ context.wait_for_all_requests(); VideoSnapshot screen = console.video().snapshot(); - const std::string item = screen ? read_item_list_name(console, screen, order.row) : ""; + const std::string item = screen ? read_item_list_name(console, language, screen, order.row) : ""; if (item == order.item){ console.log(std::format("Mart: row {} is {}.", order.row + 1, item)); return; @@ -453,7 +453,10 @@ static void check_mart_row(ConsoleHandle& console, ProControllerContext& context ); } -void buy_items(ConsoleHandle& console, ProControllerContext& context, const std::vector& orders, StoryChecks checks){ +void buy_items( + ConsoleHandle& console, ProControllerContext& context, + const std::vector& orders, StoryChecks checks, Language language +){ // "May I help you?" with BUY on top, then the list, cursor on its top. press(context, BUTTON_A, 2000ms); press(context, BUTTON_A, 2000ms); @@ -470,7 +473,7 @@ void buy_items(ConsoleHandle& console, ProControllerContext& context, const std: cursor = order.row; mart_shot(console, context, std::format("row{}-list", order.row + 1)); if (checks == StoryChecks::THOROUGH){ - check_mart_row(console, context, order); + check_mart_row(console, context, order, language); } // "How many?" drops presses while its text prints. press(context, BUTTON_A, 2500ms); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index ec2f5fa80a..3eb926ee5e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -17,6 +17,7 @@ #include #include #include "Common/Cpp/Time.h" +#include "CommonFramework/Language.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" @@ -114,7 +115,12 @@ int mart_cursor_moves(int cursor, int row); // THOROUGH: each row's item is read before buying; one that reads as // another item fails with a screenshot, one that can't be read is only // logged. -void buy_items(ConsoleHandle& console, ProControllerContext& context, const std::vector& orders, StoryChecks checks); +// `language` is the game's: in one the reader has no names for, rows are +// bought by position only. +void buy_items( + ConsoleHandle& console, ProControllerContext& context, + const std::vector& orders, StoryChecks checks, Language language +); // From the title screen of a game with no save, to the bedroom: the // controls pages, Oak's speech, BOY, and the default names for the player diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index dbc69db487..571471987c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -177,17 +177,25 @@ void tap(ProControllerContext& context, DpadPosition position){ } // In the bag, with the cursor on `row`: whether that row is `item`. FAST -// doesn't look. One that can't be read counts as a mismatch. -bool bag_row_is(ConsoleHandle& console, ProControllerContext& context, int row, const std::string& item, StoryChecks checks){ +// doesn't look. A row that can't be read (as in a language the reader has +// no names for) is taken by its position; only another item's name stops it. +bool bag_row_is( + ConsoleHandle& console, ProControllerContext& context, + int row, const std::string& item, StoryChecks checks, Language language +){ if (checks == StoryChecks::FAST){ return true; } context.wait_for_all_requests(); VideoSnapshot screen = console.video().snapshot(); - const std::string read = screen ? read_item_list_name(console, screen, row) : ""; + const std::string read = screen ? read_item_list_name(console, language, screen, row) : ""; if (read == item){ return true; } + if (read.empty()){ + console.log(std::format("Bag: row {} unread, taking it as the {} by its position.", row + 1, item), COLOR_ORANGE); + return true; + } console.log(std::format("Bag: row {} reads \"{}\", not {}: not using it.", row + 1, read, item), COLOR_RED); dump_debug_image(console, "AutoStory/bag", std::format("row{}-not-{}", row + 1, item), screen); return false; @@ -197,7 +205,10 @@ bool bag_row_is(ConsoleHandle& console, ProControllerContext& context, int row, // the starter. The bag opens on the pocket used last; Items is the first. // Returns whether it was used; if the row holds something else (THOROUGH), // backs out to the battle menu. Not run on the console yet. -bool use_item(ConsoleHandle& console, ProControllerContext& context, int row, const std::string& item, StoryChecks checks){ +bool use_item( + ConsoleHandle& console, ProControllerContext& context, + int row, const std::string& item, StoryChecks checks, Language language +){ console.log(std::format("Battle: using the {} in row {} of the Items pocket.", item, row + 1)); tap(context, DPAD_LEFT); tap(context, DPAD_UP); @@ -212,7 +223,7 @@ bool use_item(ConsoleHandle& console, ProControllerContext& context, int row, co for (int c = 0; c < row; c++){ tap(context, DPAD_DOWN); } - if (!bag_row_is(console, context, row, item, checks)){ + if (!bag_row_is(console, context, row, item, checks, language)){ pbf_press_button(context, BUTTON_B, 160ms, 1500ms); return false; } @@ -247,12 +258,16 @@ void use_move(ProControllerContext& context){ class BattleLoop{ public: - BattleLoop(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind, StoryChecks checks) + BattleLoop( + ConsoleHandle& console, ProControllerContext& context, + Supplies& supplies, BattleKind kind, StoryChecks checks, Language language + ) : m_console(console) , m_context(context) , m_supplies(supplies) , m_kind(kind) , m_checks(checks) + , m_language(language) , m_start(current_time()) , m_last_battle(m_start) , m_last_press(m_start) @@ -434,7 +449,7 @@ class BattleLoop{ return; } if (!m_items_off && hurt && m_supplies.potions > 0){ - if (use_item(m_console, m_context, item_row(m_supplies, "potion"), "potion", m_checks)){ + if (use_item(m_console, m_context, item_row(m_supplies, "potion"), "potion", m_checks, m_language)){ m_supplies.potions--; m_supplies.hurt = false; m_supplies.hp_red = false; @@ -443,7 +458,7 @@ class BattleLoop{ } }else if (!m_items_off && m_psn_reads >= PSN_READS && !m_antidote_used && m_supplies.antidotes > 0){ m_antidote_used = true; - if (use_item(m_console, m_context, item_row(m_supplies, "antidote"), "antidote", m_checks)){ + if (use_item(m_console, m_context, item_row(m_supplies, "antidote"), "antidote", m_checks, m_language)){ m_supplies.antidotes--; }else{ m_items_off = true; @@ -469,6 +484,7 @@ class BattleLoop{ Supplies& m_supplies; const BattleKind m_kind; const StoryChecks m_checks; + const Language m_language; // An item read as another in the bag: none is used again this battle. bool m_items_off = false; const WallClock m_start; @@ -506,13 +522,16 @@ void open_items_pocket(ConsoleHandle& console, ProControllerContext& context){ // From the overworld: `item`, in `row` (from 0) of the Items pocket, on // the starter. Returns whether it was used (THOROUGH reads the row first). // Not run on the console yet. -bool use_item_on_overworld(ConsoleHandle& console, ProControllerContext& context, int row, const std::string& item, StoryChecks checks){ +bool use_item_on_overworld( + ConsoleHandle& console, ProControllerContext& context, + int row, const std::string& item, StoryChecks checks, Language language +){ console.log(std::format("Story: using a {} from the bag (Items pocket, row {}).", item, row + 1)); open_items_pocket(console, context); for (int c = 0; c < row; c++){ pbf_press_dpad(context, DPAD_DOWN, 100ms, 300ms); } - if (!bag_row_is(console, context, row, item, checks)){ + if (!bag_row_is(console, context, row, item, checks, language)){ mash_until_overworld(console, context, AFTER_BATTLE_TEXT); return false; } @@ -538,9 +557,10 @@ void fail_on_blackout(ConsoleHandle& console, BattleEnd end){ // appeared!". class StoryWildBattle : public OverworldInterrupt{ public: - StoryWildBattle(Supplies& supplies, bool fight, bool late, StoryChecks checks) + StoryWildBattle(Supplies& supplies, bool fight, bool late, StoryChecks checks, Language language) : m_supplies(supplies) , m_checks(checks) + , m_language(language) , m_fight(fight) , m_late(late) {} @@ -562,13 +582,14 @@ class StoryWildBattle : public OverworldInterrupt{ // next leg. virtual void clear(ConsoleHandle& console, ProControllerContext& context) const override{ const BattleKind kind = m_fight ? BattleKind::WILD_FIGHT : BattleKind::WILD_RUN; - fail_on_blackout(console, fight_battle(console, context, m_supplies, kind, m_checks)); - recover_after_battle(console, context, m_supplies, m_checks); + fail_on_blackout(console, fight_battle(console, context, m_supplies, kind, m_checks, m_language)); + recover_after_battle(console, context, m_supplies, m_checks, m_language); } private: Supplies& m_supplies; const StoryChecks m_checks; + const Language m_language; const bool m_fight; const bool m_late; }; @@ -576,9 +597,10 @@ class StoryWildBattle : public OverworldInterrupt{ // A message: read to its end, then a trainer's battle if one starts. class StoryMessage : public OverworldInterrupt{ public: - StoryMessage(Supplies& supplies, StoryChecks checks) + StoryMessage(Supplies& supplies, StoryChecks checks, Language language) : m_supplies(supplies) , m_checks(checks) + , m_language(language) {} virtual std::string name() const override{ return "a message"; @@ -594,14 +616,15 @@ class StoryMessage : public OverworldInterrupt{ return; } console.log("Story: a trainer's battle after a message on the overworld."); - fail_on_blackout(console, fight_battle(console, context, m_supplies, BattleKind::TRAINER, m_checks)); + fail_on_blackout(console, fight_battle(console, context, m_supplies, BattleKind::TRAINER, m_checks, m_language)); mash_until_overworld(console, context, AFTER_BATTLE_TEXT); - recover_after_battle(console, context, m_supplies, m_checks); + recover_after_battle(console, context, m_supplies, m_checks, m_language); } private: Supplies& m_supplies; const StoryChecks m_checks; + const Language m_language; }; } @@ -691,12 +714,12 @@ void set_from_bag(Supplies& supplies, const std::vector& rows){ } } -std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context){ +std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context, Language language){ open_items_pocket(console, context); context.wait_for_all_requests(); VideoSnapshot screen = console.video().snapshot(); dump_debug_image(console, "AutoStory/bag", "items-pocket", screen); - std::vector rows = screen ? read_bag_pocket(console, screen) : std::vector{}; + std::vector rows = screen ? read_bag_pocket(console, language, screen) : std::vector{}; std::string text; for (const BagRow& row : rows){ text += std::format(" {} x{};", row.item, row.count); @@ -706,14 +729,17 @@ std::vector read_items_pocket(ConsoleHandle& console, ProControllerConte return rows; } -void recover_after_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, StoryChecks checks){ +void recover_after_battle( + ConsoleHandle& console, ProControllerContext& context, + Supplies& supplies, StoryChecks checks, Language language +){ if (supplies.status == StatusCondition::POISON && supplies.antidotes > 0){ - if (use_item_on_overworld(console, context, item_row(supplies, "antidote"), "antidote", checks)){ + if (use_item_on_overworld(console, context, item_row(supplies, "antidote"), "antidote", checks, language)){ supplies.antidotes--; supplies.status = StatusCondition::NONE; } }else if (supplies.status == StatusCondition::PARALYSIS && supplies.parlyz_heals > 0){ - if (use_item_on_overworld(console, context, item_row(supplies, "parlyz-heal"), "parlyz-heal", checks)){ + if (use_item_on_overworld(console, context, item_row(supplies, "parlyz-heal"), "parlyz-heal", checks, language)){ supplies.parlyz_heals--; supplies.status = StatusCondition::NONE; } @@ -721,7 +747,7 @@ void recover_after_battle(ConsoleHandle& console, ProControllerContext& context, // One Potion (20 HP) takes a starter of these levels (about 30 HP) // from red to green; the bar can't be read again on the overworld. if (supplies.hurt && supplies.potions > 0){ - if (use_item_on_overworld(console, context, item_row(supplies, "potion"), "potion", checks)){ + if (use_item_on_overworld(console, context, item_row(supplies, "potion"), "potion", checks, language)){ supplies.potions--; supplies.hurt = false; supplies.hp_red = false; @@ -729,17 +755,20 @@ void recover_after_battle(ConsoleHandle& console, ProControllerContext& context, } } -BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind, StoryChecks checks){ - return BattleLoop(console, context, supplies, kind, checks).run(); +BattleEnd fight_battle( + ConsoleHandle& console, ProControllerContext& context, + Supplies& supplies, BattleKind kind, StoryChecks checks, Language language +){ + return BattleLoop(console, context, supplies, kind, checks, language).run(); } -OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks){ +OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks, Language language){ // Battles first: their screens are checked before the message box's. OverworldInterruptSet ret; - ret.wild.emplace_back(std::make_unique(supplies, fight_wild, false, checks)); - ret.wild.emplace_back(std::make_unique(supplies, fight_wild, true, checks)); - ret.wild.emplace_back(std::make_unique(supplies, checks)); - ret.other.emplace_back(std::make_unique(supplies, checks)); + ret.wild.emplace_back(std::make_unique(supplies, fight_wild, false, checks, language)); + ret.wild.emplace_back(std::make_unique(supplies, fight_wild, true, checks, language)); + ret.wild.emplace_back(std::make_unique(supplies, checks, language)); + ret.other.emplace_back(std::make_unique(supplies, checks, language)); return ret; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index adeda47ce5..fb4eb3cd70 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -89,7 +89,7 @@ void set_from_bag(Supplies& supplies, const std::vector& rows); // From the overworld: opens the Items pocket, reads it, and closes the // bag again. Empty if nothing could be read. -std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context); +std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context, Language language); // What the HP bar and the status badge of the player's Pokemon show, on a @@ -111,20 +111,26 @@ PartyStatus read_party_status(const ImageViewRGB32& screen); // read with B on the way. Throws OperationFailedException if it runs over 10 minutes. // THOROUGH: an item's name is read in the bag before it is used, and a // different one isn't used. -BattleEnd fight_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind, StoryChecks checks); +BattleEnd fight_battle( + ConsoleHandle& console, ProControllerContext& context, + Supplies& supplies, BattleKind kind, StoryChecks checks, Language language +); // From the overworld, after a battle: an Antidote for PSN, a Parlyz Heal // for PAR, then a Potion if the HP bar wasn't green, each if one is left. // The bag's inputs are not checked on the console yet. -void recover_after_battle(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, StoryChecks checks); +void recover_after_battle( + ConsoleHandle& console, ProControllerContext& context, + Supplies& supplies, StoryChecks checks, Language language +); // The interrupts for walking story routes. Wild battles are run from, or // fought if `fight_wild`. A message is advanced until the overworld is // back; a battle that starts after it (a trainer who saw the player) is // fought. A battle lost (a blackout) throws OperationFailedException. -OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks); +OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks, Language language); void add_tests_AutoStoryItems(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 3cf48547e3..cd6ff836b1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -100,7 +100,7 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ if (!route){ return Pokemon::outcome_failed("no_route", to_string(start) + " to " + to_string(goal.position)); } - const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks); + const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks, env.language); // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name}; @@ -124,7 +124,7 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ if (!facing || !route || route->empty()){ return Pokemon::outcome_failed("bad_legs", to_string(start)); } - const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks); + const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks, env.language); // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name}; @@ -146,7 +146,7 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ if (advance_text(env.console, env.context, BATTLE_TEXT_TIMEOUT, true) != TextEnd::BATTLE){ return Pokemon::outcome_failed("no_battle"); } - const BattleEnd end = fight_battle(env.console, env.context, env.supplies, BattleKind::TRAINER, env.checks); + const BattleEnd end = fight_battle(env.console, env.context, env.supplies, BattleKind::TRAINER, env.checks, env.language); if (end == BattleEnd::LOST && !step.may_lose){ return Pokemon::outcome_failed("blackout"); } @@ -163,7 +163,7 @@ Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ "Story: before the battle, HP {}, {}, {} Potions.", supplies.hp_red ? "red" : supplies.hurt ? "yellow" : "green", status_name(supplies.status), supplies.potions )); - recover_after_battle(env.console, env.context, supplies, env.checks); + recover_after_battle(env.console, env.context, supplies, env.checks, env.language); if (!supplies.hp_red && supplies.status == StatusCondition::NONE){ return Pokemon::outcome_ok(); } @@ -182,7 +182,7 @@ Outcome shop(StoryEnv& env){ // Viridian Mart before the Boulder Badge (pokefirered ViridianCity_Mart_Items): // POKE BALL, POTION (300), ANTIDOTE (100), PARLYZ HEAL (200). 2000 of the // 3000 a new game starts with, plus the rival's prize. - buy_items(env.console, env.context, {{1, 5, "potion"}, {2, 3, "antidote"}, {3, 1, "parlyz-heal"}}, env.checks); + buy_items(env.console, env.context, {{1, 5, "potion"}, {2, 3, "antidote"}, {3, 1, "parlyz-heal"}}, env.checks, env.language); env.supplies.potions += 5; env.supplies.antidotes += 3; env.supplies.parlyz_heals += 1; @@ -191,7 +191,7 @@ Outcome shop(StoryEnv& env){ } // The counts from the bag, not from the orders: a wrong row once bought // Parlyz Heals for Antidotes unnoticed (console B, 2026-11-01). - const std::vector rows = read_items_pocket(env.console, env.context); + const std::vector rows = read_items_pocket(env.console, env.context, env.language); if (rows.empty()){ env.console.log("Story: couldn't read the Items pocket; keeping the counts ordered.", COLOR_ORANGE); return Pokemon::outcome_ok(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 8a4245561d..3c6ed03440 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -127,6 +127,9 @@ struct StoryEnv{ // Whether the game has a save to reload. bool has_save = false; StoryChecks checks = StoryChecks::THOROUGH; + // The game's language, for reading item names. In one the readers have + // no names for, the checks fall back to positions and counts. + Language language = Language::English; }; // The checkpoint `data` as events, saving at its end. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index 0713ead5c8..227a17303f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -10,6 +10,8 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Logging/AbstractLogger.h" #include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/Language.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattle.h" @@ -84,6 +86,19 @@ UnitTestResult test_pocket_rows(Logger&){ return true; } +// In a language the reader has no names for, nothing is read, so the +// checks fall back to positions instead of failing. +UnitTestResult test_unread_language(Logger& logger){ + const ImageRGB32 screen(1920, 1080); + if (!read_item_list_name(logger, Language::Japanese, screen, 0).empty()){ + return "Read an item name in Japanese."; + } + if (!read_bag_pocket(logger, Language::Japanese, screen).empty()){ + return "Read bag rows in Japanese."; + } + return true; +} + } @@ -91,6 +106,7 @@ UnitTestResult test_pocket_rows(Logger&){ void add_tests_AutoStoryItems(UnitTestDatabase& database){ database.add("Mart cursor stays on the row bought", test_mart_cursor); database.add("Items pocket rows", test_pocket_rows); + database.add("no item names read in a language without them", test_unread_language); } From c63cfacc07dd1bc245153e3ed479a1af69cc7636 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 11:59:17 -0800 Subject: [PATCH 37/75] FRLG AutoStory: refuse a save from somewhere other than the start checkpoint's A run started at 00.08 loaded the Pewter Center save and walked the forest's legs inside the Center: every leg to a wall "succeeded" against the Center's walls (console B, 2026-11-01). After loading the save, the program now opens START, SAVE and reads the place on the save card (blue, at the card's top), answers NO, and stops with a UserSetupError when it isn't where the start checkpoint begins: "The save is in pewter-city, but checkpoint 00.08 starts in viridian-forest". A card it can't read (as in a language it has no names for) is logged and let pass. The reader knows Pallet Town to Pewter City in English; its box is measured on a capture of the card. Tests check that every checkpoint's start has a place on the card, and that nothing is read in Japanese. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Menus/PokemonFRLG_SaveCardReader.cpp | 95 +++++++++++++++++++ .../Menus/PokemonFRLG_SaveCardReader.h | 41 ++++++++ .../AutoStory/PokemonFRLG_AutoStory.cpp | 30 ++++++ .../PokemonFRLG_AutoStoryActions.cpp | 16 ++++ .../AutoStory/PokemonFRLG_AutoStoryActions.h | 6 ++ .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 16 ++++ .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 4 + .../PokemonFRLG_AutoStoryItems_Tests.cpp | 4 + .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 21 ++++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 10 files changed, 235 insertions(+) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp new file mode 100644 index 0000000000..9bfd7249f7 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp @@ -0,0 +1,95 @@ +/* Save Card Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Common/Cpp/Color.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_SaveCardReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// The title's blue, about (30, 80, 225) on the capture. +const std::vector& BLUE_TEXT_FILTERS(){ + static const std::vector filters{ + {combine_rgb(0, 30, 150), combine_rgb(110, 150, 255)}, + {combine_rgb(0, 0, 120), combine_rgb(140, 180, 255)}, + }; + return filters; +} + +class PlaceNameMatcher : public OCR::SmallDictionaryMatcher{ +public: + static constexpr double MAX_LOG10P = -1.40; + static constexpr double MAX_LOG10P_SPREAD = 0.50; + + static const PlaceNameMatcher& instance(){ + static const PlaceNameMatcher matcher; + return matcher; + } + + std::string read(Logger& logger, Language language, const ImageViewRGB32& image) const{ + if (!languages()[language]){ + return ""; + } + const ImageRGB32 ready = preprocess_for_ocr(image); + const OCR::StringMatchResult result = match_substring_from_image_multifiltered( + &logger, language, ready, BLUE_TEXT_FILTERS(), + MAX_LOG10P, MAX_LOG10P_SPREAD, 0.01, 0.50 + ); + return result.results.empty() ? "" : result.results.begin()->second.token; + } + +private: + PlaceNameMatcher() + : SmallDictionaryMatcher(dictionary()) + {} + + static JsonObject dictionary(){ + JsonObject english; + for (const auto& [slug, name] : { + std::pair{"pallet-town", "Pallet Town"}, + {"viridian-city", "Viridian City"}, + {"viridian-forest", "Viridian Forest"}, + {"pewter-city", "Pewter City"}, + {"route-1", "Route 1"}, + {"route-2", "Route 2"}, + }){ + JsonArray names; + names.push_back(name); + english[slug] = std::move(names); + } + JsonObject json; + json["eng"] = std::move(english); + return json; + } +}; + +} + + +ImageFloatBox save_card_title_box(){ + return ImageFloatBox(8.0 / 240, 9.0 / 160, 114.0 / 240, 13.0 / 160); +} + +std::string read_save_card_location(Logger& logger, Language language, const ImageViewRGB32& screen){ + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + return PlaceNameMatcher::instance().read(logger, language, extract_box_reference(game, save_card_title_box())); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h new file mode 100644 index 0000000000..3c327d9e80 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h @@ -0,0 +1,41 @@ +/* Save Card Reader + * + * From: https://github.com/PokemonAutomation/ + * + * Reads where the game would be saved: the place name in blue at the top + * of the card the START menu's SAVE shows ("PALLET TOWN" over PLAYER, + * BADGES and TIME). It knows the places from a new game to Pewter City, + * in English only so far: in another language nothing is read. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_SaveCardReader_H +#define PokemonAutomation_PokemonFRLG_SaveCardReader_H + +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The card's title, as a fraction of the game screen. Measured on a +// capture of the card in Pallet Town (console B, 2026-11-01): the name +// spans x 31 to 96, y 11 to 19 of the 240x160 screen, centered. +ImageFloatBox save_card_title_box(); + +// The place on the save card: "pallet-town", "viridian-city", +// "viridian-forest", "pewter-city", "route-1" or "route-2"; empty if it +// can't be read, as in a language the reader has no names for. +std::string read_save_card_location(Logger& logger, Language language, const ImageViewRGB32& screen); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 6c63d0a04d..f37a5d79c1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -81,6 +81,35 @@ AutoStory::AutoStory() } +// The save loaded must be the one checkpoint `first` starts from: one left +// by an earlier checkpoint (a run that failed before saving) would start +// it in the wrong place (console B, 2026-11-01: 00.09 on the forest's +// save). Checked on the SAVE card; a card that can't be read is let pass. +static void check_save_place( + SingleSwitchProgramEnvironment& env, ProControllerContext& context, + const std::vector& checkpoints, size_t first, Language language +){ + const StoryCheckpoint& checkpoint = checkpoints[first]; + const std::string expected = checkpoint.start ? save_card_place(checkpoint.start->map) : ""; + if (expected.empty()){ + return; + } + // The START menu as the checkpoint before left it. + const std::string place = read_save_place(env.console, context, checkpoints[first - 1].menu, language); + if (place.empty()){ + env.console.log("Couldn't read the save card's place; starting " + checkpoint.id + " anyway.", COLOR_ORANGE); + return; + } + if (place != expected){ + throw UserSetupError( + env.console, + "The save is in " + place + ", but checkpoint " + checkpoint.id + " starts in " + expected + + " (" + checkpoint.start->map + "). Start at the checkpoint the save is for." + ); + } + env.console.log("The save is in " + place + ", where " + checkpoint.id + " starts."); +} + void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ const std::vector& checkpoints = story_checkpoints(); const size_t first = START_CHECKPOINT - 1; @@ -97,6 +126,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex env.console.log("Loading the save for " + checkpoints[first].id + "."); soft_reset(env.console, context); story.has_save = true; + check_save_place(env, context, checkpoints, first, story.language); } Pokemon::Segment segment = make_story_segment(checkpoints, story); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index 6f18982f1a..a45ea62dfc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -20,6 +20,7 @@ #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_SelectionArrowDetector.h" @@ -396,6 +397,21 @@ void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu console.log("Saved."); } +std::string read_save_place(ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language){ + open_start_menu_row(console, context, menu, start_menu_save_row(menu)); + std::string place; + if (wait_for_yes_no(console, context, 5000ms)){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + place = screen ? read_save_card_location(console, language, screen) : ""; + dump_debug_image(console, "AutoStory/save", "card-" + (place.empty() ? std::string("unread") : place), screen); + } + // NO, then out of the menu. + press(context, BUTTON_B, 1000ms); + mash_until_overworld(console, context, 20000ms); + return place; +} + void set_options(ConsoleHandle& console, ProControllerContext& context, StartMenu menu){ console.log("Options: text speed FAST, battle style SET."); open_start_menu_row(console, context, menu, start_menu_option_row(menu)); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index 3eb926ee5e..4fdb1d0a1b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -15,6 +15,7 @@ #define PokemonAutomation_PokemonFRLG_AutoStoryActions_H #include +#include #include #include "Common/Cpp/Time.h" #include "CommonFramework/Language.h" @@ -91,6 +92,11 @@ void face_wall(ProControllerContext& context, Pokemon::Direction direction); // grows. Returns to the overworld. void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu menu); +// From the overworld: the place the START menu's SAVE card names (see +// read_save_card_location()), then NO, back to the overworld. Empty if it +// can't be read. +std::string read_save_place(ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language); + // From the overworld: OPTION, text speed FAST, battle style SET (no // "Will you switch?" between a trainer's Pokemon). Returns to the // overworld. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index cd6ff836b1..0d138bc068 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -279,6 +279,22 @@ Pokemon::Pose to_pose(const StoryPose& pose){ return ret; } +std::string save_card_place(const std::string& map){ + // The longer names first: "ViridianForest" before "ViridianCity". + static const std::pair PLACES[] = { + {"PalletTown", "pallet-town"}, + {"ViridianForest", "viridian-forest"}, + {"ViridianCity", "viridian-city"}, + {"PewterCity", "pewter-city"}, + }; + for (const auto& [prefix, place] : PLACES){ + if (map.rfind(prefix, 0) == 0){ + return place; + } + } + return ""; +} + std::optional> fixed_route( const std::vector& maps, const MapPosition& start, const std::vector& legs ){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 3c6ed03440..f886212f59 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -104,6 +104,10 @@ const std::vector& story_maps(); Pokemon::Pose to_pose(const StoryPose& pose); +// The place the save card names for a save on `map` (see +// read_save_card_location()), or empty for a map whose place isn't known. +std::string save_card_place(const std::string& map); + // `legs` from `start` as route steps for the walker, each checked against // the map: nothing if a step is blocked or leaves the map. A leg ends "to // wall" if the next step its way is blocked. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index 227a17303f..97d31eb6a1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -12,6 +12,7 @@ #include "Common/Cpp/TestRunners/UnitTest.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonFramework/Language.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattle.h" @@ -96,6 +97,9 @@ UnitTestResult test_unread_language(Logger& logger){ if (!read_bag_pocket(logger, Language::Japanese, screen).empty()){ return "Read bag rows in Japanese."; } + if (!read_save_card_location(logger, Language::Japanese, screen).empty()){ + return "Read a save card's place in Japanese."; + } return true; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index ea1c53e378..8059155e38 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -278,6 +278,26 @@ UnitTestResult test_pewter_gym_walks(){ ); } +// Every checkpoint that starts from a save has a place the save card +// names, so a save left elsewhere is caught before it runs; and the +// places of the starts that matter differ. +UnitTestResult test_save_places(){ + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + if (checkpoint.start && save_card_place(checkpoint.start->map).empty()){ + return checkpoint.id + " starts on " + checkpoint.start->map + ", which has no save card place."; + } + } + if (save_card_place("ViridianForest") != "viridian-forest" || save_card_place("ViridianCity_Mart") != "viridian-city" + || save_card_place("PewterCity_PokemonCenter_1F") != "pewter-city" || save_card_place("PalletTown_ProfessorOaksLab") != "pallet-town" + ){ + return "Wrong save card places."; + } + if (!save_card_place("Route22").empty()){ + return "A place for a map the table doesn't use."; + } + return true; +} + UnitTestResult test_unique_names(){ for (const StoryCheckpoint& checkpoint : story_checkpoints()){ for (size_t i = 0; i < checkpoint.steps.size(); i++){ @@ -297,6 +317,7 @@ UnitTestResult test_unique_names(){ void add_tests_AutoStory(UnitTestDatabase& database){ database.add("every route plans, and checkpoints chain", test_routes_and_chain); database.add("step names are unique per checkpoint", test_unique_names); + database.add("every save has a place on the save card", test_save_places); database.add("Pewter Gym walks", test_pewter_gym_walks); } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 00d693c624..e784f78cd6 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1729,6 +1729,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyMenuDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyMenuDetector.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryDetector.cpp From 97454c1e9dd2a47755fe1aa6d46faea5fd9ef2ad Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 12:37:06 -0800 Subject: [PATCH 38/75] FRLG AutoStory: the shared start and end dropdowns and AutoStory stats The program's integer START/END options give way to the shared story run options' checkpoint dropdowns (#122), labelled from the table ("00.09 Pewter Gym: Camper Liam, then Brock"), and it counts the shared AutoStoryStats (#45): a segment per run, the checkpoints passed and the reloads. The reload and log hooks move into a helper, keeping program() under the function size limit. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStory.cpp | 106 +++++++++++------- .../AutoStory/PokemonFRLG_AutoStory.h | 8 +- 2 files changed, 70 insertions(+), 44 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 81aa0472a9..a6c3b4aa6c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -9,6 +9,7 @@ #include "CommonFramework/Exceptions/OperationFailedException.h" #include "CommonFramework/Notifications/ProgramNotifications.h" #include "Pokemon/Pokemon_Strings.h" +#include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" #include "Pokemon/Navigation/Pokemon_StorySegments.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "PokemonFRLG_AutoStoryEvents.h" @@ -33,21 +34,27 @@ AutoStory_Descriptor::AutoStory_Descriptor() ) {} +std::unique_ptr AutoStory_Descriptor::make_stats() const{ + return std::make_unique(); +} + + +namespace{ + +// The start and end dropdowns' entries: the table's checkpoints, 00.01 to +// 00.09. The options hold a reference to it. +const StringSelectDatabase& checkpoint_database(){ + static const StringSelectDatabase database = Pokemon::story_checkpoint_database(story_checkpoints()); + return database; +} + +} + AutoStory::AutoStory() - : START_CHECKPOINT( - "Start at checkpoint 00.0N:
1: new game, 2: bedroom, 3: Pallet Town, 4: Oak's Lab, " - "5: after the rival's battle, 6: Viridian Mart, 7: Pokedex, 8: Viridian Forest's entrance, 9: Pewter Center.", - LockMode::LOCK_WHILE_RUNNING, - 1, 9, 1, 1 - ) - , END_CHECKPOINT( - "End after checkpoint 00.0N:
9 ends with the Boulder Badge.", - LockMode::LOCK_WHILE_RUNNING, - 1, 9, 9, 9 - ) + : RUN(checkpoint_database()) , NEW_GAME_FROM_TITLE( "New game from the title screen:
The game is on its title screen with no save data. " - "Needed to start at 1. Otherwise the program loads the save, which must be the one the start checkpoint begins from.", + "Needed to start at 00.01. Otherwise the program loads the save, which must be the one the start checkpoint begins from.", LockMode::LOCK_WHILE_RUNNING, true ) @@ -56,10 +63,8 @@ AutoStory::AutoStory() &NOTIFICATION_ERROR_FATAL, }) { - PA_ADD_OPTION(START_CHECKPOINT); - PA_ADD_OPTION(END_CHECKPOINT); + PA_ADD_OPTION(RUN); PA_ADD_OPTION(NEW_GAME_FROM_TITLE); - PA_ADD_OPTION(RETRIES); PA_ADD_OPTION(NOTIFICATIONS); } @@ -93,10 +98,48 @@ static void check_save_place( env.console.log("The save is in " + place + ", where " + checkpoint.id + " starts."); } +namespace{ + +// A failed attempt reloads the last save, with the supplies it had; the +// engine's lines go to the console's log. +Pokemon::SegmentHooks story_hooks(SingleSwitchProgramEnvironment& env, StoryEnv& story){ + Pokemon::SegmentHooks hooks; + hooks.reload = [&story](Pokemon::RunState&){ + if (!story.has_save){ + return Pokemon::outcome_failed("no_save", "nothing saved yet"); + } + try{ + soft_reset(story.console, story.context); + }catch (OperationFailedException& e){ + return Pokemon::outcome_failed("reload_failed", e.message()); + } + story.supplies = story.saved_supplies; + return Pokemon::outcome_ok(); + }; + hooks.log = [&env](const std::string& line){ + env.console.log(line); + }; + return hooks; +} + +// The shared AutoStory stats for one run: a segment, the checkpoints it +// passed and the reloads after failed attempts. +void count_run(SingleSwitchProgramEnvironment& env, const Pokemon::SegmentReport& report){ + Pokemon::AutoStoryStats& stats = env.current_stats(); + stats.m_segment++; + for (const Pokemon::CheckpointRun& run : report.runs){ + stats.m_checkpoint += run.passed ? 1 : 0; + } + stats.m_reset += report.reloads; + env.update_stats(); +} + +} + void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ const std::vector& checkpoints = story_checkpoints(); - const size_t first = START_CHECKPOINT - 1; - const size_t last = END_CHECKPOINT - 1; + const size_t first = RUN.start_index(); + const size_t last = RUN.end_index(); if (first > last || last >= checkpoints.size()){ throw UserSetupError(env.console, "The start checkpoint must not come after the end checkpoint."); } @@ -104,7 +147,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex throw UserSetupError(env.console, "Checkpoint 00.01 starts a new game: start on the title screen with no save."); } - StoryEnv story{env.console, context, checkpoints[first].supplies, checkpoints[first].supplies, false, RETRIES.checks()}; + StoryEnv story{env.console, context, checkpoints[first].supplies, checkpoints[first].supplies, false, RUN.checks()}; if (!(first == 0 && NEW_GAME_FROM_TITLE)){ env.console.log("Loading the save for " + checkpoints[first].id + "."); soft_reset(env.console, context); @@ -113,33 +156,16 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex } StoryExecutor executor(story); - executor.set_checks(RETRIES.checks()); - // For #120's item-name reads (read_item_list_name()), which still read - // English; no other step reads text. - executor.set_language(RETRIES.language()); + executor.set_checks(RUN.checks()); + executor.set_language(RUN.language()); Pokemon::Segment segment = make_story_segment(checkpoints, executor); - Pokemon::SegmentHooks hooks; - hooks.reload = [&story](Pokemon::RunState&){ - if (!story.has_save){ - return Pokemon::outcome_failed("no_save", "nothing saved yet"); - } - try{ - soft_reset(story.console, story.context); - }catch (OperationFailedException& e){ - return Pokemon::outcome_failed("reload_failed", e.message()); - } - story.supplies = story.saved_supplies; - return Pokemon::outcome_ok(); - }; - hooks.log = [&env](const std::string& line){ - env.console.log(line); - }; - const Pokemon::SegmentPolicy policy = RETRIES.policy(); + Pokemon::SegmentHooks hooks = story_hooks(env, story); Pokemon::RunState state; const Pokemon::SegmentReport report = run_segment( - state, segment, Pokemon::SegmentRange{checkpoints[first].id, checkpoints[last].id}, policy, hooks + state, segment, Pokemon::SegmentRange{checkpoints[first].id, checkpoints[last].id}, RUN.policy(), hooks ); + count_run(env, report); if (!report.completed){ throw OperationFailedException( ErrorReportMode::NO_ERROR_REPORT, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h index b5652767ba..e92eb74549 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h @@ -14,7 +14,6 @@ #include "Common/Cpp/Options/BooleanCheckBoxOption.h" #include "Common/Cpp/Options/EnumDropdownOption.h" -#include "Common/Cpp/Options/SimpleIntegerOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "Pokemon/Options/Pokemon_StoryRunOptions.h" @@ -28,6 +27,7 @@ namespace PokemonFRLG{ class AutoStory_Descriptor : public SingleSwitchProgramDescriptor{ public: AutoStory_Descriptor(); + virtual std::unique_ptr make_stats() const override; }; class AutoStory : public SingleSwitchProgramInstance{ @@ -41,10 +41,10 @@ class AutoStory : public SingleSwitchProgramInstance{ ) override{} private: - SimpleIntegerOption START_CHECKPOINT; - SimpleIntegerOption END_CHECKPOINT; + // The start and end checkpoints, attempts, checks and language, as in + // every game's AutoStory. + Pokemon::StoryRunOptions RUN; BooleanCheckBoxOption NEW_GAME_FROM_TITLE; - Pokemon::StoryRunOptions RETRIES; EventNotificationsOption NOTIFICATIONS; }; From f91daf8dce438d8174e1dd742d1e70597fadffee Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 13:11:17 -0800 Subject: [PATCH 39/75] FRLG AutoStory: count the run with the shared record_story_stats() Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStory.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index a6c3b4aa6c..a2319a706a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -122,17 +122,6 @@ Pokemon::SegmentHooks story_hooks(SingleSwitchProgramEnvironment& env, StoryEnv& return hooks; } -// The shared AutoStory stats for one run: a segment, the checkpoints it -// passed and the reloads after failed attempts. -void count_run(SingleSwitchProgramEnvironment& env, const Pokemon::SegmentReport& report){ - Pokemon::AutoStoryStats& stats = env.current_stats(); - stats.m_segment++; - for (const Pokemon::CheckpointRun& run : report.runs){ - stats.m_checkpoint += run.passed ? 1 : 0; - } - stats.m_reset += report.reloads; - env.update_stats(); -} } @@ -165,7 +154,8 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex const Pokemon::SegmentReport report = run_segment( state, segment, Pokemon::SegmentRange{checkpoints[first].id, checkpoints[last].id}, RUN.policy(), hooks ); - count_run(env, report); + Pokemon::record_story_stats(env.current_stats(), report); + env.update_stats(); if (!report.completed){ throw OperationFailedException( ErrorReportMode::NO_ERROR_REPORT, From 86b4aec052c124ed04b342cb8f9c14439ffd82dc Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 13:27:20 -0800 Subject: [PATCH 40/75] FRLG AutoStory: the walker's wall check runs with Thorough checks only Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 19314c7fad..8c08769465 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -76,6 +76,12 @@ void log_arrival(StoryEnv& env, const std::string& label, const std::string& map env.console.log(Pokemon::ROUTE_LOG_TAG + Pokemon::route_arrived_line(label, {{map, tile}})); } +// The walker's check that each leg to a wall ended at it (a diagnostic): +// with Thorough checks only, as Fast trusts the walk. +WallCheck wall_check(const StoryEnv& env){ + return env.checks == StoryChecks::THOROUGH ? WallCheck::TAP : WallCheck::SKIP; +} + Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ const std::vector tiles = Pokemon::tiles_of(state.pose); if (tiles.size() != 1 || state.pose.certainty != Pokemon::PoseCertainty::TILE){ @@ -103,7 +109,7 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks, env.language); // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. - const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name}; + const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name, .wall_check = wall_check(env)}; walk_overworld_route(env.console, env.context, *route, facing, interrupts, &planning); log_arrival(env, step.name, target->map, target->tile); const std::optional end_facing = route->empty() ? facing : std::optional(route->back().facing_after); @@ -127,7 +133,7 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks, env.language); // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. - const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name}; + const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name, .wall_check = wall_check(env)}; walk_overworld_route(env.console, env.context, *route, facing, interrupts, &planning); log_arrival(env, step.name, route->back().end.map, route->back().end.point); return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after})); From d45367e4791b9e91e63fb837ba3e1ec0fef4ecc2 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 14:19:14 -0800 Subject: [PATCH 41/75] FRLG AutoStory: include the story engine from Pokemon/AutoStory Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStory.cpp | 4 ++-- .../Programs/AutoStory/PokemonFRLG_AutoStoryActions.h | 2 +- .../Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 2 +- .../Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h | 10 +++++----- .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index a2319a706a..3b18cc3e72 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -8,9 +8,9 @@ #include "Common/Cpp/Exceptions.h" #include "CommonFramework/Exceptions/OperationFailedException.h" #include "CommonFramework/Notifications/ProgramNotifications.h" -#include "Pokemon/Pokemon_Strings.h" #include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" -#include "Pokemon/Navigation/Pokemon_StorySegments.h" +#include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/Pokemon_Strings.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStoryTable.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index a6a69240dd..c72d13942c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -22,8 +22,8 @@ #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StorySteps.h" #include "Pokemon/Navigation/Pokemon_Grid.h" -#include "Pokemon/Navigation/Pokemon_StorySteps.h" namespace PokemonAutomation{ namespace NintendoSwitch{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 8c08769465..dceb6b7951 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -9,8 +9,8 @@ #include #include "CommonFramework/Exceptions/OperationFailedException.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "Pokemon/Navigation/Pokemon_RouteLog.h" -#include "Pokemon/Navigation/Pokemon_TilePose.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 94070af3a1..8f99e5ab20 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -3,9 +3,9 @@ * From: https://github.com/PokemonAutomation/ * * The FRLG story as data for the shared story engine - * (Pokemon/Navigation/Pokemon_StoryEvents.h, Pokemon_StorySegments.h). + * (Pokemon/AutoStory/Pokemon_StoryEvents.h, Pokemon_StorySegments.h). * A checkpoint is a list of the shared StorySteps - * (Pokemon/Navigation/Pokemon_StorySteps.h), each one kind of event (a + * (Pokemon/AutoStory/Pokemon_StorySteps.h), each one kind of event (a * route, a talk, text read to its end, a YES/NO, a battle, the nurse, the * Mart); StoryExecutor does each kind on the console, and * make_story_segment() turns the table into engine checkpoints. Routes @@ -25,9 +25,9 @@ #include #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" -#include "Pokemon/Navigation/Pokemon_StoryEvents.h" -#include "Pokemon/Navigation/Pokemon_StorySegments.h" -#include "Pokemon/Navigation/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryEvents.h" +#include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/AutoStory/Pokemon_StorySteps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "PokemonFRLG_AutoStoryActions.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index 7b950008eb..af4ba44ed0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -21,8 +21,8 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" -#include "Pokemon/Navigation/Pokemon_StorySegments.h" -#include "Pokemon/Navigation/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/AutoStory/Pokemon_StorySteps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "PokemonFRLG_AutoStoryTable.h" From 583d958e2eb445393bd091c39b0b6f4e3a934c4c Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 14:33:15 -0800 Subject: [PATCH 42/75] FRLG AutoStory: what code health asks for The executor's and the simulation fake's step-kind overrides are protected, as the shared executor declares them (#122); the table's walks say WildBattles::FIGHT instead of a defaulted bool; the battle loop's body is braced on its own lines; and the panel list keeps its length. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG/PokemonFRLG_Panels.cpp | 1 - .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 5 ++++- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 1 + .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 1 + .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 22 ++++++++++++------- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp index 4321d038f4..14585143c8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp @@ -59,7 +59,6 @@ PanelListFactory::PanelListFactory() std::vector PanelListFactory::make_panels() const{ std::vector ret; - ret.emplace_back("---- Settings ----"); ret.emplace_back(make_OptionsPanel()); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 571471987c..fe8f7deade 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -280,7 +280,10 @@ class BattleLoop{ m_kind == BattleKind::TRAINER ? "Battle: fighting a trainer." : m_kind == BattleKind::WILD_FIGHT ? "Battle: fighting a wild Pokemon." : "Battle: running from a wild Pokemon." ); - while (!step()){} + bool over = false; + while (!over){ + over = step(); + } m_console.log(std::format("Battle: over after {} turns{}.", m_turns, m_lost ? ", the starter fainted" : "")); return m_lost ? BattleEnd::LOST : BattleEnd::WON; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 8f99e5ab20..0177bde020 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -121,6 +121,7 @@ class StoryExecutor : public Pokemon::StoryStepExecutor{ virtual Pokemon::Outcome run(Pokemon::RunState& state, const StoryStep& step) override; +protected: virtual Pokemon::Outcome new_game(Pokemon::RunState& state, const StoryStep& step) override; virtual Pokemon::Outcome options(Pokemon::RunState& state, const StoryStep& step) override; virtual Pokemon::Outcome route(Pokemon::RunState& state, const StoryStep& step) override; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index af4ba44ed0..56f3269033 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -101,6 +101,7 @@ class FakeGame : public Pokemon::StoryStepExecutor{ } return Pokemon::StoryStepExecutor::run(state, step); } +protected: virtual Outcome route(RunState& state, const StoryStep& step) override{ return walk_to(state.pose, step); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 767f62d27f..f86b160b33 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -47,6 +47,12 @@ StoryCheckpoint row( return checkpoint; } +// What a walk does about wild Pokemon: runs, or fights them for EXP. +enum class WildBattles{ + RUN, + FIGHT, +}; + StoryStep make(StoryStepKind kind, std::string name, std::string why){ StoryStep step; step.kind = kind; @@ -55,10 +61,10 @@ StoryStep make(StoryStepKind kind, std::string name, std::string why){ return step; } -StoryStep route(std::string name, Pokemon::Pose target, std::string why, bool fight_wild = false){ +StoryStep route(std::string name, Pokemon::Pose target, std::string why, WildBattles wild = WildBattles::RUN){ StoryStep step = make(StoryStepKind::ROUTE, std::move(name), std::move(why)); step.target = std::move(target); - step.fight_wild = fight_wild; + step.fight_wild = wild == WildBattles::FIGHT; return step; } @@ -87,10 +93,10 @@ StoryStep battle(std::string name, Pokemon::Pose pose_after, bool may_lose, std: return step; } -StoryStep legs(std::string name, std::vector legs, std::string why, bool fight_wild = false){ +StoryStep legs(std::string name, std::vector legs, std::string why, WildBattles wild = WildBattles::RUN){ StoryStep step = make(StoryStepKind::LEGS, std::move(name), std::move(why)); step.legs = std::move(legs); - step.fight_wild = fight_wild; + step.fight_wild = wild == WildBattles::FIGHT; return step; } @@ -204,8 +210,8 @@ StoryCheckpoint forest(){ // east one). Rick (47, 45) sees (42..46, 45), so the last leg meets // his battle and is held on to its wall after it. The by-hand run's // detour west to (13, 46) and back is dropped. - legs("forest_east", {{EAST, 1}, {NORTH, 4}, {EAST, 14}, {NORTH, 15}}, "up the east side to (44, 43)", true), - route("forest_north", at(FOREST, 39, 25), "north part", true), + legs("forest_east", {{EAST, 1}, {NORTH, 4}, {EAST, 14}, {NORTH, 15}}, "up the east side to (44, 43)", WildBattles::FIGHT), + route("forest_north", at(FOREST, 39, 25), "north part", WildBattles::FIGHT), // To the gate by legs that end on walls, which the walker holds again // after a battle instead of estimating where it stopped: planned // routes with open legs lost the player in the north of the forest @@ -213,8 +219,8 @@ StoryCheckpoint forest(){ legs("forest_exit", { {NORTH, 10}, {WEST, 12}, {SOUTH, 10}, {WEST, 6}, {NORTH, 20}, {SOUTH, 1}, {WEST, 10}, {SOUTH, 27}, {WEST, 8}, {NORTH, 20}, {EAST, 1}, - }, "walls all the way to the gate's column", true), - route("forest_gate", at(FOREST_GATE, 7, 10, NORTH), "north onto the exit, arriving on the gate's mat", true), + }, "walls all the way to the gate's column", WildBattles::FIGHT), + route("forest_gate", at(FOREST_GATE, 7, 10, NORTH), "north onto the exit, arriving on the gate's mat", WildBattles::FIGHT), // Out of the forest, wild battles are run from; trainers are still fought. route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center"), heal("heal_pewter"), From 37b375a961985ade6b15f909ad6addcb34646c10 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 15:11:59 -0800 Subject: [PATCH 43/75] FRLG AutoStory: the story's status lines on the video overlay Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 3b18cc3e72..47ce2571af 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -8,6 +8,7 @@ #include "Common/Cpp/Exceptions.h" #include "CommonFramework/Exceptions/OperationFailedException.h" #include "CommonFramework/Notifications/ProgramNotifications.h" +#include "CommonFramework/VideoPipeline/VideoOverlay.h" #include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" #include "Pokemon/AutoStory/Pokemon_StorySegments.h" #include "Pokemon/Pokemon_Strings.h" @@ -119,6 +120,10 @@ Pokemon::SegmentHooks story_hooks(SingleSwitchProgramEnvironment& env, StoryEnv& hooks.log = [&env](const std::string& line){ env.console.log(line); }; + // The checkpoint and the step under way, for whoever watches the stream. + hooks.status = [&env](const std::string& line){ + env.console.overlay().add_log(line); + }; return hooks; } From 3358b2a605c75e5caf80cf022f9b86eb4e9e7572 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 16:46:16 -0800 Subject: [PATCH 44/75] FRLG AutoStory: the wall beside a stop is a TileKind::WALL #117 moved FRLG onto the shared Pokemon::MapData, whose tiles are Pokemon::TileKind. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index dceb6b7951..25af58fdde 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -319,7 +319,7 @@ std::optional> fixed_route( std::optional wall_beside(const MapData& map, const TilePos& tile){ for (Direction direction : {Direction::WEST, Direction::EAST, Direction::NORTH, Direction::SOUTH}){ const TilePos next = tile.next(direction); - if (in_bounds(map, next) && tile_at(map, next) == Tile::WALL && object_at(map, next) == nullptr){ + if (in_bounds(map, next) && tile_at(map, next) == TileKind::WALL && object_at(map, next) == nullptr){ return direction; } } From 07952b092e5bf732baa523b75aee6a8bc47c3abc Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 01:47:07 -0800 Subject: [PATCH 45/75] FRLG AutoStory: walk story routes with walk_overworld_route_with_recovery() #119 moved the route walk that finds the player again out of #118's walk_overworld_route() into its own function; the story's ROUTE and LEGS steps call it with the same planning as before. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 25af58fdde..b1ace4127d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -12,7 +12,7 @@ #include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "Pokemon/Navigation/Pokemon_RouteLog.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" -#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_AutoStoryEvents.h" @@ -110,7 +110,7 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name, .wall_check = wall_check(env)}; - walk_overworld_route(env.console, env.context, *route, facing, interrupts, &planning); + walk_overworld_route_with_recovery(env.console, env.context, *route, planning, facing, interrupts); log_arrival(env, step.name, target->map, target->tile); const std::optional end_facing = route->empty() ? facing : std::optional(route->back().facing_after); return Pokemon::outcome_ok(to_pose(StoryPose{target->map, target->tile, end_facing})); @@ -134,7 +134,7 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name, .wall_check = wall_check(env)}; - walk_overworld_route(env.console, env.context, *route, facing, interrupts, &planning); + walk_overworld_route_with_recovery(env.console, env.context, *route, planning, facing, interrupts); log_arrival(env, step.name, route->back().end.map, route->back().end.point); return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after})); } From 510aa66f60f1f39c4a6b9eeae1b4f3c60c2c332f Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 11:37:50 -0800 Subject: [PATCH 46/75] FRLG AutoStory: read bag counts with the digit templates; unread counts are some The Items pocket read "potion x-1; antidote x-1" for 5 Potions and 3 Antidotes (console B, 2026-11-02): Tesseract on each waterfilled digit fails on the 5 and the 3, whose strokes the GBA font joins only at a corner, so each falls apart into pieces. Read the counts with the FRLG digit reader and the stat boxes' templates instead (same font, same cream background), and add the capture as an image test. set_from_bag() took the unread -1 for 0, so every battle after the Mart thought the bag empty and the starter fainted unhealed. A row with an unread count still holds at least one: keep the count bought, or 1, and log it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Menus/PokemonFRLG_ItemListReader.cpp | 55 ++++++++++++++++++- .../Menus/PokemonFRLG_ItemListReader.h | 5 ++ .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 + .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 17 +++++- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 5 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 7 ++- .../PokemonFRLG_AutoStoryItems_Tests.cpp | 42 ++++++++++++++ 7 files changed, 126 insertions(+), 7 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp index cf63b79a6a..8dcfe96233 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp @@ -4,12 +4,14 @@ * */ +#include #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonFramework/Language.h" -#include "CommonTools/OCR/OCR_NumberReader.h" #include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" +#include "Tests/ImageUnitTest.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_DigitReader.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_ItemListReader.h" @@ -100,12 +102,61 @@ std::vector read_bag_pocket(Logger& logger, Language language, const Ima break; } const ImageViewRGB32 count = extract_box_reference(game_box(screen), bag_item_count_box(row)); - rows.push_back(BagRow{item, OCR::read_number_waterfill(logger, count, 0xff000000, 0xff808080)}); + // Not Tesseract on each waterfilled digit: the font joins some strokes + // only at a corner, so the 5 and the 3 fell apart into pieces and read + // as nothing (console B, 2026-11-02). The stat boxes' templates are + // the same digits on the same cream. + rows.push_back(BagRow{item, read_digits_waterfill_template(logger, count, DigitTemplateType::StatBox)}); } return rows; } +namespace{ + +// A capture of the Items pocket, read from the top. +class Test_BagPocket : public ImageUnitTest{ +public: + Test_BagPocket(const std::string& image, std::vector expected) + : ImageUnitTest("PokemonFRLG::ItemListReader - " + image, {image}) + , m_expected(std::move(expected)) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const std::vector rows = read_bag_pocket(logger, Language::English, images[0]); + std::string expected; + for (const BagRow& row : m_expected){ + expected += std::format(" {} x{};", row.item, row.count); + } + std::string read; + for (const BagRow& row : rows){ + read += std::format(" {} x{};", row.item, row.count); + } + if (read != expected){ + return "Expected" + expected + " read" + (read.empty() ? std::string(" nothing") : read); + } + return true; + } + +private: + const std::vector m_expected; +}; + +} + +void add_tests_ItemListReader(UnitTestDatabase& database){ + // Console B, 2026-11-02, after the Viridian Mart: the 5 and the 3 read + // as nothing before the digit templates. + database.add( + "PokemonFRLG/ItemListReader/ItemsPocket_Potion5_Antidote3_ParlyzHeal1.png", + std::vector{{"potion", 5}, {"antidote", 3}, {"parlyz-heal", 1}} + ); +} + + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h index e8d536e565..4100eeffb7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h @@ -16,6 +16,7 @@ #include #include #include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "CommonFramework/Language.h" @@ -41,6 +42,7 @@ std::string read_item_list_name(Logger& logger, Language language, const ImageVi struct BagRow{ std::string item; + // -1 if the count couldn't be read: the row still holds at least one. int count = 0; }; @@ -50,6 +52,9 @@ struct BagRow{ std::vector read_bag_pocket(Logger& logger, Language language, const ImageViewRGB32& screen); +void add_tests_ItemListReader(UnitTestDatabase& database); + + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index f28ad8f7e5..ad251f62ab 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -17,6 +17,7 @@ #include "Inference/Dialogs/PokemonFRLG_PrizeSelectDetector.h" #include "Inference/Map/PokemonFRLG_PokemonLeagueDetectors.h" #include "Inference/Menus/PokemonFRLG_BagDetector.h" +#include "Inference/Menus/PokemonFRLG_ItemListReader.h" #include "Inference/Menus/PokemonFRLG_PartyEmptySlotDetector.h" #include "Inference/Menus/PokemonFRLG_PartyHeldItemDetector.h" #include "Inference/Menus/PokemonFRLG_PartyMenuDetector.h" @@ -294,6 +295,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_HallOfFameSavingDetector(database); add_tests_BattleMoveSelectionArrow(database); add_tests_BagDetector(database); + add_tests_ItemListReader(database); add_tests_ExitWildBattle(database); add_tests_OverworldMaps(database); add_tests_OverworldRoute(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index fe8f7deade..8ad4ccaa46 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -703,18 +703,29 @@ int item_row(const Supplies& supplies, const std::string& item){ return -1; } -void set_from_bag(Supplies& supplies, const std::vector& rows){ +std::vector set_from_bag(Supplies& supplies, const std::vector& rows){ + const Supplies before = supplies; supplies.potions = 0; supplies.antidotes = 0; supplies.parlyz_heals = 0; supplies.pocket.clear(); + std::vector unread; for (const BagRow& row : rows){ supplies.pocket.push_back(row.item); int* slot = count_slot(supplies, row.item); - if (slot != nullptr){ - *slot = std::max(row.count, 0); + if (slot == nullptr){ + continue; + } + if (row.count > 0){ + *slot = row.count; + continue; } + // Taking an unread count for none left the starter unhealed at + // 9 HP until it fainted (console B, 2026-11-02). + *slot = std::max(item_count(before, row.item), 1); + unread.push_back(row.item); } + return unread; } std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context, Language language){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index fb4eb3cd70..6e9f22f15e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -85,7 +85,10 @@ int item_count(const Supplies& supplies, const std::string& item); int item_row(const Supplies& supplies, const std::string& item); // Sets the counts and the pocket's order from the Items pocket as read. -void set_from_bag(Supplies& supplies, const std::vector& rows); +// A row whose count couldn't be read still holds at least one: it keeps +// the count known before (the order bought), or 1. Returns those rows' +// items, for the log. +std::vector set_from_bag(Supplies& supplies, const std::vector& rows); // From the overworld: opens the Items pocket, reads it, and closes the // bag again. Empty if nothing could be read. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index b1ace4127d..9c8b397893 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -229,7 +229,12 @@ Outcome shop(StoryEnv& env, const StoryStep& step){ env.console.log("Story: couldn't read the Items pocket; keeping the counts ordered.", COLOR_ORANGE); return Pokemon::outcome_ok(); } - set_from_bag(env.supplies, rows); + for (const std::string& item : set_from_bag(env.supplies, rows)){ + env.console.log(std::format( + "Story: couldn't read how many {} the bag holds; counting {}.", + item, item_count(env.supplies, item) + ), COLOR_ORANGE); + } return Pokemon::outcome_ok(); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index 97d31eb6a1..aa376e8901 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -6,6 +6,7 @@ * */ +#include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Logging/AbstractLogger.h" @@ -87,6 +88,46 @@ UnitTestResult test_pocket_rows(Logger&){ return true; } +// A count the bag reader couldn't read (-1) is never taken for none: the +// row still holds some, so it keeps the count bought, or 1 with none +// known, and the battle's checks (a count above 0, a row) still use it. +UnitTestResult test_unread_counts(Logger&){ + Supplies bought; + bought.potions = 5; + bought.antidotes = 3; + bought.parlyz_heals = 1; + const std::vector rows{{"potion", -1}, {"antidote", -1}, {"parlyz-heal", 1}}; + const std::vector unread = set_from_bag(bought, rows); + if (unread != std::vector{"potion", "antidote"}){ + return "Expected the Potion and Antidote counts reported unread."; + } + if (bought.potions != 5 || bought.antidotes != 3 || bought.parlyz_heals != 1){ + return std::format( + "Expected 5 Potions, 3 Antidotes, 1 Parlyz Heal kept from the order, got {}, {}, {}.", + bought.potions, bought.antidotes, bought.parlyz_heals + ); + } + + Supplies unknown; + unknown.potions = 0; + unknown.antidotes = 0; + unknown.parlyz_heals = 0; + set_from_bag(unknown, rows); + if (item_count(unknown, "potion") <= 0 || item_count(unknown, "antidote") <= 0){ + return std::format( + "Expected unread counts with none known to count as some, got {} Potions, {} Antidotes.", + unknown.potions, unknown.antidotes + ); + } + if (item_row(unknown, "potion") != 0 || item_row(unknown, "antidote") != 1 || item_row(unknown, "parlyz-heal") != 2){ + return std::format( + "Expected rows 0, 1, 2 with unread counts, got {}, {}, {}.", + item_row(unknown, "potion"), item_row(unknown, "antidote"), item_row(unknown, "parlyz-heal") + ); + } + return true; +} + // In a language the reader has no names for, nothing is read, so the // checks fall back to positions instead of failing. UnitTestResult test_unread_language(Logger& logger){ @@ -110,6 +151,7 @@ UnitTestResult test_unread_language(Logger& logger){ void add_tests_AutoStoryItems(UnitTestDatabase& database){ database.add("Mart cursor stays on the row bought", test_mart_cursor); database.add("Items pocket rows", test_pocket_rows); + database.add("unread bag counts count as some", test_unread_counts); database.add("no item names read in a language without them", test_unread_language); } From cb3bc036a87b250e504ae3a36d50dfc5334d0e00 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 12:46:31 -0800 Subject: [PATCH 47/75] FRLG AutoStory: 00.10 the Running Shoes, 00.11 a first run 00.10 walks out of Pewter Gym to (45, 21), steps onto the aide's top trigger (46, 21) and clears his scene, ending there facing north, as measured by hand on console B. 00.11 starts from that save and runs row 21 west to the wall at (6, 21), logging the run's pace. A ROUTE or LEGS with the "run" variant walks with B held; from 00.11 on every one does, which a table test holds. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStory.cpp | 2 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 8 ++- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 9 +++ .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 30 ++++++++ .../AutoStory/PokemonFRLG_AutoStoryTable.h | 7 +- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 72 +++++++++++++++++++ 6 files changed, 122 insertions(+), 6 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 47ce2571af..192ade4046 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -43,7 +43,7 @@ std::unique_ptr AutoStory_Descriptor::make_stats() const{ namespace{ // The start and end dropdowns' entries: the table's checkpoints, 00.01 to -// 00.09. The options hold a reference to it. +// 00.11. The options hold a reference to it. const StringSelectDatabase& checkpoint_database(){ static const StringSelectDatabase database = Pokemon::story_checkpoint_database(story_checkpoints()); return database; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 9c8b397893..9c416d9850 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -110,7 +110,7 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name, .wall_check = wall_check(env)}; - walk_overworld_route_with_recovery(env.console, env.context, *route, planning, facing, interrupts); + walk_overworld_route_with_recovery(env.console, env.context, *route, planning, facing, interrupts, move_speed(step)); log_arrival(env, step.name, target->map, target->tile); const std::optional end_facing = route->empty() ? facing : std::optional(route->back().facing_after); return Pokemon::outcome_ok(to_pose(StoryPose{target->map, target->tile, end_facing})); @@ -134,7 +134,7 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name, .wall_check = wall_check(env)}; - walk_overworld_route_with_recovery(env.console, env.context, *route, planning, facing, interrupts); + walk_overworld_route_with_recovery(env.console, env.context, *route, planning, facing, interrupts, move_speed(step)); log_arrival(env, step.name, route->back().end.map, route->back().end.point); return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after})); } @@ -258,6 +258,10 @@ const std::vector& story_maps(){ return maps; } +MoveSpeed move_speed(const StoryStep& step){ + return step.variant == RUN_VARIANT ? MoveSpeed::RUN : MoveSpeed::WALK; +} + Pokemon::Pose to_pose(const StoryPose& pose){ return Pokemon::tile_pose(pose.map, {pose.tile}, pose.facing); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 0177bde020..da3bc0eff7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -30,6 +30,7 @@ #include "Pokemon/AutoStory/Pokemon_StorySteps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattle.h" @@ -51,6 +52,14 @@ struct StoryPose{ std::optional facing; }; +// The variant of a ROUTE or LEGS step that runs, with B held: the player +// has the Running Shoes (00.10 on). +inline const std::string RUN_VARIANT = "run"; + +// How `step`, a ROUTE or LEGS, moves the player: RUN_VARIANT runs. +MoveSpeed move_speed(const StoryStep& step); + + // A shared checkpoint with what FRLG adds to it. struct StoryCheckpoint : public Pokemon::StoryCheckpoint{ // The healing items at its start, for a run that loads its save. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index f86b160b33..d94a59d66b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -26,6 +26,7 @@ const char* const VIRIDIAN_MART = "ViridianCity_Mart"; const char* const VIRIDIAN_CENTER = "ViridianCity_PokemonCenter_1F"; const char* const FOREST = "ViridianForest"; const char* const FOREST_GATE = "Route2_ViridianForest_NorthEntrance"; +const char* const PEWTER = "PewterCity"; const char* const PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; const char* const GYM = "PewterCity_Gym"; @@ -100,6 +101,12 @@ StoryStep legs(std::string name, std::vector legs, std::string why, Wi return step; } +// `step`, a ROUTE or LEGS, run with B held: from the Running Shoes on. +StoryStep running(StoryStep step){ + step.variant = RUN_VARIANT; + return step; +} + StoryStep new_game_intro(Pokemon::Pose pose_after, std::string why){ StoryStep step = make(StoryStepKind::NEW_GAME, "intro", std::move(why)); step.pose_after = std::move(pose_after); @@ -246,12 +253,35 @@ StoryCheckpoint brock(){ }); } +StoryCheckpoint running_shoes(){ + return row("00.10", "Pewter: the Running Shoes from Oak's aide", at(GYM, 6, 6, NORTH), {}, StartMenu::FULL, { + // Brock's win sets VAR_MAP_SCENE_PEWTER_CITY to 1 and shows the aide at + // (46, 20); his triggers are (46, 21..23) (PewterCity map.json). The + // Gym guide's triggers at (42..43, 21..23) need the scene at 0. + route("before_aide_trigger", at(PEWTER, 45, 21, EAST), "out of the Gym, east along row 21, short of the top trigger"), + step_into("aide_trigger", EAST, "onto (46, 21), below the aide"), + // RunningShoesAideTriggerTop: the aide talks from (46, 20), no YES/NO; + // the player only turns up. He walks off and is removed; FLAG_SYS_B_DASH + // is set (console B, 2026-11-02: about 20 B presses to the overworld). + scene("shoes_from_aide", at(PEWTER, 46, 21, NORTH), "\"Oh, PLAYER!\" ... the Running Shoes; ends facing north"), + }); +} + +StoryCheckpoint first_run(){ + // From here on every route and leg runs. Route 3 isn't among the story's + // maps yet, so this checkpoint only tests running on one long leg. + return row("00.11", "Pewter: a run to a wall, to time running", at(PEWTER, 46, 21, NORTH), {}, StartMenu::FULL, { + running(legs("run_west", {{WEST, 40}}, "row 21 west to the wall at (6, 21): logs the run's pace")), + }); +} + } const std::vector& story_checkpoints(){ static const std::vector checkpoints{ new_game(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), + running_shoes(), first_run(), }; return checkpoints; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index 68adcd5141..0e45e21787 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -2,8 +2,9 @@ * * From: https://github.com/PokemonAutomation/ * - * FireRed from a new game to the Boulder Badge, as story checkpoints - * 00.01 to 00.09, each saved at its end. Taken from a by-hand run on + * FireRed from a new game to the Boulder Badge and the Running Shoes, as + * story checkpoints 00.01 to 00.11, each saved at its end. From 00.11 on + * every route and leg runs. Taken from a by-hand run on * console B (2026-11-01) and the pokefirered map scripts. * */ @@ -20,7 +21,7 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Checkpoints 00.01 to 00.09, in order. +// Checkpoints 00.01 to 00.11, in order. const std::vector& story_checkpoints(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index ac5442c2b6..07c8e3beb5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -291,6 +291,75 @@ UnitTestResult test_pewter_gym_walks(){ ); } +// 00.10: out of the Gym to the aide's top trigger. The route keeps off his +// three trigger tiles (46, 21..23), which would start the scene a step +// early, and the step east from its end lands on (46, 21). +UnitTestResult test_pewter_aide_walk(){ + const MapPosition gym{"PewterCity_Gym", {6, 6}}; + const MapPosition goal{"PewterCity", {45, 21}}; + const std::optional> route = plan_overworld_route( + story_maps(), gym, RouteGoal{goal, Direction::EAST}, default_route_costs(), Direction::NORTH + ); + if (!route || route->empty()){ + return "No route from " + to_string(gym) + " to " + to_string(goal) + "."; + } + MapPosition from = gym; + for (const RouteStep& step : *route){ + if (step.action != RouteAction::WALK){ + continue; + } + for (const MapPosition& tile : leg_tiles(story_maps(), from, step)){ + if (tile.map == "PewterCity" && tile.point.x == 46 && tile.point.y >= 21 && tile.point.y <= 23){ + return "The route crosses the aide's trigger " + to_string(tile) + ":" + describe(*route); + } + } + from = step.end; + } + if (route->back().end != goal){ + return "Expected the route to end at " + to_string(goal) + ", got " + to_string(route->back().end) + "."; + } + const MapData& pewter = *find_map_named("PewterCity"); + if (classify_step(pewter, PlayerState{{45, 21}, elevation_at(pewter, {45, 21}), false}, Direction::EAST) != StepKind::WALK){ + return "Can't step east from (45, 21) onto the trigger (46, 21)."; + } + return true; +} + +// Every ROUTE and LEGS after the Running Shoes (00.10) runs; none before. +UnitTestResult test_runs_after_shoes(){ + bool has_shoes = false; + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + for (const StoryStep& step : checkpoint.steps){ + if (step.kind != StoryStepKind::ROUTE && step.kind != StoryStepKind::LEGS){ + continue; + } + const MoveSpeed expected = has_shoes ? MoveSpeed::RUN : MoveSpeed::WALK; + if (move_speed(step) != expected){ + return checkpoint.id + "/" + step.name + ": expected to " + move_speed_name(expected) + ", it would " + move_speed_name(move_speed(step)) + "."; + } + } + has_shoes = has_shoes || checkpoint.id == "00.10"; + } + if (!has_shoes){ + return "No checkpoint 00.10, where the player gets the Running Shoes."; + } + return true; +} + +// 00.11's run: one leg west along row 21, to the wall at (6, 21). +UnitTestResult test_first_run(){ + const MapPosition start{"PewterCity", {46, 21}}; + const std::optional> route = fixed_route(story_maps(), start, {{Direction::WEST, 40}}); + if (!route || route->size() != 1){ + return "Expected one leg west from " + to_string(start) + "."; + } + const RouteStep& leg = route->front(); + if (!leg.to_wall || leg.wild || leg.end != MapPosition{"PewterCity", {6, 21}}){ + return "Expected a leg to the wall at (6, 21), off the grass, got:" + describe(*route); + } + return true; +} + // Every checkpoint that starts from a save has a place the save card // names, so a save left elsewhere is caught before it runs; and the // places of the starts that matter differ. @@ -343,6 +412,9 @@ void add_tests_AutoStory(UnitTestDatabase& database){ database.add("every save has a place on the save card", test_save_places); database.add("every checkpoint lints clean", test_lint); database.add("Pewter Gym walks", test_pewter_gym_walks); + database.add("Pewter: to the aide's trigger", test_pewter_aide_walk); + database.add("routes run after the Running Shoes", test_runs_after_shoes); + database.add("Pewter: the first run", test_first_run); } From a7c85bafe37a31c67d46f1d817fef7321be480db Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 12:47:45 -0800 Subject: [PATCH 48/75] FRLG AutoStory tests: the table has 11 checkpoints Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 07c8e3beb5..c62094cae2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -204,8 +204,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po UnitTestResult test_routes_and_chain(){ const std::vector& checkpoints = story_checkpoints(); - if (checkpoints.size() != 9 || checkpoints[0].start){ - return "Expected 9 checkpoints, the first from a new game."; + if (checkpoints.size() != 11 || checkpoints[0].start){ + return "Expected 11 checkpoints, the first from a new game."; } StoryPose pose; for (size_t c = 0; c < checkpoints.size(); c++){ From f4ac51f47e8a19a9c8318c5d5df49393dbf70ec7 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 14:05:37 -0800 Subject: [PATCH 49/75] FRLG AutoStory: confirm the save, and check a reload's save card save_game() waited 3 s for the overwrite YES/NO, then mashed. A new game over another game's save shows four WARNING pages first and its YES/NO starts on NO, so the mash answered NO and "Saved." was logged anyway (console B, 2026-11-02). The save dialog is now read screen by screen (SaveDialog): every YES/NO gets YES, pages get A, B is never pressed, and the save counts only once the overworld is back; the START menu coming back or a timeout fails it. A reload after a failed attempt loaded whatever save there was, unchecked: 00.02 then walked the bedroom's route in Pewter City. The save card check now runs after every load, not only at the program's start, and finds SAVE from the menu's own length so a save with another START menu reads too. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStory.cpp | 34 ++-- .../PokemonFRLG_AutoStoryActions.cpp | 168 ++++++++++++++++-- .../AutoStory/PokemonFRLG_AutoStoryActions.h | 53 +++++- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 25 +++ .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 14 ++ .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 100 +++++++++++ 6 files changed, 351 insertions(+), 43 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 192ade4046..73c1448168 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -74,29 +74,16 @@ AutoStory::AutoStory() // by an earlier checkpoint (a run that failed before saving) would start // it in the wrong place (console B, 2026-11-01: 00.09 on the forest's // save). Checked on the SAVE card; a card that can't be read is let pass. -static void check_save_place( - SingleSwitchProgramEnvironment& env, ProControllerContext& context, - const std::vector& checkpoints, size_t first, Language language +static void check_start_save( + SingleSwitchProgramEnvironment& env, StoryEnv& story, const StoryCheckpoint& checkpoint ){ - const StoryCheckpoint& checkpoint = checkpoints[first]; - const std::string expected = checkpoint.start ? save_card_place(checkpoint.start->map) : ""; - if (expected.empty()){ + if (!checkpoint.start){ return; } - // The START menu as the checkpoint before left it. - const std::string place = read_save_place(env.console, context, checkpoints[first - 1].menu, language); - if (place.empty()){ - env.console.log("Couldn't read the save card's place; starting " + checkpoint.id + " anyway.", COLOR_ORANGE); - return; - } - if (place != expected){ - throw UserSetupError( - env.console, - "The save is in " + place + ", but checkpoint " + checkpoint.id + " starts in " + expected + - " (" + checkpoint.start->map + "). Start at the checkpoint the save is for." - ); + const std::string error = check_save_place(story, checkpoint.start->map); + if (!error.empty()){ + throw UserSetupError(env.console, error + " Start at the checkpoint " + checkpoint.id + " the save is for."); } - env.console.log("The save is in " + place + ", where " + checkpoint.id + " starts."); } namespace{ @@ -109,8 +96,15 @@ Pokemon::SegmentHooks story_hooks(SingleSwitchProgramEnvironment& env, StoryEnv& if (!story.has_save){ return Pokemon::outcome_failed("no_save", "nothing saved yet"); } + // The save reloaded must be where the checkpoint starts: a save + // that didn't happen leaves an older one (console B, 2026-11-02: + // 00.02 walked the bedroom's route in Pewter City). try{ soft_reset(story.console, story.context); + const std::string error = check_save_place(story, story.start_map); + if (!error.empty()){ + return Pokemon::outcome_failed("wrong_save", error); + } }catch (OperationFailedException& e){ return Pokemon::outcome_failed("reload_failed", e.message()); } @@ -146,7 +140,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex env.console.log("Loading the save for " + checkpoints[first].id + "."); soft_reset(env.console, context); story.has_save = true; - check_save_place(env, context, checkpoints, first, story.language); + check_start_save(env, story, checkpoints[first]); } StoryExecutor executor(story); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index a45ea62dfc..da2d4b7ce5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -86,13 +86,13 @@ bool wait_for_yes_no(ConsoleHandle& console, ProControllerContext& context, Mill return wait_until(console, context, timeout, {yes}) >= 0; } -// The START menu's cursor onto `row`, read from the arrow. As -// move_cursor_to_position(), for a menu of any length. -bool move_start_cursor(ConsoleHandle& console, ProControllerContext& context, int rows, int row){ +// The START menu row the arrow is on, from the top, as the closest of the +// first `rows` rows. Nothing if no arrow shows. +std::optional start_cursor_row(ConsoleHandle& console, ProControllerContext& context, int rows){ SelectionArrowWatcher arrow(COLOR_RED, &console.overlay(), MENU_ARROW_BOX); context.wait_for_all_requests(); if (wait_until(console, context, 2000ms, {arrow}) < 0){ - return false; + return std::nullopt; } const double arrow_y = arrow.last_detected().y + arrow.last_detected().height / 2; int current = 0; @@ -105,9 +105,19 @@ bool move_start_cursor(ConsoleHandle& console, ProControllerContext& context, in current = c; } } - console.log(std::format("START menu: cursor on row {}, moving to row {}.", current + 1, row + 1)); - const int down = (row - current + rows) % rows; - const int up = (current - row + rows) % rows; + return current; +} + +// The START menu's cursor onto `row`, read from the arrow. As +// move_cursor_to_position(), for a menu of any length. +bool move_start_cursor(ConsoleHandle& console, ProControllerContext& context, int rows, int row){ + const std::optional current = start_cursor_row(console, context, rows); + if (!current){ + return false; + } + console.log(std::format("START menu: cursor on row {}, moving to row {}.", *current + 1, row + 1)); + const int down = (row - *current + rows) % rows; + const int up = (*current - row + rows) % rows; for (int c = 0; c < std::min(down, up); c++){ tap(context, down <= up ? DPAD_DOWN : DPAD_UP); } @@ -115,6 +125,29 @@ bool move_start_cursor(ConsoleHandle& console, ProControllerContext& context, in return true; } +// The START menu's cursor onto SAVE, in a menu of any length: up past the +// top wraps to EXIT, the last row, whose place gives the length; SAVE is +// two above it. +bool move_start_cursor_to_save(ConsoleHandle& console, ProControllerContext& context){ + const int most = start_menu_rows(StartMenu::FULL); + const std::optional current = start_cursor_row(console, context, most); + if (!current){ + return false; + } + for (int c = 0; c <= *current; c++){ + tap(context, DPAD_UP); + } + const std::optional last = start_cursor_row(console, context, most); + if (!last){ + return false; + } + console.log(std::format("START menu: {} rows, moving to SAVE.", *last + 1)); + tap(context, DPAD_UP); + tap(context, DPAD_UP); + context.wait_for_all_requests(); + return true; +} + void open_start_menu_row(ConsoleHandle& console, ProControllerContext& context, StartMenu menu, int row){ open_start_menu(console, context); if (!move_start_cursor(console, context, start_menu_rows(menu), row)){ @@ -377,6 +410,105 @@ void face_wall(ProControllerContext& context, Direction direction){ context.wait_for_all_requests(); } +SaveAction SaveDialog::next(SaveScreen screen){ + if (screen != SaveScreen::NOTHING){ + m_nothing_seen = 0; + } + switch (screen){ + case SaveScreen::YES_NO: + m_paged_since_yes = false; + return SaveAction::ANSWER_YES; + case SaveScreen::PAGED_TEXT: + m_paged_since_yes = true; + return SaveAction::NEXT_PAGE; + case SaveScreen::TEXT: + return SaveAction::WAIT; + case SaveScreen::START_MENU: + return SaveAction::FAIL_CANCELLED; + case SaveScreen::NOTHING: + // Twice in a row: not the frame between two boxes. + if (++m_nothing_seen < 2){ + return SaveAction::WAIT; + } + return m_paged_since_yes ? SaveAction::FAIL_ERROR : SaveAction::CHECK_OVERWORLD; + } + return SaveAction::WAIT; +} + +namespace{ + +// The four WARNING pages over another game's save, at the new game's text +// speed, the save itself and its 60-frame pause, with room to spare. +constexpr Milliseconds SAVE_TIMEOUT = 30000ms; + +SaveScreen read_save_screen(const ImageViewRGB32& screen){ + if (yes_no_cursor(screen)){ + return SaveScreen::YES_NO; + } + // Before the message boxes: the menu can show a help box under it. + if (StartMenuDetector(COLOR_RED).detect(screen)){ + return SaveScreen::START_MENU; + } + if (AdvanceWhiteDialogDetector(COLOR_RED).detect(screen)){ + return SaveScreen::PAGED_TEXT; + } + if (WhiteDialogDetector(COLOR_RED).detect(screen)){ + return SaveScreen::TEXT; + } + return SaveScreen::NOTHING; +} + +// From the save card's first YES/NO to the overworld, as SaveDialog says. +void run_save_dialog(ConsoleHandle& console, ProControllerContext& context){ + SaveDialog dialog; + const WallClock deadline = current_time() + SAVE_TIMEOUT; + while (current_time() < deadline){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + if (!screen){ + pbf_wait(context, POLL); + continue; + } + switch (dialog.next(read_save_screen(screen))){ + case SaveAction::WAIT: + pbf_wait(context, POLL); + break; + case SaveAction::ANSWER_YES: + // The overwrite over another game's save starts on NO. + if (yes_no_cursor(screen) == false){ + tap(context, DPAD_UP); + } + console.log("Save: YES."); + press(context, BUTTON_A, 1000ms); + break; + case SaveAction::NEXT_PAGE: + press(context, BUTTON_A, 500ms); + break; + case SaveAction::CHECK_OVERWORLD: + if (overworld_shows(console, context)){ + console.log("Saved."); + return; + } + break; + case SaveAction::FAIL_CANCELLED: + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "save_game(): the START menu came back: the save was cancelled.", console + ); + case SaveAction::FAIL_ERROR: + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "save_game(): a message after the last YES: the save failed.", console + ); + } + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("save_game(): not back on the overworld {} s after saving.", SAVE_TIMEOUT.count() / 1000), + console + ); +} + +} + void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu menu){ console.log("Saving the game."); open_start_menu_row(console, context, menu, start_menu_save_row(menu)); @@ -386,19 +518,19 @@ void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu ErrorReportMode::SEND_ERROR_REPORT, "save_game(): no YES/NO to save.", console ); } - press(context, BUTTON_A, 1500ms); - // "There is already a saved file. Is it okay to overwrite it?", except - // for the first save. - if (wait_for_yes_no(console, context, 3000ms)){ - press(context, BUTTON_A, 1500ms); - } - pbf_wait(context, 4000ms); - mash_until_overworld(console, context, 30000ms); - console.log("Saved."); + context.wait_for_all_requests(); + dump_debug_image(console, "AutoStory/save", "save-card", console.video().snapshot()); + run_save_dialog(console, context); } -std::string read_save_place(ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language){ - open_start_menu_row(console, context, menu, start_menu_save_row(menu)); +std::string read_save_place(ConsoleHandle& console, ProControllerContext& context, Language language){ + open_start_menu(console, context); + if (!move_start_cursor_to_save(console, context)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, "START menu: no cursor.", console + ); + } + press(context, BUTTON_A, 1500ms); std::string place; if (wait_for_yes_no(console, context, 5000ms)){ context.wait_for_all_requests(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index c72d13942c..7d31e2c675 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -86,15 +86,58 @@ void step_once(ProControllerContext& context, Pokemon::Direction direction, std: // player must have a wall that way. void face_wall(ProControllerContext& context, Pokemon::Direction direction); -// From the overworld: SAVE, YES, and YES again to overwrite an older save. -// The menu's cursor is read, since the game remembers it and the menu -// grows. Returns to the overworld. +// The save dialog after SAVE, as pokefirered's start_menu.c runs it: +// "Would you like to save the game?" YES/NO (YES first). Then, over a save +// of this game, "There is already a saved file. Is it okay to overwrite +// it?" YES/NO (YES first); over another game's save (a new game), "WARNING! +// There is a different game file that is already saved." on four pages, +// ending "...overwrite the other save file?" YES/NO with NO first. Then +// "SAVING... DON'T TURN OFF THE POWER.", "PLAYER saved the game." and, +// without a press, the overworld. NO at any YES/NO brings the START menu +// back; a failed save shows "Save error." and waits for A held. +enum class SaveScreen{ + YES_NO, + // A message with the arrow for the next page. + PAGED_TEXT, + // A message without an arrow: SAVING, or saved. + TEXT, + START_MENU, + // No message and no menu: the overworld, or a frame between two boxes. + NOTHING, +}; +enum class SaveAction{ + WAIT, + ANSWER_YES, + NEXT_PAGE, + // Confirm the overworld (START opens the menu): the game is saved. + CHECK_OVERWORLD, + // The START menu is back: a YES/NO was answered NO. + FAIL_CANCELLED, + // A paged message after the last YES: "Save error." + FAIL_ERROR, +}; +// What save_game() does on each screen it reads after the save card's +// first YES/NO shows. Every YES/NO gets YES; B is never pressed. +class SaveDialog{ +public: + SaveAction next(SaveScreen screen); + +private: + bool m_paged_since_yes = false; + size_t m_nothing_seen = 0; +}; + +// From the overworld: SAVE, YES, and YES again to overwrite an older save +// (see SaveDialog). The menu's cursor is read, since the game remembers it +// and the menu grows. Returns to the overworld; throws +// OperationFailedException if the save wasn't made. void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu menu); // From the overworld: the place the START menu's SAVE card names (see // read_save_card_location()), then NO, back to the overworld. Empty if it -// can't be read. -std::string read_save_place(ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language); +// can't be read. The menu's length is read, not assumed, so a save made +// with another START menu (another checkpoint's) is read too. +std::string read_save_place(ConsoleHandle& console, ProControllerContext& context, Language language); // From the overworld: OPTION, text speed FAST, battle style SET (no // "Will you switch?" between a trainer's Pokemon). Returns to the diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 9c416d9850..a7ba0f0318 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -290,6 +290,14 @@ std::string save_card_place(const std::string& map){ return ""; } +std::string save_place_error(const std::string& start_map, const std::string& place){ + const std::string expected = save_card_place(start_map); + if (expected.empty() || place.empty() || place == expected){ + return ""; + } + return "The save is in " + place + ", but the checkpoint starts in " + expected + " (" + start_map + ")."; +} + std::optional> fixed_route( const std::vector& maps, const MapPosition& start, const std::vector& legs ){ @@ -401,10 +409,27 @@ Outcome StoryExecutor::ready(RunState& state, const StoryStep& step){ } +std::string check_save_place(StoryEnv& env, const std::string& start_map){ + if (save_card_place(start_map).empty()){ + return ""; + } + const std::string place = read_save_place(env.console, env.context, env.language); + if (place.empty()){ + env.console.log("Couldn't read the save card's place; going on.", COLOR_ORANGE); + return ""; + } + const std::string error = save_place_error(start_map, place); + if (error.empty()){ + env.console.log("The save is in " + place + ", where the checkpoint starts."); + } + return error; +} + Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& executor){ executor.set_menu(data.menu); Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); StoryEnv& env = executor.env(); + env.start_map = data.start ? data.start->map : ""; const StartMenu menu = data.menu; checkpoint.save = [&env, menu](RunState&){ return guarded([&]{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index da3bc0eff7..7e69e83bb9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -81,6 +81,11 @@ std::optional story_pose(const Pokemon::Pose& pose); // read_save_card_location()), or empty for a map whose place isn't known. std::string save_card_place(const std::string& map); +// Why a save whose card names `place` can't start a checkpoint that starts +// on `start_map`, or empty if it can: the places match, the card couldn't +// be read (empty `place`), or the map has no known place. +std::string save_place_error(const std::string& start_map, const std::string& place); + // `legs` from `start` as route steps for the walker, each checked against // the map: nothing if a step is blocked or leaves the map. A leg ends "to // wall" if the next step its way is blocked. @@ -112,8 +117,17 @@ struct StoryEnv{ // The game's language, for reading item names. In one the readers have // no names for, the checks fall back to positions and counts. Language language = Language::English; + // The map the checkpoint under way starts on, where its save is: a + // reload checks the save card against it. + std::string start_map; }; +// After a save is loaded for a checkpoint that starts on `start_map`: the +// save card's place, read from the START menu, against it, at every checks +// level. Empty if the save is there (or the card can't be read), else why +// not. +std::string check_save_place(StoryEnv& env, const std::string& start_map); + // Does FRLG's kinds of story step on the console. A console step that // fails is a failed Outcome, which the segment answers by reloading. class StoryExecutor : public Pokemon::StoryStepExecutor{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index c62094cae2..c9baf479c9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -9,6 +9,9 @@ */ #include +#include +#include +#include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" @@ -380,6 +383,101 @@ UnitTestResult test_save_places(){ return true; } +// A reload's save checked against the checkpoint's start: a save left in +// Pewter City (a new game whose save didn't happen) can't start 00.02 in +// the bedroom. The check takes no checks level: Fast runs it too. +UnitTestResult test_save_place_error(){ + struct Case{ + std::string start_map; + std::string place; + bool error; + }; + const Case CASES[] = { + {.start_map = "PalletTown_PlayersHouse_2F", .place = "pewter-city", .error = true}, + {.start_map = "PalletTown_PlayersHouse_2F", .place = "pallet-town", .error = false}, + // A card that can't be read is let pass. + {.start_map = "PalletTown_PlayersHouse_2F", .place = "", .error = false}, + {.start_map = "ViridianForest", .place = "viridian-city", .error = true}, + // A map with no known place isn't checked. + {.start_map = "Route22", .place = "pewter-city", .error = false}, + }; + for (const Case& c : CASES){ + const std::string error = save_place_error(c.start_map, c.place); + if (error.empty() == c.error){ + return "A save in \"" + c.place + "\" for a start on " + c.start_map + ": expected " + + (c.error ? "an error" : "no error") + ", got \"" + error + "\"."; + } + } + return true; +} + +const char* save_action_name(SaveAction action){ + switch (action){ + case SaveAction::WAIT: + return "WAIT"; + case SaveAction::ANSWER_YES: + return "ANSWER_YES"; + case SaveAction::NEXT_PAGE: + return "NEXT_PAGE"; + case SaveAction::CHECK_OVERWORLD: + return "CHECK_OVERWORLD"; + case SaveAction::FAIL_CANCELLED: + return "FAIL_CANCELLED"; + case SaveAction::FAIL_ERROR: + return "FAIL_ERROR"; + } + return "?"; +} + +// save_game()'s answers to the save dialogs of pokefirered's start_menu.c, +// screen by screen from the first YES/NO. +UnitTestResult test_save_dialog(){ + using S = SaveScreen; + using A = SaveAction; + struct Case{ + std::string name; + std::vector> screens; + }; + const std::vector CASES = { + { + .name = "first save", + .screens = {{S::YES_NO, A::ANSWER_YES}, {S::TEXT, A::WAIT}, {S::TEXT, A::WAIT}, {S::NOTHING, A::WAIT}, {S::NOTHING, A::CHECK_OVERWORLD}}, + }, + { + .name = "over this game's save", + .screens = {{S::YES_NO, A::ANSWER_YES}, {S::TEXT, A::WAIT}, {S::YES_NO, A::ANSWER_YES}, {S::TEXT, A::WAIT}, {S::NOTHING, A::WAIT}, {S::NOTHING, A::CHECK_OVERWORLD}}, + }, + { + // WARNING!, four pages, then the YES/NO that starts on NO. + .name = "a new game over another game's save", + .screens = { + {S::YES_NO, A::ANSWER_YES}, + {S::PAGED_TEXT, A::NEXT_PAGE}, {S::NOTHING, A::WAIT}, {S::PAGED_TEXT, A::NEXT_PAGE}, {S::PAGED_TEXT, A::NEXT_PAGE}, + {S::TEXT, A::WAIT}, {S::YES_NO, A::ANSWER_YES}, {S::TEXT, A::WAIT}, {S::NOTHING, A::WAIT}, {S::NOTHING, A::CHECK_OVERWORLD}, + }, + }, + { + .name = "cancelled: the START menu is back", + .screens = {{S::YES_NO, A::ANSWER_YES}, {S::TEXT, A::WAIT}, {S::START_MENU, A::FAIL_CANCELLED}}, + }, + { + .name = "Save error.", + .screens = {{S::YES_NO, A::ANSWER_YES}, {S::TEXT, A::WAIT}, {S::PAGED_TEXT, A::NEXT_PAGE}, {S::NOTHING, A::WAIT}, {S::NOTHING, A::FAIL_ERROR}}, + }, + }; + for (const Case& c : CASES){ + SaveDialog dialog; + for (size_t i = 0; i < c.screens.size(); i++){ + const SaveAction action = dialog.next(c.screens[i].first); + if (action != c.screens[i].second){ + return c.name + ", screen " + std::to_string(i + 1) + ": expected " + save_action_name(c.screens[i].second) + + ", got " + save_action_name(action) + "."; + } + } + } + return true; +} + UnitTestResult test_lint(){ for (const StoryCheckpoint& checkpoint : story_checkpoints()){ const std::vector problems = Pokemon::lint_story_checkpoint(checkpoint); @@ -410,6 +508,8 @@ void add_tests_AutoStory(UnitTestDatabase& database){ database.add("every route plans, and checkpoints chain", test_routes_and_chain); database.add("step names are unique per checkpoint", test_unique_names); database.add("every save has a place on the save card", test_save_places); + database.add("a reload's save is checked against the start", test_save_place_error); + database.add("save dialogs: every YES/NO is YES, a cancel fails", test_save_dialog); database.add("every checkpoint lints clean", test_lint); database.add("Pewter Gym walks", test_pewter_gym_walks); database.add("Pewter: to the aide's trigger", test_pewter_aide_walk); From c73763ddc414ce6bf08ce20ad11ce2b90397173d Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 14:20:46 -0800 Subject: [PATCH 50/75] FRLG AutoStory: pick the rival's first preset name from Oak's list The intro let A open the rival's keyboard (NEW NAME is the list's first row) and confirmed an empty name there. Now the cursor goes to the first preset name (GREEN in FireRed, RED in LeafGreen) and A picks it, as SID Helper does; a rival keyboard that still opens is logged and gets the old empty-name confirm. The list is read from pokefirered's oak_speech.c layout and told from the intro's YES/NO boxes in the same corner. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG_AutoStoryActions.cpp | 110 ++++++++++++++++-- .../AutoStory/PokemonFRLG_AutoStoryActions.h | 34 +++++- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 39 +++++++ 3 files changed, 172 insertions(+), 11 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index da2d4b7ce5..fe27df080e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -159,14 +159,21 @@ void open_start_menu_row(ConsoleHandle& console, ProControllerContext& context, } -// The new game's intro, from the title screen. Everything but the keyboard +// The new game's intro, from the title screen. Everything but the names // is advanced with A, which never hurts there (BOY is the default, YES to -// GREEN); B is never pressed outside the keyboard, since in the intro it -// goes back to the controls pages (console B, 2026-11-01). The controls -// pages read as a message box without an arrow, and the arrow at the end -// of Oak's lines may be missed, so a message box gets A every 1.5 s -// whatever it shows. On the keyboard, B deletes whatever a stray A typed -// and START jumps to OK, which confirms the empty name as the default. +// "So your name is ...?" and "Er, was it GREEN?"); B is never pressed +// outside the keyboard, since in the intro it goes back to the controls +// pages (console B, 2026-11-01). The controls pages read as a message box +// without an arrow, and the arrow at the end of Oak's lines may be missed, +// so a message box gets A every 1.5 s whatever it shows. The player's name +// is asked on the keyboard straight away: B deletes whatever a stray A +// typed and START jumps to OK, which confirms the empty name as the +// default. The rival's is asked on a list with NEW NAME first, where A +// would open the keyboard: the cursor goes to the first preset name (the +// game's default rival, GREEN in FireRed, RED in LeafGreen) and A picks +// it, then YES confirms it (pokefirered oak_speech.c). If the keyboard +// opens anyway, the list was missed, and the empty name is confirmed +// there instead, which also names the rival GREEN. class NewGameIntro{ public: NewGameIntro(ConsoleHandle& console, ProControllerContext& context) @@ -220,9 +227,9 @@ class NewGameIntro{ pbf_wait(m_context, POLL); return false; } - if (NamingScreenDetector(COLOR_RED).detect(screen)){ - enter_empty_name(); + if (names(screen)){ m_last_dialog = current_time(); + m_last_press = m_last_dialog; return false; } if (yes_no_cursor(screen) || WhiteDialogDetector(COLOR_RED).detect(screen)){ @@ -239,6 +246,55 @@ class NewGameIntro{ return quiet(screen, now); } + // True if a keyboard or the rival's name list showed and was handled. + bool names(const ImageViewRGB32& screen){ + IntroNameScreen shown = IntroNameScreen::OTHER; + std::optional list_row; + if (NamingScreenDetector(COLOR_RED).detect(screen)){ + shown = IntroNameScreen::KEYBOARD; + }else if (m_keyboards_seen > 0){ + // The list shows over a message box: look for it before the A + // every 1.5 s, which would open the keyboard. + list_row = rival_name_list_cursor(screen); + shown = list_row ? IntroNameScreen::RIVAL_LIST : IntroNameScreen::OTHER; + } + switch (intro_name_step(shown, m_keyboards_seen, m_presets_picked)){ + case IntroNameStep::PLAYER_KEYBOARD: + m_keyboards_seen++; + enter_empty_name(); + return true; + case IntroNameStep::RIVAL_KEYBOARD: + m_keyboards_seen++; + m_console.log("New game: the rival's keyboard opened, so the name list was missed.", COLOR_ORANGE); + enter_empty_name(); + return true; + case IntroNameStep::RIVAL_PRESET: + pick_rival_preset(*list_row); + return true; + case IntroNameStep::NONE: + return false; + } + return false; + } + + // Row 1 is the first preset name. The cursor is read again before A, so + // a dropped press is made up on the next look. + void pick_rival_preset(int row){ + if (row != 1){ + m_console.log(std::format("New game: the rival's name list, cursor on row {}, moving to the first preset name.", row)); + const DpadPosition direction = row < 1 ? DPAD_DOWN : DPAD_UP; + for (int c = 0; c < std::abs(row - 1); c++){ + tap(m_context, direction, 300ms); + } + m_context.wait_for_all_requests(); + return; + } + m_console.log("New game: the rival's name list, picking the first preset name."); + press(m_context, BUTTON_A, 2000ms); + m_context.wait_for_all_requests(); + m_presets_picked++; + } + // No message box and no keyboard: a fade, a pause in the speech, or // the bedroom. bool quiet(const ImageViewRGB32& screen, WallClock now){ @@ -275,11 +331,27 @@ class NewGameIntro{ WallClock m_last_dialog; WallClock m_last_press; bool m_dialog_seen = false; + size_t m_keyboards_seen = 0; + size_t m_presets_picked = 0; }; } +IntroNameStep intro_name_step(IntroNameScreen screen, size_t keyboards_seen, size_t presets_picked){ + switch (screen){ + case IntroNameScreen::KEYBOARD: + return keyboards_seen == 0 ? IntroNameStep::PLAYER_KEYBOARD : IntroNameStep::RIVAL_KEYBOARD; + case IntroNameScreen::RIVAL_LIST: + // The list only comes after the player's keyboard. + return keyboards_seen > 0 && presets_picked < RIVAL_PRESET_TRIES ? IntroNameStep::RIVAL_PRESET : IntroNameStep::NONE; + case IntroNameScreen::OTHER: + return IntroNameStep::NONE; + } + return IntroNameStep::NONE; +} + + int start_menu_rows(StartMenu menu){ switch (menu){ case StartMenu::BEFORE_POKEMON: @@ -309,6 +381,26 @@ std::optional yes_no_cursor(const ImageViewRGB32& screen){ return std::nullopt; } +std::optional rival_name_list_cursor(const ImageViewRGB32& screen){ + // On the 240x160 screen: the list's window spans x 16-112, y 16-96, and + // this box (x 64-100, y 36-46) is white there, right of the names and + // below NEW NAME. A YES/NO box's right frame runs through it. + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + if (!is_white(extract_box_reference(game, ImageFloatBox(0.267, 0.225, 0.15, 0.0625)))){ + return std::nullopt; + } + for (int row = 0; row < 5; row++){ + // The START menu's arrow box (window at x 176, y 8; the box starts + // 1.4 px left and 0.4 px below), moved to the list's cursor at + // x 16, y 17 + 16 * row. + const ImageFloatBox box(14.6 / 240, (17.4 + 16 * row) / 160, 0.0369231, 0.0778846); + if (SelectionArrowDetector(COLOR_RED, nullptr, box).detect(screen)){ + return row; + } + } + return std::nullopt; +} + bool overworld_shows(ConsoleHandle& console, ProControllerContext& context){ press(context, BUTTON_PLUS, 1200ms); context.wait_for_all_requests(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index 7d31e2c675..fbe4a643c1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -14,6 +14,7 @@ #ifndef PokemonAutomation_PokemonFRLG_AutoStoryActions_H #define PokemonAutomation_PokemonFRLG_AutoStoryActions_H +#include #include #include #include @@ -60,6 +61,34 @@ bool overworld_shows(ConsoleHandle& console, ProControllerContext& context); // one shows. std::optional yes_no_cursor(const ImageViewRGB32& screen); +// The arrow's row on Oak's list of rival names (NEW NAME, then four preset +// names), if the list shows. In pokefirered's oak_speech.c the list is a +// 12x10-tile window at tile (2, 2), rows 16 px apart, the cursor starting +// on NEW NAME. The intro's YES/NO boxes open in the same corner but are +// 6x4 tiles: the list is told from them by its white past their frame. +std::optional rival_name_list_cursor(const ImageViewRGB32& screen); + +// What shows in the new game's intro, as far as the names go. +enum class IntroNameScreen{ + OTHER, + KEYBOARD, + RIVAL_LIST, +}; +// What the new game's intro does about the names. The player's name is +// asked on a keyboard, always first; the rival's on the name list, where +// the first preset name is picked, as SID Helper does. A keyboard after +// the player's is the rival's, opened because the list was missed. +enum class IntroNameStep{ + NONE, + PLAYER_KEYBOARD, + RIVAL_PRESET, + RIVAL_KEYBOARD, +}; +// A preset picked returns to the list only after NO on "Er, was it ...?", +// so after this many picks A opens the keyboard instead. +constexpr size_t RIVAL_PRESET_TRIES = 3; +IntroNameStep intro_name_step(IntroNameScreen screen, size_t keyboards_seen, size_t presets_picked); + enum class TextEnd{ OVERWORLD, @@ -171,8 +200,9 @@ void buy_items( ); // From the title screen of a game with no save, to the bedroom: the -// controls pages, Oak's speech, BOY, and the default names for the player -// and the rival (an empty name confirmed). Returns on the overworld. +// controls pages, Oak's speech, BOY, the default name for the player (an +// empty name confirmed) and the rival's first preset name. Returns on the +// overworld. void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index c9baf479c9..8ea667798d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -14,8 +14,10 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryTable.h" namespace PokemonAutomation{ @@ -500,6 +502,42 @@ UnitTestResult test_unique_names(){ } return true; } +// The intro's names: the player's keyboard first, then the rival's list, +// where a preset is picked; a keyboard after the player's means the list +// was missed. +UnitTestResult test_intro_names(){ + struct Case{ + const char* what; + IntroNameScreen screen; + size_t keyboards_seen; + size_t presets_picked; + IntroNameStep expected; + }; + const std::vector cases{ + {.what = "the first keyboard", .screen = IntroNameScreen::KEYBOARD, .keyboards_seen = 0, .presets_picked = 0, .expected = IntroNameStep::PLAYER_KEYBOARD}, + {.what = "the list after the player's keyboard", .screen = IntroNameScreen::RIVAL_LIST, .keyboards_seen = 1, .presets_picked = 0, .expected = IntroNameStep::RIVAL_PRESET}, + {.what = "a list read before the player's keyboard", .screen = IntroNameScreen::RIVAL_LIST, .keyboards_seen = 0, .presets_picked = 0, .expected = IntroNameStep::NONE}, + {.what = "the second keyboard", .screen = IntroNameScreen::KEYBOARD, .keyboards_seen = 1, .presets_picked = 0, .expected = IntroNameStep::RIVAL_KEYBOARD}, + {.what = "a keyboard after a preset was picked", .screen = IntroNameScreen::KEYBOARD, .keyboards_seen = 1, .presets_picked = 1, .expected = IntroNameStep::RIVAL_KEYBOARD}, + {.what = "the list again after a NO", .screen = IntroNameScreen::RIVAL_LIST, .keyboards_seen = 1, .presets_picked = 1, .expected = IntroNameStep::RIVAL_PRESET}, + {.what = "the list after every try", .screen = IntroNameScreen::RIVAL_LIST, .keyboards_seen = 1, .presets_picked = RIVAL_PRESET_TRIES, .expected = IntroNameStep::NONE}, + {.what = "a message box", .screen = IntroNameScreen::OTHER, .keyboards_seen = 1, .presets_picked = 0, .expected = IntroNameStep::NONE}, + }; + for (const Case& c : cases){ + const IntroNameStep step = intro_name_step(c.screen, c.keyboards_seen, c.presets_picked); + if (step != c.expected){ + return std::string(c.what) + ": expected step " + std::to_string(static_cast(c.expected)) + + ", got " + std::to_string(static_cast(step)) + "."; + } + } + // A black screen is no list. + ImageRGB32 black(1920, 1080); + black.fill(0xff000000); + if (rival_name_list_cursor(black).has_value()){ + return "Read the rival's name list on a black screen."; + } + return true; +} } @@ -515,6 +553,7 @@ void add_tests_AutoStory(UnitTestDatabase& database){ database.add("Pewter: to the aide's trigger", test_pewter_aide_walk); database.add("routes run after the Running Shoes", test_runs_after_shoes); database.add("Pewter: the first run", test_first_run); + database.add("intro: names, the rival's from the list", test_intro_names); } From f4bbb71ded1ef893bbe6747fdd7cc02f25021896 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 14:27:47 -0800 Subject: [PATCH 51/75] FRLG AutoStory: set the options by reading them, not by blind presses A new game keeps the options of the save it replaces (pokefirered resets them only for an empty save), and RIGHT wraps, so the blind RIGHT presses turned an old save's FAST/SET into SLOW/SHIFT on console B. set_options() now reads TEXT SPEED and BATTLE STYLE, presses RIGHT until each shows FAST and SET, reads them again, and fails with a screenshot if a value can't be read. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Menus/PokemonFRLG_OptionMenuReader.cpp | 138 ++++++++++++++++++ .../Menus/PokemonFRLG_OptionMenuReader.h | 58 ++++++++ .../PokemonFRLG_AutoStoryActions.cpp | 83 ++++++++++- .../AutoStory/PokemonFRLG_AutoStoryActions.h | 16 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 2 +- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 39 +++++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 7 files changed, 329 insertions(+), 9 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp new file mode 100644 index 0000000000..e4c7dcbb46 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp @@ -0,0 +1,138 @@ +/* Option Menu Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Common/Cpp/Color.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_OptionMenuReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// option_menu.c: the window's top-left at pixel (16, 56), values from its +// x 130 and y 2 + 13 * row, cleared 70 wide before each is drawn. +constexpr double VALUE_LEFT = 16 + 130 - 2; +constexpr double VALUE_WIDTH = 70 + 4; +constexpr double ROW_TOP = 56 + 2; +constexpr double ROW_STEP = 13; +constexpr double ROW_HEIGHT = 13; + +// Peach letters with red edges, on white or the darkened rows' light gray: +// red stays high while green and blue stay below the background's. The +// item names to the left are dark gray, out of the box. +const std::vector& VALUE_TEXT_FILTERS(){ + static const std::vector filters{ + {combine_rgb(150, 0, 0), combine_rgb(255, 200, 160)}, + {combine_rgb(150, 0, 0), combine_rgb(255, 210, 180)}, + {combine_rgb(170, 0, 0), combine_rgb(255, 190, 140)}, + }; + return filters; +} + +struct OptionValue{ + const char* slug; + const char* english; +}; + +// One matcher per item, so a value is only matched against its own row's. +class OptionValueMatcher : public OCR::SmallDictionaryMatcher{ +public: + static constexpr double MAX_LOG10P = -1.40; + static constexpr double MAX_LOG10P_SPREAD = 0.50; + + explicit OptionValueMatcher(const std::vector& values) + : SmallDictionaryMatcher(dictionary(values)) + {} + + std::string read(Logger& logger, Language language, const ImageViewRGB32& image) const{ + if (!languages()[language]){ + return ""; + } + const ImageRGB32 ready = preprocess_for_ocr(image); + const OCR::StringMatchResult result = match_substring_from_image_multifiltered( + &logger, language, ready, VALUE_TEXT_FILTERS(), + MAX_LOG10P, MAX_LOG10P_SPREAD, 0.01, 0.50 + ); + return result.results.empty() ? "" : result.results.begin()->second.token; + } + +private: + static JsonObject dictionary(const std::vector& values){ + JsonObject english; + for (const OptionValue& value : values){ + JsonArray names; + names.push_back(value.english); + english[value.slug] = std::move(names); + } + JsonObject json; + json["eng"] = std::move(english); + return json; + } +}; + +const std::vector& text_speed_values(){ + static const std::vector values{{"slow", "Slow"}, {"mid", "Mid"}, {"fast", "Fast"}}; + return values; +} +const std::vector& battle_style_values(){ + static const std::vector values{{"shift", "Shift"}, {"set", "Set"}}; + return values; +} +std::vector slugs(const std::vector& values){ + std::vector ret; + for (const OptionValue& value : values){ + ret.emplace_back(value.slug); + } + return ret; +} + +const OptionValueMatcher& matcher(OptionMenuItem item){ + static const OptionValueMatcher text_speed(text_speed_values()); + static const OptionValueMatcher battle_style(battle_style_values()); + return item == OptionMenuItem::TEXT_SPEED ? text_speed : battle_style; +} + +} + + +const char* option_menu_name(OptionMenuItem item){ + return item == OptionMenuItem::TEXT_SPEED ? "TEXT SPEED" : "BATTLE STYLE"; +} + +size_t option_menu_row(OptionMenuItem item){ + // option_menu.c MENUITEM_TEXTSPEED, MENUITEM_BATTLESTYLE. + return item == OptionMenuItem::TEXT_SPEED ? 0 : 2; +} + +const std::vector& option_menu_values(OptionMenuItem item){ + static const std::vector text_speed = slugs(text_speed_values()); + static const std::vector battle_style = slugs(battle_style_values()); + return item == OptionMenuItem::TEXT_SPEED ? text_speed : battle_style; +} + +ImageFloatBox option_value_box(size_t row){ + return ImageFloatBox(VALUE_LEFT / 240, (ROW_TOP + ROW_STEP * row) / 160, VALUE_WIDTH / 240, ROW_HEIGHT / 160); +} + +std::string read_option_value(Logger& logger, Language language, const ImageViewRGB32& screen, OptionMenuItem item){ + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + const ImageViewRGB32 value = extract_box_reference(game, option_value_box(option_menu_row(item))); + return matcher(item).read(logger, language, value); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h new file mode 100644 index 0000000000..290272bff7 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h @@ -0,0 +1,58 @@ +/* Option Menu Reader + * + * From: https://github.com/PokemonAutomation/ + * + * Reads the values the OPTION menu shows. pokefirered option_menu.c draws + * them in the window at tile (2, 7), from x 130 of it, one row every 13 + * pixels from y 2 (FONT_NORMAL's 14-pixel letters overlap by one), in + * LIGHT_RED with a RED shadow: peach letters, red edges. The rows but the + * cursor's are darkened by 2/16. English only so far: in another language + * a value is never read. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OptionMenuReader_H +#define PokemonAutomation_PokemonFRLG_OptionMenuReader_H + +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The options AutoStory sets. +enum class OptionMenuItem{ + TEXT_SPEED, + BATTLE_STYLE, +}; + +// "TEXT SPEED", "BATTLE STYLE", for logs. +const char* option_menu_name(OptionMenuItem item); + +// The item's row in the menu, from 0. The cursor opens on row 0. +size_t option_menu_row(OptionMenuItem item); + +// The item's values as slugs, in the order RIGHT steps through them: +// "slow", "mid", "fast"; "shift", "set" (option_menu.c sTextSpeedOptions, +// sBattleStyleOptions). +const std::vector& option_menu_values(OptionMenuItem item); + +// Where row `row` shows its value, as fractions of the game screen. +ImageFloatBox option_value_box(size_t row); + +// The value the item's row shows, one of option_menu_values(item), in a +// game in `language`; empty if it can't be read. +std::string read_option_value(Logger& logger, Language language, const ImageViewRGB32& screen, OptionMenuItem item); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index fe27df080e..5a933cfef0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -20,6 +20,7 @@ #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" @@ -636,14 +637,84 @@ std::string read_save_place(ConsoleHandle& console, ProControllerContext& contex return place; } -void set_options(ConsoleHandle& console, ProControllerContext& context, StartMenu menu){ +std::optional option_right_presses( + const std::vector& values, const std::string& current, const std::string& target +){ + const auto from = std::find(values.begin(), values.end(), current); + const auto to = std::find(values.begin(), values.end(), target); + if (from == values.end() || to == values.end()){ + return std::nullopt; + } + const size_t count = values.size(); + return (static_cast(to - values.begin()) + count - static_cast(from - values.begin())) % count; +} + +static void options_shot(ConsoleHandle& console, ProControllerContext& context, const std::string& label){ + context.wait_for_all_requests(); + dump_debug_image(console, "AutoStory/options", label, console.video().snapshot()); +} + +// The item's value, read up to 3 times while the menu may still be fading +// in or redrawing; empty if never read. +static std::string read_option( + ConsoleHandle& console, ProControllerContext& context, OptionMenuItem item, Language language +){ + for (size_t attempt = 0; attempt < 3; attempt++){ + if (attempt > 0){ + pbf_wait(context, 500ms); + } + context.wait_for_all_requests(); + const VideoSnapshot screen = console.video().snapshot(); + const std::string value = screen ? read_option_value(console, language, screen, item) : ""; + if (!value.empty()){ + return value; + } + } + return ""; +} + +// With the cursor on the item's row: RIGHT until it shows `target`. +static void set_option( + ConsoleHandle& console, ProControllerContext& context, + OptionMenuItem item, const std::string& target, Language language +){ + const char* name = option_menu_name(item); + const std::string current = read_option(console, context, item, language); + const std::optional presses = option_right_presses(option_menu_values(item), current, target); + if (!presses){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("set_options(): can't read {} (read \"{}\", language {}).", name, current, language_data(language).name), + console + ); + } + console.log(std::format("Options: {} is {}, {} RIGHT to {}.", name, current, *presses, target)); + for (size_t i = 0; i < *presses; i++){ + tap(context, DPAD_RIGHT); + } + const std::string now = read_option(console, context, item, language); + if (now != target){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("set_options(): {} reads \"{}\" after {} RIGHT from {}, not {}.", name, now, *presses, current, target), + console + ); + } +} + +void set_options(ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language){ console.log("Options: text speed FAST, battle style SET."); open_start_menu_row(console, context, menu, start_menu_option_row(menu)); - // TEXT SPEED (MID), BATTLE SCENE, BATTLE STYLE (SHIFT), ... - tap(context, DPAD_RIGHT); - tap(context, DPAD_DOWN); - tap(context, DPAD_DOWN); - tap(context, DPAD_RIGHT); + options_shot(console, context, "before"); + // The cursor opens on TEXT SPEED (option_menu.c: cursorPos = 0), and + // BATTLE STYLE is two rows down. Were it on another row, the presses + // would change that row instead, and the read after them fails. + set_option(console, context, OptionMenuItem::TEXT_SPEED, "fast", language); + for (size_t row = option_menu_row(OptionMenuItem::TEXT_SPEED); row < option_menu_row(OptionMenuItem::BATTLE_STYLE); row++){ + tap(context, DPAD_DOWN); + } + set_option(console, context, OptionMenuItem::BATTLE_STYLE, "set", language); + options_shot(console, context, "after"); press(context, BUTTON_B, 1500ms); mash_until_overworld(console, context, 20000ms); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index fbe4a643c1..24dfdddd8b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -168,10 +168,22 @@ void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu // with another START menu (another checkpoint's) is read too. std::string read_save_place(ConsoleHandle& console, ProControllerContext& context, Language language); +// RIGHT presses that turn an option showing `current` into `target`. +// RIGHT steps through `values` and wraps from the last to the first +// (pokefirered option_menu.c OptionMenu_ProcessInput). Nothing if either +// isn't one of `values`. +std::optional option_right_presses( + const std::vector& values, const std::string& current, const std::string& target +); + // From the overworld: OPTION, text speed FAST, battle style SET (no // "Will you switch?" between a trainer's Pokemon). Returns to the -// overworld. -void set_options(ConsoleHandle& console, ProControllerContext& context, StartMenu menu); +// overworld. A new game keeps the options of the save it replaces, so +// each value is read and stepped to its target, then read again; one that +// can't be read, as in a language the reader has no names for, or that +// isn't the target after the presses, fails with a screenshot and leaves +// the menu open. +void set_options(ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language); // Facing the nurse: A, YES, the heal, and the text to its end. void heal_at_center(ConsoleHandle& console, ProControllerContext& context); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index a7ba0f0318..818441aa21 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -357,7 +357,7 @@ Outcome StoryExecutor::new_game(RunState&, const StoryStep&){ } Outcome StoryExecutor::options(RunState&, const StoryStep&){ - set_options(m_env.console, m_env.context, m_menu); + set_options(m_env.console, m_env.context, m_menu, m_env.language); return Pokemon::outcome_ok(); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 8ea667798d..402bea8c86 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -9,12 +9,14 @@ */ #include +#include #include #include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "PokemonFRLG_AutoStoryActions.h" @@ -539,6 +541,42 @@ UnitTestResult test_intro_names(){ return true; } +// set_options()'s RIGHT presses from each value an old save can leave: +// on console B a save with FAST and SET became SLOW and SHIFT when the +// presses assumed MID and SHIFT. +UnitTestResult test_option_presses(){ + const std::vector& speed = option_menu_values(OptionMenuItem::TEXT_SPEED); + const std::vector& style = option_menu_values(OptionMenuItem::BATTLE_STYLE); + struct Case{ + const std::vector& values; + std::string current; + std::string target; + std::optional expected; + }; + const std::vector cases{ + {.values = speed, .current = "slow", .target = "fast", .expected = 2}, + {.values = speed, .current = "mid", .target = "fast", .expected = 1}, + {.values = speed, .current = "fast", .target = "fast", .expected = 0}, + {.values = style, .current = "shift", .target = "set", .expected = 1}, + {.values = style, .current = "set", .target = "set", .expected = 0}, + // RIGHT wraps from the last value to the first. + {.values = speed, .current = "fast", .target = "slow", .expected = 1}, + // Unread, or another row's value: no guess. + {.values = speed, .current = "", .target = "fast", .expected = std::nullopt}, + {.values = style, .current = "fast", .target = "set", .expected = std::nullopt}, + }; + for (const Case& c : cases){ + const std::optional presses = option_right_presses(c.values, c.current, c.target); + if (presses != c.expected){ + auto text = [](const std::optional& n){ + return n ? std::to_string(*n) + " RIGHT" : std::string("no presses"); + }; + return "\"" + c.current + "\" to " + c.target + ": expected " + text(c.expected) + ", got " + text(presses) + "."; + } + } + return true; +} + } @@ -554,6 +592,7 @@ void add_tests_AutoStory(UnitTestDatabase& database){ database.add("routes run after the Running Shoes", test_runs_after_shoes); database.add("Pewter: the first run", test_first_run); database.add("intro: names, the rival's from the list", test_intro_names); + database.add("options: RIGHT presses from the shown value", test_option_presses); } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 6aa0b44546..fbbfea3335 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1750,6 +1750,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_LoadMenuDetector.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyEmptySlotDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyEmptySlotDetector.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyHeldItemDetector.cpp From fff4697e04b2d5777dc37ba9c755cb774f5b235b Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 14:42:14 -0800 Subject: [PATCH 52/75] FRLG AutoStory: set BATTLE SCENE to OFF with the options set_options() now also reads BATTLE SCENE and presses RIGHT until it shows OFF, between TEXT SPEED and BATTLE STYLE, so battles skip the move animations. The option reader gets BATTLE SCENE's row and ON/OFF. Two-letter "ON" read exactly scores -1.398 (log10 of 1/25), just short of the -1.40 cutoff the longer values use, so BATTLE SCENE's cutoff is -1.30; checked offline on console B's options frames. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Menus/PokemonFRLG_OptionMenuReader.cpp | 64 ++++++++++++------- .../Menus/PokemonFRLG_OptionMenuReader.h | 7 +- .../PokemonFRLG_AutoStoryActions.cpp | 29 ++++++--- .../AutoStory/PokemonFRLG_AutoStoryActions.h | 14 ++-- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 4 ++ 5 files changed, 76 insertions(+), 42 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp index e4c7dcbb46..7a30a42823 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp @@ -48,11 +48,11 @@ struct OptionValue{ // One matcher per item, so a value is only matched against its own row's. class OptionValueMatcher : public OCR::SmallDictionaryMatcher{ public: - static constexpr double MAX_LOG10P = -1.40; static constexpr double MAX_LOG10P_SPREAD = 0.50; - explicit OptionValueMatcher(const std::vector& values) + OptionValueMatcher(const std::vector& values, double max_log10p) : SmallDictionaryMatcher(dictionary(values)) + , m_max_log10p(max_log10p) {} std::string read(Logger& logger, Language language, const ImageViewRGB32& image) const{ @@ -62,7 +62,7 @@ class OptionValueMatcher : public OCR::SmallDictionaryMatcher{ const ImageRGB32 ready = preprocess_for_ocr(image); const OCR::StringMatchResult result = match_substring_from_image_multifiltered( &logger, language, ready, VALUE_TEXT_FILTERS(), - MAX_LOG10P, MAX_LOG10P_SPREAD, 0.01, 0.50 + m_max_log10p, MAX_LOG10P_SPREAD, 0.01, 0.50 ); return result.results.empty() ? "" : result.results.begin()->second.token; } @@ -79,17 +79,11 @@ class OptionValueMatcher : public OCR::SmallDictionaryMatcher{ json["eng"] = std::move(english); return json; } + + double m_max_log10p; }; -const std::vector& text_speed_values(){ - static const std::vector values{{"slow", "Slow"}, {"mid", "Mid"}, {"fast", "Fast"}}; - return values; -} -const std::vector& battle_style_values(){ - static const std::vector values{{"shift", "Shift"}, {"set", "Set"}}; - return values; -} -std::vector slugs(const std::vector& values){ +std::vector slugs_of(const std::vector& values){ std::vector ret; for (const OptionValue& value : values){ ret.emplace_back(value.slug); @@ -97,28 +91,52 @@ std::vector slugs(const std::vector& values){ return ret; } -const OptionValueMatcher& matcher(OptionMenuItem item){ - static const OptionValueMatcher text_speed(text_speed_values()); - static const OptionValueMatcher battle_style(battle_style_values()); - return item == OptionMenuItem::TEXT_SPEED ? text_speed : battle_style; +// An item's name, its row (option_menu.c MENUITEM_*), its values and their +// matcher. +struct OptionItem{ + OptionItem(const char* name, size_t row, const std::vector& values, double max_log10p) + : name(name) + , row(row) + , slugs(slugs_of(values)) + , matcher(values, max_log10p) + {} + + const char* name; + size_t row; + std::vector slugs; + OptionValueMatcher matcher; +}; + +const OptionItem& option_item(OptionMenuItem item){ + static const OptionItem text_speed("TEXT SPEED", 0, {{"slow", "Slow"}, {"mid", "Mid"}, {"fast", "Fast"}}, -1.40); + // Two letters score at most log10(1/25): an exact "ON" (console B, + // 2026-11-02) is -1.398, short of the others' -1.40. + static const OptionItem battle_scene("BATTLE SCENE", 1, {{"on", "On"}, {"off", "Off"}}, -1.30); + static const OptionItem battle_style("BATTLE STYLE", 2, {{"shift", "Shift"}, {"set", "Set"}}, -1.40); + switch (item){ + case OptionMenuItem::TEXT_SPEED: + return text_speed; + case OptionMenuItem::BATTLE_SCENE: + return battle_scene; + case OptionMenuItem::BATTLE_STYLE: + return battle_style; + } + return text_speed; } } const char* option_menu_name(OptionMenuItem item){ - return item == OptionMenuItem::TEXT_SPEED ? "TEXT SPEED" : "BATTLE STYLE"; + return option_item(item).name; } size_t option_menu_row(OptionMenuItem item){ - // option_menu.c MENUITEM_TEXTSPEED, MENUITEM_BATTLESTYLE. - return item == OptionMenuItem::TEXT_SPEED ? 0 : 2; + return option_item(item).row; } const std::vector& option_menu_values(OptionMenuItem item){ - static const std::vector text_speed = slugs(text_speed_values()); - static const std::vector battle_style = slugs(battle_style_values()); - return item == OptionMenuItem::TEXT_SPEED ? text_speed : battle_style; + return option_item(item).slugs; } ImageFloatBox option_value_box(size_t row){ @@ -128,7 +146,7 @@ ImageFloatBox option_value_box(size_t row){ std::string read_option_value(Logger& logger, Language language, const ImageViewRGB32& screen, OptionMenuItem item){ const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); const ImageViewRGB32 value = extract_box_reference(game, option_value_box(option_menu_row(item))); - return matcher(item).read(logger, language, value); + return option_item(item).matcher.read(logger, language, value); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h index 290272bff7..8185f882bd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h @@ -29,18 +29,19 @@ namespace PokemonFRLG{ // The options AutoStory sets. enum class OptionMenuItem{ TEXT_SPEED, + BATTLE_SCENE, BATTLE_STYLE, }; -// "TEXT SPEED", "BATTLE STYLE", for logs. +// "TEXT SPEED", "BATTLE SCENE", "BATTLE STYLE", for logs. const char* option_menu_name(OptionMenuItem item); // The item's row in the menu, from 0. The cursor opens on row 0. size_t option_menu_row(OptionMenuItem item); // The item's values as slugs, in the order RIGHT steps through them: -// "slow", "mid", "fast"; "shift", "set" (option_menu.c sTextSpeedOptions, -// sBattleStyleOptions). +// "slow", "mid", "fast"; "on", "off"; "shift", "set" (option_menu.c +// sTextSpeedOptions, sBattleSceneOptions, sBattleStyleOptions). const std::vector& option_menu_values(OptionMenuItem item); // Where row `row` shows its value, as fractions of the game screen. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index 5a933cfef0..094ea6e653 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -703,17 +703,28 @@ static void set_option( } void set_options(ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language){ - console.log("Options: text speed FAST, battle style SET."); + console.log("Options: text speed FAST, battle scene OFF, battle style SET."); open_start_menu_row(console, context, menu, start_menu_option_row(menu)); options_shot(console, context, "before"); - // The cursor opens on TEXT SPEED (option_menu.c: cursorPos = 0), and - // BATTLE STYLE is two rows down. Were it on another row, the presses - // would change that row instead, and the read after them fails. - set_option(console, context, OptionMenuItem::TEXT_SPEED, "fast", language); - for (size_t row = option_menu_row(OptionMenuItem::TEXT_SPEED); row < option_menu_row(OptionMenuItem::BATTLE_STYLE); row++){ - tap(context, DPAD_DOWN); - } - set_option(console, context, OptionMenuItem::BATTLE_STYLE, "set", language); + struct Target{ + OptionMenuItem item; + const char* value; + }; + // In row order. The cursor opens on TEXT SPEED (option_menu.c: + // cursorPos = 0) and DOWN moves it a row. Were it on another row, the + // presses would change that row instead, and the read after them fails. + const Target targets[] = { + {.item = OptionMenuItem::TEXT_SPEED, .value = "fast"}, + {.item = OptionMenuItem::BATTLE_SCENE, .value = "off"}, + {.item = OptionMenuItem::BATTLE_STYLE, .value = "set"}, + }; + size_t cursor = 0; + for (const Target& target : targets){ + for (; cursor < option_menu_row(target.item); cursor++){ + tap(context, DPAD_DOWN); + } + set_option(console, context, target.item, target.value, language); + } options_shot(console, context, "after"); press(context, BUTTON_B, 1500ms); mash_until_overworld(console, context, 20000ms); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index 24dfdddd8b..78d88a0d14 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -176,13 +176,13 @@ std::optional option_right_presses( const std::vector& values, const std::string& current, const std::string& target ); -// From the overworld: OPTION, text speed FAST, battle style SET (no -// "Will you switch?" between a trainer's Pokemon). Returns to the -// overworld. A new game keeps the options of the save it replaces, so -// each value is read and stepped to its target, then read again; one that -// can't be read, as in a language the reader has no names for, or that -// isn't the target after the presses, fails with a screenshot and leaves -// the menu open. +// From the overworld: OPTION, text speed FAST, battle scene OFF (no move +// animations), battle style SET (no "Will you switch?" between a +// trainer's Pokemon). Returns to the overworld. A new game keeps the +// options of the save it replaces, so each value is read and stepped to +// its target, then read again; one that can't be read, as in a language +// the reader has no names for, or that isn't the target after the +// presses, fails with a screenshot and leaves the menu open. void set_options(ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language); // Facing the nurse: A, YES, the heal, and the text to its end. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 402bea8c86..937b56a1f2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -546,6 +546,7 @@ UnitTestResult test_intro_names(){ // presses assumed MID and SHIFT. UnitTestResult test_option_presses(){ const std::vector& speed = option_menu_values(OptionMenuItem::TEXT_SPEED); + const std::vector& scene = option_menu_values(OptionMenuItem::BATTLE_SCENE); const std::vector& style = option_menu_values(OptionMenuItem::BATTLE_STYLE); struct Case{ const std::vector& values; @@ -557,6 +558,8 @@ UnitTestResult test_option_presses(){ {.values = speed, .current = "slow", .target = "fast", .expected = 2}, {.values = speed, .current = "mid", .target = "fast", .expected = 1}, {.values = speed, .current = "fast", .target = "fast", .expected = 0}, + {.values = scene, .current = "on", .target = "off", .expected = 1}, + {.values = scene, .current = "off", .target = "off", .expected = 0}, {.values = style, .current = "shift", .target = "set", .expected = 1}, {.values = style, .current = "set", .target = "set", .expected = 0}, // RIGHT wraps from the last value to the first. @@ -564,6 +567,7 @@ UnitTestResult test_option_presses(){ // Unread, or another row's value: no guess. {.values = speed, .current = "", .target = "fast", .expected = std::nullopt}, {.values = style, .current = "fast", .target = "set", .expected = std::nullopt}, + {.values = scene, .current = "set", .target = "off", .expected = std::nullopt}, }; for (const Case& c : cases){ const std::optional presses = option_right_presses(c.values, c.current, c.target); From fbb97996e993d133cb2b65683f3c0831f5d1705d Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 15:53:12 -0800 Subject: [PATCH 53/75] FRLG AutoStory: image tests for the option, save card and Mart list readers Captures from console B (FireRed, 2026-11-02): the OPTION menu before and after AutoStory set BATTLE SCENE to OFF, with the cursor on either row; the save card in Pallet Town, Viridian Forest and Pewter City; and the Viridian Mart's BUY list read row by row. The images go in CommandLineTests under PokemonFRLG/OptionMenuReader, SaveCardReader and ItemListReader. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Menus/PokemonFRLG_ItemListReader.cpp | 34 +++++++++ .../Menus/PokemonFRLG_OptionMenuReader.cpp | 69 +++++++++++++++++++ .../Menus/PokemonFRLG_OptionMenuReader.h | 4 ++ .../Menus/PokemonFRLG_SaveCardReader.cpp | 44 ++++++++++++ .../Menus/PokemonFRLG_SaveCardReader.h | 4 ++ .../PokemonFRLG/PokemonFRLG_Tests.cpp | 4 ++ 6 files changed, 159 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp index 8dcfe96233..c0da7e4a93 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp @@ -145,6 +145,35 @@ class Test_BagPocket : public ImageUnitTest{ const std::vector m_expected; }; +// A capture of a list, read row by row from the top. +class Test_ItemListNames : public ImageUnitTest{ +public: + Test_ItemListNames(const std::string& image, std::vector expected) + : ImageUnitTest("PokemonFRLG::ItemListReader - " + image, {image}) + , m_expected(std::move(expected)) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + std::string expected; + std::string read; + for (size_t row = 0; row < m_expected.size(); row++){ + expected += " " + m_expected[row] + ";"; + const std::string item = read_item_list_name(logger, Language::English, images[0], (int)row); + read += " " + (item.empty() ? std::string("(nothing)") : item) + ";"; + } + if (read != expected){ + return "Expected" + expected + " read" + read; + } + return true; + } + +private: + const std::vector m_expected; +}; + } void add_tests_ItemListReader(UnitTestDatabase& database){ @@ -154,6 +183,11 @@ void add_tests_ItemListReader(UnitTestDatabase& database){ "PokemonFRLG/ItemListReader/ItemsPocket_Potion5_Antidote3_ParlyzHeal1.png", std::vector{{"potion", 5}, {"antidote", 3}, {"parlyz-heal", 1}} ); + // The Viridian Mart's BUY list, the same day, the cursor on POTION. + database.add( + "PokemonFRLG/ItemListReader/MartBuy_PokeBall_Potion_Antidote_ParlyzHeal.png", + std::vector{"poke-ball", "potion", "antidote", "parlyz-heal", "cancel"} + ); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp index 7a30a42823..930942238b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp @@ -4,11 +4,13 @@ * */ +#include #include "Common/Cpp/Color.h" #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" +#include "Tests/ImageUnitTest.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_OptionMenuReader.h" @@ -150,6 +152,73 @@ std::string read_option_value(Logger& logger, Language language, const ImageView } +namespace{ + +// The values the menu shows for the options AutoStory sets. +struct OptionValues{ + std::string text_speed; + std::string battle_scene; + std::string battle_style; +}; + +std::string to_string(const OptionValues& values){ + return std::format( + "TEXT SPEED \"{}\", BATTLE SCENE \"{}\", BATTLE STYLE \"{}\"", + values.text_speed, values.battle_scene, values.battle_style + ); +} + +// A capture of the OPTION menu, read on each row AutoStory sets. +class Test_OptionMenu : public ImageUnitTest{ +public: + Test_OptionMenu(const std::string& image, OptionValues expected) + : ImageUnitTest("PokemonFRLG::OptionMenuReader - " + image, {image}) + , m_expected(std::move(expected)) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const OptionValues read{ + .text_speed = read_option_value(logger, Language::English, images[0], OptionMenuItem::TEXT_SPEED), + .battle_scene = read_option_value(logger, Language::English, images[0], OptionMenuItem::BATTLE_SCENE), + .battle_style = read_option_value(logger, Language::English, images[0], OptionMenuItem::BATTLE_STYLE), + }; + const std::string expected = to_string(m_expected); + const std::string got = to_string(read); + if (got != expected){ + return "Expected " + expected + ", read " + got; + } + return true; + } + +private: + const OptionValues m_expected; +}; + +} + +void add_tests_OptionMenuReader(UnitTestDatabase& database){ + // Console B, 2026-11-02, FireRed: the menu as a new game opens it, the + // cursor on TEXT SPEED's white row. + database.add( + "PokemonFRLG/OptionMenuReader/Options_Fast_On_Set.png", + OptionValues{.text_speed = "fast", .battle_scene = "on", .battle_style = "set"} + ); + // The cursor moved down to BATTLE STYLE: TEXT SPEED's row is darkened. + database.add( + "PokemonFRLG/OptionMenuReader/Options_Fast_On_Set_CursorOnBattleStyle.png", + OptionValues{.text_speed = "fast", .battle_scene = "on", .battle_style = "set"} + ); + // After AutoStory set BATTLE SCENE to OFF. + database.add( + "PokemonFRLG/OptionMenuReader/Options_Fast_Off_Set_CursorOnBattleStyle.png", + OptionValues{.text_speed = "fast", .battle_scene = "off", .battle_style = "set"} + ); +} + + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h index 8185f882bd..77dd54e53e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h @@ -17,6 +17,7 @@ #include #include #include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "CommonFramework/Language.h" @@ -52,6 +53,9 @@ ImageFloatBox option_value_box(size_t row); std::string read_option_value(Logger& logger, Language language, const ImageViewRGB32& screen, OptionMenuItem item); +void add_tests_OptionMenuReader(UnitTestDatabase& database); + + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp index 9bfd7249f7..614d2a96d0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp @@ -9,6 +9,7 @@ #include "Common/Cpp/Json/JsonObject.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" +#include "Tests/ImageUnitTest.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_SaveCardReader.h" @@ -89,6 +90,49 @@ std::string read_save_card_location(Logger& logger, Language language, const Ima } +namespace{ + +// A capture of the save card over "Would you like to save the game?". +class Test_SaveCard : public ImageUnitTest{ +public: + Test_SaveCard(const std::string& image, std::string expected) + : ImageUnitTest("PokemonFRLG::SaveCardReader - " + image, {image}) + , m_expected(std::move(expected)) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const std::string read = read_save_card_location(logger, Language::English, images[0]); + if (read != m_expected){ + return "Expected \"" + m_expected + "\", read \"" + read + "\""; + } + return true; + } + +private: + const std::string m_expected; +}; + +} + +void add_tests_SaveCardReader(UnitTestDatabase& database){ + // Console B, 2026-11-02, FireRed. The card covers the same corner of + // the screen everywhere; the places behind it differ. + for (const auto& [image, place] : { + std::pair{"PalletTown_Bedroom.png", "pallet-town"}, + {"PalletTown_Outdoors.png", "pallet-town"}, + {"PalletTown_OaksLab.png", "pallet-town"}, + {"ViridianForest.png", "viridian-forest"}, + {"PewterCity_PokemonCenter.png", "pewter-city"}, + {"PewterCity_OneBadge.png", "pewter-city"}, + }){ + database.add(std::string("PokemonFRLG/SaveCardReader/") + image, place); + } +} + + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h index 3c327d9e80..8a037e0242 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h @@ -14,6 +14,7 @@ #include #include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "CommonFramework/Language.h" @@ -34,6 +35,9 @@ ImageFloatBox save_card_title_box(); std::string read_save_card_location(Logger& logger, Language language, const ImageViewRGB32& screen); +void add_tests_SaveCardReader(UnitTestDatabase& database); + + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 91ba5a99b6..cc050e97dd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -18,9 +18,11 @@ #include "Inference/Map/PokemonFRLG_PokemonLeagueDetectors.h" #include "Inference/Menus/PokemonFRLG_BagDetector.h" #include "Inference/Menus/PokemonFRLG_ItemListReader.h" +#include "Inference/Menus/PokemonFRLG_OptionMenuReader.h" #include "Inference/Menus/PokemonFRLG_PartyEmptySlotDetector.h" #include "Inference/Menus/PokemonFRLG_PartyHeldItemDetector.h" #include "Inference/Menus/PokemonFRLG_PartyMenuDetector.h" +#include "Inference/Menus/PokemonFRLG_SaveCardReader.h" #include "Inference/PokemonFRLG_BattleLevelUpReader.h" #include "Inference/PokemonFRLG_BattleSelectionArrowDetector.h" #include "Inference/PokemonFRLG_PartyLevelUpReader.h" @@ -297,6 +299,8 @@ void add_tests(UnitTestDatabase& database){ add_tests_BattleMoveSelectionArrow(database); add_tests_BagDetector(database); add_tests_ItemListReader(database); + add_tests_OptionMenuReader(database); + add_tests_SaveCardReader(database); add_tests_ExitWildBattle(database); add_tests_OverworldMaps(database); add_tests_OverworldRoute(database); From d81c0074ea77730267dac08d72436c683fd526df Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 16:02:56 -0800 Subject: [PATCH 54/75] FRLG AutoStory: reader image tests take the expected result from the file As upstream's image tests do, a test is registered with its image's path only. The option menu and save card tests read the expected values from the end of the file name (CursorTop_eng_fast_on_set.png, Bedroom_eng_pallet-town.png); the bag pocket and Mart list tests read a golden file next to the image (_ItemsPocket_eng.txt), through check_against_golden_file(). The language comes from the file name too. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Menus/PokemonFRLG_ItemListReader.cpp | 89 ++++++++++--------- .../Menus/PokemonFRLG_OptionMenuReader.cpp | 72 ++++++--------- .../Menus/PokemonFRLG_SaveCardReader.cpp | 44 ++++----- 3 files changed, 96 insertions(+), 109 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp index c0da7e4a93..8b795c2552 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp @@ -5,12 +5,16 @@ */ #include +#include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" +#include "CommonFramework/GlobalAutoPaths.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonFramework/Language.h" #include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" #include "Tests/ImageUnitTest.h" +#include "Tests/TestUtils.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Tests.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_DigitReader.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" @@ -114,80 +118,79 @@ std::vector read_bag_pocket(Logger& logger, Language language, const Ima namespace{ -// A capture of the Items pocket, read from the top. +// The language a test image's name ends with: _. +Language language_of_test_image(const std::string& image){ + const std::vector words = parse_words(Filesystem::Path(image).stem().string()); + return words.size() < 2 ? Language::None : language_code_to_enum(words.back()); +} + +// A capture of a bag pocket, read from the top. Its golden file holds each +// row's item and count, one per line. class Test_BagPocket : public ImageUnitTest{ public: - Test_BagPocket(const std::string& image, std::vector expected) + Test_BagPocket(const std::string& image) : ImageUnitTest("PokemonFRLG::ItemListReader - " + image, {image}) - , m_expected(std::move(expected)) {} virtual UnitTestResult run_on_images( Logger& logger, CancellableScope& scope, const std::vector& images ) const override{ - const std::vector rows = read_bag_pocket(logger, Language::English, images[0]); - std::string expected; - for (const BagRow& row : m_expected){ - expected += std::format(" {} x{};", row.item, row.count); + const Language language = language_of_test_image(image_paths()[0]); + if (language == Language::None || language == Language::EndOfList){ + return "Error: filename must be _."; } - std::string read; - for (const BagRow& row : rows){ - read += std::format(" {} x{};", row.item, row.count); + std::vector labels; + std::vector values; + const std::vector rows = read_bag_pocket(logger, language, images[0]); + for (size_t c = 0; c < rows.size(); c++){ + labels.push_back(std::format("row {} item", c + 1)); + labels.push_back(std::format("row {} count", c + 1)); + values.push_back(rows[c].item); + values.push_back(std::to_string(rows[c].count)); } - if (read != expected){ - return "Expected" + expected + " read" + (read.empty() ? std::string(" nothing") : read); - } - return true; + return check_against_golden_file(UNIT_TEST_RESOURCE_PATH() + image_paths()[0], labels, values); } - -private: - const std::vector m_expected; }; -// A capture of a list, read row by row from the top. -class Test_ItemListNames : public ImageUnitTest{ +// A capture of a Mart's BUY list, read from the top to its CANCEL. Its +// golden file holds each row's item, one per line. +class Test_MartList : public ImageUnitTest{ public: - Test_ItemListNames(const std::string& image, std::vector expected) + Test_MartList(const std::string& image) : ImageUnitTest("PokemonFRLG::ItemListReader - " + image, {image}) - , m_expected(std::move(expected)) {} virtual UnitTestResult run_on_images( Logger& logger, CancellableScope& scope, const std::vector& images ) const override{ - std::string expected; - std::string read; - for (size_t row = 0; row < m_expected.size(); row++){ - expected += " " + m_expected[row] + ";"; - const std::string item = read_item_list_name(logger, Language::English, images[0], (int)row); - read += " " + (item.empty() ? std::string("(nothing)") : item) + ";"; + const Language language = language_of_test_image(image_paths()[0]); + if (language == Language::None || language == Language::EndOfList){ + return "Error: filename must be _."; } - if (read != expected){ - return "Expected" + expected + " read" + read; + std::vector labels; + std::vector values; + for (int row = 0; row < ITEM_LIST_ROWS; row++){ + const std::string item = read_item_list_name(logger, language, images[0], row); + labels.push_back(std::format("row {}", row + 1)); + values.push_back(item.empty() ? "(nothing)" : item); + if (item.empty() || item == "cancel"){ + break; + } } - return true; + return check_against_golden_file(UNIT_TEST_RESOURCE_PATH() + image_paths()[0], labels, values); } - -private: - const std::vector m_expected; }; } void add_tests_ItemListReader(UnitTestDatabase& database){ - // Console B, 2026-11-02, after the Viridian Mart: the 5 and the 3 read - // as nothing before the digit templates. - database.add( - "PokemonFRLG/ItemListReader/ItemsPocket_Potion5_Antidote3_ParlyzHeal1.png", - std::vector{{"potion", 5}, {"antidote", 3}, {"parlyz-heal", 1}} - ); + // FireRed on console B, 2026-11-02, after the Viridian Mart: the 5 and + // the 3 read as nothing before the digit templates. + database.add("PokemonFRLG/ItemListReader/ItemsPocket_eng.png"); // The Viridian Mart's BUY list, the same day, the cursor on POTION. - database.add( - "PokemonFRLG/ItemListReader/MartBuy_PokeBall_Potion_Antidote_ParlyzHeal.png", - std::vector{"poke-ball", "potion", "antidote", "parlyz-heal", "cancel"} - ); + database.add("PokemonFRLG/ItemListReader/MartBuyList_eng.png"); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp index 930942238b..bd099bb1da 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp @@ -4,13 +4,14 @@ * */ -#include #include "Common/Cpp/Color.h" +#include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" #include "Tests/ImageUnitTest.h" +#include "Tests/TestUtils.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_OptionMenuReader.h" @@ -154,68 +155,47 @@ std::string read_option_value(Logger& logger, Language language, const ImageView namespace{ -// The values the menu shows for the options AutoStory sets. -struct OptionValues{ - std::string text_speed; - std::string battle_scene; - std::string battle_style; -}; - -std::string to_string(const OptionValues& values){ - return std::format( - "TEXT SPEED \"{}\", BATTLE SCENE \"{}\", BATTLE STYLE \"{}\"", - values.text_speed, values.battle_scene, values.battle_style - ); -} - -// A capture of the OPTION menu, read on each row AutoStory sets. +// A capture of the OPTION menu, named for what it shows: +// ____, +// e.g. CursorTop_eng_fast_on_set.png. class Test_OptionMenu : public ImageUnitTest{ public: - Test_OptionMenu(const std::string& image, OptionValues expected) + Test_OptionMenu(const std::string& image) : ImageUnitTest("PokemonFRLG::OptionMenuReader - " + image, {image}) - , m_expected(std::move(expected)) {} virtual UnitTestResult run_on_images( Logger& logger, CancellableScope& scope, const std::vector& images ) const override{ - const OptionValues read{ - .text_speed = read_option_value(logger, Language::English, images[0], OptionMenuItem::TEXT_SPEED), - .battle_scene = read_option_value(logger, Language::English, images[0], OptionMenuItem::BATTLE_SCENE), - .battle_style = read_option_value(logger, Language::English, images[0], OptionMenuItem::BATTLE_STYLE), - }; - const std::string expected = to_string(m_expected); - const std::string got = to_string(read); - if (got != expected){ - return "Expected " + expected + ", read " + got; + const std::vector words = parse_words(Filesystem::Path(image_paths()[0]).stem().string()); + if (words.size() < 5){ + return "Error: filename must be ____."; + } + const std::string& language_word = words[words.size() - 4]; + const Language language = language_code_to_enum(language_word); + if (language == Language::None || language == Language::EndOfList){ + return "Error: invalid language word in filename: " + language_word; + } + + const OptionMenuItem items[] = {OptionMenuItem::TEXT_SPEED, OptionMenuItem::BATTLE_SCENE, OptionMenuItem::BATTLE_STYLE}; + for (size_t c = 0; c < 3; c++){ + const std::string read = read_option_value(logger, language, images[0], items[c]); + TEST_RESULT_COMPONENT_EQUAL_STR(read, words[words.size() - 3 + c], option_menu_name(items[c])); } return true; } - -private: - const OptionValues m_expected; }; } void add_tests_OptionMenuReader(UnitTestDatabase& database){ - // Console B, 2026-11-02, FireRed: the menu as a new game opens it, the - // cursor on TEXT SPEED's white row. - database.add( - "PokemonFRLG/OptionMenuReader/Options_Fast_On_Set.png", - OptionValues{.text_speed = "fast", .battle_scene = "on", .battle_style = "set"} - ); - // The cursor moved down to BATTLE STYLE: TEXT SPEED's row is darkened. - database.add( - "PokemonFRLG/OptionMenuReader/Options_Fast_On_Set_CursorOnBattleStyle.png", - OptionValues{.text_speed = "fast", .battle_scene = "on", .battle_style = "set"} - ); - // After AutoStory set BATTLE SCENE to OFF. - database.add( - "PokemonFRLG/OptionMenuReader/Options_Fast_Off_Set_CursorOnBattleStyle.png", - OptionValues{.text_speed = "fast", .battle_scene = "off", .battle_style = "set"} - ); + // FireRed on console B, 2026-11-02: the menu as a new game opens it, + // then with the cursor moved to BATTLE STYLE (the other rows darkened), + // before and after AutoStory set BATTLE SCENE to OFF. + database.add("PokemonFRLG/OptionMenuReader/CursorTop_eng_fast_on_set.png"); + database.add("PokemonFRLG/OptionMenuReader/CursorBattleStyle_eng_fast_on_set.png"); + database.add("PokemonFRLG/OptionMenuReader/CursorBattleStyle_eng_fast_off_set.png"); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp index 614d2a96d0..702d314298 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp @@ -5,11 +5,13 @@ */ #include "Common/Cpp/Color.h" +#include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" #include "Tests/ImageUnitTest.h" +#include "Tests/TestUtils.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_SaveCardReader.h" @@ -92,44 +94,46 @@ std::string read_save_card_location(Logger& logger, Language language, const Ima namespace{ -// A capture of the save card over "Would you like to save the game?". +// A capture of the save card over "Would you like to save the game?", +// named __, e.g. +// Bedroom_eng_pallet-town.png. class Test_SaveCard : public ImageUnitTest{ public: - Test_SaveCard(const std::string& image, std::string expected) + Test_SaveCard(const std::string& image) : ImageUnitTest("PokemonFRLG::SaveCardReader - " + image, {image}) - , m_expected(std::move(expected)) {} virtual UnitTestResult run_on_images( Logger& logger, CancellableScope& scope, const std::vector& images ) const override{ - const std::string read = read_save_card_location(logger, Language::English, images[0]); - if (read != m_expected){ - return "Expected \"" + m_expected + "\", read \"" + read + "\""; + const std::vector words = parse_words(Filesystem::Path(image_paths()[0]).stem().string()); + if (words.size() < 3){ + return "Error: filename must be __."; } + const std::string& language_word = words[words.size() - 2]; + const Language language = language_code_to_enum(language_word); + if (language == Language::None || language == Language::EndOfList){ + return "Error: invalid language word in filename: " + language_word; + } + + const std::string read = read_save_card_location(logger, language, images[0]); + TEST_RESULT_COMPONENT_EQUAL_STR(read, words.back(), "place"); return true; } - -private: - const std::string m_expected; }; } void add_tests_SaveCardReader(UnitTestDatabase& database){ - // Console B, 2026-11-02, FireRed. The card covers the same corner of + // FireRed on console B, 2026-11-02. The card covers the same corner of // the screen everywhere; the places behind it differ. - for (const auto& [image, place] : { - std::pair{"PalletTown_Bedroom.png", "pallet-town"}, - {"PalletTown_Outdoors.png", "pallet-town"}, - {"PalletTown_OaksLab.png", "pallet-town"}, - {"ViridianForest.png", "viridian-forest"}, - {"PewterCity_PokemonCenter.png", "pewter-city"}, - {"PewterCity_OneBadge.png", "pewter-city"}, - }){ - database.add(std::string("PokemonFRLG/SaveCardReader/") + image, place); - } + database.add("PokemonFRLG/SaveCardReader/Bedroom_eng_pallet-town.png"); + database.add("PokemonFRLG/SaveCardReader/Outdoors_eng_pallet-town.png"); + database.add("PokemonFRLG/SaveCardReader/OaksLab_eng_pallet-town.png"); + database.add("PokemonFRLG/SaveCardReader/Forest_eng_viridian-forest.png"); + database.add("PokemonFRLG/SaveCardReader/PokemonCenter_eng_pewter-city.png"); + database.add("PokemonFRLG/SaveCardReader/OneBadge_eng_pewter-city.png"); } From c1dc5bca10815b6d9dde54f101a89417ecd09ace Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 18:34:32 -0800 Subject: [PATCH 55/75] FRLG AutoStory: give StoryEnv's start_map a default Windows Clang (clang-cl /W4 /WX) fails on -Wmissing-field-initializers where AutoStory::program() builds StoryEnv without start_map; the non-MSVC branch of Common/Compiler.h silences the warning elsewhere. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 7e69e83bb9..ba801005cc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -119,7 +119,7 @@ struct StoryEnv{ Language language = Language::English; // The map the checkpoint under way starts on, where its save is: a // reload checks the save card against it. - std::string start_map; + std::string start_map = {}; }; // After a save is loaded for a checkpoint that starts on `start_map`: the From b0ccc4805feffdd7b6def85e10b58fc5a0b6929c Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 19:25:05 -0800 Subject: [PATCH 56/75] FRLG AutoStory: drop 00.11's test run 00.11 only ran row 21 west to a wall to time running; the Route 3 checkpoints that follow the Running Shoes replace it. running(), RUN_VARIANT and move_speed() stay for them. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStory.cpp | 2 +- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 15 ++++----------- .../AutoStory/PokemonFRLG_AutoStoryTable.h | 4 ++-- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 15 --------------- 4 files changed, 7 insertions(+), 29 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 73c1448168..fd48481cd0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -43,7 +43,7 @@ std::unique_ptr AutoStory_Descriptor::make_stats() const{ namespace{ // The start and end dropdowns' entries: the table's checkpoints, 00.01 to -// 00.11. The options hold a reference to it. +// 00.10. The options hold a reference to it. const StringSelectDatabase& checkpoint_database(){ static const StringSelectDatabase database = Pokemon::story_checkpoint_database(story_checkpoints()); return database; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index d94a59d66b..8c0ec3a5dc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -101,8 +101,9 @@ StoryStep legs(std::string name, std::vector legs, std::string why, Wi return step; } -// `step`, a ROUTE or LEGS, run with B held: from the Running Shoes on. -StoryStep running(StoryStep step){ +// `step`, a ROUTE or LEGS, run with B held: from the Running Shoes on. No +// checkpoint after 00.10 is in the table yet. +[[maybe_unused]] StoryStep running(StoryStep step){ step.variant = RUN_VARIANT; return step; } @@ -267,21 +268,13 @@ StoryCheckpoint running_shoes(){ }); } -StoryCheckpoint first_run(){ - // From here on every route and leg runs. Route 3 isn't among the story's - // maps yet, so this checkpoint only tests running on one long leg. - return row("00.11", "Pewter: a run to a wall, to time running", at(PEWTER, 46, 21, NORTH), {}, StartMenu::FULL, { - running(legs("run_west", {{WEST, 40}}, "row 21 west to the wall at (6, 21): logs the run's pace")), - }); -} - } const std::vector& story_checkpoints(){ static const std::vector checkpoints{ new_game(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), - running_shoes(), first_run(), + running_shoes(), }; return checkpoints; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index 0e45e21787..d8a3f8b15d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -3,7 +3,7 @@ * From: https://github.com/PokemonAutomation/ * * FireRed from a new game to the Boulder Badge and the Running Shoes, as - * story checkpoints 00.01 to 00.11, each saved at its end. From 00.11 on + * story checkpoints 00.01 to 00.10, each saved at its end. After 00.10 * every route and leg runs. Taken from a by-hand run on * console B (2026-11-01) and the pokefirered map scripts. * @@ -21,7 +21,7 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Checkpoints 00.01 to 00.11, in order. +// Checkpoints 00.01 to 00.10, in order. const std::vector& story_checkpoints(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 937b56a1f2..466a50a497 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -353,20 +353,6 @@ UnitTestResult test_runs_after_shoes(){ return true; } -// 00.11's run: one leg west along row 21, to the wall at (6, 21). -UnitTestResult test_first_run(){ - const MapPosition start{"PewterCity", {46, 21}}; - const std::optional> route = fixed_route(story_maps(), start, {{Direction::WEST, 40}}); - if (!route || route->size() != 1){ - return "Expected one leg west from " + to_string(start) + "."; - } - const RouteStep& leg = route->front(); - if (!leg.to_wall || leg.wild || leg.end != MapPosition{"PewterCity", {6, 21}}){ - return "Expected a leg to the wall at (6, 21), off the grass, got:" + describe(*route); - } - return true; -} - // Every checkpoint that starts from a save has a place the save card // names, so a save left elsewhere is caught before it runs; and the // places of the starts that matter differ. @@ -594,7 +580,6 @@ void add_tests_AutoStory(UnitTestDatabase& database){ database.add("Pewter Gym walks", test_pewter_gym_walks); database.add("Pewter: to the aide's trigger", test_pewter_aide_walk); database.add("routes run after the Running Shoes", test_runs_after_shoes); - database.add("Pewter: the first run", test_first_run); database.add("intro: names, the rival's from the list", test_intro_names); database.add("options: RIGHT presses from the shown value", test_option_presses); } From 011fb2d2db4c7c519019d2d5484f085acf40dafa Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 19:35:23 -0800 Subject: [PATCH 57/75] FRLG AutoStory: the table test counts 10 checkpoints without 00.11 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 466a50a497..fa4b926b71 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -211,8 +211,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po UnitTestResult test_routes_and_chain(){ const std::vector& checkpoints = story_checkpoints(); - if (checkpoints.size() != 11 || checkpoints[0].start){ - return "Expected 11 checkpoints, the first from a new game."; + if (checkpoints.size() != 10 || checkpoints[0].start){ + return "Expected 10 checkpoints, the first from a new game."; } StoryPose pose; for (size_t c = 0; c < checkpoints.size(); c++){ From 20dbd3e6c22b06782f97a7ea85594db0c3740033 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 19:57:07 -0800 Subject: [PATCH 58/75] FRLG AutoStory: a YES/NO box needs its white, not only the arrow On Route 3 at (36, 8) the arrow detector matches a rock's dark edge where YES's arrow shows, so save_game() kept pressing A on the overworld after a good save and timed out. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index 094ea6e653..21f49c95cc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -373,6 +373,13 @@ int start_menu_option_row(StartMenu menu){ std::optional yes_no_cursor(const ImageViewRGB32& screen){ + // The box's white right of NO (x 196-212, y 92-102 on the 240x160 + // screen). Without it the arrow alone matches the dark edge of a rock + // on Route 3 at (36, 8), right where YES's arrow shows. + const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + if (!is_white(extract_box_reference(game, ImageFloatBox(196.0 / 240, 92.0 / 160, 16.0 / 240, 10.0 / 160)))){ + return std::nullopt; + } if (SelectionArrowDetector(COLOR_RED, nullptr, SelectionArrowPositionConfirmationMenu::YES).detect(screen)){ return true; } From 4f68ce0210eb567581aede110aac8c117cbec1f1 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 20:00:21 -0800 Subject: [PATCH 59/75] FRLG AutoStory: advance_text() needs a YES/NO's box too; first box is NO The YES/NO arrow watchers matched a rock's edge on Route 3, so advance_text() kept answering a box that wasn't there and never checked for the overworld. An arrow without the box now counts as nothing seen. Also, last_no started at WallClock::min(), and now - min() overflowed to a negative duration, so the first box got YES instead of NO. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG_AutoStoryActions.cpp | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index 21f49c95cc..a67e107e31 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -421,12 +421,19 @@ bool overworld_shows(ConsoleHandle& console, ProControllerContext& context){ return true; } +namespace{ +bool yes_no_shows(ConsoleHandle& console){ + VideoSnapshot screen = console.video().snapshot(); + return screen && yes_no_cursor(screen).has_value(); +} +} + TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout, bool stop_at_battle){ const WallClock deadline = current_time() + timeout; // A YES/NO here is a move to learn: "Delete a move to make room?" NO, // then, right after, "Stop learning?" YES. B to "Stop learning?" goes // back to the first, for good (console B, 2026-11-01). - WallClock last_no = WallClock::min(); + std::optional last_no; while (current_time() < deadline){ BattleScreenWatcher battle(COLOR_RED); BattleMenuWatcher battle_menu(COLOR_RED); @@ -434,7 +441,7 @@ TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Mill SelectionArrowWatcher no(COLOR_RED, &console.overlay(), SelectionArrowPositionConfirmationMenu::NO); BattleLearnDialogWatcher learn(COLOR_RED); context.wait_for_all_requests(); - const int ret = run_until( + int ret = run_until( console, context, [](ProControllerContext& context){ for (int c = 0; c < 5; c++){ @@ -443,11 +450,16 @@ TextEnd advance_text(ConsoleHandle& console, ProControllerContext& context, Mill }, {battle, battle_menu, yes, no, learn} ); + // The arrow watchers alone match scenery (a rock's edge on Route 3), + // so a YES/NO also needs its box. + if ((ret == 2 || ret == 3) && !yes_no_shows(console)){ + ret = -1; + } if (ret >= 2){ - const bool stop_learning = current_time() - last_no < 10000ms; + const bool stop_learning = last_no && current_time() - *last_no < 10000ms; console.log(stop_learning ? "Text: YES/NO, YES (stop learning)." : "Text: YES/NO, NO."); press(context, stop_learning ? BUTTON_A : BUTTON_B, 1500ms); - last_no = stop_learning ? WallClock::min() : current_time(); + last_no = stop_learning ? std::nullopt : std::optional(current_time()); continue; } if (ret >= 0 && stop_at_battle){ From 8b423c902661cfa23507233531416a8801684441 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 20:14:14 -0800 Subject: [PATCH 60/75] FRLG AutoStory simulation: fail a leg to a wall that would walk on Each planned route in the story table is now checked for a leg marked "to wall" whose end isn't stopped by the map's edge, a wall or water, or that has a warp ahead, even to a map that isn't loaded (console B, 2026-11-02, Route 4's Pokemon Center escalator). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index 56f3269033..6410a0710c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -53,6 +53,37 @@ const MapData* map_named(const std::string& name){ return nullptr; } +// Whether the player, at the end of a WALK `step`, stops there holding on: +// the map's edge, a wall, or water to Surf onto, but no warp of any kind, +// even one to a map that isn't loaded. +bool stops_past_end(const RouteStep& step){ + const MapData& map = *map_named(step.end.map); + const TilePos here = step.end.point; + const TilePos ahead = here.next(step.direction); + if (!in_bounds(map, ahead)){ + return true; + } + if (warps_on_step(map, ahead) || exit_mat(map, here) == step.direction + || (step.direction == Direction::NORTH && is_door(map, ahead)) + ){ + return false; + } + const StepKind kind = classify_step(map, PlayerState{here, elevation_at(map, here), step.surfing}, step.direction); + return kind == StepKind::BLOCKED || kind == StepKind::START_SURF; +} + +// The first leg of `route` to a wall that holding on would carry past its +// end, or nothing (console B, 2026-11-02: one rode Route 4's Pokemon +// Center escalator). +std::optional overrun_wall_leg(const std::vector& route){ + for (const RouteStep& step : route){ + if (step.to_wall && !stops_past_end(step)){ + return to_string(step); + } + } + return std::nullopt; +} + // Where the run stands, with a facing: a wall beside it when unknown. struct Standing{ MapPosition position; @@ -178,6 +209,9 @@ class FakeGame : public Pokemon::StoryStepExecutor{ if (!(end == goal.position)){ return Pokemon::outcome_failed("wrong_end", to_string(end)); } + if (const std::optional leg = overrun_wall_leg(*route)){ + return Pokemon::outcome_failed("wall_overrun", *leg); + } const Direction facing = route->empty() ? at.facing : route->back().facing_after; return Pokemon::outcome_ok(to_pose(StoryPose{target->map, target->tile, facing})); } From 0a739f2cb4cc661454e382283a3fa0ae5b0b42b6 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 21:28:03 -0800 Subject: [PATCH 61/75] FRLG AutoStory: learn moves, let evolutions finish, protect the party The battle loop declined every new move, pressed B through evolutions (Squirtle stayed Lv16 on console B) and assumed a party of one. Its choices move into BattleDecisions so they run in tests: the lead's moves and PP are tracked from pret's learnsets (data tables in PokemonFRLG_AutoStoryParty), "Delete a move?" is answered from a per-line plan (Water Gun over Bubble, Bite over Tail Whip) and the move list is walked to the slot; the preferred attack is used until its PP run out, then Tackle, and "no PP left" picks again. Nothing is pressed while an evolution may be on screen. A fainted lead runs from wild battles and never sends a protected member; the nurse restores PP, and the ready step goes to her when the attacks are low. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 + .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 241 ++++++++---- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 37 +- .../PokemonFRLG_AutoStoryBattleDecisions.cpp | 175 +++++++++ .../PokemonFRLG_AutoStoryBattleDecisions.h | 150 ++++++++ .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 12 +- .../AutoStory/PokemonFRLG_AutoStoryParty.cpp | 352 ++++++++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryParty.h | 117 ++++++ .../PokemonFRLG_AutoStoryParty_Tests.cpp | 351 +++++++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 11 +- SerialPrograms/cmake/SourceFiles.cmake | 5 + 11 files changed, 1364 insertions(+), 89 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index cc050e97dd..b59cb1ab95 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -38,6 +38,7 @@ #include "Overworld/PokemonFRLG_PlayerFacingReader.h" #include "PokemonFRLG_Navigation.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h" +#include "Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryTable.h" #include "Tests/TestUtils.h" @@ -311,6 +312,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStory(database); add_tests_AutoStorySimulation(database); add_tests_AutoStoryItems(database); + add_tests_AutoStoryParty(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 8ad4ccaa46..645160ade1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -19,9 +19,11 @@ #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyMenuDetector.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattleDecisions.h" #include "PokemonFRLG_AutoStoryBattle.h" namespace PokemonAutomation{ @@ -53,16 +55,15 @@ constexpr Milliseconds NO_MENU_NEAR = 10000ms; // is checked by START this often (a trainer's battle that never started, // console B, 2026-11-01: 10 minutes of B on the overworld). constexpr Milliseconds OVERWORLD_CHECK = 3000ms; -// A wild Pokemon is fought (WILD_FIGHT) only with green HP and this many -// Potions left; otherwise it is run from. -constexpr int MIN_POTIONS_TO_FIGHT = 2; -// RUN this many times ("Can't escape!") before fighting instead. -constexpr int RUN_TRIES = 4; // No battle menu or HP box this long after a battle was seen: there was // none (console B, 2026-11-01, Viridian Forest's north gate mat). constexpr Milliseconds NOT_A_BATTLE = 15000ms; -// PSN read at this many turns in a row before an Antidote. -constexpr int PSN_READS = 2; +// An evolution's animation, with no presses: as long as exit_wild_battle() +// (PokemonFRLG_Navigation.cpp) waits for one. +constexpr Milliseconds EVOLUTION = 20000ms; +// Below this much PP left in the lead's attacks, the nurse before a fight +// that needs them: about a trainer's worth of turns. +constexpr size_t LOW_ATTACK_PP = 10; // Text and the move learn prompts after a battle, on the overworld. constexpr Milliseconds AFTER_BATTLE_TEXT = 60000ms; @@ -167,6 +168,15 @@ BattleScreen read_battle_screen(const ImageViewRGB32& screen, bool confirmed){ return BattleScreen::NONE; } +BattleTextScreen read_text_screen(const ImageViewRGB32& screen){ + return BattleTextScreen{ + .text_box = BattleDialogDetector(COLOR_RED).detect(screen), + .hp_box = BattleScreenDetector(COLOR_RED).detect(screen), + .arrow = AdvanceBattleDialogDetector(COLOR_RED).detect(screen), + .yes_no = BattleLearnDialogDetector(COLOR_RED).detect(screen) || yes_no_cursor(screen).has_value(), + }; +} + // The player's Pokemon gone while the opponent's is still there. bool starter_fainted(const ImageViewRGB32& screen){ return !BattlePokemonDetector(COLOR_RED).detect(screen) && BattleOpponentDetector(COLOR_RED).detect(screen); @@ -243,18 +253,45 @@ void run_away(ProControllerContext& context){ pbf_press_button(context, BUTTON_A, 160ms, 500ms); } -// FIGHT, then the bottom left move (Bubble), or Tackle while that slot is -// empty: the cursor doesn't move onto an empty slot. -void use_move(ProControllerContext& context){ +// FIGHT, then the move in `slot` from the top left. The cursor doesn't +// move onto an empty slot. +void use_move(ProControllerContext& context, size_t slot){ tap(context, DPAD_LEFT); tap(context, DPAD_UP); pbf_press_button(context, BUTTON_A, 160ms, 1000ms); tap(context, DPAD_LEFT); tap(context, DPAD_UP); - tap(context, DPAD_DOWN); + if (slot % 2 == 1){ + tap(context, DPAD_RIGHT); + } + if (slot >= 2){ + tap(context, DPAD_DOWN); + } pbf_press_button(context, BUTTON_A, 160ms, 500ms); } +// After YES to "Delete a move?": the move list fades in with its cursor on +// the top move (pret pokemon_summary_screen.c); A on a move forgets it, +// B would go back to "Stop learning?". Done in one go, so the loop's B +// presses can't land on the list. +void forget_move(ProControllerContext& context, size_t slot){ + pbf_press_button(context, BUTTON_A, 160ms, 2500ms); + for (size_t c = 0; c < slot; c++){ + pbf_press_dpad(context, DPAD_DOWN, 160ms, 400ms); + } + pbf_press_button(context, BUTTON_A, 160ms, 2000ms); +} + +// The party list in battle opens on the lead: down to `slot`, then A, and +// SHIFT, the top of its menu. +void send_member(ProControllerContext& context, size_t slot){ + for (size_t c = 0; c < slot; c++){ + pbf_press_dpad(context, DPAD_DOWN, 160ms, 400ms); + } + pbf_press_button(context, BUTTON_A, 160ms, 800ms); + pbf_press_button(context, BUTTON_A, 160ms, 1500ms); +} + class BattleLoop{ public: @@ -265,6 +302,8 @@ class BattleLoop{ : m_console(console) , m_context(context) , m_supplies(supplies) + , m_decisions(supplies, kind) + , m_evolution(supplies.lead) , m_kind(kind) , m_checks(checks) , m_language(language) @@ -284,8 +323,10 @@ class BattleLoop{ while (!over){ over = step(); } - m_console.log(std::format("Battle: over after {} turns{}.", m_turns, m_lost ? ", the starter fainted" : "")); - return m_lost ? BattleEnd::LOST : BattleEnd::WON; + m_console.log(std::format( + "Battle: over after {} turns{}.", m_decisions.turns(), m_decisions.lost() ? ", the starter fainted" : "" + )); + return m_decisions.lost() ? BattleEnd::LOST : BattleEnd::WON; } private: @@ -307,13 +348,17 @@ class BattleLoop{ m_console.log("Battle: no battle menu or HP box in 15 s: not a battle.", COLOR_ORANGE); return true; } + if (between_turns(screen, now)){ + return false; + } const BattleScreen seen = read_battle_screen(screen, m_confirmed); if (seen != m_last_seen){ - m_console.log(std::format("Battle: {} (turn {}).", screen_name(seen), m_turns)); + m_console.log(std::format("Battle: {} (turn {}).", screen_name(seen), m_decisions.turns())); m_last_seen = seen; } if (seen == BattleScreen::MENU){ m_last_menu = now; + m_move_chosen = false; }else if (now - m_last_menu > NO_MENU && now - m_last_battle < NO_MENU_NEAR && now - m_last_press > 1500ms){ // Something waits that none of the battle screens knows. m_console.log(std::format("Battle: no battle menu for {} s, pressing {}.", @@ -329,10 +374,74 @@ class BattleLoop{ m_seen_battle = true; m_last_battle = now; read_hp(screen); + watch_for_faint(screen); act(seen, screen, now); return false; } + // The screens between the turns that need more than B: "no PP left", + // the party list once the lead fainted, and an evolution after the + // battle. True if one was handled. + bool between_turns(const ImageViewRGB32& screen, WallClock now){ + if (!m_confirmed){ + return false; + } + if (m_move_chosen && BattleOutOfPpDetector(COLOR_RED).detect(screen)){ + m_console.log("Battle: no PP left for that move; choosing again.", COLOR_ORANGE); + m_decisions.turn_done(TurnChoice::MOVE, false); + m_move_chosen = false; + pbf_press_button(m_context, BUTTON_B, 160ms, 800ms); + pbf_press_button(m_context, BUTTON_B, 160ms, 800ms); + m_last_press = now; + return true; + } + if (m_decisions.lost() && PartyMenuDetector(COLOR_RED).detect(screen)){ + send_next_member(now); + return true; + } + if (m_evolution.holds(read_text_screen(screen), m_decisions.turns())){ + wait_out_evolution(); + return true; + } + return false; + } + + // The party list after the lead fainted: the next member allowed in, or + // a stop with only protected members left. + void send_next_member(WallClock now){ + const std::optional slot = m_decisions.next_member_slot(); + if (!slot){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::NO_ERROR_REPORT, + "fight_battle(): the starter fainted and only protected members are left; not sending one.", + m_console + ); + } + m_console.log(std::format("Battle: the lead fainted; sending party slot {}.", *slot + 1), COLOR_ORANGE); + send_member(m_context, *slot); + m_last_press = now; + } + + // Nothing pressed while the screen may be an evolution, up to EVOLUTION. + void wait_out_evolution(){ + const WallClock start = current_time(); + bool holds = true; + while (holds && current_time() - start < EVOLUTION){ + pbf_wait(m_context, POLL); + m_context.wait_for_all_requests(); + VideoSnapshot screen = m_console.video().snapshot(); + holds = !screen || m_evolution.holds(read_text_screen(screen), m_decisions.turns()); + } + const WallClock end = current_time(); + const Milliseconds held = std::chrono::duration_cast(end - start); + if (held >= 2000ms){ + m_console.log(std::format("Battle: no B for {} s, for an evolution.", held.count() / 1000)); + } + m_evolution.held(held, m_decisions.lost()); + m_last_press = end; + m_last_battle = end; + } + // True once the battle is over: only when START opens the menu. The // battle screens are gone during the opening slide-in (console B: "over // after 0 turns" at the rival) and under a move prompt's YES/NO (console @@ -343,8 +452,8 @@ class BattleLoop{ pbf_wait(m_context, POLL); return false; } - if (m_turns > 0 && yes_no_cursor(screen)){ - answer_learn_prompt(now); + if (m_decisions.turns() > 0 && yes_no_cursor(screen)){ + answer_prompt(screen, now); return false; } if (now - m_last_battle > BATTLE_GONE && now - m_last_overworld_check > OVERWORLD_CHECK){ @@ -384,11 +493,11 @@ class BattleLoop{ m_last_press = now; return; case BattleScreen::LEARN: - if (m_turns == 0){ - // The learn prompts come after a turn; before one it is a misread. + if (m_decisions.turns() == 0){ + // The prompts come after a turn; before one it is a misread. break; } - answer_learn_prompt(now); + answer_prompt(screen, now); return; case BattleScreen::ADVANCE: pbf_press_button(m_context, BUTTON_B, 160ms, 200ms); @@ -397,7 +506,6 @@ class BattleLoop{ default: break; } - watch_for_faint(screen); if (now - m_last_press > STUCK){ pbf_press_button(m_context, BUTTON_B, 160ms, 200ms); m_last_press = now; @@ -406,9 +514,9 @@ class BattleLoop{ } // The HP bar whenever the starter's box shows, so the last reading - // includes the battle's last hit. + // includes the battle's last hit. Not once another member is out. void read_hp(const ImageViewRGB32& screen){ - if (!BattlePokemonDetector(COLOR_RED).detect(screen)){ + if (m_decisions.lost() || !BattlePokemonDetector(COLOR_RED).detect(screen)){ return; } const PartyStatus status = read_party_status(screen); @@ -419,77 +527,65 @@ class BattleLoop{ m_supplies.status = status.status; } - // "Delete a move to make room?" NO, then "Stop learning?" YES. - void answer_learn_prompt(WallClock now){ - m_console.log(m_learn_prompts % 2 == 0 ? "Battle: not deleting a move." : "Battle: stop learning."); - pbf_press_button(m_context, m_learn_prompts % 2 == 0 ? BUTTON_B : BUTTON_A, 160ms, 1500ms); - m_learn_prompts++; + void answer_prompt(const ImageViewRGB32& screen, WallClock now){ + const PromptAnswer answer = m_decisions.prompt(starter_fainted(screen)); + if (answer.forget_slot){ + m_console.log(std::format("Battle: learning the new move over move {}.", *answer.forget_slot + 1)); + forget_move(m_context, *answer.forget_slot); + }else{ + m_console.log(std::format("Battle: answering {} to a YES/NO.", answer.answer == YesNo::YES ? "YES" : "NO")); + pbf_press_button(m_context, answer.answer == YesNo::YES ? BUTTON_A : BUTTON_B, 160ms, 1500ms); + } m_last_press = now; } void take_turn(const ImageViewRGB32& screen){ - m_turns++; m_faint_polls = 0; const PartyStatus status = read_party_status(screen); - const bool hurt = status.hp_red || status.hp_yellow; - m_supplies.hurt = hurt; - m_supplies.status = status.status; - m_psn_reads = status.status == StatusCondition::POISON ? m_psn_reads + 1 : 0; + const TurnAction action = m_decisions.turn(status); m_console.log(std::format( "Battle: turn {}, HP {}, {}, {} Potions, {} Antidotes, {} Parlyz Heals.", - m_turns, status.hp_red ? "red" : status.hp_yellow ? "yellow" : "green", + m_decisions.turns(), status.hp_red ? "red" : status.hp_yellow ? "yellow" : "green", status_name(status.status), m_supplies.potions, m_supplies.antidotes, m_supplies.parlyz_heals )); - // A wild Pokemon is fought for EXP only at full strength: fighting - // every one in Viridian Forest used up all 4 Potions and then the - // starter (console B, 2026-11-01). With a status, it is run from too. - const bool weak = hurt || status.status != StatusCondition::NONE || m_supplies.potions < MIN_POTIONS_TO_FIGHT; - const bool run = m_kind == BattleKind::WILD_RUN || (m_kind == BattleKind::WILD_FIGHT && weak); - if (run && m_run_tries < RUN_TRIES){ - m_run_tries++; - m_console.log(std::format("Battle: RUN (try {}).", m_run_tries)); + switch (action.choice){ + case TurnChoice::RUN: + m_console.log("Battle: RUN."); run_away(m_context); return; - } - if (!m_items_off && hurt && m_supplies.potions > 0){ - if (use_item(m_console, m_context, item_row(m_supplies, "potion"), "potion", m_checks, m_language)){ - m_supplies.potions--; - m_supplies.hurt = false; - m_supplies.hp_red = false; - }else{ - m_items_off = true; - } - }else if (!m_items_off && m_psn_reads >= PSN_READS && !m_antidote_used && m_supplies.antidotes > 0){ - m_antidote_used = true; - if (use_item(m_console, m_context, item_row(m_supplies, "antidote"), "antidote", m_checks, m_language)){ - m_supplies.antidotes--; - }else{ - m_items_off = true; - } - }else{ - use_move(m_context); + case TurnChoice::POTION: + m_decisions.turn_done(action.choice, use_item(m_console, m_context, item_row(m_supplies, "potion"), "potion", m_checks, m_language)); + return; + case TurnChoice::ANTIDOTE: + m_decisions.turn_done(action.choice, use_item(m_console, m_context, item_row(m_supplies, "antidote"), "antidote", m_checks, m_language)); + return; + case TurnChoice::MOVE: + m_console.log(std::format("Battle: move {}.", action.slot + 1)); + use_move(m_context, action.slot); + m_move_chosen = true; + return; } } void watch_for_faint(const ImageViewRGB32& screen){ - if (m_turns == 0 || m_lost){ + if (m_decisions.turns() == 0 || m_decisions.lost()){ return; } m_faint_polls = starter_fainted(screen) ? m_faint_polls + 1 : 0; if (m_faint_polls >= FAINT_POLLS){ m_console.log("Battle: the starter fainted.", COLOR_RED); - m_lost = true; + m_decisions.lead_fainted(); } } ConsoleHandle& m_console; ProControllerContext& m_context; Supplies& m_supplies; + BattleDecisions m_decisions; + EvolutionHold m_evolution; const BattleKind m_kind; const StoryChecks m_checks; const Language m_language; - // An item read as another in the bag: none is used again this battle. - bool m_items_off = false; const WallClock m_start; WallClock m_last_battle; WallClock m_last_press; @@ -498,13 +594,9 @@ class BattleLoop{ BattleScreen m_last_seen = BattleScreen::NONE; bool m_seen_battle = false; bool m_confirmed = false; - bool m_lost = false; bool m_press_a = true; - bool m_antidote_used = false; - int m_psn_reads = 0; - int m_run_tries = 0; - size_t m_turns = 0; - size_t m_learn_prompts = 0; + // A move was chosen and no battle menu has shown since. + bool m_move_chosen = false; int m_faint_polls = 0; }; @@ -769,6 +861,17 @@ void recover_after_battle( } } +void healed_by_nurse(Supplies& supplies){ + supplies.hurt = false; + supplies.hp_red = false; + supplies.status = StatusCondition::NONE; + restore_pp(supplies.lead); +} + +bool attacks_low_on_pp(const Supplies& supplies){ + return attack_slot(supplies.lead).has_value() && attack_pp(supplies.lead) < LOW_ATTACK_PP; +} + BattleEnd fight_battle( ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind, StoryChecks checks, Language language diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index 6e9f22f15e..da0ccb241e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -2,15 +2,15 @@ * * From: https://github.com/PokemonAutomation/ * - * The battle loop of the FRLG story, for a party of one (the starter), as - * the by-hand run to Brock played it (console B, 2026-11-01): at each turn - * the cursor is put back on FIGHT and the move list's top left, since the - * game remembers both; the move is the bottom left one (Bubble), which the - * cursor can't reach while that slot is empty, so before Bubble it stays on - * Tackle. A Potion is used when the HP bar turns yellow or red, an Antidote - * (once a battle) when the status reads PSN at two turns in a row; after - * the battle, PSN and PAR are cured from the bag. - * "Delete a move to make room?" is answered NO and "Stop learning?" YES. + * The battle loop of the FRLG story, the starter leading, as the by-hand + * run to Brock played it (console B, 2026-11-01): at each turn the cursor + * is put back on FIGHT and the move list's top left, since the game + * remembers both, then onto the move BattleDecisions picks. A Potion is + * used when the HP bar turns yellow or red, an Antidote (once a battle) + * when the status reads PSN at two turns in a row; after the battle, PSN + * and PAR are cured from the bag. Move prompts, an evolution after the + * battle and a fainted lead are as PokemonFRLG_AutoStoryBattleDecisions.h + * says. * * Also the overworld interrupts the story walks routes with: wild battles * run from (or fought, for EXP), and messages, after which a trainer's @@ -30,6 +30,7 @@ #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryParty.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -63,8 +64,21 @@ struct Supplies{ // screen that showed it, and no Potion or nurse healed it since. bool hurt = false; bool hp_red = false; + // The starter's moves and their PP, as far as the story knows them: + // a new game's Squirtle unless a checkpoint's row says otherwise. + PartyMember lead = new_member("squirtle", 5); + // Party slots (from 0, the lead) that are never sent in when the lead + // faints, so they gain no EXP and learn or evolve nothing: a member + // kept for later, or one the user keeps for a trade. + std::vector protected_slots = {}; }; +// The nurse healed the party: HP, status and PP. +void healed_by_nurse(Supplies& supplies); + +// The lead's attacks are low on PP: the nurse before a fight that needs them. +bool attacks_low_on_pp(const Supplies& supplies); + enum class BattleKind{ WILD_RUN, // RUN, or fight after a few "Can't escape!" WILD_FIGHT, // fight for EXP with green HP, no status and 2 Potions, else RUN @@ -73,8 +87,9 @@ enum class BattleKind{ enum class BattleEnd{ WON, - // The starter fainted: a blackout, except in the lab's rival battle, - // which the story goes on from. + // The starter fainted: a blackout, or a wild battle run from (or won) + // by the next member, except in the lab's rival battle, which the + // story goes on from. LOST, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp new file mode 100644 index 0000000000..6c188bdefb --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -0,0 +1,175 @@ +/* AutoStory Battle Decisions + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "PokemonFRLG_AutoStoryBattleDecisions.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +constexpr size_t PARTY_SLOTS = 6; +// A wild Pokemon is fought (WILD_FIGHT) only with green HP and this many +// Potions left; otherwise it is run from. +constexpr int MIN_POTIONS_TO_FIGHT = 2; +// RUN this many times ("Can't escape!") before fighting instead. +constexpr int RUN_TRIES = 4; +// PSN read at this many turns in a row before an Antidote. +constexpr int PSN_READS = 2; +// An evolution screen held this long was an evolution, not a text box +// between two others. +constexpr Milliseconds EVOLUTION_SEEN = std::chrono::milliseconds(5000); +// Nothing pressed for at most this long in all in a battle: an evolution +// and the next member's, with room to spare. +constexpr Milliseconds EVOLUTION_HOLDS = std::chrono::milliseconds(45000); + +} + + +BattleDecisions::BattleDecisions(Supplies& supplies, BattleKind kind) + : m_supplies(supplies) + , m_kind(kind) +{} + +TurnAction BattleDecisions::turn(const PartyStatus& status){ + m_turns++; + m_last_move_slot.reset(); + if (!m_lost){ + return lead_turn(status); + } + // The next member is out: it runs from a wild Pokemon for as long as + // it takes, and against a trainer uses its first move. + if (m_kind != BattleKind::TRAINER){ + return TurnAction{.choice = TurnChoice::RUN}; + } + return TurnAction{.choice = TurnChoice::MOVE, .slot = TOP_LEFT_MOVE}; +} + +TurnAction BattleDecisions::lead_turn(const PartyStatus& status){ + const bool hurt = status.hp_red || status.hp_yellow; + m_supplies.hurt = hurt; + m_supplies.status = status.status; + m_psn_reads = status.status == StatusCondition::POISON ? m_psn_reads + 1 : 0; + // A wild Pokemon is fought for EXP only at full strength: fighting + // every one in Viridian Forest used up all 4 Potions and then the + // starter (console B, 2026-11-01). With a status, it is run from too. + const bool weak = hurt || status.status != StatusCondition::NONE || m_supplies.potions < MIN_POTIONS_TO_FIGHT; + const bool run = m_kind == BattleKind::WILD_RUN || (m_kind == BattleKind::WILD_FIGHT && weak); + if (run && m_run_tries < RUN_TRIES){ + m_run_tries++; + return TurnAction{.choice = TurnChoice::RUN}; + } + if (!m_items_off && hurt && m_supplies.potions > 0){ + return TurnAction{.choice = TurnChoice::POTION}; + } + if (!m_items_off && m_psn_reads >= PSN_READS && !m_antidote_used && m_supplies.antidotes > 0){ + m_antidote_used = true; + return TurnAction{.choice = TurnChoice::ANTIDOTE}; + } + return move_turn(); +} + +// The plan's attack with PP left. While the story doesn't know all four +// moves, the bottom left one (Bubble from Lv7), which the cursor can't +// reach while that slot is empty, so before Bubble it stays on Tackle. +TurnAction BattleDecisions::move_turn(){ + const std::optional slot = attack_slot(m_supplies.lead); + if (!slot){ + return TurnAction{.choice = TurnChoice::MOVE, .slot = BOTTOM_LEFT_MOVE}; + } + spend_pp(m_supplies.lead, *slot); + m_last_move_slot = slot; + return TurnAction{.choice = TurnChoice::MOVE, .slot = *slot}; +} + +void BattleDecisions::turn_done(TurnChoice choice, bool done){ + if (!done && choice == TurnChoice::MOVE){ + if (m_last_move_slot){ + no_pp_left(m_supplies.lead, *m_last_move_slot); + } + return; + } + if (!done){ + m_items_off = true; + return; + } + switch (choice){ + case TurnChoice::POTION: + m_supplies.potions--; + m_supplies.hurt = false; + m_supplies.hp_red = false; + return; + case TurnChoice::ANTIDOTE: + m_supplies.antidotes--; + return; + case TurnChoice::RUN: + case TurnChoice::MOVE: + return; + } +} + +PromptAnswer BattleDecisions::prompt(bool lead_box_gone){ + if (lead_box_gone){ + lead_fainted(); + // NO tries to run; if that fails, the party list opens. + return PromptAnswer{.answer = m_kind == BattleKind::TRAINER ? YesNo::YES : YesNo::NO}; + } + if (m_declined_delete){ + // "Stop learning ?" YES; NO would ask "Delete a move?" again. + m_declined_delete = false; + return PromptAnswer{.answer = YesNo::YES}; + } + const LearnDecision decision = learn_move(m_supplies.lead); + if (decision.forget_slot){ + return PromptAnswer{.answer = YesNo::YES, .forget_slot = decision.forget_slot}; + } + m_declined_delete = true; + return PromptAnswer{.answer = YesNo::NO}; +} + +std::optional BattleDecisions::next_member_slot(){ + lead_fainted(); + // A slot sent before and still offered was empty or fainted: the next. + for (size_t slot = 1; slot < PARTY_SLOTS; slot++){ + const bool kept = std::ranges::find(m_supplies.protected_slots, slot) != m_supplies.protected_slots.end(); + if (!kept && !m_sent.contains(slot)){ + m_sent.insert(slot); + return slot; + } + } + return std::nullopt; +} + +void BattleDecisions::lead_fainted(){ + m_lost = true; +} + +EvolutionHold::EvolutionHold(PartyMember& lead) + : m_lead(lead) +{} + +bool EvolutionHold::holds(const BattleTextScreen& screen, size_t turns) const{ + return turns > 0 && m_held < EVOLUTION_HOLDS && screen.text_box && !screen.hp_box && !screen.arrow && !screen.yes_no; +} + +void EvolutionHold::held(Milliseconds held, bool lead_fainted){ + m_held += held; + // Only the lead fights, so only it evolves; once a battle. + if (held < EVOLUTION_SEEN || m_evolved || lead_fainted){ + return; + } + m_evolved = true; + evolve(m_lead); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h new file mode 100644 index 0000000000..572846d6f9 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h @@ -0,0 +1,150 @@ +/* AutoStory Battle Decisions + * + * From: https://github.com/PokemonAutomation/ + * + * What the story's battle loop chooses at each screen, apart from reading + * the screens and pressing the buttons, so the choices run in tests: + * each turn's action, the YES/NO prompts (a move to learn, "Use next + * POKEMON?"), when not to press B for an evolution, and the lead's PP. + * + * The party is the lead (the starter) and members that don't fight: the + * lead is never switched out. If it faints, a wild battle is run from + * ("Use next POKEMON?" NO); a trainer's, or a failed run, sends the next + * member not in Supplies::protected_slots, which only runs or uses its + * first move; with only protected ones left, the program stops instead. + * The battle counts as lost either way. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattleDecisions_H +#define PokemonAutomation_PokemonFRLG_AutoStoryBattleDecisions_H + +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryParty.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +enum class TurnChoice{ + RUN, + POTION, + ANTIDOTE, + MOVE, +}; + +struct TurnAction{ + TurnChoice choice = TurnChoice::MOVE; + // For MOVE, the move list's slot. + size_t slot = BOTTOM_LEFT_MOVE; +}; + +enum class YesNo{ + YES, + NO, +}; + +// A battle screen as the loop reads it, for the evolution check. +struct BattleTextScreen{ + // The battle's text box. + bool text_box = false; + // The battle menu or an HP box. + bool hp_box = false; + // The text waits for a button. + bool arrow = false; + // A YES/NO box. + bool yes_no = false; +}; + +struct PromptAnswer{ + YesNo answer = YesNo::NO; + // After YES to "Delete a move?": the slot to forget on the move list + // that opens, its cursor on the top move. + std::optional forget_slot = {}; +}; + + +class BattleDecisions{ +public: + BattleDecisions(Supplies& supplies, BattleKind kind); + + // At the battle menu, with the player's box as read. + TurnAction turn(const PartyStatus& status); + // What turn() chose was done, or not: an item not used (another item + // in its row), or a move the game said has no PP left. + void turn_done(TurnChoice choice, bool done); + + // A YES/NO in or after the battle. With the lead's box gone and the + // opponent's there, it is "Use next POKEMON?"; else the move prompts: + // "Delete a move to make room?", then "Stop learning?" after a NO. + PromptAnswer prompt(bool lead_box_gone); + + // The party list opened with the lead fainted: the slot to send in, + // or none if every member left is protected. + std::optional next_member_slot(); + + // The lead's box gone for good: it fainted. + void lead_fainted(); + bool lost() const{ return m_lost; } + + size_t turns() const{ return m_turns; } + +private: + TurnAction lead_turn(const PartyStatus& status); + TurnAction move_turn(); + + Supplies& m_supplies; + const BattleKind m_kind; + size_t m_turns = 0; + int m_run_tries = 0; + int m_psn_reads = 0; + bool m_antidote_used = false; + // An item read as another in the bag: none is used again this battle. + bool m_items_off = false; + bool m_lost = false; + // NO was answered to "Delete a move?": "Stop learning?" comes next. + bool m_declined_delete = false; + std::optional m_last_move_slot; + // The members sent in after the lead fainted. + std::set m_sent; +}; + + +// No B while an evolution may be on screen: any B cancels it (pret +// evolution_scene.c; console B, 2026-11-02: Squirtle stayed Lv16 after the +// battle loop's B presses). +class EvolutionHold{ +public: + explicit EvolutionHold(PartyMember& lead); + + // Whether `screen` may be an evolution: after a turn, the text box + // with no HP box and no arrow or YES/NO, as "What? is + // evolving!" shows through the animation. Nothing is pressed while it + // shows, for at most EVOLUTION_HOLDS in all in a battle, in case it is + // something else. + bool holds(const BattleTextScreen& screen, size_t turns) const; + // Such a screen showed for `held` with nothing pressed: long enough, + // and the lead evolved (unless it had fainted). + void held(Milliseconds held, bool lead_fainted); + +private: + PartyMember& m_lead; + bool m_evolved = false; + Milliseconds m_held = Milliseconds::zero(); +}; + + +void add_tests_AutoStoryParty(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 818441aa21..61731142c8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -162,7 +162,7 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ // HP and status are the battle loop's last reading. Items first (an // Antidote, a Parlyz Heal, a Potion); the nurse only for red HP with no -// Potion left, or a status no item here cures. +// Potion left, a status no item here cures, or attacks low on PP. Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ Supplies& supplies = env.supplies; env.console.log(std::format( @@ -170,7 +170,7 @@ Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ supplies.hp_red ? "red" : supplies.hurt ? "yellow" : "green", status_name(supplies.status), supplies.potions )); recover_after_battle(env.console, env.context, supplies, env.checks, env.language); - if (!supplies.hp_red && supplies.status == StatusCondition::NONE){ + if (!supplies.hp_red && supplies.status == StatusCondition::NONE && !attacks_low_on_pp(supplies)){ return Pokemon::outcome_ok(); } Outcome walked = walk_route(env, state, step); @@ -178,9 +178,7 @@ Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ return walked; } heal_at_center(env.console, env.context); - supplies.hurt = false; - supplies.hp_red = false; - supplies.status = StatusCondition::NONE; + healed_by_nurse(supplies); return walked; } @@ -394,9 +392,7 @@ Outcome StoryExecutor::battle(RunState&, const StoryStep& step){ Outcome StoryExecutor::heal(RunState&, const StoryStep&){ heal_at_center(m_env.console, m_env.context); - m_env.supplies.hurt = false; - m_env.supplies.hp_red = false; - m_env.supplies.status = StatusCondition::NONE; + healed_by_nurse(m_env.supplies); return Pokemon::outcome_ok(); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp new file mode 100644 index 0000000000..1da41c90c1 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp @@ -0,0 +1,352 @@ +/* AutoStory Party + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "PokemonFRLG_AutoStoryParty.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +struct LevelUpMove{ + std::string_view species; + uint8_t level = 0; + std::string_view move; +}; + +// pret/pokefirered src/data/pokemon/level_up_learnsets.h, the lines the +// story's party comes from. +constexpr LevelUpMove LEVEL_UP_MOVES[] = { + {.species = "squirtle", .level = 1, .move = "tackle"}, + {.species = "squirtle", .level = 4, .move = "tail-whip"}, + {.species = "squirtle", .level = 7, .move = "bubble"}, + {.species = "squirtle", .level = 10, .move = "withdraw"}, + {.species = "squirtle", .level = 13, .move = "water-gun"}, + {.species = "squirtle", .level = 18, .move = "bite"}, + {.species = "squirtle", .level = 23, .move = "rapid-spin"}, + {.species = "squirtle", .level = 28, .move = "protect"}, + {.species = "squirtle", .level = 33, .move = "rain-dance"}, + {.species = "squirtle", .level = 40, .move = "skull-bash"}, + {.species = "squirtle", .level = 47, .move = "hydro-pump"}, + {.species = "wartortle", .level = 1, .move = "tackle"}, + {.species = "wartortle", .level = 1, .move = "tail-whip"}, + {.species = "wartortle", .level = 1, .move = "bubble"}, + {.species = "wartortle", .level = 4, .move = "tail-whip"}, + {.species = "wartortle", .level = 7, .move = "bubble"}, + {.species = "wartortle", .level = 10, .move = "withdraw"}, + {.species = "wartortle", .level = 13, .move = "water-gun"}, + {.species = "wartortle", .level = 19, .move = "bite"}, + {.species = "wartortle", .level = 25, .move = "rapid-spin"}, + {.species = "wartortle", .level = 31, .move = "protect"}, + {.species = "wartortle", .level = 37, .move = "rain-dance"}, + {.species = "wartortle", .level = 45, .move = "skull-bash"}, + {.species = "wartortle", .level = 53, .move = "hydro-pump"}, + {.species = "blastoise", .level = 1, .move = "tackle"}, + {.species = "blastoise", .level = 1, .move = "tail-whip"}, + {.species = "blastoise", .level = 1, .move = "bubble"}, + {.species = "blastoise", .level = 1, .move = "withdraw"}, + {.species = "blastoise", .level = 4, .move = "tail-whip"}, + {.species = "blastoise", .level = 7, .move = "bubble"}, + {.species = "blastoise", .level = 10, .move = "withdraw"}, + {.species = "blastoise", .level = 13, .move = "water-gun"}, + {.species = "blastoise", .level = 19, .move = "bite"}, + {.species = "blastoise", .level = 25, .move = "rapid-spin"}, + {.species = "blastoise", .level = 31, .move = "protect"}, + {.species = "blastoise", .level = 42, .move = "rain-dance"}, + {.species = "blastoise", .level = 55, .move = "skull-bash"}, + {.species = "blastoise", .level = 68, .move = "hydro-pump"}, + {.species = "magikarp", .level = 1, .move = "splash"}, + {.species = "magikarp", .level = 15, .move = "tackle"}, + {.species = "magikarp", .level = 30, .move = "flail"}, + {.species = "gyarados", .level = 1, .move = "thrash"}, + {.species = "gyarados", .level = 20, .move = "bite"}, + {.species = "gyarados", .level = 25, .move = "dragon-rage"}, + {.species = "gyarados", .level = 30, .move = "leer"}, + {.species = "gyarados", .level = 35, .move = "twister"}, + {.species = "gyarados", .level = 40, .move = "hydro-pump"}, + {.species = "gyarados", .level = 45, .move = "rain-dance"}, + {.species = "gyarados", .level = 50, .move = "dragon-dance"}, + {.species = "gyarados", .level = 55, .move = "hyper-beam"}, +}; + +struct Evolution{ + std::string_view species; + LevelEvolution evolution; +}; + +// pret/pokefirered src/data/pokemon/evolution.h. +constexpr Evolution EVOLUTIONS[] = { + {.species = "squirtle", .evolution = {.into = "wartortle", .level = 16}}, + {.species = "wartortle", .evolution = {.into = "blastoise", .level = 36}}, + {.species = "magikarp", .evolution = {.into = "gyarados", .level = 20}}, +}; + +struct MovePp{ + std::string_view move; + uint8_t pp = 0; +}; + +// pret/pokefirered src/data/battle_moves.h. +constexpr MovePp MOVE_PP[] = { + {.move = "tackle", .pp = 35}, + {.move = "tail-whip", .pp = 30}, + {.move = "bubble", .pp = 30}, + {.move = "withdraw", .pp = 40}, + {.move = "water-gun", .pp = 25}, + {.move = "bite", .pp = 25}, + {.move = "rapid-spin", .pp = 40}, + {.move = "protect", .pp = 10}, + {.move = "rain-dance", .pp = 5}, + {.move = "skull-bash", .pp = 15}, + {.move = "hydro-pump", .pp = 5}, + {.move = "splash", .pp = 40}, + {.move = "flail", .pp = 15}, + {.move = "thrash", .pp = 20}, + {.move = "dragon-rage", .pp = 10}, + {.move = "leer", .pp = 30}, + {.move = "twister", .pp = 20}, + {.move = "dragon-dance", .pp = 20}, + {.move = "hyper-beam", .pp = 5}, +}; + +// The story's plan per line (named by its first species): a level-up move +// it learns over a full move list, and the move whose slot it takes. Any +// other move offered over four is declined. Squirtle's is the speedrun's: +// Water Gun where Bubble was (so the attack stays bottom left), Bite over +// Tail Whip. TM moves are not level-up prompts and are not here. +struct LearnRule{ + std::string_view line; + std::string_view move; + std::string_view replaces; +}; +constexpr LearnRule LEARN_RULES[] = { + {.line = "squirtle", .move = "water-gun", .replaces = "bubble"}, + {.line = "squirtle", .move = "bite", .replaces = "tail-whip"}, + {.line = "magikarp", .move = "twister", .replaces = "splash"}, +}; + +// The attacks per line, the one used first at the top. +struct Attack{ + std::string_view line; + std::string_view move; +}; +constexpr Attack ATTACKS[] = { + {.line = "squirtle", .move = "water-gun"}, + {.line = "squirtle", .move = "bite"}, + {.line = "squirtle", .move = "bubble"}, + {.line = "squirtle", .move = "tackle"}, + {.line = "magikarp", .move = "bite"}, + {.line = "magikarp", .move = "twister"}, + {.line = "magikarp", .move = "tackle"}, +}; + + +// The first species of `species`'s line. +std::string_view line_of(std::string_view species){ + for (const Evolution& evolution : EVOLUTIONS){ + if (evolution.evolution.into == species){ + return line_of(evolution.species); + } + } + return species; +} + +bool knows(const PartyMember& member, std::string_view move){ + return std::ranges::any_of(member.moves, [move](const KnownMove& known){ + return known.move == move; + }); +} + +std::optional slot_of(const PartyMember& member, std::string_view move){ + for (size_t slot = 0; slot < member.moves.size(); slot++){ + if (member.moves[slot].move == move){ + return slot; + } + } + return std::nullopt; +} + +// The next level-up move past `moves_through_level` that it doesn't know. +const LevelUpMove* next_move(const PartyMember& member){ + for (const LevelUpMove& entry : LEVEL_UP_MOVES){ + if (entry.species == member.species && entry.level > member.moves_through_level && !knows(member, entry.move)){ + return &entry; + } + } + return nullptr; +} + +KnownMove at_full_pp(std::string_view move){ + return KnownMove{.move = std::string(move), .pp = max_pp(move)}; +} + +// The slot the plan gives `move`, over a full move list. +std::optional forget_slot_for(const PartyMember& member, std::string_view move){ + const std::string_view line = line_of(member.species); + for (const LearnRule& rule : LEARN_RULES){ + if (rule.line == line && rule.move == move){ + return slot_of(member, rule.replaces); + } + } + return std::nullopt; +} + +// Learns, or answers the prompt for, each of its moves at exactly `level`. +void take_level(PartyMember& member, uint8_t level){ + for (const LevelUpMove& entry : LEVEL_UP_MOVES){ + if (entry.species != member.species || entry.level != level || knows(member, entry.move)){ + continue; + } + if (member.moves.size() < MAX_MOVES){ + member.moves.emplace_back(at_full_pp(entry.move)); + }else if (std::optional slot = forget_slot_for(member, entry.move)){ + member.moves[*slot] = at_full_pp(entry.move); + } + } + member.moves_through_level = level; +} + +} + + +std::optional level_evolution(std::string_view species){ + for (const Evolution& evolution : EVOLUTIONS){ + if (evolution.species == species){ + return evolution.evolution; + } + } + return std::nullopt; +} + +uint8_t max_pp(std::string_view move){ + for (const MovePp& entry : MOVE_PP){ + if (entry.move == move){ + return entry.pp; + } + } + return 0; +} + +PartyMember new_member(std::string_view species, uint8_t level){ + PartyMember member{.species = std::string(species), .moves = {}, .moves_through_level = level}; + for (const LevelUpMove& entry : LEVEL_UP_MOVES){ + if (entry.species != species || entry.level > level || knows(member, entry.move)){ + continue; + } + if (member.moves.size() == MAX_MOVES){ + member.moves.erase(member.moves.begin()); + } + member.moves.emplace_back(at_full_pp(entry.move)); + } + return member; +} + +PartyMember grown_to(PartyMember member, uint8_t level){ + for (uint8_t at = static_cast(member.moves_through_level + 1); at <= level; at++){ + take_level(member, at); + const std::optional evolution = level_evolution(member.species); + if (evolution && evolution->level <= at){ + evolve(member); + // The new species learns its moves of the level it evolved at. + take_level(member, at); + } + } + return member; +} + +PartyMember story_lead_after_brock(){ + return grown_to(new_member("squirtle", 5), 13); +} + +LearnDecision learn_move(PartyMember& member){ + while (member.moves.size() < MAX_MOVES){ + const LevelUpMove* learned = next_move(member); + if (learned == nullptr){ + break; + } + member.moves.emplace_back(at_full_pp(learned->move)); + member.moves_through_level = learned->level; + } + const LevelUpMove* offered = next_move(member); + if (offered == nullptr){ + return LearnDecision{}; + } + member.moves_through_level = offered->level; + LearnDecision decision{.move = std::string(offered->move), .forget_slot = forget_slot_for(member, offered->move)}; + if (decision.forget_slot){ + member.moves[*decision.forget_slot] = at_full_pp(offered->move); + } + return decision; +} + +void evolve(PartyMember& member){ + if (const std::optional evolution = level_evolution(member.species)){ + member.species = std::string(evolution->into); + } +} + +std::optional attack_slot(const PartyMember& member){ + if (member.moves.size() < MAX_MOVES){ + return std::nullopt; + } + const std::string_view line = line_of(member.species); + for (const Attack& attack : ATTACKS){ + if (attack.line != line){ + continue; + } + const std::optional slot = slot_of(member, attack.move); + if (slot && member.moves[*slot].pp > 0){ + return slot; + } + } + for (size_t slot = 0; slot < member.moves.size(); slot++){ + if (member.moves[slot].pp > 0){ + return slot; + } + } + return TOP_LEFT_MOVE; +} + +size_t attack_pp(const PartyMember& member){ + const std::string_view line = line_of(member.species); + size_t pp = 0; + for (const Attack& attack : ATTACKS){ + if (attack.line != line){ + continue; + } + if (const std::optional slot = slot_of(member, attack.move)){ + pp += member.moves[*slot].pp; + } + } + return pp; +} + +void spend_pp(PartyMember& member, size_t slot){ + if (slot < member.moves.size() && member.moves[slot].pp > 0){ + member.moves[slot].pp--; + } +} + +void no_pp_left(PartyMember& member, size_t slot){ + if (slot < member.moves.size()){ + member.moves[slot].pp = 0; + } +} + +void restore_pp(PartyMember& member){ + for (KnownMove& known : member.moves){ + known.pp = max_pp(known.move); + } +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h new file mode 100644 index 0000000000..f915219ce0 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h @@ -0,0 +1,117 @@ +/* AutoStory Party + * + * From: https://github.com/PokemonAutomation/ + * + * The lead's moves as the story knows them, and the data its choices come + * from: level-up moves and evolutions (pret/pokefirered + * src/data/pokemon/level_up_learnsets.h, evolution.h), each move's PP + * (src/data/battle_moves.h), which new move takes which old one's slot, + * and which moves the lead attacks with first. + * + * Nothing reads the moves off the screen. The story starts from the moves + * a checkpoint's row says the lead has, and follows the game: a move + * learned into a free slot shows no prompt, so at the next "Delete a move?" + * the moves due before it are taken as learned. Which move is offered is + * the next level-up move after the last one, so the level isn't needed. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryParty_H +#define PokemonAutomation_PokemonFRLG_AutoStoryParty_H + +#include +#include +#include +#include +#include +#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The move slots, in the order of the battle's move list and the summary. +inline constexpr size_t TOP_LEFT_MOVE = 0; +inline constexpr size_t BOTTOM_LEFT_MOVE = 2; +inline constexpr size_t MAX_MOVES = 4; + +// A move the lead knows, by slug ("water-gun"), and the PP the story +// counts left. +struct KnownMove{ + std::string move; + uint8_t pp = 0; +}; + +struct PartyMember{ + std::string species; + // In slot order. Fewer than four while moves learned into free slots + // haven't been taken in yet (see the top of this file). + std::vector moves; + // The level of the last level-up move offered to it, learned or not. + uint8_t moves_through_level = 0; +}; + +// The species `species` evolves into by level, and at which level. +struct LevelEvolution{ + std::string_view into; + uint8_t level = 0; +}; +std::optional level_evolution(std::string_view species); + +// A move's full PP; 0 for a move the table doesn't have. +uint8_t max_pp(std::string_view move); + +// As the game gives `species` at `level` (a starter, a gift): its last four +// level-up moves up to `level`, at full PP. +PartyMember new_member(std::string_view species, uint8_t level); + +// The member as the story plays it up to `level`: each level-up move is +// learned into a free slot or answered as learn_move() says, and it +// evolves at its level. For the rows that start after a part of the story. +PartyMember grown_to(PartyMember member, uint8_t level); + +// Squirtle as the story leaves it after Brock (Lv13, Water Gun offered). +PartyMember story_lead_after_brock(); + + +// The answer to "Delete a move to make room for ?". +struct LearnDecision{ + // The move offered, if the table knows which one it is. + std::optional move = {}; + // The slot to forget for it, or none to keep the moves as they are. + std::optional forget_slot = {}; +}; + +// At "Delete a move to make room for ...?": takes in the moves learned +// into free slots since the last prompt, decides on the move offered, and +// leaves `member` as that answer will. +LearnDecision learn_move(PartyMember& member); + +// The lead evolved: its species becomes what it evolves into. +void evolve(PartyMember& member); + + +// The slot to attack with: the first of the plan's attacks for its line +// that it knows with PP left, else any move with PP left, else the top +// left (Struggle). None while the story doesn't know all four moves. +std::optional attack_slot(const PartyMember& member); + +// The PP left in the plan's attacks it knows. +size_t attack_pp(const PartyMember& member); + +// One use of the move in `slot`. +void spend_pp(PartyMember& member, size_t slot); + +// The game said the move in `slot` has no PP left. +void no_pp_left(PartyMember& member, size_t slot); + +// The nurse heals: every move back to full PP. +void restore_pp(PartyMember& member); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp new file mode 100644 index 0000000000..24f33cb033 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp @@ -0,0 +1,351 @@ +/* AutoStory Party Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The lead's moves as the story tracks them, and the battle loop's choices + * (BattleDecisions) against scripted screens: move prompts, a fainted lead, + * PP, and no B while an evolution may be on screen. + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryBattleDecisions.h" +#include "PokemonFRLG_AutoStoryParty.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace std::chrono_literals; + + +namespace{ + +class Test_AutoStoryParty : public UnitTest{ +public: + Test_AutoStoryParty(std::string name, std::function body) + : UnitTest("PokemonFRLG::AutoStoryParty - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_body(logger); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + + +std::vector move_names(const PartyMember& member){ + std::vector names; + for (const KnownMove& known : member.moves){ + names.push_back(known.move); + } + return names; +} + +std::string joined(const std::vector& names){ + std::string text; + for (const std::string& name : names){ + text += (text.empty() ? "" : ", ") + name; + } + return "[" + text + "]"; +} + +PartyMember with_moves(std::string species, std::vector moves, uint8_t through){ + PartyMember member{.species = std::move(species), .moves = {}, .moves_through_level = through}; + for (std::string& move : moves){ + const uint8_t pp = max_pp(move); + member.moves.emplace_back(KnownMove{.move = std::move(move), .pp = pp}); + } + return member; +} + +const PartyStatus GREEN{.hp_seen = true, .hp_yellow = false, .hp_red = false, .status = StatusCondition::NONE}; + + +// The moves the game gives, and the story's plan played to a level. +UnitTestResult test_movesets(Logger&){ + struct Case{ + std::string name; + PartyMember member; + std::string species; + std::vector moves; + }; + const std::vector cases{ + {.name = "new game Squirtle", .member = new_member("squirtle", 5), .species = "squirtle", .moves = {"tackle", "tail-whip"}}, + {.name = "Squirtle after Brock", .member = story_lead_after_brock(), .species = "squirtle", .moves = {"tackle", "tail-whip", "water-gun", "withdraw"}}, + {.name = "Squirtle to Lv20", .member = grown_to(new_member("squirtle", 5), 20), .species = "wartortle", .moves = {"tackle", "bite", "water-gun", "withdraw"}}, + {.name = "Magikarp to Lv25", .member = grown_to(new_member("magikarp", 5), 25), .species = "gyarados", .moves = {"splash", "tackle", "bite", "dragon-rage"}}, + }; + for (const Case& c : cases){ + if (c.member.species != c.species || move_names(c.member) != c.moves){ + return std::format( + "{}: expected {} {}, got {} {}.", + c.name, c.species, joined(c.moves), c.member.species, joined(move_names(c.member)) + ); + } + } + return true; +} + +// "Delete a move?": the move offered is the next level-up move, after the +// moves learned into free slots, and the plan says which slot it takes. +UnitTestResult test_learn_prompts(Logger&){ + struct Case{ + std::string name; + PartyMember member; + std::string offered; + std::optional forget_slot; + std::vector after; + }; + const std::vector cases{ + { + .name = "first prompt of a new game", + .member = new_member("squirtle", 5), + .offered = "water-gun", .forget_slot = BOTTOM_LEFT_MOVE, + .after = {"tackle", "tail-whip", "water-gun", "withdraw"}, + }, + { + .name = "Bite after Brock", + .member = story_lead_after_brock(), + .offered = "bite", .forget_slot = 1, + .after = {"tackle", "bite", "water-gun", "withdraw"}, + }, + { + // The lab's save from before the story learned moves. + .name = "Bite with Bubble kept", + .member = with_moves("squirtle", {"tackle", "tail-whip", "bubble", "withdraw"}, 13), + .offered = "bite", .forget_slot = 1, + .after = {"tackle", "bite", "bubble", "withdraw"}, + }, + { + .name = "Wartortle declines Rapid Spin", + .member = with_moves("wartortle", {"tackle", "bite", "water-gun", "withdraw"}, 19), + .offered = "rapid-spin", .forget_slot = std::nullopt, + .after = {"tackle", "bite", "water-gun", "withdraw"}, + }, + }; + for (Case c : cases){ + const LearnDecision decision = learn_move(c.member); + if (decision.move != c.offered || decision.forget_slot != c.forget_slot || move_names(c.member) != c.after){ + return std::format( + "{}: expected {} over slot {}, leaving {}; got {} over slot {}, leaving {}.", + c.name, c.offered, c.forget_slot ? std::to_string(*c.forget_slot) : "none", joined(c.after), + decision.move.value_or("nothing"), decision.forget_slot ? std::to_string(*decision.forget_slot) : "none", + joined(move_names(c.member)) + ); + } + } + return true; +} + +// NO to "Delete a move?" is followed by YES to "Stop learning?" (B there +// asks "Delete a move?" again, console B 2026-11-01); a move the plan +// wants is YES with the slot to forget. +UnitTestResult test_prompt_answers(Logger&){ + Supplies supplies; + supplies.lead = with_moves("wartortle", {"tackle", "bite", "water-gun", "withdraw"}, 19); + BattleDecisions decline(supplies, BattleKind::TRAINER); + decline.turn(GREEN); + const PromptAnswer first = decline.prompt(false); + const PromptAnswer second = decline.prompt(false); + if (first.answer != YesNo::NO || first.forget_slot || second.answer != YesNo::YES || second.forget_slot){ + return "Expected NO to \"Delete a move?\", then YES to \"Stop learning?\"."; + } + + Supplies learning; + learning.lead = story_lead_after_brock(); + BattleDecisions learn(learning, BattleKind::WILD_FIGHT); + learn.turn(GREEN); + const PromptAnswer answer = learn.prompt(false); + if (answer.answer != YesNo::YES || answer.forget_slot != std::optional(1)){ + return "Expected YES and Tail Whip's slot (1) for Bite."; + } + return true; +} + +// The lead fainted: a wild battle is run from, and a member sent only +// runs; in a trainer's, the next member is sent and uses its first move. +// Protected members are never sent: with only those left there is no +// slot, and the loop stops. Either way the +// battle is lost, and no item goes to the fainted lead. +UnitTestResult test_fainted_lead(Logger&){ + Supplies protected_party; + protected_party.protected_slots = {1, 2, 3, 4, 5}; + BattleDecisions only_protected(protected_party, BattleKind::WILD_FIGHT); + only_protected.turn(GREEN); + if (only_protected.prompt(true).answer != YesNo::NO || !only_protected.lost()){ + return "Expected NO to \"Use next POKEMON?\" in a wild battle, and the battle lost."; + } + if (only_protected.next_member_slot()){ + return "Expected no member sent with every member after the lead protected."; + } + + // Slot 1 protected, the rest not. + Supplies wild_supplies; + wild_supplies.potions = 3; + wild_supplies.protected_slots = {1}; + BattleDecisions wild(wild_supplies, BattleKind::WILD_FIGHT); + wild.turn(GREEN); + wild.prompt(true); + if (wild.next_member_slot() != std::optional(2) || wild.next_member_slot() != std::optional(3)){ + return "Expected slot 2 past the protected slot 1, then slot 3 if 2 couldn't go."; + } + const PartyStatus red{.hp_seen = true, .hp_yellow = false, .hp_red = true, .status = StatusCondition::NONE}; + for (int c = 0; c < 10; c++){ + if (wild.turn(red).choice != TurnChoice::RUN){ + return std::format("Expected the next member to run at turn {}, not fight or use an item.", c + 1); + } + } + + Supplies trainer_supplies; + BattleDecisions trainer(trainer_supplies, BattleKind::TRAINER); + trainer.turn(GREEN); + if (trainer.next_member_slot() != std::optional(1) || !trainer.lost()){ + return "Expected the member after the lead sent in a trainer's battle, and the battle lost."; + } + const TurnAction action = trainer.turn(GREEN); + if (action.choice != TurnChoice::MOVE || action.slot != TOP_LEFT_MOVE){ + return "Expected the next member to use its first move against a trainer."; + } + return true; +} + +// Water Gun until its 25 PP are gone, then Tackle; a "no PP left" moves +// on at once; the nurse restores all. Before the story knows four moves, +// the bottom left slot, as before. +UnitTestResult test_pp(Logger&){ + Supplies supplies; + supplies.lead = story_lead_after_brock(); + BattleDecisions decisions(supplies, BattleKind::TRAINER); + for (int c = 0; c < 25; c++){ + const TurnAction action = decisions.turn(GREEN); + if (action.choice != TurnChoice::MOVE || action.slot != BOTTOM_LEFT_MOVE){ + return std::format("Expected Water Gun (slot 2) at turn {}.", c + 1); + } + } + if (decisions.turn(GREEN).slot != TOP_LEFT_MOVE || attacks_low_on_pp(supplies)){ + return "Expected Tackle once Water Gun is out of PP, with its 34 PP not low."; + } + for (int c = 0; c < 30; c++){ + decisions.turn(GREEN); + } + if (!attacks_low_on_pp(supplies)){ + return "Expected the attacks low on PP with 4 Tackles left."; + } + healed_by_nurse(supplies); + if (supplies.lead.moves[BOTTOM_LEFT_MOVE].pp != 25 || attacks_low_on_pp(supplies)){ + return "Expected the nurse to restore Water Gun's 25 PP."; + } + + BattleDecisions out(supplies, BattleKind::TRAINER); + out.turn(GREEN); + out.turn_done(TurnChoice::MOVE, false); + if (out.turn(GREEN).slot != TOP_LEFT_MOVE){ + return "Expected Tackle after the game said Water Gun has no PP left."; + } + + Supplies new_game; + BattleDecisions unknown(new_game, BattleKind::TRAINER); + if (unknown.turn(GREEN).slot != BOTTOM_LEFT_MOVE){ + return "Expected the bottom left slot while the moves aren't all known."; + } + return true; +} + + +// A fake evolution scene: B pressed while it shows "is evolving!" cancels +// the evolution, as in the game. +struct FakeEvolution{ + std::vector frames; + size_t evolving_from = 0; + size_t evolving_to = 0; +}; + +// Plays `scene` against the loop's rule (B at any screen it doesn't hold +// for), after `turns` turns: whether the evolution went through. +bool evolves_against_loop(const FakeEvolution& scene, const EvolutionHold& hold, size_t turns){ + bool cancelled = false; + for (size_t frame = 0; frame < scene.frames.size(); frame++){ + const bool pressed_b = !hold.holds(scene.frames[frame], turns); + if (pressed_b && frame >= scene.evolving_from && frame < scene.evolving_to){ + cancelled = true; + } + } + return !cancelled; +} + +// Regression: Squirtle stayed Lv16 on console B (2026-11-02), the B +// presses after the battle cancelling its evolution. No B while "What? +// SQUIRTLE is evolving!" shows; B again for the arrow after it. +UnitTestResult test_no_b_during_evolution(Logger&){ + const BattleTextScreen in_battle{.text_box = true, .hp_box = true, .arrow = false, .yes_no = false}; + const BattleTextScreen evolving{.text_box = true, .hp_box = false, .arrow = false, .yes_no = false}; + const BattleTextScreen congratulations{.text_box = true, .hp_box = false, .arrow = true, .yes_no = false}; + const BattleTextScreen learn_prompt{.text_box = true, .hp_box = false, .arrow = false, .yes_no = true}; + FakeEvolution scene; + scene.frames = {in_battle, in_battle, congratulations}; + scene.frames.insert(scene.frames.begin() + 2, 40, evolving); + scene.evolving_from = 2; + scene.evolving_to = 42; + + PartyMember lead = with_moves("squirtle", {"tackle", "tail-whip", "bubble", "withdraw"}, 13); + EvolutionHold hold(lead); + if (!evolves_against_loop(scene, hold, 1)){ + return "B was pressed during \"is evolving!\": the evolution would be cancelled."; + } + if (hold.holds(congratulations, 1) || hold.holds(learn_prompt, 1)){ + return "Expected B (or the prompt's answer) for the text with an arrow and the YES/NO after the evolution."; + } + + hold.held(1s, false); + if (lead.species != "squirtle"){ + return "A text box held for 1 s was taken for an evolution."; + } + hold.held(15s, false); + if (lead.species != "wartortle"){ + return "Expected Squirtle to be Wartortle after 15 s of its evolution screen, got " + lead.species + "."; + } + hold.held(40s, false); + if (hold.holds(evolving, 1)){ + return "Expected no more holding once a battle's holds reach their cap."; + } + + PartyMember other = new_member("squirtle", 5); + EvolutionHold before_turn(other); + if (before_turn.holds(evolving, 0)){ + return "Held before the first turn, where Oak's text box needs B."; + } + return true; +} + + +} + + +void add_tests_AutoStoryParty(UnitTestDatabase& database){ + database.add("movesets the game gives and the story plays", test_movesets); + database.add("move offered and slot forgotten", test_learn_prompts); + database.add("YES/NO answers to move prompts", test_prompt_answers); + database.add("fainted lead runs or sends the next member", test_fainted_lead); + database.add("PP: preferred attack, then Tackle; nurse restores", test_pp); + database.add("no B during an evolution", test_no_b_during_evolution); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 8c0ec3a5dc..b21ee1c6c8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -48,6 +48,15 @@ StoryCheckpoint row( return checkpoint; } +// At the rows after Brock: no items counted, the starter with the moves +// the story gave it by Lv13. A save made before the story learned moves +// has Bubble where this says Water Gun: the same slot, 5 more PP. +Supplies after_brock(){ + Supplies supplies; + supplies.lead = story_lead_after_brock(); + return supplies; +} + // What a walk does about wild Pokemon: runs, or fights them for EXP. enum class WildBattles{ RUN, @@ -255,7 +264,7 @@ StoryCheckpoint brock(){ } StoryCheckpoint running_shoes(){ - return row("00.10", "Pewter: the Running Shoes from Oak's aide", at(GYM, 6, 6, NORTH), {}, StartMenu::FULL, { + return row("00.10", "Pewter: the Running Shoes from Oak's aide", at(GYM, 6, 6, NORTH), after_brock(), StartMenu::FULL, { // Brock's win sets VAR_MAP_SCENE_PEWTER_CITY to 1 and shows the aide at // (46, 20); his triggers are (46, 21..23) (PewterCity map.json). The // Gym guide's triggers at (42..43, 21..23) need the scene at 0. diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index fbbfea3335..ada1c5b889 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1837,9 +1837,14 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp From f58e54c9fb1f5031d3a601a3c58c652aafb9e6a0 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 21:30:58 -0800 Subject: [PATCH 62/75] FRLG AutoStory tests: register the party tests with the items tests Keeps add_tests() in PokemonFRLG_Tests.cpp within the 50-line limit once the stack above adds its own suites. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp | 2 -- .../Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index b59cb1ab95..cc050e97dd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -38,7 +38,6 @@ #include "Overworld/PokemonFRLG_PlayerFacingReader.h" #include "PokemonFRLG_Navigation.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h" -#include "Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryTable.h" #include "Tests/TestUtils.h" @@ -312,7 +311,6 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStory(database); add_tests_AutoStorySimulation(database); add_tests_AutoStoryItems(database); - add_tests_AutoStoryParty(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index aa376e8901..31926b0723 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -16,6 +16,7 @@ #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryBattleDecisions.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -153,6 +154,8 @@ void add_tests_AutoStoryItems(UnitTestDatabase& database){ database.add("Items pocket rows", test_pocket_rows); database.add("unread bag counts count as some", test_unread_counts); database.add("no item names read in a language without them", test_unread_language); + // The battle's choices, registered here to keep add_tests() within its size. + add_tests_AutoStoryParty(database); } From 450abed01e85176fa1b1d14b7af494b47e42a50c Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 21:57:27 -0800 Subject: [PATCH 63/75] FRLG AutoStory: read the lead's moves off its summary; attack by name and PP A run that loads a save reads the lead's species, level and KNOWN MOVES (names and PP) off its summary and battles with those moves, not the moves the checkpoint's row assumes. Console B's save after Route 3 has Squirtle Lv16 with Water Gun where Tackle was and Bubble kept; the plan assumed Water Gun in Bubble's slot and fell back to a Tackle it doesn't know. Attacks are picked by name and PP; past the plan's attacks, the strongest damaging move with PP left. "Delete a move?" now reads the move list's cursor before A: the DOWNs sent while the list faded in were lost, and A forgot Tackle instead of Bubble. New SummaryMovesReader (move names, PP, cursor row) with image tests; party tests for the console's moveset. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Menus/PokemonFRLG_SummaryMovesReader.cpp | 257 ++++++++++++++++++ .../Menus/PokemonFRLG_SummaryMovesReader.h | 73 +++++ .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 + .../AutoStory/PokemonFRLG_AutoStory.cpp | 1 + .../PokemonFRLG_AutoStoryActions.cpp | 97 +++++++ .../AutoStory/PokemonFRLG_AutoStoryActions.h | 20 ++ .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 66 ++++- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 13 + .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 6 + .../AutoStory/PokemonFRLG_AutoStoryParty.cpp | 103 ++++--- .../AutoStory/PokemonFRLG_AutoStoryParty.h | 36 ++- .../PokemonFRLG_AutoStoryParty_Tests.cpp | 107 +++++++- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 6 +- SerialPrograms/cmake/SourceFiles.cmake | 2 + 14 files changed, 734 insertions(+), 55 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp new file mode 100644 index 0000000000..55c66ed1a5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp @@ -0,0 +1,257 @@ +/* Summary Moves Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h" +#include "Tests/ImageUnitTest.h" +#include "Tests/TestUtils.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Tests.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_DigitReader.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_StatsReader.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryDetector.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" +#include "PokemonFRLG_SummaryMovesReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// Measured on captures of the page (console B, 2026-11-02): names from +// x 163, y 24 to 32 (with the shadow); the PP's digits y 34 to 43, the +// current PP's to x 216, "/" from 217 to 224, the full PP's from 224. +constexpr double ROW_STEP = 28; +constexpr double NAME_TOP = 22; +constexpr double PP_TOP = 33; +// The cursor box's left edge, x 120 to 121, from y 20 to 44 on the top +// row: (255, 72, 0). +constexpr double CURSOR_EDGE_LEFT = 120; +constexpr double CURSOR_EDGE_TOP = 24; +constexpr double CURSOR_EDGE_HEIGHT = 16; + +class MoveNameMatcher : public OCR::SmallDictionaryMatcher{ +public: + static constexpr double MAX_LOG10P = -1.40; + static constexpr double MAX_LOG10P_SPREAD = 0.50; + + static const MoveNameMatcher& instance(){ + static const MoveNameMatcher matcher; + return matcher; + } + + std::string read(Logger& logger, Language language, const ImageViewRGB32& image) const{ + if (!languages()[language]){ + return ""; + } + const ImageRGB32 ready = preprocess_for_ocr(image); + const OCR::StringMatchResult result = match_substring_from_image_multifiltered( + &logger, language, ready, DARK_TEXT_FILTERS(), + MAX_LOG10P, MAX_LOG10P_SPREAD, 0.01, 0.50 + ); + return result.results.empty() ? "" : result.results.begin()->second.token; + } + +private: + MoveNameMatcher() + : SmallDictionaryMatcher(dictionary()) + {} + + // The level-up moves of Squirtle's and Magikarp's lines (pret + // pokefirered src/data/pokemon/level_up_learnsets.h). + static JsonObject dictionary(){ + JsonObject english; + for (const auto& [slug, name] : { + std::pair{"tackle", "Tackle"}, + {"tail-whip", "Tail Whip"}, + {"bubble", "Bubble"}, + {"withdraw", "Withdraw"}, + {"water-gun", "Water Gun"}, + {"bite", "Bite"}, + {"rapid-spin", "Rapid Spin"}, + {"protect", "Protect"}, + {"rain-dance", "Rain Dance"}, + {"skull-bash", "Skull Bash"}, + {"hydro-pump", "Hydro Pump"}, + {"splash", "Splash"}, + {"flail", "Flail"}, + {"thrash", "Thrash"}, + {"dragon-rage", "Dragon Rage"}, + {"leer", "Leer"}, + {"twister", "Twister"}, + {"dragon-dance", "Dragon Dance"}, + {"hyper-beam", "Hyper Beam"}, + }){ + JsonArray names; + names.push_back(name); + english[slug] = std::move(names); + } + JsonObject json; + json["eng"] = std::move(english); + return json; + } +}; + +ImageViewRGB32 game_box(const ImageViewRGB32& screen){ + return extract_box_reference(screen, GameSettings::instance().GAME_BOX); +} + +bool cursor_red(uint32_t pixel){ + const int r = (pixel >> 16) & 0xff; + const int g = (pixel >> 8) & 0xff; + const int b = pixel & 0xff; + return r > 200 && g < 140 && b < 90; +} + +int read_pp(Logger& logger, const ImageViewRGB32& screen, const ImageFloatBox& box){ + const int pp = read_digits_waterfill_template(logger, extract_box_reference(game_box(screen), box), DigitTemplateType::StatBox); + // A move has at most 64 PP (40 with three PP Ups). + return pp >= 0 && pp <= 64 ? pp : -1; +} + +} + + +ImageFloatBox summary_move_name_box(size_t row){ + return ImageFloatBox(161.0 / 240, (NAME_TOP + ROW_STEP * double(row)) / 160, 76.0 / 240, 12.0 / 160); +} +ImageFloatBox summary_move_pp_box(size_t row){ + return ImageFloatBox(204.0 / 240, (PP_TOP + ROW_STEP * double(row)) / 160, 13.0 / 240, 11.0 / 160); +} +ImageFloatBox summary_move_max_pp_box(size_t row){ + return ImageFloatBox(224.0 / 240, (PP_TOP + ROW_STEP * double(row)) / 160, 15.0 / 240, 11.0 / 160); +} + +std::string read_summary_move_name(Logger& logger, Language language, const ImageViewRGB32& screen, size_t row){ + return MoveNameMatcher::instance().read(logger, language, extract_box_reference(game_box(screen), summary_move_name_box(row))); +} + +std::vector read_summary_moves(Logger& logger, Language language, const ImageViewRGB32& screen){ + std::vector moves; + for (size_t row = 0; row < SUMMARY_MOVE_ROWS - 1; row++){ + std::string move = read_summary_move_name(logger, language, screen, row); + if (move.empty()){ + break; + } + moves.push_back(SummaryMove{ + .move = std::move(move), + .pp = read_pp(logger, screen, summary_move_pp_box(row)), + .max_pp = read_pp(logger, screen, summary_move_max_pp_box(row)), + }); + } + return moves; +} + +std::optional read_summary_move_cursor(const ImageViewRGB32& screen){ + const ImageViewRGB32 game = game_box(screen); + std::optional cursor; + for (size_t row = 0; row < SUMMARY_MOVE_ROWS; row++){ + const ImageFloatBox box( + CURSOR_EDGE_LEFT / 240, (CURSOR_EDGE_TOP + ROW_STEP * double(row)) / 160, + 2.0 / 240, CURSOR_EDGE_HEIGHT / 160 + ); + const ImageViewRGB32 edge = extract_box_reference(game, box); + size_t red = 0; + for (size_t y = 0; y < edge.height(); y++){ + for (size_t x = 0; x < edge.width(); x++){ + red += cursor_red(edge.pixel(x, y)) ? 1 : 0; + } + } + // Most of the edge: the box is drawn there and nowhere else. + if (red * 2 > edge.width() * edge.height()){ + if (cursor){ + return std::nullopt; + } + cursor = row; + } + } + return cursor; +} + + +namespace{ + +// A capture of a summary page, named _.png. Its +// golden file holds the page shown; on the first page the species and the +// level; on KNOWN MOVES, or a move being picked, each move's name, PP and +// full PP, then the cursor's row (from 1) or "none". +class Test_SummaryScreen : public ImageUnitTest{ +public: + Test_SummaryScreen(const std::string& image) + : ImageUnitTest("PokemonFRLG::SummaryMovesReader - " + image, {image}) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const std::vector words = parse_words(Filesystem::Path(image_paths()[0]).stem().string()); + const Language language = words.size() < 2 ? Language::None : language_code_to_enum(words.back()); + if (language == Language::None || language == Language::EndOfList){ + return "Error: filename must be _."; + } + const ImageViewRGB32& screen = images[0]; + std::vector labels; + std::vector values; + const bool info = SummaryDetector(COLOR_RED).detect(screen); + const bool skills = SummaryPage2Detector(COLOR_RED).detect(screen); + const bool moves = SummaryPage3Detector(COLOR_RED).detect(screen); + // Picking a move turns the page's dot orange: no page detector sees it. + const std::optional cursor = read_summary_move_cursor(screen); + labels.push_back("page"); + values.push_back(info ? "info" : skills ? "skills" : moves ? "moves" : cursor ? "picking" : "none"); + if (info){ + PokemonFRLG_Stats stats; + StatsReader().read_page1(logger, language, screen, stats); + labels.push_back("species"); + values.push_back(stats.name.empty() ? "none" : stats.name); + labels.push_back("level"); + values.push_back(stats.level ? std::to_string(*stats.level) : "none"); + } + if (moves || cursor){ + const std::vector known = read_summary_moves(logger, language, screen); + for (size_t c = 0; c < known.size(); c++){ + labels.push_back(std::format("move {}", c + 1)); + values.push_back(known[c].move); + labels.push_back(std::format("move {} PP", c + 1)); + values.push_back(std::to_string(known[c].pp)); + labels.push_back(std::format("move {} full PP", c + 1)); + values.push_back(std::to_string(known[c].max_pp)); + } + labels.push_back("cursor"); + values.push_back(cursor ? std::to_string(*cursor + 1) : "none"); + } + return check_against_golden_file(UNIT_TEST_RESOURCE_PATH() + image_paths()[0], labels, values); + } +}; + +} + +void add_tests_SummaryMovesReader(UnitTestDatabase& database){ + // FireRed on console B, 2026-11-02: the story's Squirtle at Lv16, not + // evolved, with WATER GUN where TACKLE was: the battle had forgotten the + // top move for Water Gun instead of BUBBLE. + database.add("PokemonFRLG/SummaryMovesReader/Info_eng.png"); + database.add("PokemonFRLG/SummaryMovesReader/Skills_eng.png"); + database.add("PokemonFRLG/SummaryMovesReader/KnownMoves_eng.png"); + // A on KNOWN MOVES: the cursor box on the top move. + database.add("PokemonFRLG/SummaryMovesReader/MoveDetail_eng.png"); + // The party menu: no summary page. + database.add("PokemonFRLG/SummaryMovesReader/PartyMenu_eng.png"); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h new file mode 100644 index 0000000000..561713fd9f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h @@ -0,0 +1,73 @@ +/* Summary Moves Reader + * + * From: https://github.com/PokemonAutomation/ + * + * Reads the KNOWN MOVES page of a Pokemon's summary: each move's name and + * PP, and which row the red cursor box is on when the page picks a move + * (A on the page, or the move to forget for a new one). pokefirered's + * pokemon_summary_screen.c draws the moves in the right pane from (160, + * 19), 28 pixels apart: the name at x 3, the PP's line at y 16 with the + * current PP right-aligned in two digits at x 46, "/" at 58 and the full + * PP at 64. The fifth row is CANCEL, or the move offered. + * + * It knows the names of the moves of the lines the FRLG AutoStory party + * comes from, in English only so far: in another language a name is never + * read. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_SummaryMovesReader_H +#define PokemonAutomation_PokemonFRLG_SummaryMovesReader_H + +#include +#include +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The rows of the page: four moves, then CANCEL or the move offered. +constexpr size_t SUMMARY_MOVE_ROWS = 5; + +// Where row `row` (from 0) shows its move's name, its current PP and its +// full PP, as fractions of the game screen. +ImageFloatBox summary_move_name_box(size_t row); +ImageFloatBox summary_move_pp_box(size_t row); +ImageFloatBox summary_move_max_pp_box(size_t row); + +// The move named in row `row`: a slug such as "water-gun", in a game in +// `language`; empty for an empty slot, a move the reader has no name +// for, or a language it has no names for. +std::string read_summary_move_name(Logger& logger, Language language, const ImageViewRGB32& screen, size_t row); + +struct SummaryMove{ + std::string move; + // -1 if not read. The game draws a move's PP in color once it is down + // to half, which the digit templates may not read. + int pp = -1; + int max_pp = -1; +}; + +// The moves from the top, up to the first row whose name can't be read. +std::vector read_summary_moves(Logger& logger, Language language, const ImageViewRGB32& screen); + +// The row (0 to 4) the red cursor box is on, if one shows. +std::optional read_summary_move_cursor(const ImageViewRGB32& screen); + + +void add_tests_SummaryMovesReader(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index cc050e97dd..023a4deef6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -23,6 +23,7 @@ #include "Inference/Menus/PokemonFRLG_PartyHeldItemDetector.h" #include "Inference/Menus/PokemonFRLG_PartyMenuDetector.h" #include "Inference/Menus/PokemonFRLG_SaveCardReader.h" +#include "Inference/Menus/PokemonFRLG_SummaryMovesReader.h" #include "Inference/PokemonFRLG_BattleLevelUpReader.h" #include "Inference/PokemonFRLG_BattleSelectionArrowDetector.h" #include "Inference/PokemonFRLG_PartyLevelUpReader.h" @@ -301,6 +302,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_ItemListReader(database); add_tests_OptionMenuReader(database); add_tests_SaveCardReader(database); + add_tests_SummaryMovesReader(database); add_tests_ExitWildBattle(database); add_tests_OverworldMaps(database); add_tests_OverworldRoute(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index fd48481cd0..cf817a9cd4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -141,6 +141,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex soft_reset(env.console, context); story.has_save = true; check_start_save(env, story, checkpoints[first]); + read_lead_moves(story, checkpoints[first].menu); } StoryExecutor executor(story); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index a67e107e31..d2b707085d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -18,13 +18,17 @@ #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_PartyDialogs.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_SelectionArrowDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_StatsReader.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "VideoGames/PokemonFRLG/Programs/PokemonFRLG_StartMenuNavigation.h" #include "PokemonFRLG_AutoStoryActions.h" @@ -656,6 +660,99 @@ std::string read_save_place(ConsoleHandle& console, ProControllerContext& contex return place; } +namespace{ + +// Up to `timeout` for `watcher`'s screen, after a press. A screen that +// shows is given a moment to finish drawing before it is read. +bool wait_drawn(ConsoleHandle& console, ProControllerContext& context, VisualInferenceCallback& watcher, Milliseconds timeout){ + context.wait_for_all_requests(); + if (wait_until(console, context, timeout, {watcher}) < 0){ + return false; + } + pbf_wait(context, 500ms); + context.wait_for_all_requests(); + return true; +} + +// From the party menu with the cursor on the member: its summary, read. +std::optional read_open_summary(ConsoleHandle& console, ProControllerContext& context, Language language){ + PartySelectionWatcher submenu(COLOR_RED); + press(context, BUTTON_A, 0ms); + if (!wait_drawn(console, context, submenu, 5000ms)){ + console.log("Summary: the party member's menu didn't show.", COLOR_ORANGE); + return std::nullopt; + } + // SUMMARY, the menu's top row. + SummaryWatcher info(COLOR_RED); + press(context, BUTTON_A, 0ms); + if (!wait_drawn(console, context, info, 5000ms)){ + console.log("Summary: the summary's first page didn't show.", COLOR_ORANGE); + return std::nullopt; + } + SummaryRead read; + { + VideoSnapshot screen = console.video().snapshot(); + if (!screen){ + return std::nullopt; + } + PokemonFRLG_Stats stats; + StatsReader().read_page1(console, language, screen, stats); + read.species = stats.name; + read.level = stats.level; + } + SummaryPage2Watcher skills(COLOR_RED); + tap(context, DPAD_RIGHT, 0ms); + if (!wait_drawn(console, context, skills, 3000ms)){ + console.log("Summary: POKEMON SKILLS didn't show.", COLOR_ORANGE); + return std::nullopt; + } + SummaryPage3Watcher moves(COLOR_RED); + tap(context, DPAD_RIGHT, 0ms); + if (!wait_drawn(console, context, moves, 3000ms)){ + console.log("Summary: KNOWN MOVES didn't show.", COLOR_ORANGE); + return std::nullopt; + } + VideoSnapshot screen = console.video().snapshot(); + if (!screen){ + return std::nullopt; + } + read.moves = read_summary_moves(console, language, screen); + dump_debug_image(console, "AutoStory/summary", "moves", screen); + return read; +} + +} + +std::optional read_party_summary( + ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language, size_t slot +){ + if (menu == StartMenu::BEFORE_POKEMON){ + return std::nullopt; + } + open_party_menu_from_overworld( + console, context, menu == StartMenu::BEFORE_POKEDEX ? StartMenuContext::NO_DEX : StartMenuContext::STANDARD + ); + context.wait_for_all_requests(); + // The party menu opens on the lead; DOWN steps through the slots. + for (size_t c = 0; c < slot; c++){ + tap(context, DPAD_DOWN); + } + const std::optional read = read_open_summary(console, context, language); + mash_until_overworld(console, context, 20000ms); + if (read){ + std::string moves; + for (const SummaryMove& move : read->moves){ + moves += std::format("{}{} {}/{}", moves.empty() ? "" : ", ", move.move, move.pp, move.max_pp); + } + console.log(std::format( + "Summary of party slot {}: {} Lv{}, {}.", + slot + 1, read->species.empty() ? "?" : read->species, + read->level ? std::to_string(*read->level) : "?", moves.empty() ? "no moves read" : moves + )); + } + return read; +} + std::optional option_right_presses( const std::vector& values, const std::string& current, const std::string& target ){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index 78d88a0d14..ee9d2ee3cb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -25,6 +25,7 @@ #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "Pokemon/AutoStory/Pokemon_StorySteps.h" #include "Pokemon/Navigation/Pokemon_Grid.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -168,6 +169,25 @@ void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu // with another START menu (another checkpoint's) is read too. std::string read_save_place(ConsoleHandle& console, ProControllerContext& context, Language language); +// A party member as its summary shows it. +struct SummaryRead{ + // The species' slug, empty if not read. + std::string species = {}; + std::optional level = std::nullopt; + // KNOWN MOVES, from the top, up to the first name not read. + std::vector moves = {}; +}; + +// From the overworld: the party menu, party slot `slot`'s SUMMARY, its +// first page (species, level) and KNOWN MOVES, then back to the overworld. +// Each screen is waited for before the next press: a press sent before a +// menu is drawn goes to what was there before (console B, 2026-11-02, the +// PC's menus). Nothing if a screen didn't show, or before the starter +// (`menu` has no POKEMON). +std::optional read_party_summary( + ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language, size_t slot +); + // RIGHT presses that turn an option showing `current` into `target`. // RIGHT steps through `values` and wraps from the last to the first // (pokefirered option_menu.c OptionMenu_ProcessInput). Nothing if either diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 645160ade1..93e8002cf8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -20,6 +20,7 @@ #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyMenuDetector.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_AutoStoryActions.h" @@ -66,6 +67,8 @@ constexpr Milliseconds EVOLUTION = 20000ms; constexpr size_t LOW_ATTACK_PP = 10; // Text and the move learn prompts after a battle, on the overworld. constexpr Milliseconds AFTER_BATTLE_TEXT = 60000ms; +// The move list to fade in after "Delete a move?", and its cursor to move. +constexpr Milliseconds MOVE_LIST_TIMEOUT = 5000ms; // In the player's box, as fractions of the 240x160 screen: the HP bar's // fill, which grows from its left end, and the status badge left of the @@ -270,14 +273,63 @@ void use_move(ProControllerContext& context, size_t slot){ pbf_press_button(context, BUTTON_A, 160ms, 500ms); } +// The move list's cursor row once it shows, and, if `before` is given, once +// it has left that row: up to `timeout`. +std::optional read_move_list_cursor( + ConsoleHandle& console, ProControllerContext& context, + std::optional before, Milliseconds timeout +){ + const WallClock deadline = current_time() + timeout; + while (true){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + const std::optional cursor = screen ? read_summary_move_cursor(screen) : std::nullopt; + if (cursor && cursor != before){ + return cursor; + } + if (current_time() >= deadline){ + return std::nullopt; + } + pbf_wait(context, POLL); + } +} + // After YES to "Delete a move?": the move list fades in with its cursor on // the top move (pret pokemon_summary_screen.c); A on a move forgets it, -// B would go back to "Stop learning?". Done in one go, so the loop's B -// presses can't land on the list. -void forget_move(ProControllerContext& context, size_t slot){ - pbf_press_button(context, BUTTON_A, 160ms, 2500ms); - for (size_t c = 0; c < slot; c++){ - pbf_press_dpad(context, DPAD_DOWN, 160ms, 400ms); +// B would go back to "Stop learning?". The cursor is read before A and +// after each press: DOWNs sent while the list faded in were lost, and A +// forgot the top move, Tackle, for Water Gun instead of Bubble (console B, +// 2026-11-02). Done in one go, so the loop's B presses can't land on the +// list. A list whose cursor never shows gets the presses by time, as +// before; a cursor that can't be brought to `slot` fails the battle. +void forget_move(ConsoleHandle& console, ProControllerContext& context, size_t slot){ + pbf_press_button(context, BUTTON_A, 160ms, 0ms); + std::optional cursor = read_move_list_cursor(console, context, std::nullopt, MOVE_LIST_TIMEOUT); + if (!cursor){ + console.log("Battle: no cursor read on the move list; moving it by time.", COLOR_ORANGE); + for (size_t c = 0; c < slot; c++){ + pbf_press_dpad(context, DPAD_DOWN, 160ms, 400ms); + } + pbf_press_button(context, BUTTON_A, 160ms, 2000ms); + return; + } + for (size_t presses = 0; *cursor != slot; presses++){ + if (presses >= 2 * SUMMARY_MOVE_ROWS){ + break; + } + const size_t from = *cursor; + pbf_press_dpad(context, from < slot ? DPAD_DOWN : DPAD_UP, 160ms, 0ms); + cursor = read_move_list_cursor(console, context, from, MOVE_LIST_TIMEOUT); + if (!cursor){ + break; + } + } + if (cursor != slot){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("forget_move(): the cursor didn't reach move {} on the move list.", slot + 1), + console + ); } pbf_press_button(context, BUTTON_A, 160ms, 2000ms); } @@ -531,7 +583,7 @@ class BattleLoop{ const PromptAnswer answer = m_decisions.prompt(starter_fainted(screen)); if (answer.forget_slot){ m_console.log(std::format("Battle: learning the new move over move {}.", *answer.forget_slot + 1)); - forget_move(m_context, *answer.forget_slot); + forget_move(m_console, m_context, *answer.forget_slot); }else{ m_console.log(std::format("Battle: answering {} to a YES/NO.", answer.answer == YesNo::YES ? "YES" : "NO")); pbf_press_button(m_context, answer.answer == YesNo::YES ? BUTTON_A : BUTTON_B, 160ms, 1500ms); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 61731142c8..3cbd326efe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -421,6 +421,19 @@ std::string check_save_place(StoryEnv& env, const std::string& start_map){ return error; } +void read_lead_moves(StoryEnv& env, StartMenu menu){ + const std::optional read = read_party_summary(env.console, env.context, menu, env.language, 0); + if (!read || read->moves.empty()){ + env.console.log("Couldn't read the lead's moves; going on with the checkpoint's.", COLOR_ORANGE); + return; + } + const PartyMember& before = env.supplies.lead; + const std::string species = read->species.empty() ? before.species : read->species; + const uint8_t level = read->level && *read->level <= 100 ? static_cast(*read->level) : before.moves_through_level; + env.supplies.lead = member_from_summary(species, level, read->moves); + env.saved_supplies.lead = env.supplies.lead; +} + Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& executor){ executor.set_menu(data.menu); Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index ba801005cc..cc7a3fa377 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -128,6 +128,12 @@ struct StoryEnv{ // not. std::string check_save_place(StoryEnv& env, const std::string& start_map); +// After a save is loaded, with START's menu `menu`: the lead's moves as its +// summary shows them, which the battles then start from in place of the +// row's (in env's supplies and the ones a reload restores). The row's are +// kept if no move can be read. +void read_lead_moves(StoryEnv& env, StartMenu menu); + // Does FRLG's kinds of story step on the console. A console step that // fails is a failed Outcome, which the segment answers by reloading. class StoryExecutor : public Pokemon::StoryStepExecutor{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp index 1da41c90c1..c334107e41 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp @@ -87,34 +87,45 @@ constexpr Evolution EVOLUTIONS[] = { {.species = "magikarp", .evolution = {.into = "gyarados", .level = 20}}, }; -struct MovePp{ +struct MoveData{ std::string_view move; uint8_t pp = 0; + // Flail's and Dragon Rage's damage doesn't come from their power, 1. + uint8_t power = 0; }; // pret/pokefirered src/data/battle_moves.h. -constexpr MovePp MOVE_PP[] = { - {.move = "tackle", .pp = 35}, - {.move = "tail-whip", .pp = 30}, - {.move = "bubble", .pp = 30}, - {.move = "withdraw", .pp = 40}, - {.move = "water-gun", .pp = 25}, - {.move = "bite", .pp = 25}, - {.move = "rapid-spin", .pp = 40}, - {.move = "protect", .pp = 10}, - {.move = "rain-dance", .pp = 5}, - {.move = "skull-bash", .pp = 15}, - {.move = "hydro-pump", .pp = 5}, - {.move = "splash", .pp = 40}, - {.move = "flail", .pp = 15}, - {.move = "thrash", .pp = 20}, - {.move = "dragon-rage", .pp = 10}, - {.move = "leer", .pp = 30}, - {.move = "twister", .pp = 20}, - {.move = "dragon-dance", .pp = 20}, - {.move = "hyper-beam", .pp = 5}, +constexpr MoveData MOVES[] = { + {.move = "tackle", .pp = 35, .power = 35}, + {.move = "tail-whip", .pp = 30, .power = 0}, + {.move = "bubble", .pp = 30, .power = 20}, + {.move = "withdraw", .pp = 40, .power = 0}, + {.move = "water-gun", .pp = 25, .power = 40}, + {.move = "bite", .pp = 25, .power = 60}, + {.move = "rapid-spin", .pp = 40, .power = 20}, + {.move = "protect", .pp = 10, .power = 0}, + {.move = "rain-dance", .pp = 5, .power = 0}, + {.move = "skull-bash", .pp = 15, .power = 100}, + {.move = "hydro-pump", .pp = 5, .power = 120}, + {.move = "splash", .pp = 40, .power = 0}, + {.move = "flail", .pp = 15, .power = 1}, + {.move = "thrash", .pp = 20, .power = 90}, + {.move = "dragon-rage", .pp = 10, .power = 1}, + {.move = "leer", .pp = 30, .power = 0}, + {.move = "twister", .pp = 20, .power = 40}, + {.move = "dragon-dance", .pp = 20, .power = 0}, + {.move = "hyper-beam", .pp = 5, .power = 150}, }; +const MoveData* move_data(std::string_view move){ + for (const MoveData& entry : MOVES){ + if (entry.move == move){ + return &entry; + } + } + return nullptr; +} + // The story's plan per line (named by its first species): a level-up move // it learns over a full move list, and the move whose slot it takes. Any // other move offered over four is declined. Squirtle's is the speedrun's: @@ -131,7 +142,8 @@ constexpr LearnRule LEARN_RULES[] = { {.line = "magikarp", .move = "twister", .replaces = "splash"}, }; -// The attacks per line, the one used first at the top. +// The attacks per line, the one used first at the top. Past these, the +// strongest damaging move with PP left. struct Attack{ std::string_view line; std::string_view move; @@ -225,16 +237,17 @@ std::optional level_evolution(std::string_view species){ } uint8_t max_pp(std::string_view move){ - for (const MovePp& entry : MOVE_PP){ - if (entry.move == move){ - return entry.pp; - } - } - return 0; + const MoveData* data = move_data(move); + return data == nullptr ? 0 : data->pp; +} + +uint8_t move_power(std::string_view move){ + const MoveData* data = move_data(move); + return data == nullptr ? 0 : data->power; } PartyMember new_member(std::string_view species, uint8_t level){ - PartyMember member{.species = std::string(species), .moves = {}, .moves_through_level = level}; + PartyMember member{.species = std::string(species), .moves = {}, .moves_through_level = level, .moves_read = false}; for (const LevelUpMove& entry : LEVEL_UP_MOVES){ if (entry.species != species || entry.level > level || knows(member, entry.move)){ continue; @@ -264,6 +277,16 @@ PartyMember story_lead_after_brock(){ return grown_to(new_member("squirtle", 5), 13); } +PartyMember member_from_summary(std::string_view species, uint8_t level, const std::vector& moves){ + PartyMember member{.species = std::string(species), .moves = {}, .moves_through_level = level, .moves_read = true}; + for (const SummaryMove& read : moves){ + const uint8_t full = max_pp(read.move); + const uint8_t pp = read.pp >= 0 ? static_cast(std::min(read.pp, 255)) : static_cast(full / 2); + member.moves.emplace_back(KnownMove{.move = read.move, .pp = pp}); + } + return member; +} + LearnDecision learn_move(PartyMember& member){ while (member.moves.size() < MAX_MOVES){ const LevelUpMove* learned = next_move(member); @@ -292,7 +315,7 @@ void evolve(PartyMember& member){ } std::optional attack_slot(const PartyMember& member){ - if (member.moves.size() < MAX_MOVES){ + if (member.moves.size() < MAX_MOVES && !member.moves_read){ return std::nullopt; } const std::string_view line = line_of(member.species); @@ -305,6 +328,16 @@ std::optional attack_slot(const PartyMember& member){ return slot; } } + std::optional strongest; + for (size_t slot = 0; slot < member.moves.size(); slot++){ + const uint8_t power = move_power(member.moves[slot].move); + if (power > 0 && member.moves[slot].pp > 0 && (!strongest || power > move_power(member.moves[*strongest].move))){ + strongest = slot; + } + } + if (strongest){ + return strongest; + } for (size_t slot = 0; slot < member.moves.size(); slot++){ if (member.moves[slot].pp > 0){ return slot; @@ -314,14 +347,10 @@ std::optional attack_slot(const PartyMember& member){ } size_t attack_pp(const PartyMember& member){ - const std::string_view line = line_of(member.species); size_t pp = 0; - for (const Attack& attack : ATTACKS){ - if (attack.line != line){ - continue; - } - if (const std::optional slot = slot_of(member, attack.move)){ - pp += member.moves[*slot].pp; + for (const KnownMove& known : member.moves){ + if (move_power(known.move) > 0){ + pp += known.pp; } } return pp; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h index f915219ce0..1c0061f2ed 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h @@ -8,11 +8,16 @@ * (src/data/battle_moves.h), which new move takes which old one's slot, * and which moves the lead attacks with first. * - * Nothing reads the moves off the screen. The story starts from the moves - * a checkpoint's row says the lead has, and follows the game: a move - * learned into a free slot shows no prompt, so at the next "Delete a move?" - * the moves due before it are taken as learned. Which move is offered is - * the next level-up move after the last one, so the level isn't needed. + * The story starts from the moves read off the lead's summary when a run + * loads a save (member_from_summary()), else from the moves a checkpoint's + * row says the lead has, and follows the game: a move learned into a free + * slot shows no prompt, so at the next "Delete a move?" the moves due + * before it are taken as learned. Which move is offered is the next + * level-up move after the last one, so the level isn't needed. + * + * Attacks are picked by name and PP, never by slot: a save's moves can sit + * in other slots than the plan's (console B, 2026-11-02: Water Gun took + * Tackle's slot, not Bubble's). * */ @@ -25,6 +30,7 @@ #include #include #include +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -50,6 +56,9 @@ struct PartyMember{ std::vector moves; // The level of the last level-up move offered to it, learned or not. uint8_t moves_through_level = 0; + // The moves were read off its summary: they are all it knows, even + // fewer than four. + bool moves_read = false; }; // The species `species` evolves into by level, and at which level. @@ -62,6 +71,10 @@ std::optional level_evolution(std::string_view species); // A move's full PP; 0 for a move the table doesn't have. uint8_t max_pp(std::string_view move); +// A move's power; 0 for one that does no damage, or that the table +// doesn't have. +uint8_t move_power(std::string_view move); + // As the game gives `species` at `level` (a starter, a gift): its last four // level-up moves up to `level`, at full PP. PartyMember new_member(std::string_view species, uint8_t level); @@ -74,6 +87,12 @@ PartyMember grown_to(PartyMember member, uint8_t level); // Squirtle as the story leaves it after Brock (Lv13, Water Gun offered). PartyMember story_lead_after_brock(); +// `species` at `level` with `moves` as its summary shows them, in slot +// order. A PP that wasn't read is taken as half the move's full PP: the +// game draws the PP in color from half down (pokefirered +// pokemon_summary_screen.c), which the reader may not read. +PartyMember member_from_summary(std::string_view species, uint8_t level, const std::vector& moves); + // The answer to "Delete a move to make room for ?". struct LearnDecision{ @@ -93,11 +112,12 @@ void evolve(PartyMember& member); // The slot to attack with: the first of the plan's attacks for its line -// that it knows with PP left, else any move with PP left, else the top -// left (Struggle). None while the story doesn't know all four moves. +// that it knows with PP left, else its strongest damaging move with PP +// left, else any move with PP left, else the top left (Struggle). None +// while the story doesn't know all its moves (fewer than four, not read). std::optional attack_slot(const PartyMember& member); -// The PP left in the plan's attacks it knows. +// The PP left in the damaging moves it knows. size_t attack_pp(const PartyMember& member); // One use of the move in `slot`. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp index 24f33cb033..edceff56b3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp @@ -64,7 +64,7 @@ std::string joined(const std::vector& names){ } PartyMember with_moves(std::string species, std::vector moves, uint8_t through){ - PartyMember member{.species = std::move(species), .moves = {}, .moves_through_level = through}; + PartyMember member{.species = std::move(species), .moves = {}, .moves_through_level = through, .moves_read = false}; for (std::string& move : moves){ const uint8_t pp = max_pp(move); member.moves.emplace_back(KnownMove{.move = std::move(move), .pp = pp}); @@ -265,6 +265,109 @@ UnitTestResult test_pp(Logger&){ return true; } +// Regression: the save console B left after Route 3 (2026-11-02) has +// Squirtle Lv16 with WATER GUN where TACKLE was and BUBBLE kept, as its +// summary shows. From the moves read, the battle uses Water Gun from the +// top left, then Bubble; never a Tackle it doesn't know, nor Bubble's slot +// for Water Gun. +UnitTestResult test_moves_from_summary(Logger&){ + const std::vector read{ + {.move = "water-gun", .pp = 25, .max_pp = 25}, + {.move = "tail-whip", .pp = 30, .max_pp = 30}, + {.move = "bubble", .pp = 30, .max_pp = 30}, + {.move = "withdraw", .pp = 40, .max_pp = 40}, + }; + Supplies supplies; + supplies.lead = member_from_summary("squirtle", 16, read); + if (attack_pp(supplies.lead) != 55){ + return std::format("Expected 55 PP in Water Gun and Bubble, got {}.", attack_pp(supplies.lead)); + } + BattleDecisions decisions(supplies, BattleKind::TRAINER); + struct Turns{ + size_t count; + size_t slot; + std::string move; + }; + const std::vector plan{ + {.count = 25, .slot = TOP_LEFT_MOVE, .move = "Water Gun"}, + {.count = 30, .slot = BOTTOM_LEFT_MOVE, .move = "Bubble"}, + // No damaging move left: a move with PP, so the turn isn't lost to "no PP left". + {.count = 1, .slot = 1, .move = "Tail Whip"}, + }; + size_t turn = 0; + for (const Turns& turns : plan){ + for (size_t c = 0; c < turns.count; c++){ + turn++; + const TurnAction action = decisions.turn(GREEN); + if (action.choice != TurnChoice::MOVE || action.slot != turns.slot){ + return std::format("Expected {} (slot {}) at turn {}, got slot {}.", turns.move, turns.slot, turn, action.slot); + } + } + } + + // Bite at Lv18 takes Tail Whip's slot, as the plan says. + PartyMember lead = member_from_summary("squirtle", 16, read); + const LearnDecision bite = learn_move(lead); + if (bite.move != std::optional("bite") || bite.forget_slot != std::optional(1)){ + return "Expected Bite offered over Tail Whip (slot 1) after the moves read."; + } + return true; +} + +// Moves read off a summary: all it knows even when fewer than four, a PP +// not read taken as half the full PP (the game colors it from half down), +// and the strongest damaging move once the plan's attacks are gone. +UnitTestResult test_summary_members(Logger&){ + struct Case{ + std::string name; + PartyMember member; + std::optional slot; + size_t pp; + }; + const std::vector cases{ + { + .name = "three moves read", + .member = member_from_summary("squirtle", 9, { + {.move = "tackle", .pp = 35, .max_pp = 35}, {.move = "tail-whip", .pp = 30, .max_pp = 30}, + {.move = "bubble", .pp = 30, .max_pp = 30}, + }), + .slot = 2, .pp = 65, + }, + { + .name = "Water Gun's PP not read", + .member = member_from_summary("squirtle", 16, { + {.move = "water-gun", .pp = -1, .max_pp = -1}, {.move = "tail-whip", .pp = 30, .max_pp = 30}, + {.move = "bubble", .pp = 30, .max_pp = 30}, {.move = "withdraw", .pp = 40, .max_pp = 40}, + }), + .slot = 0, .pp = 42, + }, + { + .name = "none of the plan's attacks", + .member = member_from_summary("wartortle", 40, { + {.move = "tail-whip", .pp = 30, .max_pp = 30}, {.move = "rapid-spin", .pp = 40, .max_pp = 40}, + {.move = "skull-bash", .pp = 15, .max_pp = 15}, {.move = "withdraw", .pp = 40, .max_pp = 40}, + }), + .slot = 2, .pp = 55, + }, + { + .name = "four moves not read, fewer known", + .member = with_moves("squirtle", {"tackle", "tail-whip", "bubble"}, 7), + .slot = std::nullopt, .pp = 65, + }, + }; + for (const Case& c : cases){ + const std::optional slot = attack_slot(c.member); + if (slot != c.slot || attack_pp(c.member) != c.pp){ + return std::format( + "{}: expected slot {} and {} PP in attacks, got slot {} and {}.", + c.name, c.slot ? std::to_string(*c.slot) : "none", c.pp, + slot ? std::to_string(*slot) : "none", attack_pp(c.member) + ); + } + } + return true; +} + // A fake evolution scene: B pressed while it shows "is evolving!" cancels // the evolution, as in the game. @@ -341,6 +444,8 @@ void add_tests_AutoStoryParty(UnitTestDatabase& database){ database.add("YES/NO answers to move prompts", test_prompt_answers); database.add("fainted lead runs or sends the next member", test_fainted_lead); database.add("PP: preferred attack, then Tackle; nurse restores", test_pp); + database.add("moves read off the summary, Water Gun over Tackle", test_moves_from_summary); + database.add("summary members: fewer moves, unread PP, strongest attack", test_summary_members); database.add("no B during an evolution", test_no_b_during_evolution); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index b21ee1c6c8..7db4cec429 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -49,8 +49,10 @@ StoryCheckpoint row( } // At the rows after Brock: no items counted, the starter with the moves -// the story gave it by Lv13. A save made before the story learned moves -// has Bubble where this says Water Gun: the same slot, 5 more PP. +// the story gave it by Lv13. A run that loads a save reads the moves off +// the lead's summary instead (read_lead_moves()), so a save whose moves +// differ from these (console B, 2026-11-02: Water Gun where Tackle was) +// is fought with the moves it has. Supplies after_brock(){ Supplies supplies; supplies.lead = story_lead_after_brock(); diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index ada1c5b889..86bdf76ec1 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1765,6 +1765,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryDetector.h + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp + Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_TrainerCardDetector.cpp Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_TrainerCardDetector.h Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleLevelUpReader.cpp From cc051b9e875b47dce1c4659226ce1110dc133fc4 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 21:59:26 -0800 Subject: [PATCH 64/75] FRLG AutoStory: read_party_summary() in its own file Moved unchanged from PokemonFRLG_AutoStoryActions.cpp, which a later PR in the stack takes past the 1000-line limit. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG_AutoStoryActions.cpp | 97 ------------- .../AutoStory/PokemonFRLG_AutoStoryActions.h | 20 --- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 1 + .../PokemonFRLG_AutoStorySummary.cpp | 130 ++++++++++++++++++ .../AutoStory/PokemonFRLG_AutoStorySummary.h | 53 +++++++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 6 files changed, 186 insertions(+), 117 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index d2b707085d..a67e107e31 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -18,17 +18,13 @@ #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" -#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_PartyDialogs.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h" -#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_SelectionArrowDetector.h" -#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_StatsReader.h" -#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "VideoGames/PokemonFRLG/Programs/PokemonFRLG_StartMenuNavigation.h" #include "PokemonFRLG_AutoStoryActions.h" @@ -660,99 +656,6 @@ std::string read_save_place(ConsoleHandle& console, ProControllerContext& contex return place; } -namespace{ - -// Up to `timeout` for `watcher`'s screen, after a press. A screen that -// shows is given a moment to finish drawing before it is read. -bool wait_drawn(ConsoleHandle& console, ProControllerContext& context, VisualInferenceCallback& watcher, Milliseconds timeout){ - context.wait_for_all_requests(); - if (wait_until(console, context, timeout, {watcher}) < 0){ - return false; - } - pbf_wait(context, 500ms); - context.wait_for_all_requests(); - return true; -} - -// From the party menu with the cursor on the member: its summary, read. -std::optional read_open_summary(ConsoleHandle& console, ProControllerContext& context, Language language){ - PartySelectionWatcher submenu(COLOR_RED); - press(context, BUTTON_A, 0ms); - if (!wait_drawn(console, context, submenu, 5000ms)){ - console.log("Summary: the party member's menu didn't show.", COLOR_ORANGE); - return std::nullopt; - } - // SUMMARY, the menu's top row. - SummaryWatcher info(COLOR_RED); - press(context, BUTTON_A, 0ms); - if (!wait_drawn(console, context, info, 5000ms)){ - console.log("Summary: the summary's first page didn't show.", COLOR_ORANGE); - return std::nullopt; - } - SummaryRead read; - { - VideoSnapshot screen = console.video().snapshot(); - if (!screen){ - return std::nullopt; - } - PokemonFRLG_Stats stats; - StatsReader().read_page1(console, language, screen, stats); - read.species = stats.name; - read.level = stats.level; - } - SummaryPage2Watcher skills(COLOR_RED); - tap(context, DPAD_RIGHT, 0ms); - if (!wait_drawn(console, context, skills, 3000ms)){ - console.log("Summary: POKEMON SKILLS didn't show.", COLOR_ORANGE); - return std::nullopt; - } - SummaryPage3Watcher moves(COLOR_RED); - tap(context, DPAD_RIGHT, 0ms); - if (!wait_drawn(console, context, moves, 3000ms)){ - console.log("Summary: KNOWN MOVES didn't show.", COLOR_ORANGE); - return std::nullopt; - } - VideoSnapshot screen = console.video().snapshot(); - if (!screen){ - return std::nullopt; - } - read.moves = read_summary_moves(console, language, screen); - dump_debug_image(console, "AutoStory/summary", "moves", screen); - return read; -} - -} - -std::optional read_party_summary( - ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language, size_t slot -){ - if (menu == StartMenu::BEFORE_POKEMON){ - return std::nullopt; - } - open_party_menu_from_overworld( - console, context, menu == StartMenu::BEFORE_POKEDEX ? StartMenuContext::NO_DEX : StartMenuContext::STANDARD - ); - context.wait_for_all_requests(); - // The party menu opens on the lead; DOWN steps through the slots. - for (size_t c = 0; c < slot; c++){ - tap(context, DPAD_DOWN); - } - const std::optional read = read_open_summary(console, context, language); - mash_until_overworld(console, context, 20000ms); - if (read){ - std::string moves; - for (const SummaryMove& move : read->moves){ - moves += std::format("{}{} {}/{}", moves.empty() ? "" : ", ", move.move, move.pp, move.max_pp); - } - console.log(std::format( - "Summary of party slot {}: {} Lv{}, {}.", - slot + 1, read->species.empty() ? "?" : read->species, - read->level ? std::to_string(*read->level) : "?", moves.empty() ? "no moves read" : moves - )); - } - return read; -} - std::optional option_right_presses( const std::vector& values, const std::string& current, const std::string& target ){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index ee9d2ee3cb..78d88a0d14 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -25,7 +25,6 @@ #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "Pokemon/AutoStory/Pokemon_StorySteps.h" #include "Pokemon/Navigation/Pokemon_Grid.h" -#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -169,25 +168,6 @@ void save_game(ConsoleHandle& console, ProControllerContext& context, StartMenu // with another START menu (another checkpoint's) is read too. std::string read_save_place(ConsoleHandle& console, ProControllerContext& context, Language language); -// A party member as its summary shows it. -struct SummaryRead{ - // The species' slug, empty if not read. - std::string species = {}; - std::optional level = std::nullopt; - // KNOWN MOVES, from the top, up to the first name not read. - std::vector moves = {}; -}; - -// From the overworld: the party menu, party slot `slot`'s SUMMARY, its -// first page (species, level) and KNOWN MOVES, then back to the overworld. -// Each screen is waited for before the next press: a press sent before a -// menu is drawn goes to what was there before (console B, 2026-11-02, the -// PC's menus). Nothing if a screen didn't show, or before the starter -// (`menu` has no POKEMON). -std::optional read_party_summary( - ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language, size_t slot -); - // RIGHT presses that turn an option showing `current` into `target`. // RIGHT steps through `values` and wraps from the last to the first // (pokefirered option_menu.c OptionMenu_ProcessInput). Nothing if either diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 3cbd326efe..7749a3985a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -16,6 +16,7 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStorySummary.h" namespace PokemonAutomation{ namespace NintendoSwitch{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp new file mode 100644 index 0000000000..815baad92d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp @@ -0,0 +1,130 @@ +/* AutoStory Summary + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "CommonFramework/Tools/DebugDumper.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_PartyDialogs.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_StatsReader.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" +#include "PokemonFRLG_AutoStorySummary.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace std::chrono_literals; + + +namespace{ + +void press(ProControllerContext& context, Button button){ + pbf_press_button(context, button, 160ms, 0ms); +} + +void tap(ProControllerContext& context, DpadPosition position, Milliseconds after = 400ms){ + pbf_press_dpad(context, position, 160ms, after); +} + +// Up to `timeout` for `watcher`'s screen, after a press. A screen that +// shows is given a moment to finish drawing before it is read. +bool wait_drawn(ConsoleHandle& console, ProControllerContext& context, VisualInferenceCallback& watcher, Milliseconds timeout){ + context.wait_for_all_requests(); + if (wait_until(console, context, timeout, {watcher}) < 0){ + return false; + } + pbf_wait(context, 500ms); + context.wait_for_all_requests(); + return true; +} + +// From the party menu with the cursor on the member: its summary, read. +std::optional read_open_summary(ConsoleHandle& console, ProControllerContext& context, Language language){ + PartySelectionWatcher submenu(COLOR_RED); + press(context, BUTTON_A); + if (!wait_drawn(console, context, submenu, 5000ms)){ + console.log("Summary: the party member's menu didn't show.", COLOR_ORANGE); + return std::nullopt; + } + // SUMMARY, the menu's top row. + SummaryWatcher info(COLOR_RED); + press(context, BUTTON_A); + if (!wait_drawn(console, context, info, 5000ms)){ + console.log("Summary: the summary's first page didn't show.", COLOR_ORANGE); + return std::nullopt; + } + SummaryRead read; + { + VideoSnapshot screen = console.video().snapshot(); + if (!screen){ + return std::nullopt; + } + PokemonFRLG_Stats stats; + StatsReader().read_page1(console, language, screen, stats); + read.species = stats.name; + read.level = stats.level; + } + SummaryPage2Watcher skills(COLOR_RED); + tap(context, DPAD_RIGHT, 0ms); + if (!wait_drawn(console, context, skills, 3000ms)){ + console.log("Summary: POKEMON SKILLS didn't show.", COLOR_ORANGE); + return std::nullopt; + } + SummaryPage3Watcher moves(COLOR_RED); + tap(context, DPAD_RIGHT, 0ms); + if (!wait_drawn(console, context, moves, 3000ms)){ + console.log("Summary: KNOWN MOVES didn't show.", COLOR_ORANGE); + return std::nullopt; + } + VideoSnapshot screen = console.video().snapshot(); + if (!screen){ + return std::nullopt; + } + read.moves = read_summary_moves(console, language, screen); + dump_debug_image(console, "AutoStory/summary", "moves", screen); + return read; +} + +} + +std::optional read_party_summary( + ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language, size_t slot +){ + if (menu == StartMenu::BEFORE_POKEMON){ + return std::nullopt; + } + open_party_menu_from_overworld( + console, context, menu == StartMenu::BEFORE_POKEDEX ? StartMenuContext::NO_DEX : StartMenuContext::STANDARD + ); + context.wait_for_all_requests(); + // The party menu opens on the lead; DOWN steps through the slots. + for (size_t c = 0; c < slot; c++){ + tap(context, DPAD_DOWN); + } + const std::optional read = read_open_summary(console, context, language); + mash_until_overworld(console, context, 20000ms); + if (read){ + std::string moves; + for (const SummaryMove& move : read->moves){ + moves += std::format("{}{} {}/{}", moves.empty() ? "" : ", ", move.move, move.pp, move.max_pp); + } + console.log(std::format( + "Summary of party slot {}: {} Lv{}, {}.", + slot + 1, read->species.empty() ? "?" : read->species, + read->level ? std::to_string(*read->level) : "?", moves.empty() ? "no moves read" : moves + )); + } + return read; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h new file mode 100644 index 0000000000..f5b61cd819 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h @@ -0,0 +1,53 @@ +/* AutoStory Summary + * + * From: https://github.com/PokemonAutomation/ + * + * Reading a party member's summary from the overworld: its species, + * level and moves, for the battles' move plan and the steps that check a + * level. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStorySummary_H +#define PokemonAutomation_PokemonFRLG_AutoStorySummary_H + +#include +#include +#include +#include +#include "CommonFramework/Language.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" +#include "PokemonFRLG_AutoStoryActions.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// A party member as its summary shows it. +struct SummaryRead{ + // The species' slug, empty if not read. + std::string species = {}; + std::optional level = std::nullopt; + // KNOWN MOVES, from the top, up to the first name not read. + std::vector moves = {}; +}; + +// From the overworld: the party menu, party slot `slot`'s SUMMARY, its +// first page (species, level) and KNOWN MOVES, then back to the overworld. +// Each screen is waited for before the next press: a press sent before a +// menu is drawn goes to what was there before (console B, 2026-11-02, the +// PC's menus). Nothing if a screen didn't show, or before the starter +// (`menu` has no POKEMON). +std::optional read_party_summary( + ConsoleHandle& console, ProControllerContext& context, StartMenu menu, Language language, size_t slot +); + + + +} +} +} +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 86bdf76ec1..f6e0827969 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1847,6 +1847,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp From 6ae10fed9e3bb7470fed4c03c5944e8325a4d42a Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 22:01:16 -0800 Subject: [PATCH 65/75] FRLG tests: register AutoStory's menu readers in one group Keeps add_tests() under the 50-line limit as the stack adds suites. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 023a4deef6..1973dbe3e4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -275,6 +275,15 @@ void add_tests_ExitWildBattle(UnitTestDatabase& database){ } +// The menu readers AutoStory brought: the bag's and Marts' lists, the +// options, the save card and the summary's moves. +static void add_tests_AutoStoryReaders(UnitTestDatabase& database){ + add_tests_ItemListReader(database); + add_tests_OptionMenuReader(database); + add_tests_SaveCardReader(database); + add_tests_SummaryMovesReader(database); +} + void add_tests(UnitTestDatabase& database){ add_tests_AdvanceWhiteDialogDetector(database); add_tests_BoxCellOccupiedDetector(database); @@ -299,10 +308,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_HallOfFameSavingDetector(database); add_tests_BattleMoveSelectionArrow(database); add_tests_BagDetector(database); - add_tests_ItemListReader(database); - add_tests_OptionMenuReader(database); - add_tests_SaveCardReader(database); - add_tests_SummaryMovesReader(database); + add_tests_AutoStoryReaders(database); add_tests_ExitWildBattle(database); add_tests_OverworldMaps(database); add_tests_OverworldRoute(database); From ecd7fc63b6884e7037a33b6eb8f59e5e32c6bddf Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 01:39:31 -0800 Subject: [PATCH 66/75] FRLG AutoStory: attacks by matchup against known trainers; bag counts on load Against a trainer whose party pret's trainer_parties.h gives (the Cerulean rival, Misty), the battle loop picks the move with the most expected damage (power x STAB x type effectiveness, with PP left); unknown trainers and wild battles keep the plan's order. Bite is learned over Tail Whip, else Withdraw. A run that loads a save reads the Items pocket for its item counts. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStory.cpp | 1 + .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 12 + .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 10 + .../PokemonFRLG_AutoStoryBattleDecisions.cpp | 12 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 21 ++ .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 6 + .../PokemonFRLG_AutoStoryItems_Tests.cpp | 28 +++ .../AutoStory/PokemonFRLG_AutoStoryParty.cpp | 215 ++++++++++++++++-- .../AutoStory/PokemonFRLG_AutoStoryParty.h | 14 ++ .../PokemonFRLG_AutoStoryParty_Tests.cpp | 99 ++++++++ 10 files changed, 392 insertions(+), 26 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index cf817a9cd4..7995396f60 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -142,6 +142,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex story.has_save = true; check_start_save(env, story, checkpoints[first]); read_lead_moves(story, checkpoints[first].menu); + read_bag_supplies(story, checkpoints[first].menu); } StoryExecutor executor(story); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 93e8002cf8..c6987ba411 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -872,6 +872,18 @@ std::vector set_from_bag(Supplies& supplies, const std::vector set_from_loaded_bag(Supplies& supplies, Supplies& saved, const std::vector& rows){ + if (rows.empty()){ + return {}; + } + std::vector unread = set_from_bag(supplies, rows); + saved.potions = supplies.potions; + saved.antidotes = supplies.antidotes; + saved.parlyz_heals = supplies.parlyz_heals; + saved.pocket = supplies.pocket; + return unread; +} + std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context, Language language){ open_items_pocket(console, context); context.wait_for_all_requests(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index da0ccb241e..20e4bbda40 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -71,6 +71,10 @@ struct Supplies{ // faints, so they gain no EXP and learn or evolve nothing: a member // kept for later, or one the user keeps for a trade. std::vector protected_slots = {}; + // The party of the trainer the table's battle step fights, when the + // story knows it (trainer_party()): the lead's attacks are chosen + // against it. Empty otherwise; wild battles never use it. + std::vector foes = {}; }; // The nurse healed the party: HP, status and PP. @@ -105,6 +109,12 @@ int item_row(const Supplies& supplies, const std::string& item); // items, for the log. std::vector set_from_bag(Supplies& supplies, const std::vector& rows); +// After a save is loaded: the Items pocket as read, taken into `supplies` +// and `saved` (what a reload restores) in place of the row's counts, as +// set_from_bag() does. With nothing read both keep the row's. Returns the +// items whose count couldn't be read. +std::vector set_from_loaded_bag(Supplies& supplies, Supplies& saved, const std::vector& rows); + // From the overworld: opens the Items pocket, reads it, and closes the // bag again. Empty if nothing could be read. std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context, Language language); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp index 6c188bdefb..51378d7cf5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -75,11 +75,15 @@ TurnAction BattleDecisions::lead_turn(const PartyStatus& status){ return move_turn(); } -// The plan's attack with PP left. While the story doesn't know all four -// moves, the bottom left one (Bubble from Lv7), which the cursor can't -// reach while that slot is empty, so before Bubble it stays on Tackle. +// The plan's attack with PP left, or against a trainer whose party is +// known, the one that does it most damage. While the story doesn't know +// all four moves, the bottom left one (Bubble from Lv7), which the cursor +// can't reach while that slot is empty, so before Bubble it stays on +// Tackle. TurnAction BattleDecisions::move_turn(){ - const std::optional slot = attack_slot(m_supplies.lead); + const std::optional slot = m_kind == BattleKind::TRAINER + ? attack_slot_against(m_supplies.lead, m_supplies.foes) + : attack_slot(m_supplies.lead); if (!slot){ return TurnAction{.choice = TurnChoice::MOVE, .slot = BOTTOM_LEFT_MOVE}; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 7749a3985a..a5ef7c37c5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -153,7 +153,12 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ if (advance_text(env.console, env.context, BATTLE_TEXT_TIMEOUT, true) != TextEnd::BATTLE){ return Pokemon::outcome_failed("no_battle"); } + env.supplies.foes = trainer_party(step.name); + if (!env.supplies.foes.empty()){ + env.console.log("Story: " + step.name + "'s party is known; attacks are chosen against it."); + } const BattleEnd end = fight_battle(env.console, env.context, env.supplies, BattleKind::TRAINER, env.checks, env.language); + env.supplies.foes.clear(); if (end == BattleEnd::LOST && !step.may_lose){ return Pokemon::outcome_failed("blackout"); } @@ -435,6 +440,22 @@ void read_lead_moves(StoryEnv& env, StartMenu menu){ env.saved_supplies.lead = env.supplies.lead; } +void read_bag_supplies(StoryEnv& env, StartMenu menu){ + if (menu != StartMenu::FULL){ + return; + } + const std::vector rows = read_items_pocket(env.console, env.context, env.language); + if (rows.empty()){ + env.console.log("Couldn't read the Items pocket; going on with the checkpoint's items.", COLOR_ORANGE); + return; + } + for (const std::string& item : set_from_loaded_bag(env.supplies, env.saved_supplies, rows)){ + env.console.log(std::format( + "Story: couldn't read how many {} the bag holds; counting {}.", item, item_count(env.supplies, item) + ), COLOR_ORANGE); + } +} + Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& executor){ executor.set_menu(data.menu); Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index cc7a3fa377..38e97d706c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -134,6 +134,12 @@ std::string check_save_place(StoryEnv& env, const std::string& start_map); // kept if no move can be read. void read_lead_moves(StoryEnv& env, StartMenu menu); +// After a save is loaded, with START's menu `menu`: the Items pocket's +// counts as read (set_from_loaded_bag()), in place of the row's, which +// are kept if nothing can be read. Only with the full menu: the rows +// before it carry the items they have. +void read_bag_supplies(StoryEnv& env, StartMenu menu); + // Does FRLG's kinds of story step on the console. A console step that // fails is a failed Outcome, which the segment answers by reloading. class StoryExecutor : public Pokemon::StoryStepExecutor{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index 31926b0723..eb2e0193d2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -89,6 +89,33 @@ UnitTestResult test_pocket_rows(Logger&){ return true; } +// #211: a row loaded from a save counted no Potions, so its wild battles +// were all run from. The counts come from the bag as read, both for the +// run and for a reload; with nothing read, the row's are kept. +UnitTestResult test_loaded_bag(Logger&){ + Supplies row; + Supplies saved = row; + const std::vector unread = set_from_loaded_bag(row, saved, {{"potion", 4}, {"antidote", 2}}); + if (row.potions != 4 || saved.potions != 4 || row.antidotes != 2 || saved.antidotes != 2 || !unread.empty()){ + return std::format( + "Expected 4 Potions and 2 Antidotes from the bag, now and for a reload; got {} and {}, {} and {}.", + row.potions, saved.potions, row.antidotes, saved.antidotes + ); + } + if (item_row(saved, "antidote") != 1){ + return "Expected the reload's pocket order from the bag."; + } + + Supplies known; + known.potions = 2; + Supplies known_saved = known; + set_from_loaded_bag(known, known_saved, {}); + if (known.potions != 2 || known_saved.potions != 2){ + return "Expected the row's 2 Potions kept with nothing read."; + } + return true; +} + // A count the bag reader couldn't read (-1) is never taken for none: the // row still holds some, so it keeps the count bought, or 1 with none // known, and the battle's checks (a count above 0, a row) still use it. @@ -152,6 +179,7 @@ UnitTestResult test_unread_language(Logger& logger){ void add_tests_AutoStoryItems(UnitTestDatabase& database){ database.add("Mart cursor stays on the row bought", test_mart_cursor); database.add("Items pocket rows", test_pocket_rows); + database.add("a loaded save's counts come from the bag", test_loaded_bag); database.add("unread bag counts count as some", test_unread_counts); database.add("no item names read in a language without them", test_unread_language); // The battle's choices, registered here to keep add_tests() within its size. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp index c334107e41..989e1c995e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp @@ -5,6 +5,7 @@ */ #include +#include #include "PokemonFRLG_AutoStoryParty.h" namespace PokemonAutomation{ @@ -87,34 +88,102 @@ constexpr Evolution EVOLUTIONS[] = { {.species = "magikarp", .evolution = {.into = "gyarados", .level = 20}}, }; +// pret/pokefirered include/constants/pokemon.h TYPE_*, MYSTERY left out. +enum class Type{ + NORMAL, FIGHTING, FLYING, POISON, GROUND, ROCK, BUG, GHOST, STEEL, + FIRE, WATER, GRASS, ELECTRIC, PSYCHIC, ICE, DRAGON, DARK, +}; + struct MoveData{ std::string_view move; uint8_t pp = 0; // Flail's and Dragon Rage's damage doesn't come from their power, 1. uint8_t power = 0; + Type type = Type::NORMAL; }; // pret/pokefirered src/data/battle_moves.h. constexpr MoveData MOVES[] = { - {.move = "tackle", .pp = 35, .power = 35}, - {.move = "tail-whip", .pp = 30, .power = 0}, - {.move = "bubble", .pp = 30, .power = 20}, - {.move = "withdraw", .pp = 40, .power = 0}, - {.move = "water-gun", .pp = 25, .power = 40}, - {.move = "bite", .pp = 25, .power = 60}, - {.move = "rapid-spin", .pp = 40, .power = 20}, - {.move = "protect", .pp = 10, .power = 0}, - {.move = "rain-dance", .pp = 5, .power = 0}, - {.move = "skull-bash", .pp = 15, .power = 100}, - {.move = "hydro-pump", .pp = 5, .power = 120}, - {.move = "splash", .pp = 40, .power = 0}, - {.move = "flail", .pp = 15, .power = 1}, - {.move = "thrash", .pp = 20, .power = 90}, - {.move = "dragon-rage", .pp = 10, .power = 1}, - {.move = "leer", .pp = 30, .power = 0}, - {.move = "twister", .pp = 20, .power = 40}, - {.move = "dragon-dance", .pp = 20, .power = 0}, - {.move = "hyper-beam", .pp = 5, .power = 150}, + {.move = "tackle", .pp = 35, .power = 35, .type = Type::NORMAL}, + {.move = "tail-whip", .pp = 30, .power = 0, .type = Type::NORMAL}, + {.move = "bubble", .pp = 30, .power = 20, .type = Type::WATER}, + {.move = "withdraw", .pp = 40, .power = 0, .type = Type::WATER}, + {.move = "water-gun", .pp = 25, .power = 40, .type = Type::WATER}, + {.move = "bite", .pp = 25, .power = 60, .type = Type::DARK}, + {.move = "rapid-spin", .pp = 40, .power = 20, .type = Type::NORMAL}, + {.move = "protect", .pp = 10, .power = 0, .type = Type::NORMAL}, + {.move = "rain-dance", .pp = 5, .power = 0, .type = Type::WATER}, + {.move = "skull-bash", .pp = 15, .power = 100, .type = Type::NORMAL}, + {.move = "hydro-pump", .pp = 5, .power = 120, .type = Type::WATER}, + {.move = "splash", .pp = 40, .power = 0, .type = Type::NORMAL}, + {.move = "flail", .pp = 15, .power = 1, .type = Type::NORMAL}, + {.move = "thrash", .pp = 20, .power = 90, .type = Type::NORMAL}, + {.move = "dragon-rage", .pp = 10, .power = 1, .type = Type::DRAGON}, + {.move = "leer", .pp = 30, .power = 0, .type = Type::NORMAL}, + {.move = "twister", .pp = 20, .power = 40, .type = Type::DRAGON}, + {.move = "dragon-dance", .pp = 20, .power = 0, .type = Type::DRAGON}, + {.move = "hyper-beam", .pp = 5, .power = 150, .type = Type::NORMAL}, +}; + +// The types of the party's species and of the trainers' in +// TRAINER_PARTIES (pret/pokefirered src/data/pokemon/species_info.h). +struct SpeciesTypes{ + std::string_view species; + Type first; + Type second; +}; +constexpr SpeciesTypes SPECIES_TYPES[] = { + {.species = "squirtle", .first = Type::WATER, .second = Type::WATER}, + {.species = "wartortle", .first = Type::WATER, .second = Type::WATER}, + {.species = "blastoise", .first = Type::WATER, .second = Type::WATER}, + {.species = "magikarp", .first = Type::WATER, .second = Type::WATER}, + {.species = "gyarados", .first = Type::WATER, .second = Type::FLYING}, + {.species = "pidgeotto", .first = Type::NORMAL, .second = Type::FLYING}, + {.species = "abra", .first = Type::PSYCHIC, .second = Type::PSYCHIC}, + {.species = "rattata", .first = Type::NORMAL, .second = Type::NORMAL}, + {.species = "bulbasaur", .first = Type::GRASS, .second = Type::POISON}, + {.species = "staryu", .first = Type::WATER, .second = Type::WATER}, + {.species = "starmie", .first = Type::WATER, .second = Type::PSYCHIC}, +}; + +// pret/pokefirered src/battle_main.c gTypeEffectiveness, the rows of the +// types the party's moves have (Normal, Water, Dark, Dragon): every +// pairing not here is 1x. In tenths: 20 is 2x, 5 is 0.5x. +struct Effectiveness{ + Type attack; + Type defend; + uint8_t tenths; +}; +constexpr Effectiveness TYPE_CHART[] = { + {.attack = Type::NORMAL, .defend = Type::ROCK, .tenths = 5}, + {.attack = Type::NORMAL, .defend = Type::STEEL, .tenths = 5}, + {.attack = Type::NORMAL, .defend = Type::GHOST, .tenths = 0}, + {.attack = Type::WATER, .defend = Type::FIRE, .tenths = 20}, + {.attack = Type::WATER, .defend = Type::WATER, .tenths = 5}, + {.attack = Type::WATER, .defend = Type::GRASS, .tenths = 5}, + {.attack = Type::WATER, .defend = Type::GROUND, .tenths = 20}, + {.attack = Type::WATER, .defend = Type::ROCK, .tenths = 20}, + {.attack = Type::WATER, .defend = Type::DRAGON, .tenths = 5}, + {.attack = Type::DARK, .defend = Type::FIGHTING, .tenths = 5}, + {.attack = Type::DARK, .defend = Type::PSYCHIC, .tenths = 20}, + {.attack = Type::DARK, .defend = Type::GHOST, .tenths = 20}, + {.attack = Type::DARK, .defend = Type::DARK, .tenths = 5}, + {.attack = Type::DARK, .defend = Type::STEEL, .tenths = 5}, + {.attack = Type::DRAGON, .defend = Type::DRAGON, .tenths = 20}, + {.attack = Type::DRAGON, .defend = Type::STEEL, .tenths = 5}, +}; + +// The species of a trainer's party, by the table's battle step, from +// pret/pokefirered src/data/trainer_parties.h. +struct TrainerParty{ + std::string_view battle; + std::array species; +}; +constexpr TrainerParty TRAINER_PARTIES[] = { + // sParty_RivalCeruleanBulbasaur: Lv17, Lv16, Lv15, Lv18. + {.battle = "rival_cerulean", .species = {"pidgeotto", "abra", "rattata", "bulbasaur"}}, + // sParty_Misty: Lv18, Lv21. + {.battle = "misty", .species = {"staryu", "starmie"}}, }; const MoveData* move_data(std::string_view move){ @@ -139,6 +208,8 @@ struct LearnRule{ constexpr LearnRule LEARN_RULES[] = { {.line = "squirtle", .move = "water-gun", .replaces = "bubble"}, {.line = "squirtle", .move = "bite", .replaces = "tail-whip"}, + // A save whose Water Gun took another slot may have no Tail Whip. + {.line = "squirtle", .move = "bite", .replaces = "withdraw"}, {.line = "magikarp", .move = "twister", .replaces = "splash"}, }; @@ -198,12 +269,16 @@ KnownMove at_full_pp(std::string_view move){ return KnownMove{.move = std::string(move), .pp = max_pp(move)}; } -// The slot the plan gives `move`, over a full move list. +// The slot the plan gives `move`, over a full move list: the first of +// its rules' moves the member knows. std::optional forget_slot_for(const PartyMember& member, std::string_view move){ const std::string_view line = line_of(member.species); for (const LearnRule& rule : LEARN_RULES){ - if (rule.line == line && rule.move == move){ - return slot_of(member, rule.replaces); + if (rule.line != line || rule.move != move){ + continue; + } + if (const std::optional slot = slot_of(member, rule.replaces)){ + return slot; } } return std::nullopt; @@ -224,6 +299,70 @@ void take_level(PartyMember& member, uint8_t level){ member.moves_through_level = level; } +const SpeciesTypes* species_types(std::string_view species){ + for (const SpeciesTypes& entry : SPECIES_TYPES){ + if (entry.species == species){ + return &entry; + } + } + return nullptr; +} + +// In tenths; 10 for a species the table doesn't have. +size_t effectiveness(Type attack, std::string_view defender){ + const SpeciesTypes* types = species_types(defender); + if (types == nullptr){ + return 10; + } + size_t tenths = 10; + for (Type defend : {types->first, types->second}){ + for (const Effectiveness& entry : TYPE_CHART){ + if (entry.attack == attack && entry.defend == defend){ + tenths = tenths * entry.tenths / 10; + } + } + if (types->second == types->first){ + break; + } + } + return tenths; +} + +// `move`'s power times STAB times its effectiveness, summed over `foes`, +// in hundredths of a point. +size_t expected_damage(const PartyMember& member, std::string_view move, const std::vector& foes){ + const MoveData* data = move_data(move); + if (data == nullptr){ + return 0; + } + const SpeciesTypes* own = species_types(member.species); + const bool stab = own != nullptr && (own->first == data->type || own->second == data->type); + size_t damage = 0; + for (const std::string& foe : foes){ + damage += (size_t)data->power * (stab ? 15 : 10) * effectiveness(data->type, foe); + } + return damage; +} + +// The member's slots in the plan's order: its line's attacks first, as +// ATTACKS lists them, then the rest in slot order. +std::vector attack_order(const PartyMember& member){ + std::vector order; + const std::string_view line = line_of(member.species); + for (const Attack& attack : ATTACKS){ + const std::optional slot = attack.line == line ? slot_of(member, attack.move) : std::nullopt; + if (slot && std::ranges::find(order, *slot) == order.end()){ + order.push_back(*slot); + } + } + for (size_t slot = 0; slot < member.moves.size(); slot++){ + if (std::ranges::find(order, slot) == order.end()){ + order.push_back(slot); + } + } + return order; +} + } @@ -346,6 +485,38 @@ std::optional attack_slot(const PartyMember& member){ return TOP_LEFT_MOVE; } +std::vector trainer_party(std::string_view battle){ + std::vector party; + for (const TrainerParty& trainer : TRAINER_PARTIES){ + if (trainer.battle != battle){ + continue; + } + for (std::string_view species : trainer.species){ + if (!species.empty()){ + party.emplace_back(species); + } + } + } + return party; +} + +std::optional attack_slot_against(const PartyMember& member, const std::vector& foes){ + const std::optional plan = attack_slot(member); + if (foes.empty() || !plan){ + return plan; + } + std::optional best; + size_t best_damage = 0; + for (size_t slot : attack_order(member)){ + const size_t damage = expected_damage(member, member.moves[slot].move, foes); + if (member.moves[slot].pp > 0 && damage > best_damage){ + best = slot; + best_damage = damage; + } + } + return best ? best : plan; +} + size_t attack_pp(const PartyMember& member){ size_t pp = 0; for (const KnownMove& known : member.moves){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h index 1c0061f2ed..468975f473 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h @@ -117,6 +117,20 @@ void evolve(PartyMember& member); // while the story doesn't know all its moves (fewer than four, not read). std::optional attack_slot(const PartyMember& member); +// The species of a trainer's party, by the table's name for the battle +// ("rival_cerulean"), from pret/pokefirered src/data/trainer_parties.h +// (the rival's for a player who took Squirtle). Empty for a battle whose +// party the story doesn't know. +std::vector trainer_party(std::string_view battle); + +// The slot to attack a trainer whose party is `foes` with, any of them +// as likely to be out: the move with PP left that does the most expected +// damage, its power times STAB times its type's effectiveness against +// each foe (pret's type chart), ties going to attack_slot()'s order. +// attack_slot() itself with no foes, or while the story doesn't know all +// its moves. +std::optional attack_slot_against(const PartyMember& member, const std::vector& foes); + // The PP left in the damaging moves it knows. size_t attack_pp(const PartyMember& member); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp index edceff56b3..d3172fbed5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp @@ -369,6 +369,102 @@ UnitTestResult test_summary_members(Logger&){ } +// #211: Bite, not Water Gun, against the trainers whose parties resist +// Water Gun: the Cerulean rival's Bulbasaur, and Misty's Staryu and +// Starmie (Water, Psychic: Bite does twice). Once Bite is out of PP, +// Tackle (35) over the resisted Water Gun (40 x 1.5 x 0.5); and the battle +// loop picks Bite against a known party, but not in a wild battle. +UnitTestResult test_attack_by_matchup(Logger&){ + PartyMember wartortle = grown_to(new_member("squirtle", 5), 20); + const std::vector bulbasaur{"bulbasaur"}; + const std::optional bite = 1; + const std::optional water_gun = BOTTOM_LEFT_MOVE; + if (move_names(wartortle) != std::vector{"tackle", "bite", "water-gun", "withdraw"}){ + return "Expected Wartortle Lv20 with Tackle, Bite, Water Gun, Withdraw, got " + joined(move_names(wartortle)) + "."; + } + struct Case{ + std::string name; + std::vector foes; + }; + const std::vector cases{ + {.name = "the rival's Bulbasaur", .foes = bulbasaur}, + {.name = "the Cerulean rival's party", .foes = trainer_party("rival_cerulean")}, + {.name = "Misty's party", .foes = trainer_party("misty")}, + }; + for (const Case& c : cases){ + const std::optional slot = attack_slot_against(wartortle, c.foes); + if (slot != bite){ + return std::format("{} ({}): expected Bite (slot 1), got slot {}.", c.name, joined(c.foes), slot ? std::to_string(*slot) : "none"); + } + } + if (trainer_party("rival_cerulean") != std::vector{"pidgeotto", "abra", "rattata", "bulbasaur"}){ + return "Expected the Cerulean rival's party from pret's sParty_RivalCeruleanBulbasaur, got " + joined(trainer_party("rival_cerulean")) + "."; + } + + PartyMember no_bite = wartortle; + no_bite.moves[1].pp = 0; + if (attack_slot_against(no_bite, bulbasaur) != TOP_LEFT_MOVE || attack_slot_against(no_bite, {"pidgeotto"}) != water_gun){ + return "Expected Tackle against Bulbasaur once Bite is out of PP, and Water Gun against Pidgeotto."; + } + + Supplies supplies; + supplies.lead = wartortle; + supplies.foes = bulbasaur; + BattleDecisions trainer(supplies, BattleKind::TRAINER); + if (trainer.turn(GREEN).slot != *bite || supplies.lead.moves[1].pp != 24){ + return "Expected the trainer battle's turn to use Bite against Bulbasaur, spending its PP."; + } + BattleDecisions wild(supplies, BattleKind::WILD_FIGHT); + supplies.potions = 5; + if (wild.turn(GREEN).slot != *water_gun){ + return "Expected a wild battle to keep the plan's order (Water Gun), whatever foes are set."; + } + return true; +} + +// A trainer whose party the story doesn't know, and no foes at all, get +// the plan's order: Water Gun first. +UnitTestResult test_attack_unknown_foe(Logger&){ + const PartyMember wartortle = grown_to(new_member("squirtle", 5), 20); + if (!trainer_party("bug_catcher_cale").empty()){ + return "Expected no party for a trainer the story doesn't know."; + } + const std::vector> unknown{{}, {"missingno"}, trainer_party("bug_catcher_cale")}; + for (const std::vector& foes : unknown){ + if (attack_slot_against(wartortle, foes) != attack_slot(wartortle) || attack_slot(wartortle) != BOTTOM_LEFT_MOVE){ + return "Expected the plan's order (Water Gun) against " + joined(foes) + "."; + } + } + return true; +} + +// Bite is learned when offered (Wartortle Lv19, pret's +// sWartortleLevelUpLearnset) over Tail Whip, else over Withdraw; never +// over Water Gun. +UnitTestResult test_bite_learned(Logger&){ + struct Case{ + std::string name; + std::vector moves; + size_t forget; + }; + const std::vector cases{ + {.name = "with Tail Whip", .moves = {"tackle", "tail-whip", "water-gun", "withdraw"}, .forget = 1}, + {.name = "Water Gun over Tackle, no Tail Whip", .moves = {"water-gun", "bubble", "tackle", "withdraw"}, .forget = 3}, + }; + for (const Case& c : cases){ + PartyMember member = with_moves("wartortle", c.moves, 18); + const LearnDecision decision = learn_move(member); + if (decision.move != "bite" || decision.forget_slot != c.forget){ + return std::format( + "{}: expected Bite over slot {}, got {} over slot {}.", c.name, c.forget, + decision.move.value_or("nothing"), decision.forget_slot ? std::to_string(*decision.forget_slot) : "none" + ); + } + } + return true; +} + + // A fake evolution scene: B pressed while it shows "is evolving!" cancels // the evolution, as in the game. struct FakeEvolution{ @@ -447,6 +543,9 @@ void add_tests_AutoStoryParty(UnitTestDatabase& database){ database.add("moves read off the summary, Water Gun over Tackle", test_moves_from_summary); database.add("summary members: fewer moves, unread PP, strongest attack", test_summary_members); database.add("no B during an evolution", test_no_b_during_evolution); + database.add("attacks by matchup: Bite on the rival's Bulbasaur and Misty", test_attack_by_matchup); + database.add("attacks against an unknown foe: the plan's order", test_attack_unknown_foe); + database.add("Bite learned over Tail Whip or Withdraw", test_bite_learned); } From af87b2299b5f7312056f8016915c6b67a8f9b716 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 02:43:35 -0800 Subject: [PATCH 67/75] FRLG AutoStory battle: end on the overworld after RUN in a dark cave On Mt. Moon B2F (console B, 2026-11-03) the battle loop ran from a wild Pokemon and then never ended: the corridor's black lower half reads as the battle's text box, so the loop waited a minute for an evolution and then pressed A and B for 9 minutes until the 10-minute timeout. - An evolution is only waited for after a turn that attacked, not after RUN (EvolutionHold::turn_taken()). - The battle counts as on screen by its menu, an HP box or a YES/NO (battle_shows()). With none for 3 s, START checks for the overworld, whatever the text box detector reads (BattleEndWatch). - A and B pressed blind stop after 30 s with no battle menu; the walk, which finds the player again, takes over. Tests: the Mt. Moon B2F capture reads as no battle; RUN then the dark cave holds nothing and checks for the overworld within seconds; the end watch's timing and the blind presses' cap. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 49 ++++++-- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 9 +- .../PokemonFRLG_AutoStoryBattleDecisions.cpp | 42 ++++++- .../PokemonFRLG_AutoStoryBattleDecisions.h | 49 +++++++- .../PokemonFRLG_AutoStoryItems_Tests.cpp | 27 +++++ .../PokemonFRLG_AutoStoryParty_Tests.cpp | 107 ++++++++++++++++-- 6 files changed, 259 insertions(+), 24 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index c6987ba411..6ade581a46 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -403,6 +403,9 @@ class BattleLoop{ if (between_turns(screen, now)){ return false; } + if (battle_gone(screen, now)){ + return true; + } const BattleScreen seen = read_battle_screen(screen, m_confirmed); if (seen != m_last_seen){ m_console.log(std::format("Battle: {} (turn {}).", screen_name(seen), m_decisions.turns())); @@ -413,12 +416,7 @@ class BattleLoop{ m_move_chosen = false; }else if (now - m_last_menu > NO_MENU && now - m_last_battle < NO_MENU_NEAR && now - m_last_press > 1500ms){ // Something waits that none of the battle screens knows. - m_console.log(std::format("Battle: no battle menu for {} s, pressing {}.", - std::chrono::duration_cast(now - m_last_menu).count(), m_press_a ? "A" : "B")); - pbf_press_button(m_context, m_press_a ? BUTTON_A : BUTTON_B, 160ms, 200ms); - m_press_a = !m_press_a; - m_last_press = now; - return false; + return press_blind(now); } if (seen == BattleScreen::NONE){ return no_battle_screen(screen, now); @@ -451,7 +449,7 @@ class BattleLoop{ send_next_member(now); return true; } - if (m_evolution.holds(read_text_screen(screen), m_decisions.turns())){ + if (m_evolution.holds(read_text_screen(screen))){ wait_out_evolution(); return true; } @@ -482,7 +480,7 @@ class BattleLoop{ pbf_wait(m_context, POLL); m_context.wait_for_all_requests(); VideoSnapshot screen = m_console.video().snapshot(); - holds = !screen || m_evolution.holds(read_text_screen(screen), m_decisions.turns()); + holds = !screen || m_evolution.holds(read_text_screen(screen)); } const WallClock end = current_time(); const Milliseconds held = std::chrono::duration_cast(end - start); @@ -494,6 +492,34 @@ class BattleLoop{ m_last_battle = end; } + // True once START opens the menu, after no battle menu, HP box or + // YES/NO for a while: whatever the text box reads, the battle is over. + bool battle_gone(const ImageViewRGB32& screen, WallClock now){ + const BattleSeen seen = BattleMenuDetector(COLOR_RED).detect(screen) ? BattleSeen::MENU + : battle_shows(screen) ? BattleSeen::BATTLE : BattleSeen::NONE; + m_end.seen(seen, now); + if (!m_end.check_overworld(now)){ + return false; + } + m_last_overworld_check = now; + return overworld_shows(m_console, m_context); + } + + // A or B, in turn. True once they have gone on too long: the walk, + // which finds the player again, takes over. + bool press_blind(WallClock now){ + if (m_end.pressed_blind(now)){ + m_console.log("Battle: no battle menu after pressing A and B; leaving the rest to the walk.", COLOR_RED); + return true; + } + m_console.log(std::format("Battle: no battle menu for {} s, pressing {}.", + std::chrono::duration_cast(now - m_last_menu).count(), m_press_a ? "A" : "B")); + pbf_press_button(m_context, m_press_a ? BUTTON_A : BUTTON_B, 160ms, 200ms); + m_press_a = !m_press_a; + m_last_press = now; + return false; + } + // True once the battle is over: only when START opens the menu. The // battle screens are gone during the opening slide-in (console B: "over // after 0 turns" at the rival) and under a move prompt's YES/NO (console @@ -595,6 +621,7 @@ class BattleLoop{ m_faint_polls = 0; const PartyStatus status = read_party_status(screen); const TurnAction action = m_decisions.turn(status); + m_evolution.turn_taken(action.choice); m_console.log(std::format( "Battle: turn {}, HP {}, {}, {} Potions, {} Antidotes, {} Parlyz Heals.", m_decisions.turns(), status.hp_red ? "red" : status.hp_yellow ? "yellow" : "green", @@ -635,6 +662,7 @@ class BattleLoop{ Supplies& m_supplies; BattleDecisions m_decisions; EvolutionHold m_evolution; + BattleEndWatch m_end; const BattleKind m_kind; const StoryChecks m_checks; const Language m_language; @@ -806,6 +834,11 @@ PartyStatus read_party_status(const ImageViewRGB32& screen){ return status; } +bool battle_shows(const ImageViewRGB32& screen){ + const BattleTextScreen text = read_text_screen(screen); + return text.hp_box || text.yes_no; +} + // The count the story keeps for `item`, or null for an item it doesn't count. static int* count_slot(Supplies& supplies, const std::string& item){ if (item == "potion"){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index 20e4bbda40..2deeb3cb03 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -133,10 +133,17 @@ struct PartyStatus{ }; PartyStatus read_party_status(const ImageViewRGB32& screen); +// Whether `screen` shows a battle, for the battle loop's end: the battle +// menu, an HP box or a YES/NO. Not the text box alone, which also reads on +// the black below a small room or a dark cave's corridor. +bool battle_shows(const ImageViewRGB32& screen); + // From anywhere in a battle (or its opening), plays it to the end as // `kind` says, using `supplies` as needed. Returns once START opens the // menu on the overworld: text after the battle (a gym leader's speech) is -// read with B on the way. Throws OperationFailedException if it runs over 10 minutes. +// read with B on the way. After 30 s of A and B for a screen nothing reads, +// returns anyway, for the walk to find the player. Throws +// OperationFailedException if it runs over 10 minutes. // THOROUGH: an item's name is read in the bag before it is used, and a // different one isn't used. BattleEnd fight_battle( diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp index 51378d7cf5..e5643d84e8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -28,6 +28,13 @@ constexpr Milliseconds EVOLUTION_SEEN = std::chrono::milliseconds(5000); // Nothing pressed for at most this long in all in a battle: an evolution // and the next member's, with room to spare. constexpr Milliseconds EVOLUTION_HOLDS = std::chrono::milliseconds(45000); +// No battle menu, HP box or YES/NO for this long: START, to see whether +// the overworld is back. Longer than a turn's text between two HP boxes. +constexpr Milliseconds BATTLE_GONE = std::chrono::milliseconds(3000); +// START at most this often: each look takes over a second. +constexpr Milliseconds OVERWORLD_CHECK = std::chrono::milliseconds(3000); +// A and B pressed blind for this long with no battle menu: give up. +constexpr Milliseconds BLIND_PRESSES = std::chrono::milliseconds(30000); } @@ -158,8 +165,12 @@ EvolutionHold::EvolutionHold(PartyMember& lead) : m_lead(lead) {} -bool EvolutionHold::holds(const BattleTextScreen& screen, size_t turns) const{ - return turns > 0 && m_held < EVOLUTION_HOLDS && screen.text_box && !screen.hp_box && !screen.arrow && !screen.yes_no; +void EvolutionHold::turn_taken(TurnChoice choice){ + m_attacked = choice == TurnChoice::MOVE; +} + +bool EvolutionHold::holds(const BattleTextScreen& screen) const{ + return m_attacked && m_held < EVOLUTION_HOLDS && screen.text_box && !screen.hp_box && !screen.arrow && !screen.yes_no; } void EvolutionHold::held(Milliseconds held, bool lead_fainted){ @@ -172,6 +183,33 @@ void EvolutionHold::held(Milliseconds held, bool lead_fainted){ evolve(m_lead); } +void BattleEndWatch::seen(BattleSeen what, WallClock now){ + if (what != BattleSeen::NONE){ + m_last_battle = now; + } + if (what == BattleSeen::MENU){ + m_blind_since.reset(); + } +} + +bool BattleEndWatch::check_overworld(WallClock now){ + if (!m_last_battle || now - *m_last_battle < BATTLE_GONE){ + return false; + } + if (m_last_check && now - *m_last_check < OVERWORLD_CHECK){ + return false; + } + m_last_check = now; + return true; +} + +bool BattleEndWatch::pressed_blind(WallClock now){ + if (!m_blind_since){ + m_blind_since = now; + } + return now - *m_blind_since >= BLIND_PRESSES; +} + } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h index 572846d6f9..e2a1cb5240 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h @@ -123,23 +123,60 @@ class EvolutionHold{ public: explicit EvolutionHold(PartyMember& lead); - // Whether `screen` may be an evolution: after a turn, the text box - // with no HP box and no arrow or YES/NO, as "What? is - // evolving!" shows through the animation. Nothing is pressed while it - // shows, for at most EVOLUTION_HOLDS in all in a battle, in case it is - // something else. - bool holds(const BattleTextScreen& screen, size_t turns) const; + // The loop took a turn: only one that attacked can end the battle in a + // win, and so in an evolution. + void turn_taken(TurnChoice choice); + // Whether `screen` may be an evolution: after a turn that attacked (not + // after RUN: console B, 2026-11-03, a minute without B after "Got away + // safely!"), the text box with no HP box and no arrow or YES/NO, as + // "What? is evolving!" shows through the animation. Nothing + // is pressed while it shows, for at most EVOLUTION_HOLDS in all in a + // battle, in case it is something else. + bool holds(const BattleTextScreen& screen) const; // Such a screen showed for `held` with nothing pressed: long enough, // and the lead evolved (unless it had fainted). void held(Milliseconds held, bool lead_fainted); private: PartyMember& m_lead; + bool m_attacked = false; bool m_evolved = false; Milliseconds m_held = Milliseconds::zero(); }; +// What the battle loop saw of the battle at a poll. +enum class BattleSeen{ + NONE, + BATTLE, // as battle_shows() reads it + MENU, // the battle menu +}; + +// When the battle loop presses START to see whether the overworld is +// back, and when it gives up pressing A and B for a screen nothing reads. +// The battle counts as on screen by its menu, an HP box or a YES/NO only: +// its text box alone also reads on the black below a dark cave's corridor +// (console B, 2026-11-03, Mt. Moon B2F: after "Got away safely!" the loop +// took the cave for the battle and pressed A and B for 9 minutes). +class BattleEndWatch{ +public: + // What the loop read at `now`. + void seen(BattleSeen what, WallClock now); + // Whether to press START at `now`: a battle was seen, and none since + // for BATTLE_GONE. At most every OVERWORLD_CHECK. + bool check_overworld(WallClock now); + // A or B was pressed blind at `now`. True once that has gone on for + // BLIND_PRESSES with no battle menu: the loop stops, and the walker, + // which finds the player again, goes on. + bool pressed_blind(WallClock now); + +private: + std::optional m_last_battle; + std::optional m_last_check; + std::optional m_blind_since; +}; + + void add_tests_AutoStoryParty(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index eb2e0193d2..380b03db46 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -13,6 +13,7 @@ #include "Common/Cpp/TestRunners/UnitTest.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonFramework/Language.h" +#include "Tests/ImageUnitTest.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattle.h" @@ -173,6 +174,27 @@ UnitTestResult test_unread_language(Logger& logger){ } +// battle_shows(), the battle loop's look at whether the battle is still on +// screen, on console B's captures. +class Test_BattleShows : public ImageUnitTest{ +public: + Test_BattleShows(const std::string& image, bool expected) + : ImageUnitTest("PokemonFRLG::AutoStoryBattle - " + image, {image}) + , m_expected(expected) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + return battle_shows(images[0]) == m_expected; + } + +private: + bool m_expected; +}; + + } @@ -182,6 +204,11 @@ void add_tests_AutoStoryItems(UnitTestDatabase& database){ database.add("a loaded save's counts come from the bag", test_loaded_bag); database.add("unread bag counts count as some", test_unread_counts); database.add("no item names read in a language without them", test_unread_language); + // "Wild CHANSEY appeared!" with its HP box, and Mt. Moon B2F's corridor + // after "Got away safely!", whose black lower half reads as the battle's + // text box (console B, 2026-11-03: 9 minutes of A and B there). + database.add("PokemonFRLG/WildEncounterReader/eng_chansey.jpg", true); + database.add("PokemonFRLG/AutoStoryBattle/MtMoonB2F_AfterRun_False.png", false); // The battle's choices, registered here to keep add_tests() within its size. add_tests_AutoStoryParty(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp index d3172fbed5..42b244a6cc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp @@ -474,11 +474,11 @@ struct FakeEvolution{ }; // Plays `scene` against the loop's rule (B at any screen it doesn't hold -// for), after `turns` turns: whether the evolution went through. -bool evolves_against_loop(const FakeEvolution& scene, const EvolutionHold& hold, size_t turns){ +// for): whether the evolution went through. +bool evolves_against_loop(const FakeEvolution& scene, const EvolutionHold& hold){ bool cancelled = false; for (size_t frame = 0; frame < scene.frames.size(); frame++){ - const bool pressed_b = !hold.holds(scene.frames[frame], turns); + const bool pressed_b = !hold.holds(scene.frames[frame]); if (pressed_b && frame >= scene.evolving_from && frame < scene.evolving_to){ cancelled = true; } @@ -502,10 +502,11 @@ UnitTestResult test_no_b_during_evolution(Logger&){ PartyMember lead = with_moves("squirtle", {"tackle", "tail-whip", "bubble", "withdraw"}, 13); EvolutionHold hold(lead); - if (!evolves_against_loop(scene, hold, 1)){ + hold.turn_taken(TurnChoice::MOVE); + if (!evolves_against_loop(scene, hold)){ return "B was pressed during \"is evolving!\": the evolution would be cancelled."; } - if (hold.holds(congratulations, 1) || hold.holds(learn_prompt, 1)){ + if (hold.holds(congratulations) || hold.holds(learn_prompt)){ return "Expected B (or the prompt's answer) for the text with an arrow and the YES/NO after the evolution."; } @@ -518,18 +519,108 @@ UnitTestResult test_no_b_during_evolution(Logger&){ return "Expected Squirtle to be Wartortle after 15 s of its evolution screen, got " + lead.species + "."; } hold.held(40s, false); - if (hold.holds(evolving, 1)){ + if (hold.holds(evolving)){ return "Expected no more holding once a battle's holds reach their cap."; } PartyMember other = new_member("squirtle", 5); EvolutionHold before_turn(other); - if (before_turn.holds(evolving, 0)){ + if (before_turn.holds(evolving)){ return "Held before the first turn, where Oak's text box needs B."; } return true; } +// A poll of the battle loop: what it read, at `ms` from the start. +struct LoopPoll{ + int ms; + BattleTextScreen screen; + bool menu = false; +}; + +// Regression: console B, 2026-11-03, Mt. Moon B2F: RUN, "Got away +// safely!", then the cave corridor, whose black lower half reads as the +// battle's text box with no HP box. The loop held B for an evolution for +// a minute, then pressed A and B for 9 minutes. After RUN nothing is held, +// and START looks for the overworld within seconds of the last HP box. +UnitTestResult test_run_then_overworld(Logger&){ + const BattleTextScreen menu_screen{.text_box = true, .hp_box = true, .arrow = false, .yes_no = false}; + const BattleTextScreen got_away{.text_box = true, .hp_box = true, .arrow = true, .yes_no = false}; + const BattleTextScreen dark_cave{.text_box = true, .hp_box = false, .arrow = false, .yes_no = false}; + std::vector polls{{.ms = 0, .screen = menu_screen, .menu = true}}; + for (int ms = 300; ms <= 1500; ms += 300){ + polls.push_back({.ms = ms, .screen = got_away}); + } + for (int ms = 1800; ms <= 60000; ms += 300){ + polls.push_back({.ms = ms, .screen = dark_cave}); + } + + Supplies supplies; + BattleDecisions decisions(supplies, BattleKind::WILD_RUN); + EvolutionHold hold(supplies.lead); + BattleEndWatch watch; + const WallClock start = current_time(); + const TurnChoice choice = decisions.turn(PartyStatus{.hp_seen = true}).choice; + if (choice != TurnChoice::RUN){ + return "Expected RUN from a wild Pokemon."; + } + hold.turn_taken(choice); + for (const LoopPoll& poll : polls){ + const WallClock now = start + std::chrono::milliseconds(poll.ms); + if (hold.holds(poll.screen)){ + return std::format("Held B for an evolution at {} ms, after RUN.", poll.ms); + } + const bool battle = poll.screen.hp_box || poll.screen.yes_no; + watch.seen(poll.menu ? BattleSeen::MENU : battle ? BattleSeen::BATTLE : BattleSeen::NONE, now); + if (watch.check_overworld(now)){ + // The last HP box at 1.5 s; START within the next 3.5 s. + if (poll.ms > 5000){ + return std::format("START first looked for the overworld at {} ms.", poll.ms); + } + return true; + } + } + return "START never looked for the overworld in the dark cave."; +} + +// START only once the battle is gone for a while, and then not at every +// poll; A and B blind for at most 30 s since the last battle menu. +UnitTestResult test_end_watch_timing(Logger&){ + const WallClock start = current_time(); + const auto at = [&](int ms){ return start + std::chrono::milliseconds(ms); }; + BattleEndWatch watch; + if (watch.check_overworld(at(10000))){ + return "Looked for the overworld before any battle screen showed."; + } + for (int ms = 0; ms <= 20000; ms += 300){ + watch.seen(BattleSeen::BATTLE, at(ms)); + if (watch.check_overworld(at(ms))){ + return std::format("Looked for the overworld at {} ms with an HP box on screen.", ms); + } + } + int checks = 0; + for (int ms = 20100; ms <= 32000; ms += 300){ + watch.seen(BattleSeen::NONE, at(ms)); + checks += watch.check_overworld(at(ms)) ? 1 : 0; + } + if (checks < 2 || checks > 4){ + return std::format("Expected START every 3 s for 12 s without the battle, got {} looks.", checks); + } + for (int ms = 0; ms < 30000; ms += 1500){ + if (watch.pressed_blind(at(40000 + ms))){ + return std::format("Gave up pressing blind after {} ms.", ms); + } + } + if (!watch.pressed_blind(at(70000))){ + return "Expected to give up after 30 s of blind presses."; + } + watch.seen(BattleSeen::MENU, at(71000)); + if (watch.pressed_blind(at(72000))){ + return "Expected the battle menu to start the blind presses' time over."; + } + return true; +} + } @@ -543,6 +634,8 @@ void add_tests_AutoStoryParty(UnitTestDatabase& database){ database.add("moves read off the summary, Water Gun over Tackle", test_moves_from_summary); database.add("summary members: fewer moves, unread PP, strongest attack", test_summary_members); database.add("no B during an evolution", test_no_b_during_evolution); + database.add("RUN, then a dark cave: no evolution wait, START soon", test_run_then_overworld); + database.add("battle end: START after the battle is gone, A and B for 30 s at most", test_end_watch_timing); database.add("attacks by matchup: Bite on the rival's Bulbasaur and Misty", test_attack_by_matchup); database.add("attacks against an unknown foe: the plan's order", test_attack_unknown_foe); database.add("Bite learned over Tail Whip or Withdraw", test_bite_learned); From 6bdc7dabe3de1168142f51141eab583db89fd76f Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 04:06:50 -0800 Subject: [PATCH 68/75] FRLG AutoStory battle: a disabled move, and a move list that never showed Console B, 2026-11-03, Mt. Moon B2F: the starter blacked out against Super Nerd Miguel. His Grimer (Lv12: Poison Gas, Pound, Harden, Disable) disabled Water Gun after turn 1; the loop chose it 17 more times, each turned down with no turn passing and each spending a PP of the story's count. Once that count ran out it chose "Bite" in slot 2, which the story had recorded over Tail Whip from a YES/NO read at a level-up where no move list followed. The game still had Tail Whip there: 7 Tail Whips, and the starter fainted. - A move turned down (the move list back, then the battle menu sooner than any turn) gets its PP back and is left alone for 5 turns, as long as Disable lasts (pret Cmd_disablelastusedattack). turn_done() takes a TurnResult for it. - The moves change only once the move list opened: prompt() hands the learned lead back, and the loop keeps it only then. With no move list, nothing more is pressed (it pressed DOWN and A by time before). - Each turn's battle menu and each YES/NO is dumped to AutoStory/battle, and the turn line logs the HP bar's fill. - healed_by_nurse() and attacks_low_on_pp() move to the decisions file, which keeps the battle file under 1000 lines. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 55 +++++----- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 2 + .../PokemonFRLG_AutoStoryBattleDecisions.cpp | 81 +++++++++++++- .../PokemonFRLG_AutoStoryBattleDecisions.h | 47 +++++++- .../PokemonFRLG_AutoStoryParty_Tests.cpp | 100 +++++++++++++++++- 5 files changed, 249 insertions(+), 36 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 6ade581a46..2a9e87358e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -62,9 +62,6 @@ constexpr Milliseconds NOT_A_BATTLE = 15000ms; // An evolution's animation, with no presses: as long as exit_wild_battle() // (PokemonFRLG_Navigation.cpp) waits for one. constexpr Milliseconds EVOLUTION = 20000ms; -// Below this much PP left in the lead's attacks, the nurse before a fight -// that needs them: about a trainer's worth of turns. -constexpr size_t LOW_ATTACK_PP = 10; // Text and the move learn prompts after a battle, on the overworld. constexpr Milliseconds AFTER_BATTLE_TEXT = 60000ms; // The move list to fade in after "Delete a move?", and its cursor to move. @@ -302,16 +299,13 @@ std::optional read_move_list_cursor( // 2026-11-02). Done in one go, so the loop's B presses can't land on the // list. A list whose cursor never shows gets the presses by time, as // before; a cursor that can't be brought to `slot` fails the battle. -void forget_move(ConsoleHandle& console, ProControllerContext& context, size_t slot){ +// YES, then `slot` on the move list. False, with nothing more pressed, if no move list showed. +bool forget_move(ConsoleHandle& console, ProControllerContext& context, size_t slot){ pbf_press_button(context, BUTTON_A, 160ms, 0ms); std::optional cursor = read_move_list_cursor(console, context, std::nullopt, MOVE_LIST_TIMEOUT); if (!cursor){ - console.log("Battle: no cursor read on the move list; moving it by time.", COLOR_ORANGE); - for (size_t c = 0; c < slot; c++){ - pbf_press_dpad(context, DPAD_DOWN, 160ms, 400ms); - } - pbf_press_button(context, BUTTON_A, 160ms, 2000ms); - return; + console.log("Battle: no move list after YES; the moves stay as they were.", COLOR_ORANGE); + return false; } for (size_t presses = 0; *cursor != slot; presses++){ if (presses >= 2 * SUMMARY_MOVE_ROWS){ @@ -332,10 +326,15 @@ void forget_move(ConsoleHandle& console, ProControllerContext& context, size_t s ); } pbf_press_button(context, BUTTON_A, 160ms, 2000ms); + return true; } // The party list in battle opens on the lead: down to `slot`, then A, and // SHIFT, the top of its menu. +TurnResult item_result(bool used){ + return used ? TurnResult::DONE : TurnResult::NOT_DONE; +} + void send_member(ProControllerContext& context, size_t slot){ for (size_t c = 0; c < slot; c++){ pbf_press_dpad(context, DPAD_DOWN, 160ms, 400ms); @@ -419,6 +418,7 @@ class BattleLoop{ return press_blind(now); } if (seen == BattleScreen::NONE){ + m_refusal.no_battle_screen(); return no_battle_screen(screen, now); } m_seen_battle = true; @@ -438,8 +438,9 @@ class BattleLoop{ } if (m_move_chosen && BattleOutOfPpDetector(COLOR_RED).detect(screen)){ m_console.log("Battle: no PP left for that move; choosing again.", COLOR_ORANGE); - m_decisions.turn_done(TurnChoice::MOVE, false); + m_decisions.turn_done(TurnChoice::MOVE, TurnResult::NOT_DONE); m_move_chosen = false; + m_refusal = MoveRefusalWatch(); pbf_press_button(m_context, BUTTON_B, 160ms, 800ms); pbf_press_button(m_context, BUTTON_B, 160ms, 800ms); m_last_press = now; @@ -606,10 +607,13 @@ class BattleLoop{ } void answer_prompt(const ImageViewRGB32& screen, WallClock now){ + dump_debug_image(m_console, "AutoStory/battle", std::format("turn{}-yes-no", m_decisions.turns()), screen); const PromptAnswer answer = m_decisions.prompt(starter_fainted(screen)); if (answer.forget_slot){ m_console.log(std::format("Battle: learning the new move over move {}.", *answer.forget_slot + 1)); - forget_move(m_console, m_context, *answer.forget_slot); + if (forget_move(m_console, m_context, *answer.forget_slot) && answer.learned){ + m_supplies.lead = *answer.learned; + } }else{ m_console.log(std::format("Battle: answering {} to a YES/NO.", answer.answer == YesNo::YES ? "YES" : "NO")); pbf_press_button(m_context, answer.answer == YesNo::YES ? BUTTON_A : BUTTON_B, 160ms, 1500ms); @@ -619,27 +623,33 @@ class BattleLoop{ void take_turn(const ImageViewRGB32& screen){ m_faint_polls = 0; + if (m_refusal.refused(current_time())){ + m_console.log("Battle: the move list came back without a turn (Disable?); choosing another move.", COLOR_ORANGE); + m_decisions.turn_done(TurnChoice::MOVE, TurnResult::REFUSED); + } const PartyStatus status = read_party_status(screen); const TurnAction action = m_decisions.turn(status); m_evolution.turn_taken(action.choice); m_console.log(std::format( - "Battle: turn {}, HP {}, {}, {} Potions, {} Antidotes, {} Parlyz Heals.", - m_decisions.turns(), status.hp_red ? "red" : status.hp_yellow ? "yellow" : "green", + "Battle: turn {}, HP {} ({:.0f}% of the bar), {}, {} Potions, {} Antidotes, {} Parlyz Heals.", + m_decisions.turns(), status.hp_red ? "red" : status.hp_yellow ? "yellow" : "green", 100 * status.hp_fill, status_name(status.status), m_supplies.potions, m_supplies.antidotes, m_supplies.parlyz_heals )); + dump_debug_image(m_console, "AutoStory/battle", std::format("turn{}-menu", m_decisions.turns()), screen); switch (action.choice){ case TurnChoice::RUN: m_console.log("Battle: RUN."); run_away(m_context); return; case TurnChoice::POTION: - m_decisions.turn_done(action.choice, use_item(m_console, m_context, item_row(m_supplies, "potion"), "potion", m_checks, m_language)); + m_decisions.turn_done(action.choice, item_result(use_item(m_console, m_context, item_row(m_supplies, "potion"), "potion", m_checks, m_language))); return; case TurnChoice::ANTIDOTE: - m_decisions.turn_done(action.choice, use_item(m_console, m_context, item_row(m_supplies, "antidote"), "antidote", m_checks, m_language)); + m_decisions.turn_done(action.choice, item_result(use_item(m_console, m_context, item_row(m_supplies, "antidote"), "antidote", m_checks, m_language))); return; case TurnChoice::MOVE: m_console.log(std::format("Battle: move {}.", action.slot + 1)); + m_refusal.move_chosen(current_time()); use_move(m_context, action.slot); m_move_chosen = true; return; @@ -663,6 +673,7 @@ class BattleLoop{ BattleDecisions m_decisions; EvolutionHold m_evolution; BattleEndWatch m_end; + MoveRefusalWatch m_refusal; const BattleKind m_kind; const StoryChecks m_checks; const Language m_language; @@ -830,6 +841,7 @@ PartyStatus read_party_status(const ImageViewRGB32& screen){ status.hp_seen = most >= seen; status.hp_yellow = status.hp_seen && counts.yellow == most; status.hp_red = status.hp_seen && !status.hp_yellow && counts.red == most; + status.hp_fill = counts.total == 0 ? 0 : double(counts.green + counts.yellow + counts.red) / counts.total; status.status = read_status_badge(extract_box_reference(game, STATUS_BADGE_BOX)); return status; } @@ -958,17 +970,6 @@ void recover_after_battle( } } -void healed_by_nurse(Supplies& supplies){ - supplies.hurt = false; - supplies.hp_red = false; - supplies.status = StatusCondition::NONE; - restore_pp(supplies.lead); -} - -bool attacks_low_on_pp(const Supplies& supplies){ - return attack_slot(supplies.lead).has_value() && attack_pp(supplies.lead) < LOW_ATTACK_PP; -} - BattleEnd fight_battle( ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, BattleKind kind, StoryChecks checks, Language language diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index 2deeb3cb03..527e8ff33f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -129,6 +129,8 @@ struct PartyStatus{ bool hp_seen = false; bool hp_yellow = false; bool hp_red = false; + // The HP bar's colored share, 0 to 1, for the log. + double hp_fill = 0; StatusCondition status = StatusCondition::NONE; }; PartyStatus read_party_status(const ImageViewRGB32& screen); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp index e5643d84e8..2ce9fb9725 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -5,6 +5,7 @@ */ #include +#include #include "PokemonFRLG_AutoStoryBattleDecisions.h" namespace PokemonAutomation{ @@ -35,10 +36,31 @@ constexpr Milliseconds BATTLE_GONE = std::chrono::milliseconds(3000); constexpr Milliseconds OVERWORLD_CHECK = std::chrono::milliseconds(3000); // A and B pressed blind for this long with no battle menu: give up. constexpr Milliseconds BLIND_PRESSES = std::chrono::milliseconds(30000); +// Turns a move turned down is left alone: the longest Disable (pret +// battle_script_commands.c Cmd_disablelastusedattack, 2 to 5 turns). +constexpr int DISABLE_TURNS = 5; +// The battle menu back this soon after a move was chosen, with the move +// list between: the move wasn't used. +constexpr Milliseconds REFUSED_WITHIN = std::chrono::milliseconds(7000); +// Below this much PP left in the lead's attacks, the nurse before a fight +// that needs them: about a trainer's worth of turns. +constexpr size_t LOW_ATTACK_PP = 10; } +void healed_by_nurse(Supplies& supplies){ + supplies.hurt = false; + supplies.hp_red = false; + supplies.status = StatusCondition::NONE; + restore_pp(supplies.lead); +} + +bool attacks_low_on_pp(const Supplies& supplies){ + return attack_slot(supplies.lead).has_value() && attack_pp(supplies.lead) < LOW_ATTACK_PP; +} + + BattleDecisions::BattleDecisions(Supplies& supplies, BattleKind kind) : m_supplies(supplies) , m_kind(kind) @@ -46,6 +68,7 @@ BattleDecisions::BattleDecisions(Supplies& supplies, BattleKind kind) TurnAction BattleDecisions::turn(const PartyStatus& status){ m_turns++; + count_down_refused(); m_last_move_slot.reset(); if (!m_lost){ return lead_turn(status); @@ -88,9 +111,15 @@ TurnAction BattleDecisions::lead_turn(const PartyStatus& status){ // can't reach while that slot is empty, so before Bubble it stays on // Tackle. TurnAction BattleDecisions::move_turn(){ + PartyMember usable = m_supplies.lead; + for (const auto& refused : m_refused){ + if (refused.first < usable.moves.size()){ + usable.moves[refused.first].pp = 0; + } + } const std::optional slot = m_kind == BattleKind::TRAINER - ? attack_slot_against(m_supplies.lead, m_supplies.foes) - : attack_slot(m_supplies.lead); + ? attack_slot_against(usable, m_supplies.foes) + : attack_slot(usable); if (!slot){ return TurnAction{.choice = TurnChoice::MOVE, .slot = BOTTOM_LEFT_MOVE}; } @@ -99,7 +128,31 @@ TurnAction BattleDecisions::move_turn(){ return TurnAction{.choice = TurnChoice::MOVE, .slot = *slot}; } -void BattleDecisions::turn_done(TurnChoice choice, bool done){ +void BattleDecisions::count_down_refused(){ + for (auto it = m_refused.begin(); it != m_refused.end();){ + it = --it->second <= 0 ? m_refused.erase(it) : std::next(it); + } +} + +void BattleDecisions::move_refused(){ + if (!m_last_move_slot){ + return; + } + const size_t slot = *m_last_move_slot; + if (slot < m_supplies.lead.moves.size()){ + m_supplies.lead.moves[slot].pp++; + } + // One more: the next turn() counts down the one that didn't happen. + m_refused[slot] = DISABLE_TURNS + 1; + m_last_move_slot.reset(); +} + +void BattleDecisions::turn_done(TurnChoice choice, TurnResult result){ + if (result == TurnResult::REFUSED){ + move_refused(); + return; + } + const bool done = result == TurnResult::DONE; if (!done && choice == TurnChoice::MOVE){ if (m_last_move_slot){ no_pp_left(m_supplies.lead, *m_last_move_slot); @@ -136,10 +189,12 @@ PromptAnswer BattleDecisions::prompt(bool lead_box_gone){ m_declined_delete = false; return PromptAnswer{.answer = YesNo::YES}; } - const LearnDecision decision = learn_move(m_supplies.lead); + PartyMember learning = m_supplies.lead; + const LearnDecision decision = learn_move(learning); if (decision.forget_slot){ - return PromptAnswer{.answer = YesNo::YES, .forget_slot = decision.forget_slot}; + return PromptAnswer{.answer = YesNo::YES, .forget_slot = decision.forget_slot, .learned = std::move(learning)}; } + m_supplies.lead = std::move(learning); m_declined_delete = true; return PromptAnswer{.answer = YesNo::NO}; } @@ -203,6 +258,22 @@ bool BattleEndWatch::check_overworld(WallClock now){ return true; } +void MoveRefusalWatch::move_chosen(WallClock now){ + m_chosen = now; + m_list_back = false; +} + +void MoveRefusalWatch::no_battle_screen(){ + m_list_back = m_chosen.has_value(); +} + +bool MoveRefusalWatch::refused(WallClock now){ + const bool refused = m_chosen && m_list_back && now - *m_chosen < REFUSED_WITHIN; + m_chosen.reset(); + m_list_back = false; + return refused; +} + bool BattleEndWatch::pressed_blind(WallClock now){ if (!m_blind_since){ m_blind_since = now; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h index e2a1cb5240..3df8ef806c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h @@ -20,6 +20,7 @@ #define PokemonAutomation_PokemonFRLG_AutoStoryBattleDecisions_H #include +#include #include #include #include "Common/Cpp/Time.h" @@ -45,6 +46,20 @@ struct TurnAction{ size_t slot = BOTTOM_LEFT_MOVE; }; +// What came of a TurnAction. +enum class TurnResult{ + DONE, + // An item not used (another item in its row), or a move the game said + // has no PP left. + NOT_DONE, + // The game turned the move down although it has PP left: a foe's + // Disable (console B, 2026-11-03, Mt. Moon: Miguel's Grimer disabled + // Water Gun, and the loop chose it 17 more times while no turn passed). + // Its PP comes back, and it isn't chosen for as long as Disable can + // last (pret: 2 to 5 turns). + REFUSED, +}; + enum class YesNo{ YES, NO, @@ -67,6 +82,11 @@ struct PromptAnswer{ // After YES to "Delete a move?": the slot to forget on the move list // that opens, its cursor on the top move. std::optional forget_slot = {}; + // With forget_slot: the lead once the move is learned, to keep only if + // the move list opened (console B, 2026-11-03: a YES/NO read where no + // move list followed was taken as Bite over Tail Whip, and the loop + // later chose Tail Whip for Bite). + std::optional learned = {}; }; @@ -76,9 +96,8 @@ class BattleDecisions{ // At the battle menu, with the player's box as read. TurnAction turn(const PartyStatus& status); - // What turn() chose was done, or not: an item not used (another item - // in its row), or a move the game said has no PP left. - void turn_done(TurnChoice choice, bool done); + // What came of what turn() chose. + void turn_done(TurnChoice choice, TurnResult result); // A YES/NO in or after the battle. With the lead's box gone and the // opponent's there, it is "Use next POKEMON?"; else the move prompts: @@ -98,6 +117,8 @@ class BattleDecisions{ private: TurnAction lead_turn(const PartyStatus& status); TurnAction move_turn(); + void count_down_refused(); + void move_refused(); Supplies& m_supplies; const BattleKind m_kind; @@ -111,6 +132,8 @@ class BattleDecisions{ // NO was answered to "Delete a move?": "Stop learning?" comes next. bool m_declined_delete = false; std::optional m_last_move_slot; + // The slots the game turned down, and the turns until they are tried again. + std::map m_refused; // The members sent in after the lead fainted. std::set m_sent; }; @@ -177,6 +200,24 @@ class BattleEndWatch{ }; +// Whether the game turned down the move chosen, at the battle menu after +// it: the move list came back (no battle screen reads on it) and the menu +// followed sooner than any turn (console B, 2026-11-03: 5.7 s from the +// choice for a disabled move, 8.3 s and up for a turn). +class MoveRefusalWatch{ +public: + void move_chosen(WallClock now); + // No battle screen read while the battle goes on. + void no_battle_screen(); + // At the battle menu: true if the move chosen before it was turned down. + bool refused(WallClock now); + +private: + std::optional m_chosen; + bool m_list_back = false; +}; + + void add_tests_AutoStoryParty(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp index 42b244a6cc..55cddac2e8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp @@ -252,7 +252,7 @@ UnitTestResult test_pp(Logger&){ BattleDecisions out(supplies, BattleKind::TRAINER); out.turn(GREEN); - out.turn_done(TurnChoice::MOVE, false); + out.turn_done(TurnChoice::MOVE, TurnResult::NOT_DONE); if (out.turn(GREEN).slot != TOP_LEFT_MOVE){ return "Expected Tackle after the game said Water Gun has no PP left."; } @@ -625,6 +625,101 @@ UnitTestResult test_end_watch_timing(Logger&){ } +// The lead console B took into Super Nerd Miguel's battle (2026-11-03, +// Mt. Moon B2F), as its summary read before the run. +PartyMember squirtle_before_miguel(){ + return member_from_summary("squirtle", 16, { + {.move = "water-gun", .pp = 25, .max_pp = 25}, + {.move = "tail-whip", .pp = 30, .max_pp = 30}, + {.move = "bubble", .pp = 30, .max_pp = 30}, + {.move = "withdraw", .pp = 40, .max_pp = 40}, + }); +} + +// Regression, console B 2026-11-03: in the trainer's battle before the +// Rocket Grunt, a YES/NO read at a level-up (Lv17: no move to learn) got +// the plan's YES for Bite over Tail Whip, and no move list followed. The +// story still took Tail Whip as Bite, and in Miguel's battle chose it as +// its attack for 7 turns, until the starter fainted. The moves change only +// once the move list was seen. +UnitTestResult test_yes_no_without_move_list(Logger&){ + Supplies supplies; + supplies.lead = squirtle_before_miguel(); + BattleDecisions decisions(supplies, BattleKind::TRAINER); + decisions.turn(GREEN); + const PromptAnswer answer = decisions.prompt(false); + if (answer.answer != YesNo::YES || answer.forget_slot != std::optional(1)){ + return "Expected the plan's YES, Bite over Tail Whip (slot 1)."; + } + const std::vector before{"water-gun", "tail-whip", "bubble", "withdraw"}; + if (move_names(supplies.lead) != before){ + return "Expected the moves unchanged with no move list seen, got " + joined(move_names(supplies.lead)) + "."; + } + const std::vector after{"water-gun", "bite", "bubble", "withdraw"}; + if (!answer.learned || move_names(*answer.learned) != after){ + return "Expected the lead to keep once the move list shows to have Bite over Tail Whip."; + } + return true; +} + +// Regression, console B 2026-11-03, Super Nerd Miguel (pret +// sParty_SuperNerdMiguel: Grimer Lv12, whose moves include Disable): after +// turn 1, Water Gun was turned down 17 times with no turn passing, and +// each try spent a PP of the story's count. Turned down once, it is left +// alone for as long as Disable lasts, its PP given back, and Bubble (not +// Tail Whip) attacks meanwhile. +UnitTestResult test_disabled_move(Logger&){ + Supplies supplies; + supplies.lead = squirtle_before_miguel(); + supplies.foes = {"grimer", "voltorb", "koffing"}; + BattleDecisions decisions(supplies, BattleKind::TRAINER); + if (decisions.turn(GREEN).slot != TOP_LEFT_MOVE || decisions.turn(GREEN).slot != TOP_LEFT_MOVE){ + return "Expected Water Gun (slot 0) at turns 1 and 2."; + } + decisions.turn_done(TurnChoice::MOVE, TurnResult::REFUSED); + if (supplies.lead.moves[TOP_LEFT_MOVE].pp != 24){ + return std::format("Expected Water Gun at 24 PP after one turn and one refused, got {}.", supplies.lead.moves[TOP_LEFT_MOVE].pp); + } + for (int c = 0; c < 5; c++){ + const TurnAction action = decisions.turn(GREEN); + if (action.choice != TurnChoice::MOVE || action.slot != BOTTOM_LEFT_MOVE){ + return std::format("Expected Bubble (slot 2) at turn {} after Water Gun was turned down, got slot {}.", c + 1, action.slot); + } + } + if (decisions.turn(GREEN).slot != TOP_LEFT_MOVE){ + return "Expected Water Gun again once Disable is over."; + } + return true; +} + +// The loop's view of a move turned down (console B, 2026-11-03): the move +// list back (no battle screen) and the battle menu 5.7 s after the choice. +// Not a turn (8.3 s and up, with no move list), nor a menu long after one +// (a YES/NO's presses, 25 s). +UnitTestResult test_move_refusal_watch(Logger&){ + const WallClock start = current_time(); + MoveRefusalWatch watch; + watch.move_chosen(start); + watch.no_battle_screen(); + if (!watch.refused(start + 5700ms)){ + return "Expected the move list then the menu at 5.7 s read as the move turned down."; + } + watch.move_chosen(start); + if (watch.refused(start + 5000ms)){ + return "Expected no refusal without the move list between."; + } + watch.move_chosen(start); + watch.no_battle_screen(); + if (watch.refused(start + 25000ms)){ + return "Expected no refusal for a menu 25 s after the choice."; + } + watch.no_battle_screen(); + if (watch.refused(start + 26000ms)){ + return "Expected no refusal with no move chosen."; + } + return true; +} + void add_tests_AutoStoryParty(UnitTestDatabase& database){ database.add("movesets the game gives and the story plays", test_movesets); database.add("move offered and slot forgotten", test_learn_prompts); @@ -639,6 +734,9 @@ void add_tests_AutoStoryParty(UnitTestDatabase& database){ database.add("attacks by matchup: Bite on the rival's Bulbasaur and Misty", test_attack_by_matchup); database.add("attacks against an unknown foe: the plan's order", test_attack_unknown_foe); database.add("Bite learned over Tail Whip or Withdraw", test_bite_learned); + database.add("a YES/NO with no move list after it changes no move", test_yes_no_without_move_list); + database.add("a disabled move: left alone while Disable lasts, PP back", test_disabled_move); + database.add("a move turned down: the move list, then the menu sooner than a turn", test_move_refusal_watch); } From c2a42d697216e32cf4700b46d9810d6ad536904d Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 04:48:57 -0800 Subject: [PATCH 69/75] FRLG AutoStory battle: attacks by matchup in every battle, from pret's data The matchup choice knew only the Cerulean rival's and Misty's parties, and wild battles always used the fixed order. devtools/maps/frlg_battle_data.py now generates BattleData/*.json from pret/pokefirered (type chart, species types and base Attack/Sp. Atk, move power/type/PP, every trainer's party, the trainers each map battles), built into the program. Each story battle step maps to its trainer by map and name; a wild battle reads its Pokemon at the first battle menu and falls back to the plan's order when unread. Expected damage now scales by the lead's Attack or Sp. Atk, by the Gen 3 type split. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- SerialPrograms/CMakeLists.txt | 2 + .../AutoStory/BattleData/map_trainers.json | 106 +++ .../Programs/AutoStory/BattleData/moves.json | 356 ++++++++++ .../AutoStory/BattleData/species.json | 388 +++++++++++ .../AutoStory/BattleData/trainers.json | 641 ++++++++++++++++++ .../AutoStory/BattleData/type_chart.json | 112 +++ .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 4 + .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 4 + .../PokemonFRLG_AutoStoryBattleData.cpp | 231 +++++++ .../PokemonFRLG_AutoStoryBattleData.h | 111 +++ .../PokemonFRLG_AutoStoryBattleData_Tests.cpp | 202 ++++++ .../PokemonFRLG_AutoStoryBattleDecisions.cpp | 8 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 6 +- .../AutoStory/PokemonFRLG_AutoStoryParty.cpp | 177 +---- .../AutoStory/PokemonFRLG_AutoStoryParty.h | 35 +- .../PokemonFRLG_AutoStoryParty_Tests.cpp | 28 +- SerialPrograms/cmake/SourceFiles.cmake | 3 + devtools/maps/frlg_battle_data.py | 195 ++++++ 18 files changed, 2426 insertions(+), 183 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/map_trainers.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/type_chart.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp create mode 100644 devtools/maps/frlg_battle_data.py diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 6a94155e3d..9b3302b834 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -199,6 +199,8 @@ pa_embed_text_files(SerialProgramsLib Source/Pokemon/Navigation/TestMaps Pokemon/Navigation/Pokemon_Navigation_Tests.h PokemonAutomation::Pokemon navigation_test_map_json) pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Overworld/Maps VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h PokemonAutomation::NintendoSwitch::PokemonFRLG overworld_map_json) +pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData + VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_battle_json) # Create binary target diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/map_trainers.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/map_trainers.json new file mode 100644 index 0000000000..0e600db748 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/map_trainers.json @@ -0,0 +1,106 @@ +{ +"CeladonCity_GameCorner": ["TRAINER_TEAM_ROCKET_GRUNT_7"], +"CeladonCity_Gym": ["TRAINER_BEAUTY_BRIDGET", "TRAINER_BEAUTY_LORI", "TRAINER_BEAUTY_TAMIA", "TRAINER_COOLTRAINER_MARY", "TRAINER_LASS_KAY", "TRAINER_LASS_LISA", "TRAINER_LEADER_ERIKA", "TRAINER_PICNICKER_TINA"], +"CeruleanCity": ["TRAINER_RIVAL_CERULEAN_BULBASAUR", "TRAINER_RIVAL_CERULEAN_CHARMANDER", "TRAINER_RIVAL_CERULEAN_SQUIRTLE", "TRAINER_TEAM_ROCKET_GRUNT_5"], +"CeruleanCity_Gym": ["TRAINER_LEADER_MISTY", "TRAINER_PICNICKER_DIANA", "TRAINER_SWIMMER_MALE_LUIS"], +"CinnabarIsland_Gym": ["TRAINER_BURGLAR_DUSTY", "TRAINER_BURGLAR_QUINN", "TRAINER_BURGLAR_RAMON", "TRAINER_LEADER_BLAINE", "TRAINER_SUPER_NERD_AVERY", "TRAINER_SUPER_NERD_DEREK", "TRAINER_SUPER_NERD_ERIK", "TRAINER_SUPER_NERD_ZAC"], +"FiveIsland_LostCave_Room1": ["TRAINER_RUIN_MANIAC_LAWSON"], +"FiveIsland_LostCave_Room10": ["TRAINER_LADY_SELPHY"], +"FiveIsland_LostCave_Room4": ["TRAINER_PSYCHIC_LAURA"], +"FiveIsland_Meadow": ["TRAINER_TEAM_ROCKET_GRUNT_49", "TRAINER_TEAM_ROCKET_GRUNT_50", "TRAINER_TEAM_ROCKET_GRUNT_51"], +"FiveIsland_MemorialPillar": ["TRAINER_BIRD_KEEPER_CHAZ", "TRAINER_BIRD_KEEPER_HAROLD", "TRAINER_BIRD_KEEPER_MILO"], +"FiveIsland_ResortGorgeous": ["TRAINER_LADY_GILLIAN", "TRAINER_LADY_JACKI", "TRAINER_PAINTER_CELINA", "TRAINER_PAINTER_DAISY", "TRAINER_PAINTER_RAYNA", "TRAINER_SWIMMER_MALE_TOBY", "TRAINER_YOUNGSTER_DESTIN"], +"FiveIsland_RocketWarehouse": ["TRAINER_SCIENTIST_GIDEON", "TRAINER_TEAM_ROCKET_ADMIN", "TRAINER_TEAM_ROCKET_ADMIN_2", "TRAINER_TEAM_ROCKET_GRUNT_42", "TRAINER_TEAM_ROCKET_GRUNT_47", "TRAINER_TEAM_ROCKET_GRUNT_48"], +"FiveIsland_WaterLabyrinth": ["TRAINER_PKMN_BREEDER_ALIZE"], +"FourIsland_IcefallCave_Back": ["TRAINER_TEAM_ROCKET_GRUNT_45"], +"FuchsiaCity_Gym": ["TRAINER_JUGGLER_KAYDEN", "TRAINER_JUGGLER_KIRK", "TRAINER_JUGGLER_NATE", "TRAINER_JUGGLER_SHAWN", "TRAINER_LEADER_KOGA", "TRAINER_TAMER_EDGAR", "TRAINER_TAMER_PHIL"], +"MtEmber_Exterior": ["TRAINER_CRUSH_GIRL_JOCELYN", "TRAINER_PKMN_RANGER_BETH", "TRAINER_PKMN_RANGER_LOGAN", "TRAINER_TEAM_ROCKET_GRUNT_43", "TRAINER_TEAM_ROCKET_GRUNT_44"], +"MtMoon_1F": ["TRAINER_BUG_CATCHER_KENT", "TRAINER_BUG_CATCHER_ROBBY", "TRAINER_HIKER_MARCOS", "TRAINER_LASS_IRIS", "TRAINER_LASS_MIRIAM", "TRAINER_SUPER_NERD_JOVAN", "TRAINER_YOUNGSTER_JOSH"], +"MtMoon_B2F": ["TRAINER_SUPER_NERD_MIGUEL", "TRAINER_TEAM_ROCKET_GRUNT", "TRAINER_TEAM_ROCKET_GRUNT_2", "TRAINER_TEAM_ROCKET_GRUNT_3", "TRAINER_TEAM_ROCKET_GRUNT_4"], +"OneIsland_KindleRoad": ["TRAINER_BLACK_BELT_HUGH", "TRAINER_BLACK_BELT_SHEA", "TRAINER_CAMPER_BRYCE", "TRAINER_CRUSH_GIRL_SHARON", "TRAINER_CRUSH_GIRL_TANYA", "TRAINER_CRUSH_KIN_MIK_KIA", "TRAINER_FISHERMAN_TOMMY", "TRAINER_PICNICKER_CLAIRE", "TRAINER_SWIMMER_FEMALE_ABIGAIL", "TRAINER_SWIMMER_FEMALE_MARIA", "TRAINER_SWIMMER_MALE_FINN", "TRAINER_SWIMMER_MALE_GARRETT"], +"OneIsland_TreasureBeach": ["TRAINER_SWIMMER_FEMALE_AMARA"], +"PalletTown_ProfessorOaksLab": ["TRAINER_RIVAL_OAKS_LAB_BULBASAUR", "TRAINER_RIVAL_OAKS_LAB_CHARMANDER", "TRAINER_RIVAL_OAKS_LAB_SQUIRTLE"], +"PewterCity_Gym": ["TRAINER_CAMPER_LIAM", "TRAINER_LEADER_BROCK"], +"PokemonLeague_AgathasRoom": ["TRAINER_ELITE_FOUR_AGATHA", "TRAINER_ELITE_FOUR_AGATHA_2"], +"PokemonLeague_BrunosRoom": ["TRAINER_ELITE_FOUR_BRUNO", "TRAINER_ELITE_FOUR_BRUNO_2"], +"PokemonLeague_ChampionsRoom": ["TRAINER_CHAMPION_FIRST_BULBASAUR", "TRAINER_CHAMPION_FIRST_CHARMANDER", "TRAINER_CHAMPION_FIRST_SQUIRTLE", "TRAINER_CHAMPION_REMATCH_BULBASAUR", "TRAINER_CHAMPION_REMATCH_CHARMANDER", "TRAINER_CHAMPION_REMATCH_SQUIRTLE"], +"PokemonLeague_LancesRoom": ["TRAINER_ELITE_FOUR_LANCE", "TRAINER_ELITE_FOUR_LANCE_2"], +"PokemonLeague_LoreleisRoom": ["TRAINER_ELITE_FOUR_LORELEI", "TRAINER_ELITE_FOUR_LORELEI_2"], +"PokemonMansion_1F": ["TRAINER_SCIENTIST_TED", "TRAINER_YOUNGSTER_JOHNSON"], +"PokemonMansion_2F": ["TRAINER_BURGLAR_ARNIE"], +"PokemonMansion_3F": ["TRAINER_BURGLAR_SIMON", "TRAINER_SCIENTIST_BRAYDON"], +"PokemonMansion_B1F": ["TRAINER_BURGLAR_LEWIS", "TRAINER_SCIENTIST_IVAN"], +"PokemonTower_2F": ["TRAINER_RIVAL_POKEMON_TOWER_BULBASAUR", "TRAINER_RIVAL_POKEMON_TOWER_CHARMANDER", "TRAINER_RIVAL_POKEMON_TOWER_SQUIRTLE"], +"PokemonTower_3F": ["TRAINER_CHANNELER_CARLY", "TRAINER_CHANNELER_HOPE", "TRAINER_CHANNELER_PATRICIA"], +"PokemonTower_4F": ["TRAINER_CHANNELER_JODY", "TRAINER_CHANNELER_LAUREL", "TRAINER_CHANNELER_PAULA"], +"PokemonTower_5F": ["TRAINER_CHANNELER_JANAE", "TRAINER_CHANNELER_KARINA", "TRAINER_CHANNELER_RUTH", "TRAINER_CHANNELER_TAMMY"], +"PokemonTower_6F": ["TRAINER_CHANNELER_ANGELICA", "TRAINER_CHANNELER_EMILIA", "TRAINER_CHANNELER_JENNIFER"], +"PokemonTower_7F": ["TRAINER_TEAM_ROCKET_GRUNT_19", "TRAINER_TEAM_ROCKET_GRUNT_20", "TRAINER_TEAM_ROCKET_GRUNT_21"], +"RockTunnel_1F": ["TRAINER_HIKER_LENNY", "TRAINER_HIKER_LUCAS", "TRAINER_HIKER_OLIVER", "TRAINER_PICNICKER_ARIANA", "TRAINER_PICNICKER_DANA", "TRAINER_PICNICKER_LEAH", "TRAINER_POKEMANIAC_ASHTON"], +"RockTunnel_B1F": ["TRAINER_HIKER_ALLEN", "TRAINER_HIKER_DUDLEY", "TRAINER_HIKER_ERIC", "TRAINER_PICNICKER_MARTHA", "TRAINER_PICNICKER_SOFIA", "TRAINER_POKEMANIAC_COOPER", "TRAINER_POKEMANIAC_STEVE", "TRAINER_POKEMANIAC_WINSTON"], +"RocketHideout_B1F": ["TRAINER_TEAM_ROCKET_GRUNT_10", "TRAINER_TEAM_ROCKET_GRUNT_11", "TRAINER_TEAM_ROCKET_GRUNT_12", "TRAINER_TEAM_ROCKET_GRUNT_8", "TRAINER_TEAM_ROCKET_GRUNT_9"], +"RocketHideout_B2F": ["TRAINER_TEAM_ROCKET_GRUNT_13"], +"RocketHideout_B3F": ["TRAINER_TEAM_ROCKET_GRUNT_14", "TRAINER_TEAM_ROCKET_GRUNT_15"], +"RocketHideout_B4F": ["TRAINER_BOSS_GIOVANNI", "TRAINER_TEAM_ROCKET_GRUNT_16", "TRAINER_TEAM_ROCKET_GRUNT_17", "TRAINER_TEAM_ROCKET_GRUNT_18"], +"Route10": ["TRAINER_HIKER_CLARK", "TRAINER_HIKER_TRENT", "TRAINER_PICNICKER_CAROL", "TRAINER_PICNICKER_HEIDI", "TRAINER_POKEMANIAC_HERMAN", "TRAINER_POKEMANIAC_MARK"], +"Route11": ["TRAINER_ENGINEER_BERNIE", "TRAINER_ENGINEER_BRAXTON", "TRAINER_GAMER_DARIAN", "TRAINER_GAMER_DIRK", "TRAINER_GAMER_HUGO", "TRAINER_GAMER_JASPER", "TRAINER_YOUNGSTER_DAVE", "TRAINER_YOUNGSTER_DILLON", "TRAINER_YOUNGSTER_EDDIE", "TRAINER_YOUNGSTER_YASU"], +"Route12": ["TRAINER_CAMPER_JUSTIN", "TRAINER_FISHERMAN_ANDREW", "TRAINER_FISHERMAN_CHIP", "TRAINER_FISHERMAN_ELLIOT", "TRAINER_FISHERMAN_HANK", "TRAINER_FISHERMAN_NED", "TRAINER_ROCKER_LUCA", "TRAINER_YOUNG_COUPLE_GIA_JES"], +"Route13": ["TRAINER_BEAUTY_LOLA", "TRAINER_BEAUTY_SHEILA", "TRAINER_BIKER_JARED", "TRAINER_BIRD_KEEPER_PERRY", "TRAINER_BIRD_KEEPER_ROBERT", "TRAINER_BIRD_KEEPER_SEBASTIAN", "TRAINER_PICNICKER_ALMA", "TRAINER_PICNICKER_GWEN", "TRAINER_PICNICKER_SUSIE", "TRAINER_PICNICKER_VALERIE"], +"Route14": ["TRAINER_BIKER_GERALD", "TRAINER_BIKER_ISAAC", "TRAINER_BIKER_LUKAS", "TRAINER_BIKER_MALIK", "TRAINER_BIRD_KEEPER_BECK", "TRAINER_BIRD_KEEPER_BENNY", "TRAINER_BIRD_KEEPER_CARTER", "TRAINER_BIRD_KEEPER_DONALD", "TRAINER_BIRD_KEEPER_MARLON", "TRAINER_BIRD_KEEPER_MITCH", "TRAINER_TWINS_KIRI_JAN"], +"Route15": ["TRAINER_BEAUTY_GRACE", "TRAINER_BEAUTY_OLIVIA", "TRAINER_BIKER_ALEX", "TRAINER_BIKER_ERNEST", "TRAINER_BIRD_KEEPER_CHESTER", "TRAINER_BIRD_KEEPER_EDWIN", "TRAINER_CRUSH_KIN_RON_MYA", "TRAINER_PICNICKER_BECKY", "TRAINER_PICNICKER_CELIA", "TRAINER_PICNICKER_KINDRA", "TRAINER_PICNICKER_YAZMIN"], +"Route16": ["TRAINER_BIKER_HIDEO", "TRAINER_BIKER_LAO", "TRAINER_BIKER_RUBEN", "TRAINER_CUE_BALL_CAMRON", "TRAINER_CUE_BALL_KOJI", "TRAINER_CUE_BALL_LUKE", "TRAINER_YOUNG_COUPLE_LEA_JED"], +"Route17": ["TRAINER_BIKER_BILLY", "TRAINER_BIKER_JAXON", "TRAINER_BIKER_NIKOLAS", "TRAINER_BIKER_VIRGIL", "TRAINER_BIKER_WILLIAM", "TRAINER_CUE_BALL_COREY", "TRAINER_CUE_BALL_ISAIAH", "TRAINER_CUE_BALL_JAMAL", "TRAINER_CUE_BALL_RAUL", "TRAINER_CUE_BALL_ZEEK"], +"Route18": ["TRAINER_BIRD_KEEPER_JACOB", "TRAINER_BIRD_KEEPER_RAMIRO", "TRAINER_BIRD_KEEPER_WILTON"], +"Route19": ["TRAINER_SIS_AND_BRO_LIA_LUC", "TRAINER_SWIMMER_FEMALE_ALICE", "TRAINER_SWIMMER_FEMALE_ANYA", "TRAINER_SWIMMER_FEMALE_CONNIE", "TRAINER_SWIMMER_MALE_AXLE", "TRAINER_SWIMMER_MALE_DAVID", "TRAINER_SWIMMER_MALE_DOUGLAS", "TRAINER_SWIMMER_MALE_MATTHEW", "TRAINER_SWIMMER_MALE_REECE", "TRAINER_SWIMMER_MALE_RICHARD", "TRAINER_SWIMMER_MALE_TONY"], +"Route20": ["TRAINER_BIRD_KEEPER_ROGER", "TRAINER_PICNICKER_IRENE", "TRAINER_PICNICKER_MISSY", "TRAINER_SWIMMER_FEMALE_MELISSA", "TRAINER_SWIMMER_FEMALE_NORA", "TRAINER_SWIMMER_FEMALE_SHIRLEY", "TRAINER_SWIMMER_FEMALE_TIFFANY", "TRAINER_SWIMMER_MALE_BARRY", "TRAINER_SWIMMER_MALE_DARRIN", "TRAINER_SWIMMER_MALE_DEAN"], +"Route21_North": ["TRAINER_FISHERMAN_RONALD", "TRAINER_FISHERMAN_WADE", "TRAINER_SIS_AND_BRO_LIL_IAN", "TRAINER_SWIMMER_MALE_SPENCER"], +"Route21_South": ["TRAINER_FISHERMAN_CLAUDE", "TRAINER_FISHERMAN_NOLAN", "TRAINER_SWIMMER_MALE_JACK", "TRAINER_SWIMMER_MALE_JEROME", "TRAINER_SWIMMER_MALE_ROLAND"], +"Route22": ["TRAINER_RIVAL_ROUTE22_EARLY_BULBASAUR", "TRAINER_RIVAL_ROUTE22_EARLY_CHARMANDER", "TRAINER_RIVAL_ROUTE22_EARLY_SQUIRTLE", "TRAINER_RIVAL_ROUTE22_LATE_BULBASAUR", "TRAINER_RIVAL_ROUTE22_LATE_CHARMANDER", "TRAINER_RIVAL_ROUTE22_LATE_SQUIRTLE"], +"Route24": ["TRAINER_BUG_CATCHER_CALE", "TRAINER_CAMPER_ETHAN", "TRAINER_CAMPER_SHANE", "TRAINER_LASS_ALI", "TRAINER_LASS_RELI", "TRAINER_TEAM_ROCKET_GRUNT_6", "TRAINER_YOUNGSTER_TIMMY"], +"Route25": ["TRAINER_CAMPER_FLINT", "TRAINER_HIKER_FRANKLIN", "TRAINER_HIKER_NOB", "TRAINER_HIKER_WAYNE", "TRAINER_LASS_HALEY", "TRAINER_PICNICKER_KELSEY", "TRAINER_YOUNGSTER_CHAD", "TRAINER_YOUNGSTER_DAN", "TRAINER_YOUNGSTER_JOEY"], +"Route3": ["TRAINER_BUG_CATCHER_COLTON", "TRAINER_BUG_CATCHER_GREG", "TRAINER_BUG_CATCHER_JAMES", "TRAINER_LASS_JANICE", "TRAINER_LASS_ROBIN", "TRAINER_LASS_SALLY", "TRAINER_YOUNGSTER_BEN", "TRAINER_YOUNGSTER_CALVIN"], +"Route4": ["TRAINER_LASS_CRISSY"], +"Route6": ["TRAINER_BUG_CATCHER_ELIJAH", "TRAINER_BUG_CATCHER_KEIGO", "TRAINER_CAMPER_JEFF", "TRAINER_CAMPER_RICKY", "TRAINER_PICNICKER_ISABELLE", "TRAINER_PICNICKER_NANCY"], +"Route8": ["TRAINER_BIKER_JAREN", "TRAINER_BIKER_RICARDO", "TRAINER_GAMER_RICH", "TRAINER_GAMER_STAN", "TRAINER_LASS_ANDREA", "TRAINER_LASS_JULIA", "TRAINER_LASS_MEGAN", "TRAINER_LASS_PAIGE", "TRAINER_SUPER_NERD_AIDAN", "TRAINER_SUPER_NERD_GLENN", "TRAINER_SUPER_NERD_LESLIE", "TRAINER_TWINS_ELI_ANNE"], +"Route9": ["TRAINER_BUG_CATCHER_BRENT", "TRAINER_BUG_CATCHER_CONNER", "TRAINER_CAMPER_CHRIS", "TRAINER_CAMPER_DREW", "TRAINER_HIKER_ALAN", "TRAINER_HIKER_BRICE", "TRAINER_HIKER_JEREMY", "TRAINER_PICNICKER_ALICIA", "TRAINER_PICNICKER_CAITLIN"], +"SSAnne_1F_Room2": ["TRAINER_LASS_ANN", "TRAINER_YOUNGSTER_TYLER"], +"SSAnne_1F_Room5": ["TRAINER_GENTLEMAN_ARTHUR"], +"SSAnne_1F_Room7": ["TRAINER_GENTLEMAN_THOMAS"], +"SSAnne_2F_Corridor": ["TRAINER_RIVAL_SS_ANNE_BULBASAUR", "TRAINER_RIVAL_SS_ANNE_CHARMANDER", "TRAINER_RIVAL_SS_ANNE_SQUIRTLE"], +"SSAnne_2F_Room2": ["TRAINER_FISHERMAN_DALE", "TRAINER_GENTLEMAN_BROOKS"], +"SSAnne_2F_Room4": ["TRAINER_GENTLEMAN_LAMAR", "TRAINER_LASS_DAWN"], +"SSAnne_B1F_Room1": ["TRAINER_FISHERMAN_BARNY", "TRAINER_SAILOR_PHILLIP"], +"SSAnne_B1F_Room2": ["TRAINER_SAILOR_HUEY"], +"SSAnne_B1F_Room3": ["TRAINER_SAILOR_DYLAN"], +"SSAnne_B1F_Room4": ["TRAINER_SAILOR_DUNCAN", "TRAINER_SAILOR_LEONARD"], +"SSAnne_Deck": ["TRAINER_SAILOR_EDMOND", "TRAINER_SAILOR_TREVOR"], +"SaffronCity_Dojo": ["TRAINER_BLACK_BELT_AARON", "TRAINER_BLACK_BELT_HIDEKI", "TRAINER_BLACK_BELT_HITOSHI", "TRAINER_BLACK_BELT_KOICHI", "TRAINER_BLACK_BELT_MIKE"], +"SaffronCity_Gym": ["TRAINER_CHANNELER_AMANDA", "TRAINER_CHANNELER_STACY", "TRAINER_CHANNELER_TASHA", "TRAINER_LEADER_SABRINA", "TRAINER_PSYCHIC_CAMERON", "TRAINER_PSYCHIC_JOHAN", "TRAINER_PSYCHIC_PRESTON", "TRAINER_PSYCHIC_TYRON"], +"SevenIsland_SevaultCanyon": ["TRAINER_COOLTRAINER_LEROY", "TRAINER_COOLTRAINER_MICHELLE", "TRAINER_COOL_COUPLE_LEX_NYA", "TRAINER_CRUSH_GIRL_CYNDY", "TRAINER_PKMN_RANGER_JACKSON", "TRAINER_PKMN_RANGER_KATELYN", "TRAINER_TAMER_EVAN"], +"SevenIsland_SevaultCanyon_Entrance": ["TRAINER_AROMA_LADY_MIAH", "TRAINER_JUGGLER_MASON", "TRAINER_PKMN_RANGER_MADELINE", "TRAINER_PKMN_RANGER_NICOLAS", "TRAINER_YOUNG_COUPLE_EVE_JON"], +"SevenIsland_TanobyRuins": ["TRAINER_GENTLEMAN_CLIFFORD", "TRAINER_PAINTER_EDNA", "TRAINER_RUIN_MANIAC_BENJAMIN", "TRAINER_RUIN_MANIAC_BRANDON"], +"SevenIsland_TrainerTower": ["TRAINER_PSYCHIC_DARIO", "TRAINER_PSYCHIC_RODETTE"], +"SilphCo_10F": ["TRAINER_SCIENTIST_TRAVIS", "TRAINER_TEAM_ROCKET_GRUNT_39"], +"SilphCo_11F": ["TRAINER_BOSS_GIOVANNI_2", "TRAINER_TEAM_ROCKET_GRUNT_40", "TRAINER_TEAM_ROCKET_GRUNT_41"], +"SilphCo_2F": ["TRAINER_SCIENTIST_CONNOR", "TRAINER_SCIENTIST_JERRY", "TRAINER_TEAM_ROCKET_GRUNT_23", "TRAINER_TEAM_ROCKET_GRUNT_24"], +"SilphCo_3F": ["TRAINER_SCIENTIST_JOSE", "TRAINER_TEAM_ROCKET_GRUNT_25"], +"SilphCo_4F": ["TRAINER_SCIENTIST_RODNEY", "TRAINER_TEAM_ROCKET_GRUNT_26", "TRAINER_TEAM_ROCKET_GRUNT_27"], +"SilphCo_5F": ["TRAINER_JUGGLER_DALTON", "TRAINER_SCIENTIST_BEAU", "TRAINER_TEAM_ROCKET_GRUNT_28", "TRAINER_TEAM_ROCKET_GRUNT_29"], +"SilphCo_6F": ["TRAINER_SCIENTIST_TAYLOR", "TRAINER_TEAM_ROCKET_GRUNT_30", "TRAINER_TEAM_ROCKET_GRUNT_31"], +"SilphCo_7F": ["TRAINER_RIVAL_SILPH_BULBASAUR", "TRAINER_RIVAL_SILPH_CHARMANDER", "TRAINER_RIVAL_SILPH_SQUIRTLE", "TRAINER_SCIENTIST_JOSHUA", "TRAINER_TEAM_ROCKET_GRUNT_33", "TRAINER_TEAM_ROCKET_GRUNT_34", "TRAINER_TEAM_ROCKET_GRUNT_35"], +"SilphCo_8F": ["TRAINER_SCIENTIST_PARKER", "TRAINER_TEAM_ROCKET_GRUNT_32", "TRAINER_TEAM_ROCKET_GRUNT_36"], +"SilphCo_9F": ["TRAINER_SCIENTIST_ED", "TRAINER_TEAM_ROCKET_GRUNT_37", "TRAINER_TEAM_ROCKET_GRUNT_38"], +"SixIsland_GreenPath": ["TRAINER_PSYCHIC_JACLYN"], +"SixIsland_OutcastIsland": ["TRAINER_FISHERMAN_TYLOR", "TRAINER_SIS_AND_BRO_AVA_GEB", "TRAINER_SWIMMER_FEMALE_NICOLE", "TRAINER_SWIMMER_MALE_MYMO", "TRAINER_TEAM_ROCKET_GRUNT_46"], +"SixIsland_PatternBush": ["TRAINER_BUG_CATCHER_GARRET", "TRAINER_BUG_CATCHER_JONAH", "TRAINER_BUG_CATCHER_VANCE", "TRAINER_CAMPER_RILEY", "TRAINER_LASS_DALIA", "TRAINER_LASS_JOANA", "TRAINER_PICNICKER_MARCY", "TRAINER_PKMN_BREEDER_ALLISON", "TRAINER_PKMN_BREEDER_BETHANY", "TRAINER_RUIN_MANIAC_LAYTON", "TRAINER_YOUNGSTER_CORDELL", "TRAINER_YOUNGSTER_NASH"], +"SixIsland_RuinValley": ["TRAINER_HIKER_DARYL", "TRAINER_POKEMANIAC_HECTOR", "TRAINER_RUIN_MANIAC_FOSTER", "TRAINER_RUIN_MANIAC_LARRY", "TRAINER_RUIN_MANIAC_STANLY"], +"SixIsland_WaterPath": ["TRAINER_AROMA_LADY_ROSE", "TRAINER_HIKER_EARL", "TRAINER_JUGGLER_EDWARD", "TRAINER_SWIMMER_FEMALE_DENISE", "TRAINER_SWIMMER_MALE_SAMIR", "TRAINER_TWINS_MIU_MIA"], +"ThreeIsland": ["TRAINER_BIKER_GOON", "TRAINER_BIKER_GOON_2", "TRAINER_BIKER_GOON_3", "TRAINER_CUE_BALL_PAXTON"], +"ThreeIsland_BondBridge": ["TRAINER_AROMA_LADY_NIKKI", "TRAINER_AROMA_LADY_VIOLET", "TRAINER_SWIMMER_FEMALE_TISHA", "TRAINER_TUBER_ALEXIS", "TRAINER_TUBER_AMIRA", "TRAINER_TWINS_JOY_MEG"], +"VermilionCity_Gym": ["TRAINER_ENGINEER_BAILY", "TRAINER_GENTLEMAN_TUCKER", "TRAINER_LEADER_LT_SURGE", "TRAINER_SAILOR_DWAYNE"], +"VictoryRoad_1F": ["TRAINER_COOLTRAINER_NAOMI", "TRAINER_COOLTRAINER_ROLANDO"], +"VictoryRoad_2F": ["TRAINER_BLACK_BELT_DAISUKE", "TRAINER_JUGGLER_GREGORY", "TRAINER_JUGGLER_NELSON", "TRAINER_POKEMANIAC_DAWSON", "TRAINER_TAMER_VINCENT"], +"VictoryRoad_3F": ["TRAINER_COOLTRAINER_ALEXA", "TRAINER_COOLTRAINER_CAROLINE", "TRAINER_COOLTRAINER_COLBY", "TRAINER_COOLTRAINER_GEORGE", "TRAINER_COOL_COUPLE_RAY_TYRA"], +"ViridianCity_Gym": ["TRAINER_BLACK_BELT_ATSUSHI", "TRAINER_BLACK_BELT_KIYO", "TRAINER_BLACK_BELT_TAKASHI", "TRAINER_COOLTRAINER_SAMUEL", "TRAINER_COOLTRAINER_WARREN", "TRAINER_COOLTRAINER_YUJI", "TRAINER_LEADER_GIOVANNI", "TRAINER_TAMER_COLE", "TRAINER_TAMER_JASON"], +"ViridianForest": ["TRAINER_BUG_CATCHER_ANTHONY", "TRAINER_BUG_CATCHER_CHARLIE", "TRAINER_BUG_CATCHER_DOUG", "TRAINER_BUG_CATCHER_RICK", "TRAINER_BUG_CATCHER_SAMMY"] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json new file mode 100644 index 0000000000..e619c049fb --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json @@ -0,0 +1,356 @@ +{ +"pound": [40, "normal", 35], +"karate-chop": [50, "fighting", 25], +"double-slap": [15, "normal", 10], +"comet-punch": [18, "normal", 15], +"mega-punch": [80, "normal", 20], +"pay-day": [40, "normal", 20], +"fire-punch": [75, "fire", 15], +"ice-punch": [75, "ice", 15], +"thunder-punch": [75, "electric", 15], +"scratch": [40, "normal", 35], +"vise-grip": [55, "normal", 30], +"guillotine": [1, "normal", 5], +"razor-wind": [80, "normal", 10], +"swords-dance": [0, "normal", 30], +"cut": [50, "normal", 30], +"gust": [40, "flying", 35], +"wing-attack": [60, "flying", 35], +"whirlwind": [0, "normal", 20], +"fly": [70, "flying", 15], +"bind": [15, "normal", 20], +"slam": [80, "normal", 20], +"vine-whip": [35, "grass", 10], +"stomp": [65, "normal", 20], +"double-kick": [30, "fighting", 30], +"mega-kick": [120, "normal", 5], +"jump-kick": [70, "fighting", 25], +"rolling-kick": [60, "fighting", 15], +"sand-attack": [0, "ground", 15], +"headbutt": [70, "normal", 15], +"horn-attack": [65, "normal", 25], +"fury-attack": [15, "normal", 20], +"horn-drill": [1, "normal", 5], +"tackle": [35, "normal", 35], +"body-slam": [85, "normal", 15], +"wrap": [15, "normal", 20], +"take-down": [90, "normal", 20], +"thrash": [90, "normal", 20], +"double-edge": [120, "normal", 15], +"tail-whip": [0, "normal", 30], +"poison-sting": [15, "poison", 35], +"twineedle": [25, "bug", 20], +"pin-missile": [14, "bug", 20], +"leer": [0, "normal", 30], +"bite": [60, "dark", 25], +"growl": [0, "normal", 40], +"roar": [0, "normal", 20], +"sing": [0, "normal", 15], +"supersonic": [0, "normal", 20], +"sonic-boom": [1, "normal", 20], +"disable": [0, "normal", 20], +"acid": [40, "poison", 30], +"ember": [40, "fire", 25], +"flamethrower": [95, "fire", 15], +"mist": [0, "ice", 30], +"water-gun": [40, "water", 25], +"hydro-pump": [120, "water", 5], +"surf": [95, "water", 15], +"ice-beam": [95, "ice", 10], +"blizzard": [120, "ice", 5], +"psybeam": [65, "psychic", 20], +"bubble-beam": [65, "water", 20], +"aurora-beam": [65, "ice", 20], +"hyper-beam": [150, "normal", 5], +"peck": [35, "flying", 35], +"drill-peck": [80, "flying", 20], +"submission": [80, "fighting", 25], +"low-kick": [1, "fighting", 20], +"counter": [1, "fighting", 20], +"seismic-toss": [1, "fighting", 20], +"strength": [80, "normal", 15], +"absorb": [20, "grass", 20], +"mega-drain": [40, "grass", 10], +"leech-seed": [0, "grass", 10], +"growth": [0, "normal", 40], +"razor-leaf": [55, "grass", 25], +"solar-beam": [120, "grass", 10], +"poison-powder": [0, "poison", 35], +"stun-spore": [0, "grass", 30], +"sleep-powder": [0, "grass", 15], +"petal-dance": [70, "grass", 20], +"string-shot": [0, "bug", 40], +"dragon-rage": [1, "dragon", 10], +"fire-spin": [15, "fire", 15], +"thunder-shock": [40, "electric", 30], +"thunderbolt": [95, "electric", 15], +"thunder-wave": [0, "electric", 20], +"thunder": [120, "electric", 10], +"rock-throw": [50, "rock", 15], +"earthquake": [100, "ground", 10], +"fissure": [1, "ground", 5], +"dig": [60, "ground", 10], +"toxic": [0, "poison", 10], +"confusion": [50, "psychic", 25], +"psychic": [90, "psychic", 10], +"hypnosis": [0, "psychic", 20], +"meditate": [0, "psychic", 40], +"agility": [0, "psychic", 30], +"quick-attack": [40, "normal", 30], +"rage": [20, "normal", 20], +"teleport": [0, "psychic", 20], +"night-shade": [1, "ghost", 15], +"mimic": [0, "normal", 10], +"screech": [0, "normal", 40], +"double-team": [0, "normal", 15], +"recover": [0, "normal", 20], +"harden": [0, "normal", 30], +"minimize": [0, "normal", 20], +"smokescreen": [0, "normal", 20], +"confuse-ray": [0, "ghost", 10], +"withdraw": [0, "water", 40], +"defense-curl": [0, "normal", 40], +"barrier": [0, "psychic", 30], +"light-screen": [0, "psychic", 30], +"haze": [0, "ice", 30], +"reflect": [0, "psychic", 20], +"focus-energy": [0, "normal", 30], +"bide": [1, "normal", 10], +"metronome": [0, "normal", 10], +"mirror-move": [0, "flying", 20], +"self-destruct": [200, "normal", 5], +"egg-bomb": [100, "normal", 10], +"lick": [20, "ghost", 30], +"smog": [20, "poison", 20], +"sludge": [65, "poison", 20], +"bone-club": [65, "ground", 20], +"fire-blast": [120, "fire", 5], +"waterfall": [80, "water", 15], +"clamp": [35, "water", 10], +"swift": [60, "normal", 20], +"skull-bash": [100, "normal", 15], +"spike-cannon": [20, "normal", 15], +"constrict": [10, "normal", 35], +"amnesia": [0, "psychic", 20], +"kinesis": [0, "psychic", 15], +"soft-boiled": [0, "normal", 10], +"high-jump-kick": [85, "fighting", 20], +"glare": [0, "normal", 30], +"dream-eater": [100, "psychic", 15], +"poison-gas": [0, "poison", 40], +"barrage": [15, "normal", 20], +"leech-life": [20, "bug", 15], +"lovely-kiss": [0, "normal", 10], +"sky-attack": [140, "flying", 5], +"transform": [0, "normal", 10], +"bubble": [20, "water", 30], +"dizzy-punch": [70, "normal", 10], +"spore": [0, "grass", 15], +"flash": [0, "normal", 20], +"psywave": [1, "psychic", 15], +"splash": [0, "normal", 40], +"acid-armor": [0, "poison", 40], +"crabhammer": [90, "water", 10], +"explosion": [250, "normal", 5], +"fury-swipes": [18, "normal", 15], +"bonemerang": [50, "ground", 10], +"rest": [0, "psychic", 10], +"rock-slide": [75, "rock", 10], +"hyper-fang": [80, "normal", 15], +"sharpen": [0, "normal", 30], +"conversion": [0, "normal", 30], +"tri-attack": [80, "normal", 10], +"super-fang": [1, "normal", 10], +"slash": [70, "normal", 20], +"substitute": [0, "normal", 10], +"struggle": [50, "normal", 1], +"sketch": [0, "normal", 1], +"triple-kick": [10, "fighting", 10], +"thief": [40, "dark", 10], +"spider-web": [0, "bug", 10], +"mind-reader": [0, "normal", 5], +"nightmare": [0, "ghost", 15], +"flame-wheel": [60, "fire", 25], +"snore": [40, "normal", 15], +"curse": [0, "mystery", 10], +"flail": [1, "normal", 15], +"conversion-2": [0, "normal", 30], +"aeroblast": [100, "flying", 5], +"cotton-spore": [0, "grass", 40], +"reversal": [1, "fighting", 15], +"spite": [0, "ghost", 10], +"powder-snow": [40, "ice", 25], +"protect": [0, "normal", 10], +"mach-punch": [40, "fighting", 30], +"scary-face": [0, "normal", 10], +"feint-attack": [60, "dark", 20], +"sweet-kiss": [0, "normal", 10], +"belly-drum": [0, "normal", 10], +"sludge-bomb": [90, "poison", 10], +"mud-slap": [20, "ground", 10], +"octazooka": [65, "water", 10], +"spikes": [0, "ground", 20], +"zap-cannon": [100, "electric", 5], +"foresight": [0, "normal", 40], +"destiny-bond": [0, "ghost", 5], +"perish-song": [0, "normal", 5], +"icy-wind": [55, "ice", 15], +"detect": [0, "fighting", 5], +"bone-rush": [25, "ground", 10], +"lock-on": [0, "normal", 5], +"outrage": [90, "dragon", 15], +"sandstorm": [0, "rock", 10], +"giga-drain": [60, "grass", 5], +"endure": [0, "normal", 10], +"charm": [0, "normal", 20], +"rollout": [30, "rock", 20], +"false-swipe": [40, "normal", 40], +"swagger": [0, "normal", 15], +"milk-drink": [0, "normal", 10], +"spark": [65, "electric", 20], +"fury-cutter": [10, "bug", 20], +"steel-wing": [70, "steel", 25], +"mean-look": [0, "normal", 5], +"attract": [0, "normal", 15], +"sleep-talk": [0, "normal", 10], +"heal-bell": [0, "normal", 5], +"return": [1, "normal", 20], +"present": [1, "normal", 15], +"frustration": [1, "normal", 20], +"safeguard": [0, "normal", 25], +"pain-split": [0, "normal", 20], +"sacred-fire": [100, "fire", 5], +"magnitude": [1, "ground", 30], +"dynamic-punch": [100, "fighting", 5], +"megahorn": [120, "bug", 10], +"dragon-breath": [60, "dragon", 20], +"baton-pass": [0, "normal", 40], +"encore": [0, "normal", 5], +"pursuit": [40, "dark", 20], +"rapid-spin": [20, "normal", 40], +"sweet-scent": [0, "normal", 20], +"iron-tail": [100, "steel", 15], +"metal-claw": [50, "steel", 35], +"vital-throw": [70, "fighting", 10], +"morning-sun": [0, "normal", 5], +"synthesis": [0, "grass", 5], +"moonlight": [0, "normal", 5], +"hidden-power": [1, "normal", 15], +"cross-chop": [100, "fighting", 5], +"twister": [40, "dragon", 20], +"rain-dance": [0, "water", 5], +"sunny-day": [0, "fire", 5], +"crunch": [80, "dark", 15], +"mirror-coat": [1, "psychic", 20], +"psych-up": [0, "normal", 10], +"extreme-speed": [80, "normal", 5], +"ancient-power": [60, "rock", 5], +"shadow-ball": [80, "ghost", 15], +"future-sight": [80, "psychic", 15], +"rock-smash": [20, "fighting", 15], +"whirlpool": [15, "water", 15], +"beat-up": [10, "dark", 10], +"fake-out": [40, "normal", 10], +"uproar": [50, "normal", 10], +"stockpile": [0, "normal", 10], +"spit-up": [100, "normal", 10], +"swallow": [0, "normal", 10], +"heat-wave": [100, "fire", 10], +"hail": [0, "ice", 10], +"torment": [0, "dark", 15], +"flatter": [0, "dark", 15], +"will-o-wisp": [0, "fire", 15], +"memento": [0, "dark", 10], +"facade": [70, "normal", 20], +"focus-punch": [150, "fighting", 20], +"smelling-salts": [60, "normal", 10], +"follow-me": [0, "normal", 20], +"nature-power": [0, "normal", 20], +"charge": [0, "electric", 20], +"taunt": [0, "dark", 20], +"helping-hand": [0, "normal", 20], +"trick": [0, "psychic", 10], +"role-play": [0, "psychic", 10], +"wish": [0, "normal", 10], +"assist": [0, "normal", 20], +"ingrain": [0, "grass", 20], +"superpower": [120, "fighting", 5], +"magic-coat": [0, "psychic", 15], +"recycle": [0, "normal", 10], +"revenge": [60, "fighting", 10], +"brick-break": [75, "fighting", 15], +"yawn": [0, "normal", 10], +"knock-off": [20, "dark", 20], +"endeavor": [1, "normal", 5], +"eruption": [150, "fire", 5], +"skill-swap": [0, "psychic", 10], +"imprison": [0, "psychic", 10], +"refresh": [0, "normal", 20], +"grudge": [0, "ghost", 5], +"snatch": [0, "dark", 10], +"secret-power": [70, "normal", 20], +"dive": [60, "water", 10], +"arm-thrust": [15, "fighting", 20], +"camouflage": [0, "normal", 20], +"tail-glow": [0, "bug", 20], +"luster-purge": [70, "psychic", 5], +"mist-ball": [70, "psychic", 5], +"feather-dance": [0, "flying", 15], +"teeter-dance": [0, "normal", 20], +"blaze-kick": [85, "fire", 10], +"mud-sport": [0, "ground", 15], +"ice-ball": [30, "ice", 20], +"needle-arm": [60, "grass", 15], +"slack-off": [0, "normal", 10], +"hyper-voice": [90, "normal", 10], +"poison-fang": [50, "poison", 15], +"crush-claw": [75, "normal", 10], +"blast-burn": [150, "fire", 5], +"hydro-cannon": [150, "water", 5], +"meteor-mash": [100, "steel", 10], +"astonish": [30, "ghost", 15], +"weather-ball": [50, "normal", 10], +"aromatherapy": [0, "grass", 5], +"fake-tears": [0, "dark", 20], +"air-cutter": [55, "flying", 25], +"overheat": [140, "fire", 5], +"odor-sleuth": [0, "normal", 40], +"rock-tomb": [50, "rock", 10], +"silver-wind": [60, "bug", 5], +"metal-sound": [0, "steel", 40], +"grass-whistle": [0, "grass", 15], +"tickle": [0, "normal", 20], +"cosmic-power": [0, "psychic", 20], +"water-spout": [150, "water", 5], +"signal-beam": [75, "bug", 15], +"shadow-punch": [60, "ghost", 20], +"extrasensory": [80, "psychic", 30], +"sky-uppercut": [85, "fighting", 15], +"sand-tomb": [15, "ground", 15], +"sheer-cold": [1, "ice", 5], +"muddy-water": [95, "water", 10], +"bullet-seed": [10, "grass", 30], +"aerial-ace": [60, "flying", 20], +"icicle-spear": [10, "ice", 30], +"iron-defense": [0, "steel", 15], +"block": [0, "normal", 5], +"howl": [0, "normal", 40], +"dragon-claw": [80, "dragon", 15], +"frenzy-plant": [150, "grass", 5], +"bulk-up": [0, "fighting", 20], +"bounce": [85, "flying", 5], +"mud-shot": [55, "ground", 15], +"poison-tail": [50, "poison", 25], +"covet": [40, "normal", 40], +"volt-tackle": [120, "electric", 15], +"magical-leaf": [60, "grass", 20], +"water-sport": [0, "water", 15], +"calm-mind": [0, "psychic", 20], +"leaf-blade": [70, "grass", 15], +"dragon-dance": [0, "dragon", 20], +"rock-blast": [25, "rock", 10], +"shock-wave": [60, "electric", 20], +"water-pulse": [60, "water", 20], +"doom-desire": [120, "steel", 5], +"psycho-boost": [140, "psychic", 5] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json new file mode 100644 index 0000000000..bbbc54e80e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json @@ -0,0 +1,388 @@ +{ +"bulbasaur": ["grass", "poison", 49, 65], +"ivysaur": ["grass", "poison", 62, 80], +"venusaur": ["grass", "poison", 82, 100], +"charmander": ["fire", "fire", 52, 60], +"charmeleon": ["fire", "fire", 64, 80], +"charizard": ["fire", "flying", 84, 109], +"squirtle": ["water", "water", 48, 50], +"wartortle": ["water", "water", 63, 65], +"blastoise": ["water", "water", 83, 85], +"caterpie": ["bug", "bug", 30, 20], +"metapod": ["bug", "bug", 20, 25], +"butterfree": ["bug", "flying", 45, 80], +"weedle": ["bug", "poison", 35, 20], +"kakuna": ["bug", "poison", 25, 25], +"beedrill": ["bug", "poison", 80, 45], +"pidgey": ["normal", "flying", 45, 35], +"pidgeotto": ["normal", "flying", 60, 50], +"pidgeot": ["normal", "flying", 80, 70], +"rattata": ["normal", "normal", 56, 25], +"raticate": ["normal", "normal", 81, 50], +"spearow": ["normal", "flying", 60, 31], +"fearow": ["normal", "flying", 90, 61], +"ekans": ["poison", "poison", 60, 40], +"arbok": ["poison", "poison", 85, 65], +"pikachu": ["electric", "electric", 55, 50], +"raichu": ["electric", "electric", 90, 90], +"sandshrew": ["ground", "ground", 75, 20], +"sandslash": ["ground", "ground", 100, 45], +"nidoran-f": ["poison", "poison", 47, 40], +"nidorina": ["poison", "poison", 62, 55], +"nidoqueen": ["poison", "ground", 82, 75], +"nidoran-m": ["poison", "poison", 57, 40], +"nidorino": ["poison", "poison", 72, 55], +"nidoking": ["poison", "ground", 92, 85], +"clefairy": ["normal", "normal", 45, 60], +"clefable": ["normal", "normal", 70, 85], +"vulpix": ["fire", "fire", 41, 50], +"ninetales": ["fire", "fire", 76, 81], +"jigglypuff": ["normal", "normal", 45, 45], +"wigglytuff": ["normal", "normal", 70, 75], +"zubat": ["poison", "flying", 45, 30], +"golbat": ["poison", "flying", 80, 65], +"oddish": ["grass", "poison", 50, 75], +"gloom": ["grass", "poison", 65, 85], +"vileplume": ["grass", "poison", 80, 100], +"paras": ["bug", "grass", 70, 45], +"parasect": ["bug", "grass", 95, 60], +"venonat": ["bug", "poison", 55, 40], +"venomoth": ["bug", "poison", 65, 90], +"diglett": ["ground", "ground", 55, 35], +"dugtrio": ["ground", "ground", 80, 50], +"meowth": ["normal", "normal", 45, 40], +"persian": ["normal", "normal", 70, 65], +"psyduck": ["water", "water", 52, 65], +"golduck": ["water", "water", 82, 95], +"mankey": ["fighting", "fighting", 80, 35], +"primeape": ["fighting", "fighting", 105, 60], +"growlithe": ["fire", "fire", 70, 70], +"arcanine": ["fire", "fire", 110, 100], +"poliwag": ["water", "water", 50, 40], +"poliwhirl": ["water", "water", 65, 50], +"poliwrath": ["water", "fighting", 85, 70], +"abra": ["psychic", "psychic", 20, 105], +"kadabra": ["psychic", "psychic", 35, 120], +"alakazam": ["psychic", "psychic", 50, 135], +"machop": ["fighting", "fighting", 80, 35], +"machoke": ["fighting", "fighting", 100, 50], +"machamp": ["fighting", "fighting", 130, 65], +"bellsprout": ["grass", "poison", 75, 70], +"weepinbell": ["grass", "poison", 90, 85], +"victreebel": ["grass", "poison", 105, 100], +"tentacool": ["water", "poison", 40, 50], +"tentacruel": ["water", "poison", 70, 80], +"geodude": ["rock", "ground", 80, 30], +"graveler": ["rock", "ground", 95, 45], +"golem": ["rock", "ground", 110, 55], +"ponyta": ["fire", "fire", 85, 65], +"rapidash": ["fire", "fire", 100, 80], +"slowpoke": ["water", "psychic", 65, 40], +"slowbro": ["water", "psychic", 75, 100], +"magnemite": ["electric", "steel", 35, 95], +"magneton": ["electric", "steel", 60, 120], +"farfetch-d": ["normal", "flying", 65, 58], +"doduo": ["normal", "flying", 85, 35], +"dodrio": ["normal", "flying", 110, 60], +"seel": ["water", "water", 45, 45], +"dewgong": ["water", "ice", 70, 70], +"grimer": ["poison", "poison", 80, 40], +"muk": ["poison", "poison", 105, 65], +"shellder": ["water", "water", 65, 45], +"cloyster": ["water", "ice", 95, 85], +"gastly": ["ghost", "poison", 35, 100], +"haunter": ["ghost", "poison", 50, 115], +"gengar": ["ghost", "poison", 65, 130], +"onix": ["rock", "ground", 45, 30], +"drowzee": ["psychic", "psychic", 48, 43], +"hypno": ["psychic", "psychic", 73, 73], +"krabby": ["water", "water", 105, 25], +"kingler": ["water", "water", 130, 50], +"voltorb": ["electric", "electric", 30, 55], +"electrode": ["electric", "electric", 50, 80], +"exeggcute": ["grass", "psychic", 40, 60], +"exeggutor": ["grass", "psychic", 95, 125], +"cubone": ["ground", "ground", 50, 40], +"marowak": ["ground", "ground", 80, 50], +"hitmonlee": ["fighting", "fighting", 120, 35], +"hitmonchan": ["fighting", "fighting", 105, 35], +"lickitung": ["normal", "normal", 55, 60], +"koffing": ["poison", "poison", 65, 60], +"weezing": ["poison", "poison", 90, 85], +"rhyhorn": ["ground", "rock", 85, 30], +"rhydon": ["ground", "rock", 130, 45], +"chansey": ["normal", "normal", 5, 35], +"tangela": ["grass", "grass", 55, 100], +"kangaskhan": ["normal", "normal", 95, 40], +"horsea": ["water", "water", 40, 70], +"seadra": ["water", "water", 65, 95], +"goldeen": ["water", "water", 67, 35], +"seaking": ["water", "water", 92, 65], +"staryu": ["water", "water", 45, 70], +"starmie": ["water", "psychic", 75, 100], +"mr-mime": ["psychic", "psychic", 45, 100], +"scyther": ["bug", "flying", 110, 55], +"jynx": ["ice", "psychic", 50, 115], +"electabuzz": ["electric", "electric", 83, 95], +"magmar": ["fire", "fire", 95, 100], +"pinsir": ["bug", "bug", 125, 55], +"tauros": ["normal", "normal", 100, 40], +"magikarp": ["water", "water", 10, 15], +"gyarados": ["water", "flying", 125, 60], +"lapras": ["water", "ice", 85, 85], +"ditto": ["normal", "normal", 48, 48], +"eevee": ["normal", "normal", 55, 45], +"vaporeon": ["water", "water", 65, 110], +"jolteon": ["electric", "electric", 65, 110], +"flareon": ["fire", "fire", 130, 95], +"porygon": ["normal", "normal", 60, 85], +"omanyte": ["rock", "water", 40, 90], +"omastar": ["rock", "water", 60, 115], +"kabuto": ["rock", "water", 80, 55], +"kabutops": ["rock", "water", 115, 65], +"aerodactyl": ["rock", "flying", 105, 60], +"snorlax": ["normal", "normal", 110, 65], +"articuno": ["ice", "flying", 85, 95], +"zapdos": ["electric", "flying", 90, 125], +"moltres": ["fire", "flying", 100, 125], +"dratini": ["dragon", "dragon", 64, 50], +"dragonair": ["dragon", "dragon", 84, 70], +"dragonite": ["dragon", "flying", 134, 100], +"mewtwo": ["psychic", "psychic", 110, 154], +"mew": ["psychic", "psychic", 100, 100], +"chikorita": ["grass", "grass", 49, 49], +"bayleef": ["grass", "grass", 62, 63], +"meganium": ["grass", "grass", 82, 83], +"cyndaquil": ["fire", "fire", 52, 60], +"quilava": ["fire", "fire", 64, 80], +"typhlosion": ["fire", "fire", 84, 109], +"totodile": ["water", "water", 65, 44], +"croconaw": ["water", "water", 80, 59], +"feraligatr": ["water", "water", 105, 79], +"sentret": ["normal", "normal", 46, 35], +"furret": ["normal", "normal", 76, 45], +"hoothoot": ["normal", "flying", 30, 36], +"noctowl": ["normal", "flying", 50, 76], +"ledyba": ["bug", "flying", 20, 40], +"ledian": ["bug", "flying", 35, 55], +"spinarak": ["bug", "poison", 60, 40], +"ariados": ["bug", "poison", 90, 60], +"crobat": ["poison", "flying", 90, 70], +"chinchou": ["water", "electric", 38, 56], +"lanturn": ["water", "electric", 58, 76], +"pichu": ["electric", "electric", 40, 35], +"cleffa": ["normal", "normal", 25, 45], +"igglybuff": ["normal", "normal", 30, 40], +"togepi": ["normal", "normal", 20, 40], +"togetic": ["normal", "flying", 40, 80], +"natu": ["psychic", "flying", 50, 70], +"xatu": ["psychic", "flying", 75, 95], +"mareep": ["electric", "electric", 40, 65], +"flaaffy": ["electric", "electric", 55, 80], +"ampharos": ["electric", "electric", 75, 115], +"bellossom": ["grass", "grass", 80, 90], +"marill": ["water", "water", 20, 20], +"azumarill": ["water", "water", 50, 50], +"sudowoodo": ["rock", "rock", 100, 30], +"politoed": ["water", "water", 75, 90], +"hoppip": ["grass", "flying", 35, 35], +"skiploom": ["grass", "flying", 45, 45], +"jumpluff": ["grass", "flying", 55, 55], +"aipom": ["normal", "normal", 70, 40], +"sunkern": ["grass", "grass", 30, 30], +"sunflora": ["grass", "grass", 75, 105], +"yanma": ["bug", "flying", 65, 75], +"wooper": ["water", "ground", 45, 25], +"quagsire": ["water", "ground", 85, 65], +"espeon": ["psychic", "psychic", 65, 130], +"umbreon": ["dark", "dark", 65, 60], +"murkrow": ["dark", "flying", 85, 85], +"slowking": ["water", "psychic", 75, 100], +"misdreavus": ["ghost", "ghost", 60, 85], +"unown": ["psychic", "psychic", 72, 72], +"wobbuffet": ["psychic", "psychic", 33, 33], +"girafarig": ["normal", "psychic", 80, 90], +"pineco": ["bug", "bug", 65, 35], +"forretress": ["bug", "steel", 90, 60], +"dunsparce": ["normal", "normal", 70, 65], +"gligar": ["ground", "flying", 75, 35], +"steelix": ["steel", "ground", 85, 55], +"snubbull": ["normal", "normal", 80, 40], +"granbull": ["normal", "normal", 120, 60], +"qwilfish": ["water", "poison", 95, 55], +"scizor": ["bug", "steel", 130, 55], +"shuckle": ["bug", "rock", 10, 10], +"heracross": ["bug", "fighting", 125, 40], +"sneasel": ["dark", "ice", 95, 35], +"teddiursa": ["normal", "normal", 80, 50], +"ursaring": ["normal", "normal", 130, 75], +"slugma": ["fire", "fire", 40, 70], +"magcargo": ["fire", "rock", 50, 80], +"swinub": ["ice", "ground", 50, 30], +"piloswine": ["ice", "ground", 100, 60], +"corsola": ["water", "rock", 55, 65], +"remoraid": ["water", "water", 65, 65], +"octillery": ["water", "water", 105, 105], +"delibird": ["ice", "flying", 55, 65], +"mantine": ["water", "flying", 40, 80], +"skarmory": ["steel", "flying", 80, 40], +"houndour": ["dark", "fire", 60, 80], +"houndoom": ["dark", "fire", 90, 110], +"kingdra": ["water", "dragon", 95, 95], +"phanpy": ["ground", "ground", 60, 40], +"donphan": ["ground", "ground", 120, 60], +"porygon2": ["normal", "normal", 80, 105], +"stantler": ["normal", "normal", 95, 85], +"smeargle": ["normal", "normal", 20, 20], +"tyrogue": ["fighting", "fighting", 35, 35], +"hitmontop": ["fighting", "fighting", 95, 35], +"smoochum": ["ice", "psychic", 30, 85], +"elekid": ["electric", "electric", 63, 65], +"magby": ["fire", "fire", 75, 70], +"miltank": ["normal", "normal", 80, 40], +"blissey": ["normal", "normal", 10, 75], +"raikou": ["electric", "electric", 85, 115], +"entei": ["fire", "fire", 115, 90], +"suicune": ["water", "water", 75, 90], +"larvitar": ["rock", "ground", 64, 45], +"pupitar": ["rock", "ground", 84, 65], +"tyranitar": ["rock", "dark", 134, 95], +"lugia": ["psychic", "flying", 90, 90], +"ho-oh": ["fire", "flying", 130, 110], +"celebi": ["psychic", "grass", 100, 100], +"treecko": ["grass", "grass", 45, 65], +"grovyle": ["grass", "grass", 65, 85], +"sceptile": ["grass", "grass", 85, 105], +"torchic": ["fire", "fire", 60, 70], +"combusken": ["fire", "fighting", 85, 85], +"blaziken": ["fire", "fighting", 120, 110], +"mudkip": ["water", "water", 70, 50], +"marshtomp": ["water", "ground", 85, 60], +"swampert": ["water", "ground", 110, 85], +"poochyena": ["dark", "dark", 55, 30], +"mightyena": ["dark", "dark", 90, 60], +"zigzagoon": ["normal", "normal", 30, 30], +"linoone": ["normal", "normal", 70, 50], +"wurmple": ["bug", "bug", 45, 20], +"silcoon": ["bug", "bug", 35, 25], +"beautifly": ["bug", "flying", 70, 90], +"cascoon": ["bug", "bug", 35, 25], +"dustox": ["bug", "poison", 50, 50], +"lotad": ["water", "grass", 30, 40], +"lombre": ["water", "grass", 50, 60], +"ludicolo": ["water", "grass", 70, 90], +"seedot": ["grass", "grass", 40, 30], +"nuzleaf": ["grass", "dark", 70, 60], +"shiftry": ["grass", "dark", 100, 90], +"nincada": ["bug", "ground", 45, 30], +"ninjask": ["bug", "flying", 90, 50], +"shedinja": ["bug", "ghost", 90, 30], +"taillow": ["normal", "flying", 55, 30], +"swellow": ["normal", "flying", 85, 50], +"shroomish": ["grass", "grass", 40, 40], +"breloom": ["grass", "fighting", 130, 60], +"spinda": ["normal", "normal", 60, 60], +"wingull": ["water", "flying", 30, 55], +"pelipper": ["water", "flying", 50, 85], +"surskit": ["bug", "water", 30, 50], +"masquerain": ["bug", "flying", 60, 80], +"wailmer": ["water", "water", 70, 70], +"wailord": ["water", "water", 90, 90], +"skitty": ["normal", "normal", 45, 35], +"delcatty": ["normal", "normal", 65, 55], +"kecleon": ["normal", "normal", 90, 60], +"baltoy": ["ground", "psychic", 40, 40], +"claydol": ["ground", "psychic", 70, 70], +"nosepass": ["rock", "rock", 45, 45], +"torkoal": ["fire", "fire", 85, 85], +"sableye": ["dark", "ghost", 75, 65], +"barboach": ["water", "ground", 48, 46], +"whiscash": ["water", "ground", 78, 76], +"luvdisc": ["water", "water", 30, 40], +"corphish": ["water", "water", 80, 50], +"crawdaunt": ["water", "dark", 120, 90], +"feebas": ["water", "water", 15, 10], +"milotic": ["water", "water", 60, 100], +"carvanha": ["water", "dark", 90, 65], +"sharpedo": ["water", "dark", 120, 95], +"trapinch": ["ground", "ground", 100, 45], +"vibrava": ["ground", "dragon", 70, 50], +"flygon": ["ground", "dragon", 100, 80], +"makuhita": ["fighting", "fighting", 60, 20], +"hariyama": ["fighting", "fighting", 120, 40], +"electrike": ["electric", "electric", 45, 65], +"manectric": ["electric", "electric", 75, 105], +"numel": ["fire", "ground", 60, 65], +"camerupt": ["fire", "ground", 100, 105], +"spheal": ["ice", "water", 40, 55], +"sealeo": ["ice", "water", 60, 75], +"walrein": ["ice", "water", 80, 95], +"cacnea": ["grass", "grass", 85, 85], +"cacturne": ["grass", "dark", 115, 115], +"snorunt": ["ice", "ice", 50, 50], +"glalie": ["ice", "ice", 80, 80], +"lunatone": ["rock", "psychic", 55, 95], +"solrock": ["rock", "psychic", 95, 55], +"azurill": ["normal", "normal", 20, 20], +"spoink": ["psychic", "psychic", 25, 70], +"grumpig": ["psychic", "psychic", 45, 90], +"plusle": ["electric", "electric", 50, 85], +"minun": ["electric", "electric", 40, 75], +"mawile": ["steel", "steel", 85, 55], +"meditite": ["fighting", "psychic", 40, 40], +"medicham": ["fighting", "psychic", 60, 60], +"swablu": ["normal", "flying", 40, 40], +"altaria": ["dragon", "flying", 70, 70], +"wynaut": ["psychic", "psychic", 23, 23], +"duskull": ["ghost", "ghost", 40, 30], +"dusclops": ["ghost", "ghost", 70, 60], +"roselia": ["grass", "poison", 60, 100], +"slakoth": ["normal", "normal", 60, 35], +"vigoroth": ["normal", "normal", 80, 55], +"slaking": ["normal", "normal", 160, 95], +"gulpin": ["poison", "poison", 43, 43], +"swalot": ["poison", "poison", 73, 73], +"tropius": ["grass", "flying", 68, 72], +"whismur": ["normal", "normal", 51, 51], +"loudred": ["normal", "normal", 71, 71], +"exploud": ["normal", "normal", 91, 91], +"clamperl": ["water", "water", 64, 74], +"huntail": ["water", "water", 104, 94], +"gorebyss": ["water", "water", 84, 114], +"absol": ["dark", "dark", 130, 75], +"shuppet": ["ghost", "ghost", 75, 63], +"banette": ["ghost", "ghost", 115, 83], +"seviper": ["poison", "poison", 100, 100], +"zangoose": ["normal", "normal", 115, 60], +"relicanth": ["water", "rock", 90, 45], +"aron": ["steel", "rock", 70, 40], +"lairon": ["steel", "rock", 90, 50], +"aggron": ["steel", "rock", 110, 60], +"castform": ["normal", "normal", 70, 70], +"volbeat": ["bug", "bug", 73, 47], +"illumise": ["bug", "bug", 47, 73], +"lileep": ["rock", "grass", 41, 61], +"cradily": ["rock", "grass", 81, 81], +"anorith": ["rock", "bug", 95, 40], +"armaldo": ["rock", "bug", 125, 70], +"ralts": ["psychic", "psychic", 25, 45], +"kirlia": ["psychic", "psychic", 35, 65], +"gardevoir": ["psychic", "psychic", 65, 125], +"bagon": ["dragon", "dragon", 75, 40], +"shelgon": ["dragon", "dragon", 95, 60], +"salamence": ["dragon", "flying", 135, 110], +"beldum": ["steel", "psychic", 55, 35], +"metang": ["steel", "psychic", 75, 55], +"metagross": ["steel", "psychic", 135, 95], +"regirock": ["rock", "rock", 100, 50], +"regice": ["ice", "ice", 50, 100], +"registeel": ["steel", "steel", 75, 75], +"kyogre": ["water", "water", 100, 150], +"groudon": ["ground", "ground", 150, 100], +"rayquaza": ["dragon", "flying", 150, 150], +"latias": ["dragon", "psychic", 80, 110], +"latios": ["dragon", "psychic", 90, 130], +"jirachi": ["steel", "psychic", 100, 100], +"deoxys": ["psychic", "psychic", 150, 150], +"chimecho": ["psychic", "psychic", 50, 95] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json new file mode 100644 index 0000000000..82880e1d31 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json @@ -0,0 +1,641 @@ +{ +"TRAINER_YOUNGSTER_BEN": [["rattata", 11], ["ekans", 11]], +"TRAINER_YOUNGSTER_CALVIN": [["spearow", 14]], +"TRAINER_YOUNGSTER_JOSH": [["rattata", 10], ["rattata", 10], ["zubat", 10]], +"TRAINER_YOUNGSTER_TIMMY": [["sandshrew", 14], ["ekans", 14]], +"TRAINER_YOUNGSTER_JOEY": [["rattata", 15], ["spearow", 15]], +"TRAINER_YOUNGSTER_DAN": [["slowpoke", 17]], +"TRAINER_YOUNGSTER_CHAD": [["ekans", 14], ["sandshrew", 14]], +"TRAINER_YOUNGSTER_TYLER": [["nidoran-m", 21]], +"TRAINER_YOUNGSTER_EDDIE": [["ekans", 21]], +"TRAINER_YOUNGSTER_DILLON": [["sandshrew", 19], ["zubat", 19]], +"TRAINER_YOUNGSTER_YASU": [["rattata", 17], ["rattata", 17], ["raticate", 17]], +"TRAINER_YOUNGSTER_DAVE": [["nidoran-m", 18], ["nidorino", 18]], +"TRAINER_YOUNGSTER_BEN_2": [["rattata", 17], ["ekans", 17]], +"TRAINER_BUG_CATCHER_RICK": [["weedle", 6], ["caterpie", 6]], +"TRAINER_BUG_CATCHER_DOUG": [["weedle", 7], ["kakuna", 7], ["weedle", 7]], +"TRAINER_BUG_CATCHER_SAMMY": [["weedle", 9]], +"TRAINER_BUG_CATCHER_COLTON": [["caterpie", 10], ["weedle", 10], ["caterpie", 10]], +"TRAINER_BUG_CATCHER_GREG": [["weedle", 9], ["kakuna", 9], ["caterpie", 9], ["metapod", 9]], +"TRAINER_BUG_CATCHER_JAMES": [["caterpie", 11], ["metapod", 11]], +"TRAINER_BUG_CATCHER_KENT": [["weedle", 11], ["kakuna", 11]], +"TRAINER_BUG_CATCHER_ROBBY": [["caterpie", 10], ["metapod", 10], ["caterpie", 10]], +"TRAINER_BUG_CATCHER_CALE": [["caterpie", 10], ["weedle", 10], ["metapod", 10], ["kakuna", 10]], +"TRAINER_BUG_CATCHER_KEIGO": [["weedle", 16], ["caterpie", 16], ["weedle", 16]], +"TRAINER_BUG_CATCHER_ELIJAH": [["butterfree", 20]], +"TRAINER_BUG_CATCHER_2": [["metapod", 18], ["caterpie", 18], ["venonat", 18]], +"TRAINER_BUG_CATCHER_BRENT": [["beedrill", 19], ["beedrill", 19]], +"TRAINER_BUG_CATCHER_CONNER": [["caterpie", 20], ["weedle", 20], ["venonat", 20]], +"TRAINER_LASS_JANICE": [["pidgey", 9], ["pidgey", 9]], +"TRAINER_LASS_SALLY": [["rattata", 10], ["nidoran-f", 10]], +"TRAINER_LASS_ROBIN": [["jigglypuff", 14]], +"TRAINER_LASS_CRISSY": [["paras", 31], ["paras", 31], ["parasect", 31]], +"TRAINER_LASS_MIRIAM": [["oddish", 11], ["bellsprout", 11]], +"TRAINER_LASS_IRIS": [["clefairy", 14]], +"TRAINER_LASS_RELI": [["nidoran-m", 16], ["nidoran-f", 16]], +"TRAINER_LASS_ALI": [["pidgey", 12], ["oddish", 12], ["bellsprout", 12]], +"TRAINER_LASS_2": [["nidoran-m", 15], ["nidoran-f", 15]], +"TRAINER_LASS_HALEY": [["oddish", 13], ["pidgey", 13], ["oddish", 13]], +"TRAINER_LASS_ANN": [["pidgey", 18], ["nidoran-f", 18]], +"TRAINER_LASS_DAWN": [["rattata", 18], ["pikachu", 18]], +"TRAINER_LASS_PAIGE": [["nidoran-f", 23], ["nidorina", 23]], +"TRAINER_LASS_ANDREA": [["meowth", 24], ["meowth", 24], ["meowth", 24]], +"TRAINER_LASS_MEGAN": [["pidgey", 19], ["rattata", 19], ["nidoran-m", 19], ["meowth", 19], ["pikachu", 19]], +"TRAINER_LASS_JULIA": [["clefairy", 22], ["clefairy", 22]], +"TRAINER_LASS_KAY": [["bellsprout", 23], ["weepinbell", 23]], +"TRAINER_LASS_LISA": [["oddish", 23], ["gloom", 23]], +"TRAINER_SAILOR_EDMOND": [["machop", 18], ["shellder", 18]], +"TRAINER_SAILOR_TREVOR": [["machop", 17], ["tentacool", 17]], +"TRAINER_SAILOR_LEONARD": [["shellder", 21]], +"TRAINER_SAILOR_DUNCAN": [["horsea", 17], ["shellder", 17], ["tentacool", 17]], +"TRAINER_SAILOR_HUEY": [["tentacool", 18], ["staryu", 18]], +"TRAINER_SAILOR_DYLAN": [["horsea", 17], ["horsea", 17], ["horsea", 17]], +"TRAINER_SAILOR_PHILLIP": [["machop", 20]], +"TRAINER_SAILOR_DWAYNE": [["pikachu", 21], ["pikachu", 21]], +"TRAINER_CAMPER_LIAM": [["geodude", 10, ["tackle", "defense-curl"]], ["sandshrew", 11, ["scratch", "defense-curl", "sand-attack"]]], +"TRAINER_CAMPER_SHANE": [["rattata", 14], ["ekans", 14]], +"TRAINER_CAMPER_ETHAN": [["mankey", 18]], +"TRAINER_CAMPER_RICKY": [["squirtle", 20]], +"TRAINER_CAMPER_JEFF": [["spearow", 16], ["raticate", 16]], +"TRAINER_CAMPER_CHRIS": [["growlithe", 21], ["charmander", 21]], +"TRAINER_CAMPER_DREW": [["rattata", 19], ["sandshrew", 19], ["ekans", 19], ["sandshrew", 19]], +"TRAINER_PICNICKER_DIANA": [["goldeen", 19]], +"TRAINER_PICNICKER_NANCY": [["rattata", 16], ["pikachu", 16]], +"TRAINER_PICNICKER_ISABELLE": [["pidgey", 16], ["pidgey", 16], ["pidgey", 16]], +"TRAINER_PICNICKER_KELSEY": [["nidoran-m", 15], ["nidoran-f", 15]], +"TRAINER_PICNICKER_ALICIA": [["oddish", 18], ["bellsprout", 18], ["oddish", 18], ["bellsprout", 18]], +"TRAINER_PICNICKER_CAITLIN": [["meowth", 23]], +"TRAINER_PICNICKER_HEIDI": [["pikachu", 20], ["clefairy", 20]], +"TRAINER_PICNICKER_CAROL": [["pidgey", 21], ["pidgeotto", 21]], +"TRAINER_PICNICKER_SOFIA": [["jigglypuff", 21], ["pidgey", 21], ["meowth", 21]], +"TRAINER_PICNICKER_MARTHA": [["oddish", 22], ["bulbasaur", 22]], +"TRAINER_PICNICKER_TINA": [["bulbasaur", 24], ["ivysaur", 24]], +"TRAINER_PICNICKER_HANNAH": [["pidgey", 24], ["meowth", 24], ["rattata", 24], ["pikachu", 24], ["meowth", 24]], +"TRAINER_POKEMANIAC_MARK": [["rhyhorn", 29], ["lickitung", 29]], +"TRAINER_POKEMANIAC_HERMAN": [["cubone", 20], ["slowpoke", 20]], +"TRAINER_POKEMANIAC_COOPER": [["slowpoke", 20], ["slowpoke", 20], ["slowpoke", 20]], +"TRAINER_POKEMANIAC_STEVE": [["charmander", 22], ["cubone", 22]], +"TRAINER_POKEMANIAC_WINSTON": [["slowpoke", 25]], +"TRAINER_POKEMANIAC_DAWSON": [["charmeleon", 40], ["lapras", 40], ["lickitung", 40]], +"TRAINER_POKEMANIAC_ASHTON": [["cubone", 23], ["slowpoke", 23]], +"TRAINER_SUPER_NERD_JOVAN": [["magnemite", 11], ["voltorb", 11]], +"TRAINER_SUPER_NERD_MIGUEL": [["grimer", 12], ["voltorb", 12], ["koffing", 12]], +"TRAINER_SUPER_NERD_AIDAN": [["voltorb", 20, ["sonic-boom", "screech", "tackle", "charge"]], ["koffing", 20, ["sludge", "smog", "tackle", "poison-gas"]], ["voltorb", 20, ["sonic-boom", "screech", "tackle", "charge"]], ["magnemite", 20, ["sonic-boom", "supersonic", "thunder-shock", "tackle"]]], +"TRAINER_SUPER_NERD_GLENN": [["grimer", 22], ["muk", 22], ["grimer", 22]], +"TRAINER_SUPER_NERD_LESLIE": [["koffing", 26, ["sludge", "smokescreen", "smog", "self-destruct"]]], +"TRAINER_SUPER_NERD_1": [["koffing", 22], ["magnemite", 22], ["weezing", 22]], +"TRAINER_SUPER_NERD_2": [["magnemite", 20], ["magnemite", 20], ["koffing", 20], ["magnemite", 20]], +"TRAINER_SUPER_NERD_3": [["magnemite", 24], ["voltorb", 24]], +"TRAINER_SUPER_NERD_ERIK": [["vulpix", 36], ["vulpix", 36], ["ninetales", 36]], +"TRAINER_SUPER_NERD_AVERY": [["ponyta", 34], ["charmander", 34], ["vulpix", 34], ["growlithe", 34]], +"TRAINER_SUPER_NERD_DEREK": [["rapidash", 41]], +"TRAINER_SUPER_NERD_ZAC": [["growlithe", 37], ["vulpix", 37]], +"TRAINER_HIKER_MARCOS": [["geodude", 10], ["geodude", 10], ["onix", 10]], +"TRAINER_HIKER_FRANKLIN": [["machop", 15], ["geodude", 15]], +"TRAINER_HIKER_NOB": [["geodude", 13], ["geodude", 13], ["machop", 13], ["geodude", 13]], +"TRAINER_HIKER_WAYNE": [["onix", 17]], +"TRAINER_HIKER_ALAN": [["geodude", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["onix", 21, ["harden", "rock-throw", "bind", "screech"]]], +"TRAINER_HIKER_BRICE": [["geodude", 20], ["machop", 20], ["geodude", 20]], +"TRAINER_HIKER_CLARK": [["geodude", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["onix", 21, ["harden", "rock-throw", "bind", "screech"]]], +"TRAINER_HIKER_TRENT": [["onix", 19], ["graveler", 19]], +"TRAINER_HIKER_DUDLEY": [["geodude", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["geodude", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["graveler", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]], +"TRAINER_HIKER_ALLEN": [["geodude", 25, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]], +"TRAINER_HIKER_ERIC": [["machop", 20], ["onix", 20]], +"TRAINER_HIKER_LENNY": [["geodude", 19], ["machop", 19], ["geodude", 19], ["geodude", 19]], +"TRAINER_HIKER_OLIVER": [["onix", 20], ["onix", 20], ["geodude", 20]], +"TRAINER_HIKER_LUCAS": [["geodude", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["graveler", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]], +"TRAINER_BIKER_JARED": [["koffing", 28, ["smokescreen", "sludge", "smog", "poison-gas"]], ["koffing", 28, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, ["smokescreen", "sludge", "smog", "tackle"]]], +"TRAINER_BIKER_MALIK": [["koffing", 29, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 29, ["screech", "minimize", "sludge", "disable"]]], +"TRAINER_BIKER_ERNEST": [["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 25, ["minimize", "sludge", "disable", "pound"]]], +"TRAINER_BIKER_ALEX": [["koffing", 28, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 28, ["screech", "minimize", "sludge", "disable"]], ["weezing", 28, ["smokescreen", "sludge", "smog", "tackle"]]], +"TRAINER_BIKER_LAO": [["grimer", 29, ["screech", "minimize", "sludge", "disable"]], ["koffing", 29, ["smokescreen", "sludge", "smog", "tackle"]]], +"TRAINER_BIKER_HIDEO": [["weezing", 33]], +"TRAINER_BIKER_RUBEN": [["weezing", 28, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 28, ["smokescreen", "sludge", "smog", "tackle"]]], +"TRAINER_BIKER_BILLY": [["muk", 33]], +"TRAINER_BIKER_NIKOLAS": [["voltorb", 29, ["spark", "sonic-boom", "screech", "charge"]], ["voltorb", 29, ["spark", "sonic-boom", "screech", "charge"]]], +"TRAINER_BIKER_JAXON": [["weezing", 29, ["sludge", "smokescreen", "smog", "tackle"]], ["muk", 29, ["screech", "minimize", "sludge", "disable"]]], +"TRAINER_BIKER_WILLIAM": [["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, ["smokescreen", "sludge", "self-destruct", "tackle"]]], +"TRAINER_BIKER_LUKAS": [["koffing", 26, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 26, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 26, ["screech", "minimize", "sludge", "disable"]], ["koffing", 26, ["smokescreen", "sludge", "smog", "tackle"]]], +"TRAINER_BIKER_ISAAC": [["grimer", 28, ["screech", "minimize", "sludge", "disable"]], ["grimer", 28, ["screech", "minimize", "sludge", "disable"]], ["koffing", 28, ["smokescreen", "sludge", "smog", "tackle"]]], +"TRAINER_BIKER_GERALD": [["koffing", 29, ["smokescreen", "sludge", "smog", "tackle"]], ["muk", 29, ["screech", "minimize", "sludge", "disable"]]], +"TRAINER_BURGLAR_1": [["growlithe", 29], ["vulpix", 29]], +"TRAINER_BURGLAR_2": [["growlithe", 33]], +"TRAINER_BURGLAR_3": [["vulpix", 28], ["charmander", 28], ["ponyta", 28]], +"TRAINER_BURGLAR_QUINN": [["growlithe", 36], ["vulpix", 36], ["ninetales", 36]], +"TRAINER_BURGLAR_RAMON": [["ponyta", 41]], +"TRAINER_BURGLAR_DUSTY": [["vulpix", 37], ["growlithe", 37]], +"TRAINER_BURGLAR_ARNIE": [["charmander", 34], ["charmeleon", 34]], +"TRAINER_BURGLAR_4": [["charmander", 34], ["charmeleon", 34]], +"TRAINER_BURGLAR_SIMON": [["ninetales", 38]], +"TRAINER_BURGLAR_LEWIS": [["growlithe", 34], ["ponyta", 34]], +"TRAINER_ENGINEER_BAILY": [["voltorb", 21], ["magnemite", 21]], +"TRAINER_ENGINEER_BRAXTON": [["magnemite", 21]], +"TRAINER_ENGINEER_BERNIE": [["magnemite", 18], ["magnemite", 18], ["magneton", 18]], +"TRAINER_FISHERMAN_DALE": [["goldeen", 17], ["tentacool", 17], ["goldeen", 17]], +"TRAINER_FISHERMAN_BARNY": [["tentacool", 17], ["staryu", 17], ["shellder", 17]], +"TRAINER_FISHERMAN_NED": [["goldeen", 22], ["poliwag", 22], ["goldeen", 22]], +"TRAINER_FISHERMAN_CHIP": [["tentacool", 24], ["goldeen", 24]], +"TRAINER_FISHERMAN_HANK": [["goldeen", 27]], +"TRAINER_FISHERMAN_ELLIOT": [["poliwag", 21], ["shellder", 21], ["goldeen", 21], ["horsea", 21]], +"TRAINER_FISHERMAN_RONALD": [["seaking", 28], ["goldeen", 28], ["seaking", 28], ["seaking", 28]], +"TRAINER_FISHERMAN_CLAUDE": [["shellder", 31], ["cloyster", 31]], +"TRAINER_FISHERMAN_WADE": [["magikarp", 27], ["magikarp", 27], ["magikarp", 27], ["magikarp", 27], ["magikarp", 27], ["magikarp", 27]], +"TRAINER_FISHERMAN_NOLAN": [["seaking", 33], ["goldeen", 33]], +"TRAINER_FISHERMAN_ANDREW": [["magikarp", 24], ["magikarp", 24]], +"TRAINER_SWIMMER_MALE_LUIS": [["horsea", 16], ["shellder", 16]], +"TRAINER_SWIMMER_MALE_RICHARD": [["tentacool", 30], ["shellder", 30]], +"TRAINER_SWIMMER_MALE_REECE": [["goldeen", 29], ["horsea", 29], ["staryu", 29]], +"TRAINER_SWIMMER_MALE_MATTHEW": [["poliwag", 30], ["poliwhirl", 30]], +"TRAINER_SWIMMER_MALE_DOUGLAS": [["horsea", 27], ["tentacool", 27], ["tentacool", 27], ["goldeen", 27]], +"TRAINER_SWIMMER_MALE_DAVID": [["goldeen", 29], ["shellder", 29], ["seaking", 29]], +"TRAINER_SWIMMER_MALE_TONY": [["horsea", 30], ["horsea", 30]], +"TRAINER_SWIMMER_MALE_AXLE": [["tentacool", 27], ["tentacool", 27], ["staryu", 27], ["horsea", 27], ["tentacruel", 27]], +"TRAINER_SWIMMER_MALE_BARRY": [["shellder", 31], ["cloyster", 31]], +"TRAINER_SWIMMER_MALE_DEAN": [["staryu", 35]], +"TRAINER_SWIMMER_MALE_DARRIN": [["horsea", 28], ["horsea", 28], ["seadra", 28], ["horsea", 28]], +"TRAINER_SWIMMER_MALE_SPENCER": [["seadra", 33], ["tentacruel", 33]], +"TRAINER_SWIMMER_MALE_JACK": [["starmie", 37]], +"TRAINER_SWIMMER_MALE_JEROME": [["staryu", 33], ["wartortle", 33]], +"TRAINER_SWIMMER_MALE_ROLAND": [["poliwhirl", 32], ["tentacool", 32], ["seadra", 32]], +"TRAINER_CUE_BALL_KOJI": [["machop", 28], ["mankey", 28], ["machop", 28]], +"TRAINER_CUE_BALL_LUKE": [["mankey", 29], ["machop", 29]], +"TRAINER_CUE_BALL_CAMRON": [["mankey", 29], ["machop", 29]], +"TRAINER_CUE_BALL_RAUL": [["mankey", 29], ["primeape", 29]], +"TRAINER_CUE_BALL_ISAIAH": [["machop", 29], ["machamp", 29]], +"TRAINER_CUE_BALL_ZEEK": [["machoke", 33]], +"TRAINER_CUE_BALL_JAMAL": [["mankey", 26], ["mankey", 26], ["machamp", 26], ["machop", 26]], +"TRAINER_CUE_BALL_COREY": [["primeape", 29], ["machoke", 29]], +"TRAINER_CUE_BALL_CHASE": [["tentacool", 31], ["tentacool", 31], ["tentacruel", 31]], +"TRAINER_GAMER_HUGO": [["poliwag", 18], ["horsea", 18]], +"TRAINER_GAMER_JASPER": [["bellsprout", 18], ["oddish", 18]], +"TRAINER_GAMER_DIRK": [["voltorb", 18], ["magnemite", 18]], +"TRAINER_GAMER_DARIAN": [["growlithe", 18], ["vulpix", 18]], +"TRAINER_GAMER_STAN": [["poliwag", 22], ["poliwag", 22], ["poliwhirl", 22]], +"TRAINER_GAMER_RICH": [["growlithe", 24], ["vulpix", 24]], +"TRAINER_BEAUTY_BRIDGET": [["oddish", 21], ["bellsprout", 21], ["oddish", 21], ["bellsprout", 21]], +"TRAINER_BEAUTY_TAMIA": [["bellsprout", 24], ["bellsprout", 24]], +"TRAINER_BEAUTY_LORI": [["exeggcute", 24]], +"TRAINER_BEAUTY_LOLA": [["rattata", 27], ["pikachu", 27], ["rattata", 27]], +"TRAINER_BEAUTY_SHEILA": [["clefairy", 29], ["meowth", 29]], +"TRAINER_SWIMMER_FEMALE_TIFFANY": [["seaking", 35]], +"TRAINER_SWIMMER_FEMALE_NORA": [["shellder", 30], ["shellder", 30], ["cloyster", 30]], +"TRAINER_SWIMMER_FEMALE_MELISSA": [["poliwag", 31], ["seaking", 31]], +"TRAINER_BEAUTY_GRACE": [["pidgeotto", 29], ["wigglytuff", 29]], +"TRAINER_BEAUTY_OLIVIA": [["bulbasaur", 29], ["ivysaur", 29]], +"TRAINER_BEAUTY_LAUREN": [["weepinbell", 33], ["bellsprout", 33], ["weepinbell", 33]], +"TRAINER_SWIMMER_FEMALE_ANYA": [["poliwag", 27], ["goldeen", 27], ["seaking", 27], ["goldeen", 27], ["poliwag", 27]], +"TRAINER_SWIMMER_FEMALE_ALICE": [["goldeen", 30], ["seaking", 30]], +"TRAINER_SWIMMER_FEMALE_CONNIE": [["staryu", 29], ["staryu", 29], ["staryu", 29]], +"TRAINER_SWIMMER_FEMALE_SHIRLEY": [["seadra", 30], ["horsea", 30], ["seadra", 30]], +"TRAINER_PSYCHIC_JOHAN": [["kadabra", 31], ["slowpoke", 31], ["mr-mime", 31], ["kadabra", 31]], +"TRAINER_PSYCHIC_TYRON": [["mr-mime", 34], ["kadabra", 34]], +"TRAINER_PSYCHIC_CAMERON": [["slowpoke", 33], ["slowpoke", 33], ["slowbro", 33]], +"TRAINER_PSYCHIC_PRESTON": [["slowbro", 38]], +"TRAINER_ROCKER_RANDALL": [["voltorb", 20], ["magnemite", 20], ["voltorb", 20]], +"TRAINER_ROCKER_LUCA": [["voltorb", 29], ["electrode", 29]], +"TRAINER_JUGGLER_DALTON": [["kadabra", 29], ["mr-mime", 29]], +"TRAINER_JUGGLER_NELSON": [["drowzee", 41], ["hypno", 41], ["kadabra", 41], ["kadabra", 41]], +"TRAINER_JUGGLER_KIRK": [["drowzee", 31], ["drowzee", 31], ["kadabra", 31], ["drowzee", 31]], +"TRAINER_JUGGLER_SHAWN": [["drowzee", 34], ["hypno", 34]], +"TRAINER_JUGGLER_GREGORY": [["mr-mime", 48, ["psychic", "role-play", "double-slap", "encore"]]], +"TRAINER_JUGGLER_EDWARD": [["voltorb", 46, ["swift", "light-screen", "spark", "sonic-boom"]], ["voltorb", 46, ["swift", "light-screen", "spark", "sonic-boom"]], ["electrode", 47, ["swift", "spark", "self-destruct", "sonic-boom"]], ["mr-mime", 48, ["psychic", "role-play", "reflect", "encore"]]], +"TRAINER_JUGGLER_KAYDEN": [["hypno", 38]], +"TRAINER_JUGGLER_NATE": [["drowzee", 34], ["kadabra", 34]], +"TRAINER_TAMER_PHIL": [["sandslash", 34], ["arbok", 34]], +"TRAINER_TAMER_EDGAR": [["arbok", 33], ["sandslash", 33], ["arbok", 33]], +"TRAINER_TAMER_JASON": [["rhyhorn", 43]], +"TRAINER_TAMER_COLE": [["arbok", 39], ["tauros", 39]], +"TRAINER_TAMER_VINCENT": [["persian", 44], ["golduck", 44]], +"TRAINER_TAMER_JOHN": [["rhyhorn", 42], ["primeape", 42], ["arbok", 42], ["tauros", 42]], +"TRAINER_BIRD_KEEPER_SEBASTIAN": [["pidgey", 29], ["pidgeotto", 29]], +"TRAINER_BIRD_KEEPER_PERRY": [["spearow", 25], ["pidgey", 25], ["pidgey", 25], ["spearow", 25], ["spearow", 25]], +"TRAINER_BIRD_KEEPER_ROBERT": [["pidgey", 26], ["pidgeotto", 26], ["spearow", 26], ["fearow", 26]], +"TRAINER_BIRD_KEEPER_DONALD": [["farfetch-d", 33]], +"TRAINER_BIRD_KEEPER_BENNY": [["spearow", 29], ["fearow", 29]], +"TRAINER_BIRD_KEEPER_EDWIN": [["pidgeotto", 26], ["farfetch-d", 26], ["doduo", 26], ["pidgey", 26]], +"TRAINER_BIRD_KEEPER_CHESTER": [["dodrio", 28], ["doduo", 28], ["doduo", 28]], +"TRAINER_BIRD_KEEPER_WILTON": [["spearow", 29], ["fearow", 29]], +"TRAINER_BIRD_KEEPER_RAMIRO": [["dodrio", 34]], +"TRAINER_BIRD_KEEPER_JACOB": [["spearow", 26], ["spearow", 26], ["fearow", 26], ["spearow", 26]], +"TRAINER_BIRD_KEEPER_ROGER": [["fearow", 30], ["fearow", 30], ["pidgeotto", 30]], +"TRAINER_BIRD_KEEPER_REED": [["pidgeotto", 39], ["pidgeotto", 39], ["pidgey", 39], ["pidgeotto", 39]], +"TRAINER_BIRD_KEEPER_KEITH": [["farfetch-d", 39], ["fearow", 39]], +"TRAINER_BIRD_KEEPER_CARTER": [["pidgey", 28], ["doduo", 28], ["pidgeotto", 28]], +"TRAINER_BIRD_KEEPER_MITCH": [["pidgey", 26], ["spearow", 26], ["pidgey", 26], ["fearow", 26]], +"TRAINER_BIRD_KEEPER_BECK": [["pidgeotto", 29], ["fearow", 29]], +"TRAINER_BIRD_KEEPER_MARLON": [["spearow", 28], ["doduo", 28], ["fearow", 28]], +"TRAINER_BLACK_BELT_KOICHI": [["hitmonlee", 37], ["hitmonchan", 37]], +"TRAINER_BLACK_BELT_MIKE": [["mankey", 31], ["mankey", 31], ["primeape", 31]], +"TRAINER_BLACK_BELT_HIDEKI": [["machop", 32], ["machoke", 32]], +"TRAINER_BLACK_BELT_AARON": [["primeape", 36]], +"TRAINER_BLACK_BELT_HITOSHI": [["machop", 31], ["mankey", 31], ["primeape", 31]], +"TRAINER_BLACK_BELT_ATSUSHI": [["machop", 40], ["machoke", 40]], +"TRAINER_BLACK_BELT_KIYO": [["machoke", 43]], +"TRAINER_BLACK_BELT_TAKASHI": [["machoke", 38], ["machop", 38], ["machoke", 38]], +"TRAINER_BLACK_BELT_DAISUKE": [["machoke", 43], ["machop", 43], ["machoke", 43]], +"TRAINER_RIVAL_OAKS_LAB_SQUIRTLE": [["squirtle", 5]], +"TRAINER_RIVAL_OAKS_LAB_BULBASAUR": [["bulbasaur", 5]], +"TRAINER_RIVAL_OAKS_LAB_CHARMANDER": [["charmander", 5]], +"TRAINER_RIVAL_ROUTE22_EARLY_SQUIRTLE": [["pidgey", 9, ["tackle", "sand-attack"]], ["squirtle", 9, ["tackle", "tail-whip"]]], +"TRAINER_RIVAL_ROUTE22_EARLY_BULBASAUR": [["pidgey", 9, ["tackle", "sand-attack"]], ["bulbasaur", 9, ["tackle", "growl"]]], +"TRAINER_RIVAL_ROUTE22_EARLY_CHARMANDER": [["pidgey", 9, ["tackle", "sand-attack"]], ["charmander", 9, ["scratch", "growl"]]], +"TRAINER_RIVAL_CERULEAN_SQUIRTLE": [["pidgeotto", 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, ["teleport"]], ["rattata", 15, ["tackle", "tail-whip", "quick-attack"]], ["squirtle", 18, ["tackle", "tail-whip", "withdraw", "water-gun"]]], +"TRAINER_RIVAL_CERULEAN_BULBASAUR": [["pidgeotto", 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, ["teleport"]], ["rattata", 15, ["tackle", "tail-whip", "quick-attack"]], ["bulbasaur", 18, ["sleep-powder", "poison-powder", "vine-whip", "leech-seed"]]], +"TRAINER_RIVAL_CERULEAN_CHARMANDER": [["pidgeotto", 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, ["teleport"]], ["rattata", 15, ["tackle", "tail-whip", "quick-attack"]], ["charmander", 18, ["metal-claw", "ember", "growl", "scratch"]]], +"TRAINER_SCIENTIST_TED": [["electrode", 29], ["weezing", 29]], +"TRAINER_SCIENTIST_CONNOR": [["grimer", 26, ["screech", "minimize", "sludge", "disable"]], ["weezing", 26, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 26, ["smokescreen", "sludge", "smog", "self-destruct"]], ["weezing", 26, ["smokescreen", "sludge", "smog", "tackle"]]], +"TRAINER_SCIENTIST_JERRY": [["magnemite", 28], ["voltorb", 28], ["magneton", 28]], +"TRAINER_SCIENTIST_JOSE": [["electrode", 29, ["spark", "sonic-boom", "screech", "tackle"]], ["weezing", 29, ["smokescreen", "sludge", "smog", "tackle"]]], +"TRAINER_SCIENTIST_RODNEY": [["electrode", 33]], +"TRAINER_SCIENTIST_BEAU": [["magneton", 26, ["spark", "thunder-wave", "sonic-boom", "supersonic"]], ["koffing", 26, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 26, ["smokescreen", "sludge", "smog", "tackle"]], ["magnemite", 26, ["spark", "thunder-wave", "sonic-boom", "supersonic"]]], +"TRAINER_SCIENTIST_TAYLOR": [["voltorb", 25, ["spark", "sonic-boom", "screech", "tackle"]], ["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["magneton", 25, ["thunder-wave", "sonic-boom", "supersonic", "thunder-shock"]], ["magnemite", 25, ["thunder-wave", "sonic-boom", "supersonic", "thunder-shock"]], ["koffing", 25, ["smokescreen", "sludge", "smog", "self-destruct"]]], +"TRAINER_SCIENTIST_JOSHUA": [["electrode", 29], ["muk", 29]], +"TRAINER_SCIENTIST_PARKER": [["grimer", 29], ["electrode", 29]], +"TRAINER_SCIENTIST_ED": [["voltorb", 28, ["spark", "sonic-boom", "screech", "tackle"]], ["koffing", 28, ["smokescreen", "sludge", "tackle", "smog"]], ["magneton", 28, ["spark", "thunder-wave", "sonic-boom", "supersonic"]]], +"TRAINER_SCIENTIST_TRAVIS": [["magnemite", 29], ["koffing", 29]], +"TRAINER_SCIENTIST_BRAYDON": [["magnemite", 33], ["magneton", 33], ["voltorb", 33]], +"TRAINER_SCIENTIST_IVAN": [["magnemite", 34], ["electrode", 34]], +"TRAINER_BOSS_GIOVANNI": [["onix", 25], ["rhyhorn", 24], ["kangaskhan", 29]], +"TRAINER_BOSS_GIOVANNI_2": [["nidorino", 37], ["kangaskhan", 35], ["rhyhorn", 37], ["nidoqueen", 41]], +"TRAINER_LEADER_GIOVANNI": [["rhyhorn", 45, ["take-down", "rock-blast", "scary-face", "earthquake"]], ["dugtrio", 42, ["slash", "sand-tomb", "mud-slap", "earthquake"]], ["nidoqueen", 44, ["body-slam", "double-kick", "poison-sting", "earthquake"]], ["nidoking", 45, ["thrash", "double-kick", "poison-sting", "earthquake"]], ["rhyhorn", 50, ["take-down", "rock-blast", "scary-face", "earthquake"]]], +"TRAINER_TEAM_ROCKET_GRUNT": [["rattata", 13], ["zubat", 13]], +"TRAINER_TEAM_ROCKET_GRUNT_2": [["sandshrew", 11], ["rattata", 11], ["zubat", 11]], +"TRAINER_TEAM_ROCKET_GRUNT_3": [["zubat", 11], ["ekans", 11]], +"TRAINER_TEAM_ROCKET_GRUNT_4": [["rattata", 13], ["sandshrew", 13]], +"TRAINER_TEAM_ROCKET_GRUNT_5": [["machop", 17], ["drowzee", 17]], +"TRAINER_TEAM_ROCKET_GRUNT_6": [["ekans", 15], ["zubat", 15]], +"TRAINER_TEAM_ROCKET_GRUNT_7": [["raticate", 20], ["zubat", 20]], +"TRAINER_TEAM_ROCKET_GRUNT_8": [["drowzee", 21], ["machop", 21]], +"TRAINER_TEAM_ROCKET_GRUNT_9": [["raticate", 21], ["raticate", 21]], +"TRAINER_TEAM_ROCKET_GRUNT_10": [["grimer", 20, ["minimize", "sludge", "disable", "harden"]], ["koffing", 20, ["smog", "tackle", "poison-gas"]], ["koffing", 20, ["smog", "tackle", "poison-gas"]]], +"TRAINER_TEAM_ROCKET_GRUNT_11": [["rattata", 19], ["raticate", 19], ["raticate", 19], ["rattata", 19]], +"TRAINER_TEAM_ROCKET_GRUNT_12": [["grimer", 22, ["minimize", "sludge", "disable", "harden"]], ["koffing", 22, ["sludge", "smog", "tackle", "poison-gas"]]], +"TRAINER_TEAM_ROCKET_GRUNT_13": [["zubat", 17, ["bite", "astonish", "supersonic", "leech-life"]], ["koffing", 17, ["smog", "tackle", "poison-gas"]], ["grimer", 17, ["sludge", "disable", "harden", "pound"]], ["zubat", 17, ["bite", "astonish", "supersonic", "leech-life"]], ["raticate", 17, ["hyper-fang", "quick-attack", "tail-whip", "tackle"]]], +"TRAINER_TEAM_ROCKET_GRUNT_14": [["rattata", 20], ["raticate", 20], ["drowzee", 20]], +"TRAINER_TEAM_ROCKET_GRUNT_15": [["machop", 21], ["machop", 21]], +"TRAINER_TEAM_ROCKET_GRUNT_16": [["sandshrew", 23], ["ekans", 23], ["sandslash", 23]], +"TRAINER_TEAM_ROCKET_GRUNT_17": [["ekans", 23], ["sandshrew", 23], ["arbok", 23]], +"TRAINER_TEAM_ROCKET_GRUNT_18": [["koffing", 21], ["zubat", 21]], +"TRAINER_TEAM_ROCKET_GRUNT_19": [["zubat", 25], ["zubat", 25], ["golbat", 25]], +"TRAINER_TEAM_ROCKET_GRUNT_20": [["koffing", 26], ["drowzee", 26]], +"TRAINER_TEAM_ROCKET_GRUNT_21": [["zubat", 23], ["rattata", 23], ["raticate", 23], ["zubat", 23]], +"TRAINER_TEAM_ROCKET_GRUNT_22": [["drowzee", 26], ["koffing", 26]], +"TRAINER_TEAM_ROCKET_GRUNT_23": [["cubone", 29], ["zubat", 29]], +"TRAINER_TEAM_ROCKET_GRUNT_24": [["golbat", 25], ["zubat", 25], ["zubat", 25], ["raticate", 25], ["zubat", 25]], +"TRAINER_TEAM_ROCKET_GRUNT_25": [["raticate", 28], ["hypno", 28], ["raticate", 28]], +"TRAINER_TEAM_ROCKET_GRUNT_26": [["machop", 29], ["drowzee", 29]], +"TRAINER_TEAM_ROCKET_GRUNT_27": [["ekans", 28], ["zubat", 28], ["cubone", 28]], +"TRAINER_TEAM_ROCKET_GRUNT_28": [["arbok", 33]], +"TRAINER_TEAM_ROCKET_GRUNT_29": [["hypno", 33]], +"TRAINER_TEAM_ROCKET_GRUNT_30": [["machop", 29], ["machoke", 29]], +"TRAINER_TEAM_ROCKET_GRUNT_31": [["zubat", 28], ["zubat", 28], ["golbat", 28]], +"TRAINER_TEAM_ROCKET_GRUNT_32": [["raticate", 26, ["scary-face", "hyper-fang", "quick-attack", "tail-whip"]], ["arbok", 26, ["glare", "bite", "poison-sting", "leer"]], ["koffing", 26, ["smokescreen", "sludge", "smog", "tackle"]], ["golbat", 26, ["wing-attack", "bite", "astonish", "supersonic"]]], +"TRAINER_TEAM_ROCKET_GRUNT_33": [["cubone", 29], ["cubone", 29]], +"TRAINER_TEAM_ROCKET_GRUNT_34": [["sandshrew", 29], ["sandslash", 29]], +"TRAINER_TEAM_ROCKET_GRUNT_35": [["raticate", 26], ["zubat", 26], ["golbat", 26], ["rattata", 26]], +"TRAINER_TEAM_ROCKET_GRUNT_36": [["weezing", 28], ["golbat", 28], ["koffing", 28]], +"TRAINER_TEAM_ROCKET_GRUNT_37": [["drowzee", 28], ["grimer", 28], ["machop", 28]], +"TRAINER_TEAM_ROCKET_GRUNT_38": [["golbat", 28], ["drowzee", 28], ["hypno", 28]], +"TRAINER_TEAM_ROCKET_GRUNT_39": [["machoke", 33]], +"TRAINER_TEAM_ROCKET_GRUNT_40": [["rattata", 25], ["rattata", 25], ["zubat", 25], ["rattata", 25], ["ekans", 25]], +"TRAINER_TEAM_ROCKET_GRUNT_41": [["cubone", 32], ["drowzee", 32], ["marowak", 32]], +"TRAINER_COOLTRAINER_SAMUEL": [["sandslash", 37, ["slash", "swift", "sand-attack", "poison-sting"]], ["sandslash", 37, ["slash", "swift", "sand-attack", "poison-sting"]], ["rhyhorn", 38, ["take-down", "rock-blast", "fury-attack", "scary-face"]], ["nidorino", 39, ["fury-attack", "horn-attack", "poison-sting", "double-kick"]], ["nidoking", 39, ["thrash", "double-kick", "poison-sting", "focus-energy"]]], +"TRAINER_COOLTRAINER_GEORGE": [["exeggutor", 42, ["egg-bomb", "confusion", "stun-spore", "sleep-powder"]], ["sandslash", 42, ["fury-swipes", "swift", "poison-sting", "sand-attack"]], ["cloyster", 42, ["spike-cannon", "spikes", "aurora-beam", "supersonic"]], ["electrode", 42, ["spark", "sonic-boom", "screech", "light-screen"]], ["arcanine", 42, ["flame-wheel", "roar", "bite", "take-down"]]], +"TRAINER_COOLTRAINER_COLBY": [["kingler", 41, ["guillotine", "stomp", "mud-shot", "bubble"]], ["poliwhirl", 42, ["body-slam", "double-slap", "water-gun", "hypnosis"]], ["tentacruel", 42, ["barrier", "wrap", "bubble-beam", "acid"]], ["seadra", 42, ["water-gun", "smokescreen", "twister", "leer"]], ["blastoise", 43, ["water-gun", "bite", "rapid-spin", "rain-dance"]]], +"TRAINER_COOLTRAINER_PAUL": [["slowpoke", 42, ["headbutt", "confusion", "water-gun", "disable"]], ["shellder", 42, ["aurora-beam", "clamp", "supersonic", "leer"]], ["kingler", 42, ["guillotine", "stomp", "mud-shot", "bubble"]], ["starmie", 42, ["bubble-beam", "swift", "recover", "rapid-spin"]], ["golduck", 42, ["confusion", "scratch", "screech", "disable"]]], +"TRAINER_COOLTRAINER_ROLANDO": [["raticate", 42, ["super-fang", "pursuit", "scary-face", "quick-attack"]], ["ivysaur", 42, ["razor-leaf", "sleep-powder", "sweet-scent", "synthesis"]], ["wartortle", 42, ["water-gun", "bite", "rapid-spin", "tail-whip"]], ["charmeleon", 42, ["flamethrower", "slash", "smokescreen", "scary-face"]], ["charizard", 42, ["flamethrower", "wing-attack", "smokescreen", "scary-face"]]], +"TRAINER_COOLTRAINER_GILBERT": [["pidgeotto", 42, ["wing-attack", "feather-dance", "whirlwind", "quick-attack"]], ["fearow", 42, ["drill-peck", "mirror-move", "pursuit", "leer"]], ["persian", 42, ["pay-day", "feint-attack", "screech", "bite"]], ["lickitung", 42, ["slam", "disable", "wrap", "supersonic"]], ["tauros", 42, ["horn-attack", "scary-face", "swagger", "tail-whip"]]], +"TRAINER_COOLTRAINER_OWEN": [["nidorino", 42, ["scratch", "poison-sting", "double-kick", "bite"]], ["nidorina", 42, ["horn-attack", "poison-sting", "double-kick", "leer"]], ["raticate", 42, ["super-fang", "pursuit", "scary-face", "quick-attack"]], ["sandslash", 42, ["fury-swipes", "swift", "slash", "poison-sting"]], ["rhyhorn", 42, ["rock-blast", "scary-face", "stomp", "tail-whip"]]], +"TRAINER_COOLTRAINER_BERKE": [["seel", 42, ["take-down", "aurora-beam", "icy-wind", "growl"]], ["graveler", 42, ["rock-blast", "magnitude", "rock-throw", "mud-sport"]], ["kingler", 42, ["guillotine", "stomp", "mud-shot", "bubble"]], ["onix", 42, ["slam", "sandstorm", "dragon-breath", "rock-throw"]], ["cloyster", 42, ["spike-cannon", "aurora-beam", "supersonic", "protect"]]], +"TRAINER_COOLTRAINER_YUJI": [["sandslash", 38, ["slash", "swift", "sand-attack", "poison-sting"]], ["graveler", 38, ["rock-blast", "magnitude", "mud-sport", "defense-curl"]], ["onix", 38, ["dragon-breath", "sandstorm", "rock-throw", "bind"]], ["graveler", 38, ["rock-blast", "magnitude", "rollout", "defense-curl"]], ["marowak", 38, ["bonemerang", "headbutt", "leer", "growl"]]], +"TRAINER_COOLTRAINER_WARREN": [["marowak", 37, ["bonemerang", "headbutt", "leer", "growl"]], ["marowak", 37, ["bonemerang", "headbutt", "leer", "growl"]], ["rhyhorn", 38, ["take-down", "rock-blast", "fury-attack", "scary-face"]], ["nidorina", 39, ["fury-swipes", "bite", "poison-sting", "double-kick"]], ["nidoqueen", 39, ["body-slam", "bite", "poison-sting", "double-kick"]]], +"TRAINER_COOLTRAINER_MARY": [["bellsprout", 22, ["wrap", "stun-spore", "poison-powder", "growth"]], ["oddish", 22, ["poison-powder", "stun-spore", "absorb", "sweet-scent"]], ["weepinbell", 22, ["vine-whip", "stun-spore", "poison-powder", "growth"]], ["gloom", 22, ["absorb", "stun-spore", "poison-powder", "sweet-scent"]], ["ivysaur", 22, ["razor-leaf", "sleep-powder", "vine-whip", "leech-seed"]]], +"TRAINER_COOLTRAINER_CAROLINE": [["bellsprout", 42, ["razor-leaf", "acid", "stun-spore", "poison-powder"]], ["weepinbell", 42, ["razor-leaf", "acid", "sleep-powder", "poison-powder"]], ["victreebel", 42, ["razor-leaf", "acid", "stun-spore", "sleep-powder"]], ["paras", 42, ["growth", "slash", "leech-life", "stun-spore"]], ["parasect", 42, ["spore", "slash", "leech-life", "poison-powder"]]], +"TRAINER_COOLTRAINER_ALEXA": [["clefairy", 42, ["light-screen", "cosmic-power", "double-slap", "encore"]], ["jigglypuff", 42, ["sing", "body-slam", "rollout", "disable"]], ["persian", 42, ["pay-day", "feint-attack", "bite", "screech"]], ["dewgong", 42, ["sheer-cold", "take-down", "rest", "aurora-beam"]], ["chansey", 42, ["sing", "egg-bomb", "soft-boiled", "minimize"]]], +"TRAINER_COOLTRAINER_SHANNON": [["beedrill", 42, ["pin-missile", "twineedle", "agility", "pursuit"]], ["butterfree", 42, ["safeguard", "psybeam", "gust", "supersonic"]], ["parasect", 42, ["spore", "leech-life", "slash", "growth"]], ["venonat", 42, ["psybeam", "stun-spore", "leech-life", "disable"]], ["venomoth", 42, ["psybeam", "gust", "supersonic", "leech-life"]]], +"TRAINER_COOLTRAINER_NAOMI": [["persian", 42, ["fury-swipes", "screech", "feint-attack", "pay-day"]], ["ponyta", 42, ["agility", "take-down", "fire-spin", "stomp"]], ["rapidash", 42, ["fury-attack", "fire-spin", "stomp", "growl"]], ["vulpix", 42, ["flamethrower", "confuse-ray", "quick-attack", "imprison"]], ["ninetales", 42, ["safeguard", "will-o-wisp", "confuse-ray", "fire-spin"]]], +"TRAINER_COOLTRAINER_BROOKE": [["tangela", 42, ["slam", "bind", "mega-drain", "ingrain"]], ["gloom", 42, ["acid", "moonlight", "sleep-powder", "stun-spore"]], ["vileplume", 42, ["mega-drain", "acid", "stun-spore", "aromatherapy"]], ["ivysaur", 42, ["razor-leaf", "sweet-scent", "growl", "leech-seed"]], ["venusaur", 42, ["razor-leaf", "growth", "sleep-powder", "poison-powder"]]], +"TRAINER_COOLTRAINER_AUSTINA": [["rhyhorn", 42, ["horn-drill", "rock-blast", "scary-face", "stomp"]], ["nidorina", 42, ["double-kick", "fury-swipes", "bite", "flatter"]], ["nidoqueen", 42, ["body-slam", "double-kick", "bite", "growl"]], ["nidorino", 42, ["horn-attack", "poison-sting", "focus-energy", "leer"]], ["nidoking", 42, ["thrash", "double-kick", "poison-sting", "peck"]]], +"TRAINER_COOLTRAINER_JULIE": [["persian", 42, ["fury-swipes", "bite", "screech", "feint-attack"]], ["ninetales", 42, ["flamethrower", "will-o-wisp", "confuse-ray", "grudge"]], ["rapidash", 42, ["fury-attack", "fire-spin", "take-down", "agility"]], ["pikachu", 42, ["thunderbolt", "thunder-wave", "double-team", "quick-attack"]], ["raichu", 42, ["thunder", "thunder-wave", "slam", "double-team"]]], +"TRAINER_ELITE_FOUR_LORELEI": [["dewgong", 52, ["ice-beam", "surf", "hail", "safeguard"]], ["cloyster", 51, ["spikes", "protect", "hail", "dive"]], ["slowbro", 52, ["ice-beam", "surf", "amnesia", "yawn"]], ["jynx", 54, ["ice-punch", "double-slap", "lovely-kiss", "attract"]], ["lapras", 54, ["confuse-ray", "ice-beam", "surf", "body-slam"]]], +"TRAINER_ELITE_FOUR_BRUNO": [["onix", 51, ["earthquake", "rock-tomb", "iron-tail", "roar"]], ["hitmonchan", 53, ["sky-uppercut", "mach-punch", "rock-tomb", "counter"]], ["hitmonlee", 53, ["mega-kick", "foresight", "brick-break", "facade"]], ["onix", 54, ["double-edge", "earthquake", "iron-tail", "sand-tomb"]], ["machamp", 56, ["cross-chop", "bulk-up", "scary-face", "rock-tomb"]]], +"TRAINER_ELITE_FOUR_AGATHA": [["gengar", 54, ["shadow-punch", "confuse-ray", "toxic", "double-team"]], ["golbat", 54, ["confuse-ray", "poison-fang", "air-cutter", "bite"]], ["haunter", 53, ["hypnosis", "dream-eater", "curse", "mean-look"]], ["arbok", 56, ["sludge-bomb", "screech", "iron-tail", "bite"]], ["gengar", 58, ["shadow-ball", "sludge-bomb", "hypnosis", "nightmare"]]], +"TRAINER_ELITE_FOUR_LANCE": [["gyarados", 56, ["hyper-beam", "dragon-rage", "twister", "bite"]], ["dragonair", 54, ["hyper-beam", "safeguard", "dragon-rage", "outrage"]], ["dragonair", 54, ["hyper-beam", "safeguard", "thunder-wave", "outrage"]], ["aerodactyl", 58, ["hyper-beam", "ancient-power", "wing-attack", "scary-face"]], ["dragonite", 60, ["hyper-beam", "safeguard", "outrage", "wing-attack"]]], +"TRAINER_LEADER_BROCK": [["geodude", 12, ["tackle", "defense-curl"]], ["onix", 14, ["tackle", "bind", "rock-tomb"]]], +"TRAINER_LEADER_MISTY": [["staryu", 18, ["tackle", "harden", "recover", "water-pulse"]], ["starmie", 21, ["swift", "recover", "rapid-spin", "water-pulse"]]], +"TRAINER_LEADER_LT_SURGE": [["voltorb", 21, ["sonic-boom", "tackle", "screech", "shock-wave"]], ["pikachu", 18, ["quick-attack", "thunder-wave", "double-team", "shock-wave"]], ["raichu", 24, ["quick-attack", "thunder-wave", "double-team", "shock-wave"]]], +"TRAINER_LEADER_ERIKA": [["victreebel", 29, ["stun-spore", "acid", "poison-powder", "giga-drain"]], ["tangela", 24, ["poison-powder", "constrict", "ingrain", "giga-drain"]], ["vileplume", 29, ["sleep-powder", "acid", "stun-spore", "giga-drain"]]], +"TRAINER_LEADER_KOGA": [["koffing", 37, ["self-destruct", "sludge", "smokescreen", "toxic"]], ["muk", 39, ["minimize", "sludge", "acid-armor", "toxic"]], ["koffing", 37, ["self-destruct", "sludge", "smokescreen", "toxic"]], ["weezing", 43, ["tackle", "sludge", "smokescreen", "toxic"]]], +"TRAINER_LEADER_BLAINE": [["growlithe", 42, ["bite", "roar", "take-down", "fire-blast"]], ["ponyta", 40, ["stomp", "bounce", "fire-spin", "fire-blast"]], ["rapidash", 42, ["stomp", "bounce", "fire-spin", "fire-blast"]], ["arcanine", 47, ["bite", "roar", "take-down", "fire-blast"]]], +"TRAINER_LEADER_SABRINA": [["kadabra", 38, ["psybeam", "reflect", "future-sight", "calm-mind"]], ["mr-mime", 37, ["barrier", "psybeam", "baton-pass", "calm-mind"]], ["venomoth", 38, ["psybeam", "gust", "leech-life", "supersonic"]], ["alakazam", 43, ["psychic", "recover", "future-sight", "calm-mind"]]], +"TRAINER_GENTLEMAN_THOMAS": [["growlithe", 18], ["growlithe", 18]], +"TRAINER_GENTLEMAN_ARTHUR": [["nidoran-m", 19], ["nidoran-f", 19]], +"TRAINER_GENTLEMAN_TUCKER": [["pikachu", 23]], +"TRAINER_GENTLEMAN_NORTON": [["persian", 48]], +"TRAINER_GENTLEMAN_WALTER": [["growlithe", 17], ["ponyta", 17]], +"TRAINER_RIVAL_SS_ANNE_SQUIRTLE": [["pidgeotto", 19], ["raticate", 16], ["kadabra", 18], ["wartortle", 20]], +"TRAINER_RIVAL_SS_ANNE_BULBASAUR": [["pidgeotto", 19], ["raticate", 16], ["kadabra", 18], ["ivysaur", 20]], +"TRAINER_RIVAL_SS_ANNE_CHARMANDER": [["pidgeotto", 19], ["raticate", 16], ["kadabra", 18], ["charmeleon", 20]], +"TRAINER_RIVAL_POKEMON_TOWER_SQUIRTLE": [["pidgeotto", 25], ["growlithe", 23], ["exeggcute", 22], ["kadabra", 20], ["wartortle", 25]], +"TRAINER_RIVAL_POKEMON_TOWER_BULBASAUR": [["pidgeotto", 25], ["gyarados", 23], ["growlithe", 22], ["kadabra", 20], ["ivysaur", 25]], +"TRAINER_RIVAL_POKEMON_TOWER_CHARMANDER": [["pidgeotto", 25], ["exeggcute", 23], ["gyarados", 22], ["kadabra", 20], ["charmeleon", 25]], +"TRAINER_RIVAL_SILPH_SQUIRTLE": [["pidgeot", 37], ["growlithe", 38], ["exeggcute", 35], ["alakazam", 35], ["blastoise", 40]], +"TRAINER_RIVAL_SILPH_BULBASAUR": [["pidgeot", 37], ["gyarados", 38], ["growlithe", 35], ["alakazam", 35], ["venusaur", 40]], +"TRAINER_RIVAL_SILPH_CHARMANDER": [["pidgeot", 37], ["exeggcute", 38], ["gyarados", 35], ["alakazam", 35], ["charizard", 40]], +"TRAINER_RIVAL_ROUTE22_LATE_SQUIRTLE": [["pidgeot", 47, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["growlithe", 45, ["flame-wheel", "take-down", "leer", "agility"]], ["exeggcute", 45, ["solar-beam", "sleep-powder", "poison-powder", "stun-spore"]], ["alakazam", 47, ["psychic", "calm-mind", "future-sight", "disable"]], ["blastoise", 53, ["water-gun", "rain-dance", "bite", "rapid-spin"]]], +"TRAINER_RIVAL_ROUTE22_LATE_BULBASAUR": [["pidgeot", 47, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["gyarados", 45, ["hydro-pump", "twister", "leer", "rain-dance"]], ["growlithe", 45, ["flame-wheel", "take-down", "leer", "agility"]], ["alakazam", 47, ["psychic", "calm-mind", "future-sight", "disable"]], ["venusaur", 53, ["razor-leaf", "sweet-scent", "growth", "synthesis"]]], +"TRAINER_RIVAL_ROUTE22_LATE_CHARMANDER": [["pidgeot", 47, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["exeggcute", 45, ["solar-beam", "sleep-powder", "poison-powder", "stun-spore"]], ["gyarados", 45, ["hydro-pump", "twister", "leer", "rain-dance"]], ["alakazam", 47, ["psychic", "calm-mind", "future-sight", "disable"]], ["charizard", 53, ["flamethrower", "wing-attack", "slash", "scary-face"]]], +"TRAINER_CHAMPION_FIRST_SQUIRTLE": [["pidgeot", 59, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["arcanine", 59, ["extreme-speed", "flamethrower", "roar", "bite"]], ["exeggutor", 61, ["giga-drain", "egg-bomb", "sleep-powder", "light-screen"]], ["blastoise", 63, ["hydro-pump", "rain-dance", "skull-bash", "bite"]]], +"TRAINER_CHAMPION_FIRST_BULBASAUR": [["pidgeot", 59, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["gyarados", 59, ["hydro-pump", "dragon-rage", "bite", "thrash"]], ["arcanine", 61, ["extreme-speed", "flamethrower", "roar", "bite"]], ["venusaur", 63, ["solar-beam", "synthesis", "sunny-day", "growth"]]], +"TRAINER_CHAMPION_FIRST_CHARMANDER": [["pidgeot", 59, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["exeggutor", 59, ["giga-drain", "egg-bomb", "sleep-powder", "light-screen"]], ["gyarados", 61, ["hydro-pump", "dragon-rage", "bite", "thrash"]], ["charizard", 63, ["fire-blast", "aerial-ace", "slash", "fire-spin"]]], +"TRAINER_CHANNELER_PATRICIA": [["gastly", 22]], +"TRAINER_CHANNELER_CARLY": [["gastly", 24]], +"TRAINER_CHANNELER_HOPE": [["gastly", 23]], +"TRAINER_CHANNELER_PAULA": [["gastly", 24]], +"TRAINER_CHANNELER_LAUREL": [["gastly", 23], ["gastly", 23]], +"TRAINER_CHANNELER_JODY": [["gastly", 22]], +"TRAINER_CHANNELER_TAMMY": [["haunter", 23]], +"TRAINER_CHANNELER_RUTH": [["gastly", 22]], +"TRAINER_CHANNELER_KARINA": [["gastly", 24]], +"TRAINER_CHANNELER_JANAE": [["gastly", 22]], +"TRAINER_CHANNELER_ANGELICA": [["gastly", 22], ["gastly", 22], ["gastly", 22]], +"TRAINER_CHANNELER_EMILIA": [["gastly", 24]], +"TRAINER_CHANNELER_JENNIFER": [["gastly", 24]], +"TRAINER_CHANNELER_1": [["haunter", 23]], +"TRAINER_CHANNELER_2": [["gastly", 24]], +"TRAINER_CHANNELER_3": [["gastly", 22]], +"TRAINER_CHANNELER_4": [["gastly", 24]], +"TRAINER_CHANNELER_5": [["haunter", 22]], +"TRAINER_CHANNELER_6": [["gastly", 22], ["gastly", 22], ["gastly", 22]], +"TRAINER_CHANNELER_7": [["gastly", 24]], +"TRAINER_CHANNELER_8": [["gastly", 24]], +"TRAINER_CHANNELER_AMANDA": [["gastly", 34], ["haunter", 34]], +"TRAINER_CHANNELER_STACY": [["haunter", 38]], +"TRAINER_CHANNELER_TASHA": [["gastly", 33], ["gastly", 33], ["haunter", 33]], +"TRAINER_HIKER_JEREMY": [["machop", 20], ["onix", 20]], +"TRAINER_PICNICKER_ALMA": [["goldeen", 28], ["poliwag", 28], ["horsea", 28]], +"TRAINER_PICNICKER_SUSIE": [["pidgey", 24], ["meowth", 24], ["rattata", 24], ["pikachu", 24], ["meowth", 24]], +"TRAINER_PICNICKER_VALERIE": [["poliwag", 30], ["poliwag", 30]], +"TRAINER_PICNICKER_GWEN": [["pidgey", 27], ["meowth", 27], ["pidgey", 27], ["pidgeotto", 27]], +"TRAINER_BIKER_VIRGIL": [["weezing", 28, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 28, ["smokescreen", "sludge", "smog", "tackle"]]], +"TRAINER_CAMPER_FLINT": [["rattata", 14], ["ekans", 14]], +"TRAINER_PICNICKER_MISSY": [["goldeen", 31], ["seaking", 31]], +"TRAINER_PICNICKER_IRENE": [["tentacool", 30], ["horsea", 30], ["seel", 30]], +"TRAINER_PICNICKER_DANA": [["meowth", 20], ["oddish", 20], ["pidgey", 20]], +"TRAINER_PICNICKER_ARIANA": [["pidgey", 19], ["rattata", 19], ["rattata", 19], ["bellsprout", 19]], +"TRAINER_PICNICKER_LEAH": [["bellsprout", 22], ["clefairy", 22]], +"TRAINER_CAMPER_JUSTIN": [["nidoran-m", 29], ["nidorino", 29]], +"TRAINER_PICNICKER_YAZMIN": [["bellsprout", 29], ["oddish", 29], ["tangela", 29]], +"TRAINER_PICNICKER_KINDRA": [["gloom", 28], ["oddish", 28], ["oddish", 28]], +"TRAINER_PICNICKER_BECKY": [["pikachu", 29], ["raichu", 29]], +"TRAINER_PICNICKER_CELIA": [["clefairy", 33]], +"TRAINER_GENTLEMAN_BROOKS": [["pikachu", 23]], +"TRAINER_GENTLEMAN_LAMAR": [["growlithe", 17], ["ponyta", 17]], +"TRAINER_TWINS_ELI_ANNE": [["clefairy", 22], ["jigglypuff", 22]], +"TRAINER_COOL_COUPLE_RAY_TYRA": [["nidoqueen", 45, ["superpower", "body-slam", "double-kick", "poison-sting"]], ["nidoking", 45, ["megahorn", "thrash", "double-kick", "poison-sting"]]], +"TRAINER_YOUNG_COUPLE_GIA_JES": [["nidoran-m", 24], ["nidoran-f", 24]], +"TRAINER_TWINS_KIRI_JAN": [["charmander", 29], ["squirtle", 29]], +"TRAINER_CRUSH_KIN_RON_MYA": [["hitmonchan", 29], ["hitmonlee", 29]], +"TRAINER_YOUNG_COUPLE_LEA_JED": [["rapidash", 29], ["ninetales", 29]], +"TRAINER_SIS_AND_BRO_LIA_LUC": [["goldeen", 30], ["seaking", 30]], +"TRAINER_SIS_AND_BRO_LIL_IAN": [["seadra", 33], ["starmie", 33]], +"TRAINER_YOUNGSTER_BEN_3": [["raticate", 28], ["ekans", 28]], +"TRAINER_YOUNGSTER_BEN_4": [["raticate", 48], ["arbok", 48]], +"TRAINER_YOUNGSTER_CHAD_2": [["ekans", 20], ["sandshrew", 20]], +"TRAINER_LASS_RELI_2": [["pidgey", 20], ["nidoran-f", 20]], +"TRAINER_LASS_RELI_3": [["pidgeotto", 28], ["nidorina", 28]], +"TRAINER_YOUNGSTER_TIMMY_2": [["raticate", 19], ["ekans", 19], ["zubat", 19]], +"TRAINER_YOUNGSTER_TIMMY_3": [["raticate", 27], ["ekans", 27], ["golbat", 27]], +"TRAINER_YOUNGSTER_TIMMY_4": [["raticate", 52], ["arbok", 52], ["golbat", 52]], +"TRAINER_YOUNGSTER_CHAD_3": [["arbok", 28], ["sandshrew", 28]], +"TRAINER_LASS_JANICE_2": [["pidgeotto", 20], ["pidgeotto", 20]], +"TRAINER_LASS_JANICE_3": [["pidgeotto", 28], ["pidgeotto", 28]], +"TRAINER_YOUNGSTER_CHAD_4": [["arbok", 48], ["sandslash", 48]], +"TRAINER_HIKER_FRANKLIN_2": [["machoke", 25], ["graveler", 25]], +"TRAINER_TEAM_ROCKET_GRUNT_42": [["houndour", 49], ["houndour", 49]], +"TRAINER_PSYCHIC_JACLYN": [["natu", 48, ["night-shade", "confuse-ray", "future-sight", "wish"]], ["slowbro", 48, ["psychic", "headbutt", "amnesia", "yawn"]], ["kadabra", 49, ["psychic", "future-sight", "recover", "reflect"]]], +"TRAINER_CRUSH_GIRL_SHARON": [["mankey", 37], ["primeape", 37]], +"TRAINER_TUBER_AMIRA": [["poliwag", 34], ["poliwhirl", 35], ["poliwag", 34]], +"TRAINER_PKMN_BREEDER_ALIZE": [["pikachu", 48], ["clefairy", 48], ["marill", 48]], +"TRAINER_PKMN_RANGER_NICOLAS": [["weepinbell", 51, ["razor-leaf", "acid", "sweet-scent", "wrap"]], ["victreebel", 51, ["razor-leaf", "acid", "sleep-powder", "stun-spore"]]], +"TRAINER_PKMN_RANGER_MADELINE": [["gloom", 51, ["petal-dance", "acid", "sweet-scent", "poison-powder"]], ["vileplume", 51, ["petal-dance", "moonlight", "acid", "stun-spore"]]], +"TRAINER_AROMA_LADY_NIKKI": [["bellsprout", 37], ["weepinbell", 37]], +"TRAINER_RUIN_MANIAC_STANLY": [["graveler", 48], ["onix", 48], ["graveler", 48]], +"TRAINER_LADY_JACKI": [["hoppip", 48], ["skiploom", 50]], +"TRAINER_PAINTER_DAISY": [["smeargle", 50, ["dynamic-punch", "dizzy-punch", "focus-punch", "mega-punch"]]], +"TRAINER_BIKER_GOON": [["koffing", 37, ["haze", "smokescreen", "sludge", "tackle"]], ["grimer", 37, ["acid-armor", "screech", "minimize", "sludge"]]], +"TRAINER_BIKER_GOON_2": [["koffing", 38, ["haze", "smokescreen", "sludge", "tackle"]]], +"TRAINER_BIKER_GOON_3": [["grimer", 38]], +"TRAINER_BUG_CATCHER_ANTHONY": [["caterpie", 7], ["caterpie", 8]], +"TRAINER_BUG_CATCHER_CHARLIE": [["metapod", 7], ["caterpie", 7], ["metapod", 7]], +"TRAINER_TWINS_ELI_ANNE_2": [["clefairy", 28], ["jigglypuff", 28]], +"TRAINER_YOUNGSTER_JOHNSON": [["ekans", 33], ["ekans", 33], ["raticate", 34]], +"TRAINER_BIKER_RICARDO": [["koffing", 22, ["sludge", "smog", "tackle", "poison-gas"]], ["koffing", 22, ["sludge", "smog", "tackle", "poison-gas"]], ["grimer", 23, ["minimize", "sludge", "disable", "pound"]]], +"TRAINER_BIKER_JAREN": [["grimer", 24], ["grimer", 24]], +"TRAINER_TEAM_ROCKET_GRUNT_43": [["cubone", 37], ["marowak", 37]], +"TRAINER_TEAM_ROCKET_GRUNT_44": [["rattata", 35], ["raticate", 35], ["sandshrew", 35], ["sandslash", 35]], +"TRAINER_TEAM_ROCKET_GRUNT_45": [["zubat", 38], ["zubat", 38], ["golbat", 38]], +"TRAINER_TEAM_ROCKET_GRUNT_46": [["muk", 48], ["golbat", 48], ["raticate", 48]], +"TRAINER_TEAM_ROCKET_GRUNT_47": [["machop", 48], ["machop", 48], ["machoke", 48]], +"TRAINER_TEAM_ROCKET_GRUNT_48": [["hypno", 49], ["hypno", 49]], +"TRAINER_TEAM_ROCKET_ADMIN": [["muk", 52, ["sludge-bomb", "screech", "minimize", "rock-tomb"]], ["arbok", 53, ["sludge-bomb", "bite", "earthquake", "iron-tail"]], ["vileplume", 54, ["sludge-bomb", "giga-drain", "sleep-powder", "stun-spore"]]], +"TRAINER_TEAM_ROCKET_ADMIN_2": [["golbat", 53, ["confuse-ray", "sludge-bomb", "air-cutter", "shadow-ball"]], ["weezing", 54, ["sludge-bomb", "thunderbolt", "explosion", "shadow-ball"]], ["houndoom", 55, ["flamethrower", "crunch", "iron-tail", "shadow-ball"]]], +"TRAINER_SCIENTIST_GIDEON": [["voltorb", 46, ["swift", "screech", "spark", "sonic-boom"]], ["electrode", 46, ["spark", "sonic-boom", "screech", "charge"]], ["magnemite", 46, ["screech", "swift", "spark", "thunder-wave"]], ["magneton", 46, ["tri-attack", "spark", "thunder-wave", "sonic-boom"]], ["porygon", 46, ["tri-attack", "conversion", "recover", "psybeam"]]], +"TRAINER_SWIMMER_FEMALE_AMARA": [["seel", 36], ["seel", 36], ["dewgong", 36]], +"TRAINER_SWIMMER_FEMALE_MARIA": [["seadra", 37], ["seadra", 37]], +"TRAINER_SWIMMER_FEMALE_ABIGAIL": [["psyduck", 35], ["psyduck", 36], ["golduck", 37]], +"TRAINER_SWIMMER_MALE_FINN": [["starmie", 38]], +"TRAINER_SWIMMER_MALE_GARRETT": [["shellder", 35], ["cloyster", 35], ["wartortle", 38]], +"TRAINER_FISHERMAN_TOMMY": [["goldeen", 33], ["goldeen", 33], ["seaking", 35], ["seaking", 35], ["seaking", 35]], +"TRAINER_CRUSH_GIRL_TANYA": [["hitmonlee", 38], ["hitmonchan", 38]], +"TRAINER_BLACK_BELT_SHEA": [["machop", 38], ["machoke", 38]], +"TRAINER_BLACK_BELT_HUGH": [["machop", 37], ["machoke", 37]], +"TRAINER_CAMPER_BRYCE": [["nidorino", 36], ["raticate", 36], ["sandslash", 36]], +"TRAINER_PICNICKER_CLAIRE": [["meowth", 35], ["meowth", 35], ["pikachu", 35], ["clefairy", 35]], +"TRAINER_CRUSH_KIN_MIK_KIA": [["machoke", 39], ["primeape", 39]], +"TRAINER_AROMA_LADY_VIOLET": [["bulbasaur", 36], ["ivysaur", 36], ["ivysaur", 36]], +"TRAINER_TUBER_ALEXIS": [["staryu", 34], ["staryu", 34], ["krabby", 34], ["krabby", 34]], +"TRAINER_TWINS_JOY_MEG": [["clefairy", 37], ["clefairy", 37]], +"TRAINER_SWIMMER_FEMALE_TISHA": [["kingler", 38]], +"TRAINER_PAINTER_CELINA": [["smeargle", 50, ["fly", "dig", "dive", "bounce"]]], +"TRAINER_PAINTER_RAYNA": [["smeargle", 50, ["cross-chop", "megahorn", "double-edge", "self-destruct"]]], +"TRAINER_LADY_GILLIAN": [["mareep", 47], ["mareep", 48], ["flaaffy", 49]], +"TRAINER_YOUNGSTER_DESTIN": [["raticate", 48], ["pidgeotto", 48]], +"TRAINER_SWIMMER_MALE_TOBY": [["poliwhirl", 48], ["tentacool", 48], ["tentacruel", 48]], +"TRAINER_TEAM_ROCKET_GRUNT_49": [["rattata", 48], ["grimer", 48], ["muk", 48]], +"TRAINER_TEAM_ROCKET_GRUNT_50": [["koffing", 49, ["memento", "haze", "smokescreen", "sludge"]], ["weezing", 49, ["haze", "smokescreen", "sludge", "self-destruct"]]], +"TRAINER_TEAM_ROCKET_GRUNT_51": [["ekans", 48], ["gloom", 48], ["gloom", 48]], +"TRAINER_BIRD_KEEPER_MILO": [["pidgey", 47], ["pidgeotto", 49]], +"TRAINER_BIRD_KEEPER_CHAZ": [["spearow", 47], ["fearow", 49]], +"TRAINER_BIRD_KEEPER_HAROLD": [["hoothoot", 47], ["noctowl", 49]], +"TRAINER_FISHERMAN_TYLOR": [["qwilfish", 49], ["qwilfish", 49]], +"TRAINER_SWIMMER_MALE_MYMO": [["kingler", 49], ["wartortle", 49]], +"TRAINER_SWIMMER_FEMALE_NICOLE": [["marill", 50]], +"TRAINER_SIS_AND_BRO_AVA_GEB": [["poliwhirl", 50], ["starmie", 50]], +"TRAINER_AROMA_LADY_ROSE": [["sunkern", 49], ["sunflora", 49]], +"TRAINER_SWIMMER_MALE_SAMIR": [["gyarados", 50]], +"TRAINER_SWIMMER_FEMALE_DENISE": [["chinchou", 49], ["lanturn", 49]], +"TRAINER_TWINS_MIU_MIA": [["pikachu", 50], ["pikachu", 50]], +"TRAINER_HIKER_EARL": [["onix", 49], ["machoke", 49]], +"TRAINER_RUIN_MANIAC_FOSTER": [["golem", 50]], +"TRAINER_RUIN_MANIAC_LARRY": [["machoke", 49], ["machoke", 49]], +"TRAINER_HIKER_DARYL": [["sudowoodo", 50]], +"TRAINER_POKEMANIAC_HECTOR": [["rhyhorn", 49], ["kangaskhan", 49]], +"TRAINER_PSYCHIC_DARIO": [["girafarig", 52, ["crunch", "psybeam", "odor-sleuth", "agility"]]], +"TRAINER_PSYCHIC_RODETTE": [["natu", 48, ["night-shade", "confuse-ray", "wish", "future-sight"]], ["drowzee", 48, ["psychic", "disable", "psych-up", "future-sight"]], ["hypno", 50, ["psychic", "hypnosis", "psych-up", "future-sight"]]], +"TRAINER_AROMA_LADY_MIAH": [["bellossom", 50], ["bellossom", 50]], +"TRAINER_YOUNG_COUPLE_EVE_JON": [["golduck", 50], ["psyduck", 50]], +"TRAINER_JUGGLER_MASON": [["voltorb", 47, ["swift", "light-screen", "spark", "sonic-boom"]], ["pineco", 47, ["spikes", "bide", "rapid-spin", "take-down"]], ["voltorb", 47, ["swift", "light-screen", "spark", "sonic-boom"]], ["pineco", 47, ["spikes", "bide", "rapid-spin", "explosion"]]], +"TRAINER_CRUSH_GIRL_CYNDY": [["primeape", 48], ["hitmontop", 48], ["machoke", 48]], +"TRAINER_CRUSH_GIRL_JOCELYN": [["hitmonchan", 38], ["hitmonchan", 38]], +"TRAINER_TAMER_EVAN": [["sandslash", 48], ["lickitung", 48], ["ursaring", 49]], +"TRAINER_POKEMANIAC_MARK_2": [["rhyhorn", 33], ["lickitung", 33]], +"TRAINER_PKMN_RANGER_LOGAN": [["exeggcute", 37, ["sleep-powder", "poison-powder", "stun-spore", "confusion"]], ["exeggutor", 40, ["egg-bomb", "stomp", "confusion", "hypnosis"]]], +"TRAINER_PKMN_RANGER_JACKSON": [["tangela", 49, ["slam", "mega-drain", "bind", "ingrain"]], ["exeggcute", 49, ["confusion", "poison-powder", "barrage", "reflect"]], ["exeggutor", 49, ["confusion", "egg-bomb", "sleep-powder", "stomp"]]], +"TRAINER_PKMN_RANGER_BETH": [["bellsprout", 38], ["gloom", 38], ["gloom", 38]], +"TRAINER_PKMN_RANGER_KATELYN": [["chansey", 52, ["egg-bomb", "defense-curl", "minimize", "soft-boiled"]]], +"TRAINER_COOLTRAINER_LEROY": [["rhydon", 47, ["take-down", "horn-drill", "rock-blast", "scary-face"]], ["slowbro", 48, ["psychic", "headbutt", "amnesia", "disable"]], ["kangaskhan", 47, ["dizzy-punch", "bite", "endure", "reversal"]], ["machoke", 48, ["cross-chop", "vital-throw", "revenge", "seismic-toss"]], ["ursaring", 50, ["slash", "feint-attack", "snore", "rest"]]], +"TRAINER_COOLTRAINER_MICHELLE": [["persian", 47, ["slash", "screech", "feint-attack", "bite"]], ["dewgong", 47, ["ice-beam", "take-down", "icy-wind", "growl"]], ["ninetales", 48, ["flamethrower", "confuse-ray", "will-o-wisp", "grudge"]], ["rapidash", 48, ["bounce", "agility", "fire-spin", "take-down"]], ["girafarig", 50, ["crunch", "psybeam", "stomp", "odor-sleuth"]]], +"TRAINER_COOL_COUPLE_LEX_NYA": [["miltank", 52, ["body-slam", "milk-drink", "growl", "defense-curl"]], ["tauros", 52, ["thrash", "horn-attack", "pursuit", "swagger"]]], +"TRAINER_RUIN_MANIAC_BRANDON": [["onix", 50]], +"TRAINER_RUIN_MANIAC_BENJAMIN": [["geodude", 48, ["earthquake", "rock-blast", "rollout", "self-destruct"]], ["graveler", 48, ["earthquake", "rock-blast", "rock-throw", "self-destruct"]], ["graveler", 48, ["earthquake", "rock-blast", "rock-throw", "self-destruct"]]], +"TRAINER_PAINTER_EDNA": [["smeargle", 50, ["fake-out", "extreme-speed", "protect", "quick-attack"]]], +"TRAINER_GENTLEMAN_CLIFFORD": [["marowak", 49], ["golduck", 49]], +"TRAINER_LADY_SELPHY": [["persian", 49, ["pay-day", "bite", "taunt", "torment"]], ["persian", 49, ["pay-day", "scratch", "torment", "taunt"]]], +"TRAINER_RUIN_MANIAC_LAWSON": [["onix", 47], ["graveler", 48], ["marowak", 49]], +"TRAINER_PSYCHIC_LAURA": [["natu", 48], ["natu", 48], ["xatu", 49]], +"TRAINER_PKMN_BREEDER_BETHANY": [["chansey", 50]], +"TRAINER_PKMN_BREEDER_ALLISON": [["clefairy", 48], ["clefairy", 48], ["clefable", 48]], +"TRAINER_BUG_CATCHER_GARRET": [["heracross", 49]], +"TRAINER_BUG_CATCHER_JONAH": [["yanma", 45], ["beedrill", 45], ["yanma", 46], ["beedrill", 47]], +"TRAINER_BUG_CATCHER_VANCE": [["venonat", 48], ["venomoth", 48]], +"TRAINER_YOUNGSTER_NASH": [["weepinbell", 47], ["weepinbell", 47], ["victreebel", 49]], +"TRAINER_YOUNGSTER_CORDELL": [["farfetch-d", 48], ["farfetch-d", 48]], +"TRAINER_LASS_DALIA": [["hoppip", 46], ["hoppip", 47], ["skiploom", 47], ["skiploom", 48]], +"TRAINER_LASS_JOANA": [["snubbull", 49]], +"TRAINER_CAMPER_RILEY": [["pinsir", 49], ["heracross", 50]], +"TRAINER_PICNICKER_MARCY": [["paras", 48], ["paras", 48], ["parasect", 49]], +"TRAINER_RUIN_MANIAC_LAYTON": [["sandslash", 48], ["onix", 48], ["sandslash", 48]], +"TRAINER_PICNICKER_KELSEY_2": [["nidoran-m", 21], ["nidoran-f", 21]], +"TRAINER_PICNICKER_KELSEY_3": [["nidorino", 29], ["nidorina", 29]], +"TRAINER_PICNICKER_KELSEY_4": [["nidorino", 49], ["nidorina", 49]], +"TRAINER_CAMPER_RICKY_2": [["squirtle", 22]], +"TRAINER_CAMPER_RICKY_3": [["wartortle", 30]], +"TRAINER_CAMPER_RICKY_4": [["wartortle", 55]], +"TRAINER_CAMPER_JEFF_2": [["spearow", 21], ["raticate", 21]], +"TRAINER_CAMPER_JEFF_3": [["fearow", 29], ["raticate", 29]], +"TRAINER_CAMPER_JEFF_4": [["fearow", 54], ["raticate", 54]], +"TRAINER_PICNICKER_ISABELLE_2": [["pidgeotto", 21], ["pidgeotto", 21], ["pidgey", 18]], +"TRAINER_PICNICKER_ISABELLE_3": [["pidgeotto", 29], ["pidgeotto", 29], ["pidgeotto", 26]], +"TRAINER_PICNICKER_ISABELLE_4": [["pidgeotto", 47], ["pidgeotto", 47], ["pidgeot", 50]], +"TRAINER_YOUNGSTER_YASU_2": [["rattata", 22], ["raticate", 22], ["raticate", 22]], +"TRAINER_YOUNGSTER_YASU_3": [["raticate", 47], ["raticate", 47], ["raticate", 47]], +"TRAINER_ENGINEER_BERNIE_2": [["magneton", 28], ["magneton", 28], ["magneton", 28]], +"TRAINER_GAMER_DARIAN_2": [["growlithe", 29], ["vulpix", 29]], +"TRAINER_CAMPER_CHRIS_2": [["growlithe", 24], ["charmander", 24]], +"TRAINER_CAMPER_CHRIS_3": [["growlithe", 29], ["charmeleon", 29]], +"TRAINER_CAMPER_CHRIS_4": [["arcanine", 54], ["charmeleon", 54]], +"TRAINER_PICNICKER_ALICIA_2": [["meowth", 25]], +"TRAINER_PICNICKER_ALICIA_3": [["persian", 30]], +"TRAINER_PICNICKER_ALICIA_4": [["persian", 55]], +"TRAINER_HIKER_JEREMY_2": [["machoke", 30], ["onix", 28]], +"TRAINER_POKEMANIAC_MARK_3": [["rhydon", 54], ["lickitung", 54]], +"TRAINER_POKEMANIAC_HERMAN_2": [["marowak", 29], ["slowbro", 29]], +"TRAINER_POKEMANIAC_HERMAN_3": [["marowak", 54], ["slowbro", 54]], +"TRAINER_HIKER_TRENT_2": [["onix", 31], ["graveler", 31]], +"TRAINER_LASS_MEGAN_2": [["pidgeotto", 22], ["raticate", 22], ["nidoran-m", 23], ["meowth", 21], ["pikachu", 22]], +"TRAINER_LASS_MEGAN_3": [["pidgeot", 46], ["raticate", 47], ["nidorino", 47], ["persian", 47], ["raichu", 48]], +"TRAINER_SUPER_NERD_GLENN_2": [["muk", 28], ["muk", 28], ["muk", 28]], +"TRAINER_GAMER_RICH_2": [["growlithe", 30], ["vulpix", 30]], +"TRAINER_BIKER_JAREN_2": [["muk", 28], ["muk", 30]], +"TRAINER_FISHERMAN_ELLIOT_2": [["poliwhirl", 28], ["cloyster", 28], ["seaking", 28], ["seadra", 28]], +"TRAINER_ROCKER_LUCA_2": [["electrode", 33], ["electrode", 33]], +"TRAINER_BEAUTY_SHEILA_2": [["clefairy", 49], ["persian", 49]], +"TRAINER_BIRD_KEEPER_ROBERT_2": [["pidgeotto", 28], ["pidgeotto", 28], ["fearow", 28], ["fearow", 28]], +"TRAINER_BIRD_KEEPER_ROBERT_3": [["pidgeot", 47], ["pidgeot", 47], ["fearow", 47], ["fearow", 47]], +"TRAINER_PICNICKER_SUSIE_2": [["pidgeotto", 27], ["meowth", 27], ["raticate", 27], ["pikachu", 27], ["meowth", 27]], +"TRAINER_PICNICKER_SUSIE_3": [["pidgeotto", 47], ["persian", 47], ["raticate", 47], ["pikachu", 47], ["persian", 47]], +"TRAINER_PICNICKER_SUSIE_4": [["pidgeot", 52], ["persian", 52], ["raticate", 52], ["raichu", 52], ["persian", 52]], +"TRAINER_BIKER_LUKAS_2": [["koffing", 47], ["koffing", 47], ["muk", 47], ["weezing", 47]], +"TRAINER_BIRD_KEEPER_BENNY_2": [["fearow", 32], ["fearow", 32]], +"TRAINER_BIRD_KEEPER_BENNY_3": [["fearow", 49], ["fearow", 49]], +"TRAINER_BIRD_KEEPER_MARLON_2": [["fearow", 30], ["doduo", 30], ["fearow", 30]], +"TRAINER_BIRD_KEEPER_MARLON_3": [["fearow", 48], ["dodrio", 48], ["fearow", 48]], +"TRAINER_BEAUTY_GRACE_2": [["pidgeot", 49], ["wigglytuff", 49]], +"TRAINER_BIRD_KEEPER_CHESTER_2": [["dodrio", 30], ["dodrio", 30], ["doduo", 30]], +"TRAINER_BIRD_KEEPER_CHESTER_3": [["dodrio", 48], ["dodrio", 48], ["dodrio", 48]], +"TRAINER_PICNICKER_BECKY_2": [["pikachu", 32], ["raichu", 32]], +"TRAINER_PICNICKER_BECKY_3": [["pikachu", 49], ["raichu", 49]], +"TRAINER_PICNICKER_BECKY_4": [["raichu", 54], ["raichu", 54]], +"TRAINER_CRUSH_KIN_RON_MYA_2": [["hitmonchan", 33], ["hitmonlee", 33]], +"TRAINER_CRUSH_KIN_RON_MYA_3": [["hitmonchan", 51], ["hitmonlee", 51]], +"TRAINER_CRUSH_KIN_RON_MYA_4": [["hitmonchan", 56], ["hitmonlee", 56]], +"TRAINER_BIKER_RUBEN_2": [["weezing", 48], ["weezing", 48], ["weezing", 48]], +"TRAINER_CUE_BALL_CAMRON_2": [["primeape", 49], ["machoke", 49]], +"TRAINER_BIKER_JAXON_2": [["weezing", 49], ["muk", 49]], +"TRAINER_CUE_BALL_ISAIAH_2": [["machoke", 49], ["machamp", 49]], +"TRAINER_CUE_BALL_COREY_2": [["primeape", 49], ["machamp", 49]], +"TRAINER_BIRD_KEEPER_JACOB_2": [["fearow", 28], ["spearow", 28], ["fearow", 28], ["spearow", 28]], +"TRAINER_BIRD_KEEPER_JACOB_3": [["fearow", 47], ["fearow", 47], ["fearow", 47], ["fearow", 47]], +"TRAINER_SWIMMER_FEMALE_ALICE_2": [["seaking", 49], ["seaking", 49]], +"TRAINER_SWIMMER_MALE_DARRIN_2": [["seadra", 52], ["seadra", 52], ["seadra", 52], ["seadra", 52]], +"TRAINER_PICNICKER_MISSY_2": [["seaking", 49], ["seaking", 49]], +"TRAINER_PICNICKER_MISSY_3": [["seaking", 54], ["seaking", 54]], +"TRAINER_FISHERMAN_WADE_2": [["magikarp", 47], ["magikarp", 47], ["magikarp", 47], ["magikarp", 47], ["magikarp", 47], ["magikarp", 47]], +"TRAINER_SWIMMER_MALE_JACK_2": [["starmie", 50]], +"TRAINER_SIS_AND_BRO_LIL_IAN_2": [["seadra", 50], ["starmie", 50]], +"TRAINER_SIS_AND_BRO_LIL_IAN_3": [["seadra", 55], ["starmie", 55]], +"TRAINER_SWIMMER_MALE_FINN_2": [["starmie", 50]], +"TRAINER_CRUSH_GIRL_SHARON_2": [["mankey", 50], ["primeape", 50]], +"TRAINER_CRUSH_GIRL_SHARON_3": [["primeape", 55], ["primeape", 55]], +"TRAINER_CRUSH_GIRL_TANYA_2": [["hitmonlee", 50], ["hitmonchan", 50]], +"TRAINER_CRUSH_GIRL_TANYA_3": [["hitmonlee", 55], ["hitmonchan", 55]], +"TRAINER_BLACK_BELT_SHEA_2": [["machoke", 50], ["machoke", 50]], +"TRAINER_BLACK_BELT_SHEA_3": [["machoke", 55], ["machamp", 55]], +"TRAINER_BLACK_BELT_HUGH_2": [["machoke", 50], ["machoke", 50]], +"TRAINER_BLACK_BELT_HUGH_3": [["machoke", 55], ["machamp", 55]], +"TRAINER_CRUSH_KIN_MIK_KIA_2": [["machoke", 51], ["primeape", 51]], +"TRAINER_CRUSH_KIN_MIK_KIA_3": [["machamp", 56], ["primeape", 56]], +"TRAINER_TUBER_AMIRA_2": [["poliwhirl", 47], ["poliwhirl", 47], ["poliwhirl", 47]], +"TRAINER_TWINS_JOY_MEG_2": [["clefairy", 49], ["clefairy", 49]], +"TRAINER_PAINTER_RAYNA_2": [["smeargle", 54, ["cross-chop", "megahorn", "double-edge", "self-destruct"]]], +"TRAINER_YOUNGSTER_DESTIN_2": [["raticate", 53], ["pidgeot", 53]], +"TRAINER_PKMN_BREEDER_ALIZE_2": [["pikachu", 53], ["clefairy", 53], ["marill", 53]], +"TRAINER_YOUNG_COUPLE_GIA_JES_2": [["nidorina", 30], ["nidorino", 30]], +"TRAINER_YOUNG_COUPLE_GIA_JES_3": [["nidoking", 55], ["nidoqueen", 55]], +"TRAINER_BIRD_KEEPER_MILO_2": [["pidgeotto", 53], ["pidgeot", 55]], +"TRAINER_BIRD_KEEPER_CHAZ_2": [["fearow", 53], ["fearow", 55]], +"TRAINER_BIRD_KEEPER_HAROLD_2": [["noctowl", 53], ["noctowl", 55]], +"TRAINER_SWIMMER_FEMALE_NICOLE_2": [["marill", 54]], +"TRAINER_PSYCHIC_JACLYN_2": [["natu", 52, ["psychic", "confuse-ray", "future-sight", "wish"]], ["slowbro", 52, ["psychic", "headbutt", "amnesia", "yawn"]], ["kadabra", 54, ["psychic", "future-sight", "recover", "reflect"]]], +"TRAINER_SWIMMER_MALE_SAMIR_2": [["gyarados", 55]], +"TRAINER_HIKER_EARL_2": [["onix", 54], ["machamp", 54]], +"TRAINER_RUIN_MANIAC_LARRY_2": [["machoke", 54], ["machoke", 54]], +"TRAINER_POKEMANIAC_HECTOR_2": [["rhydon", 55], ["kangaskhan", 55]], +"TRAINER_PSYCHIC_DARIO_2": [["girafarig", 56, ["crunch", "psybeam", "odor-sleuth", "agility"]]], +"TRAINER_PSYCHIC_RODETTE_2": [["natu", 53, ["psychic", "confuse-ray", "wish", "future-sight"]], ["hypno", 53, ["psychic", "disable", "psych-up", "future-sight"]], ["hypno", 53, ["psychic", "hypnosis", "psych-up", "future-sight"]]], +"TRAINER_JUGGLER_MASON_2": [["electrode", 52], ["pineco", 52], ["electrode", 52], ["pineco", 52]], +"TRAINER_PKMN_RANGER_NICOLAS_2": [["victreebel", 55, ["razor-leaf", "acid", "stun-spore", "wrap"]], ["victreebel", 55, ["razor-leaf", "acid", "sleep-powder", "slam"]]], +"TRAINER_PKMN_RANGER_MADELINE_2": [["vileplume", 55, ["petal-dance", "moonlight", "acid", "sleep-powder"]], ["vileplume", 55, ["petal-dance", "moonlight", "acid", "stun-spore"]]], +"TRAINER_CRUSH_GIRL_CYNDY_2": [["primeape", 54], ["hitmontop", 54], ["machamp", 54]], +"TRAINER_TAMER_EVAN_2": [["sandslash", 52], ["lickitung", 52], ["ursaring", 55]], +"TRAINER_PKMN_RANGER_JACKSON_2": [["tangela", 53, ["slam", "mega-drain", "bind", "ingrain"]], ["exeggutor", 54, ["confusion", "egg-bomb", "stun-spore", "reflect"]], ["exeggutor", 55, ["confusion", "egg-bomb", "sleep-powder", "stomp"]]], +"TRAINER_PKMN_RANGER_KATELYN_2": [["chansey", 56, ["egg-bomb", "defense-curl", "minimize", "soft-boiled"]]], +"TRAINER_COOLTRAINER_LEROY_2": [["rhydon", 52, ["earthquake", "horn-drill", "rock-blast", "scary-face"]], ["slowbro", 54, ["psychic", "headbutt", "amnesia", "disable"]], ["kangaskhan", 52, ["dizzy-punch", "bite", "endure", "reversal"]], ["machamp", 52, ["cross-chop", "vital-throw", "revenge", "seismic-toss"]], ["ursaring", 55, ["slash", "feint-attack", "snore", "rest"]]], +"TRAINER_COOLTRAINER_MICHELLE_2": [["persian", 53, ["slash", "screech", "feint-attack", "bite"]], ["dewgong", 53, ["ice-beam", "take-down", "icy-wind", "sheer-cold"]], ["ninetales", 54, ["flamethrower", "confuse-ray", "will-o-wisp", "grudge"]], ["rapidash", 54, ["bounce", "agility", "fire-spin", "take-down"]], ["girafarig", 56, ["crunch", "psybeam", "stomp", "odor-sleuth"]]], +"TRAINER_COOL_COUPLE_LEX_NYA_2": [["miltank", 57, ["body-slam", "milk-drink", "growl", "defense-curl"]], ["tauros", 57, ["take-down", "scary-face", "pursuit", "swagger"]]], +"TRAINER_BUG_CATCHER_COLTON_2": [["metapod", 19], ["weedle", 19], ["metapod", 19]], +"TRAINER_BUG_CATCHER_COLTON_3": [["butterfree", 27], ["kakuna", 27], ["butterfree", 27]], +"TRAINER_BUG_CATCHER_COLTON_4": [["butterfree", 51], ["beedrill", 54], ["butterfree", 51]], +"TRAINER_SWIMMER_MALE_MATTHEW_2": [["poliwhirl", 49], ["poliwrath", 49]], +"TRAINER_SWIMMER_MALE_TONY_2": [["seadra", 49], ["seadra", 49]], +"TRAINER_SWIMMER_FEMALE_MELISSA_2": [["poliwhirl", 49], ["seaking", 49]], +"TRAINER_ELITE_FOUR_LORELEI_2": [["dewgong", 64, ["ice-beam", "surf", "signal-beam", "double-team"]], ["cloyster", 63, ["ice-beam", "surf", "supersonic", "rain-dance"]], ["piloswine", 63, ["blizzard", "earthquake", "double-edge", "rock-slide"]], ["jynx", 66, ["ice-beam", "psychic", "lovely-kiss", "attract"]], ["lapras", 66, ["ice-beam", "surf", "psychic", "thunder"]]], +"TRAINER_ELITE_FOUR_BRUNO_2": [["steelix", 65, ["earthquake", "iron-tail", "crunch", "rock-tomb"]], ["hitmonchan", 65, ["sky-uppercut", "mach-punch", "rock-slide", "counter"]], ["hitmonlee", 65, ["mega-kick", "foresight", "earthquake", "rock-slide"]], ["steelix", 66, ["earthquake", "iron-tail", "crunch", "dragon-breath"]], ["machamp", 68, ["cross-chop", "earthquake", "brick-break", "rock-slide"]]], +"TRAINER_ELITE_FOUR_AGATHA_2": [["gengar", 66, ["shadow-ball", "psychic", "confuse-ray", "hypnosis"]], ["crobat", 66, ["sludge-bomb", "air-cutter", "shadow-ball", "confuse-ray"]], ["misdreavus", 65, ["shadow-ball", "psychic", "thunderbolt", "attract"]], ["arbok", 68, ["sludge-bomb", "earthquake", "giga-drain", "double-team"]], ["gengar", 70, ["shadow-ball", "psychic", "thunderbolt", "sludge-bomb"]]], +"TRAINER_ELITE_FOUR_LANCE_2": [["gyarados", 68, ["hyper-beam", "dragon-dance", "earthquake", "thunder-wave"]], ["dragonite", 66, ["hyper-beam", "earthquake", "dragon-claw", "flamethrower"]], ["kingdra", 66, ["hyper-beam", "dragon-dance", "surf", "ice-beam"]], ["aerodactyl", 70, ["hyper-beam", "ancient-power", "aerial-ace", "earthquake"]], ["dragonite", 72, ["hyper-beam", "outrage", "thunderbolt", "ice-beam"]]], +"TRAINER_CHAMPION_REMATCH_SQUIRTLE": [["heracross", 72, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["arcanine", 73, ["extreme-speed", "overheat", "aerial-ace", "iron-tail"]], ["exeggutor", 73, ["giga-drain", "psychic", "sleep-powder", "light-screen"]], ["blastoise", 75, ["hydro-pump", "ice-beam", "earthquake", "rain-dance"]]], +"TRAINER_CHAMPION_REMATCH_BULBASAUR": [["heracross", 72, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["gyarados", 73, ["hydro-pump", "dragon-dance", "earthquake", "hyper-beam"]], ["arcanine", 73, ["extreme-speed", "overheat", "aerial-ace", "iron-tail"]], ["venusaur", 75, ["solar-beam", "sludge-bomb", "earthquake", "sunny-day"]]], +"TRAINER_CHAMPION_REMATCH_CHARMANDER": [["heracross", 72, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["exeggutor", 73, ["giga-drain", "psychic", "sleep-powder", "light-screen"]], ["gyarados", 73, ["hydro-pump", "dragon-dance", "earthquake", "hyper-beam"]], ["charizard", 75, ["fire-blast", "dragon-claw", "aerial-ace", "earthquake"]]], +"TRAINER_CUE_BALL_PAXTON": [["weezing", 39], ["muk", 39]] +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/type_chart.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/type_chart.json new file mode 100644 index 0000000000..555a4f323d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/type_chart.json @@ -0,0 +1,112 @@ +[ +["normal", "rock", 5], +["normal", "steel", 5], +["fire", "fire", 5], +["fire", "water", 5], +["fire", "grass", 20], +["fire", "ice", 20], +["fire", "bug", 20], +["fire", "rock", 5], +["fire", "dragon", 5], +["fire", "steel", 20], +["water", "fire", 20], +["water", "water", 5], +["water", "grass", 5], +["water", "ground", 20], +["water", "rock", 20], +["water", "dragon", 5], +["electric", "water", 20], +["electric", "electric", 5], +["electric", "grass", 5], +["electric", "ground", 0], +["electric", "flying", 20], +["electric", "dragon", 5], +["grass", "fire", 5], +["grass", "water", 20], +["grass", "grass", 5], +["grass", "poison", 5], +["grass", "ground", 20], +["grass", "flying", 5], +["grass", "bug", 5], +["grass", "rock", 20], +["grass", "dragon", 5], +["grass", "steel", 5], +["ice", "water", 5], +["ice", "grass", 20], +["ice", "ice", 5], +["ice", "ground", 20], +["ice", "flying", 20], +["ice", "dragon", 20], +["ice", "steel", 5], +["ice", "fire", 5], +["fighting", "normal", 20], +["fighting", "ice", 20], +["fighting", "poison", 5], +["fighting", "flying", 5], +["fighting", "psychic", 5], +["fighting", "bug", 5], +["fighting", "rock", 20], +["fighting", "dark", 20], +["fighting", "steel", 20], +["poison", "grass", 20], +["poison", "poison", 5], +["poison", "ground", 5], +["poison", "rock", 5], +["poison", "ghost", 5], +["poison", "steel", 0], +["ground", "fire", 20], +["ground", "electric", 20], +["ground", "grass", 5], +["ground", "poison", 20], +["ground", "flying", 0], +["ground", "bug", 5], +["ground", "rock", 20], +["ground", "steel", 20], +["flying", "electric", 5], +["flying", "grass", 20], +["flying", "fighting", 20], +["flying", "bug", 20], +["flying", "rock", 5], +["flying", "steel", 5], +["psychic", "fighting", 20], +["psychic", "poison", 20], +["psychic", "psychic", 5], +["psychic", "dark", 0], +["psychic", "steel", 5], +["bug", "fire", 5], +["bug", "grass", 20], +["bug", "fighting", 5], +["bug", "poison", 5], +["bug", "flying", 5], +["bug", "psychic", 20], +["bug", "ghost", 5], +["bug", "dark", 20], +["bug", "steel", 5], +["rock", "fire", 20], +["rock", "ice", 20], +["rock", "fighting", 5], +["rock", "ground", 5], +["rock", "flying", 20], +["rock", "bug", 20], +["rock", "steel", 5], +["ghost", "normal", 0], +["ghost", "psychic", 20], +["ghost", "dark", 5], +["ghost", "steel", 5], +["ghost", "ghost", 20], +["dragon", "dragon", 20], +["dragon", "steel", 5], +["dark", "fighting", 5], +["dark", "psychic", 20], +["dark", "ghost", 20], +["dark", "dark", 5], +["dark", "steel", 5], +["steel", "fire", 5], +["steel", "water", 5], +["steel", "electric", 5], +["steel", "ice", 20], +["steel", "rock", 20], +["steel", "steel", 5], +["normal", "ghost", 0], +["fighting", "ghost", 0] +] diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 2a9e87358e..5b0043d814 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -24,6 +24,7 @@ #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryBattleDecisions.h" #include "PokemonFRLG_AutoStoryBattle.h" @@ -623,6 +624,9 @@ class BattleLoop{ void take_turn(const ImageViewRGB32& screen){ m_faint_polls = 0; + if (m_kind != BattleKind::TRAINER && m_decisions.turns() == 0){ + m_supplies.wild_foes = read_wild_foes(m_console.logger(), m_language, screen); + } if (m_refusal.refused(current_time())){ m_console.log("Battle: the move list came back without a turn (Disable?); choosing another move.", COLOR_ORANGE); m_decisions.turn_done(TurnChoice::MOVE, TurnResult::REFUSED); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index 527e8ff33f..6536a174e3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -75,6 +75,10 @@ struct Supplies{ // story knows it (trainer_party()): the lead's attacks are chosen // against it. Empty otherwise; wild battles never use it. std::vector foes = {}; + // The wild Pokemon of the battle going on, as read at its first battle + // menu (read_wild_foes()): the lead's attacks are chosen against it. + // Empty when it wasn't read; trainer battles never use it. + std::vector wild_foes = {}; }; // The nurse healed the party: HP, status and PP. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp new file mode 100644 index 0000000000..141de1a96e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp @@ -0,0 +1,231 @@ +/* AutoStory Battle Data + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "Common/Cpp/Json/JsonValue.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_WildEncounterReader.h" +#include "PokemonFRLG_AutoStoryBattleData.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// The trainer each of the story's battle steps fights, by the map the +// step leaves the player on and the step's name. The rival's teams are +// those against a player who took Squirtle. On a map with more than one +// trainer of a kind, the object's tile and script (pret +// data/maps//map.json, scripts.inc) say which. +struct StoryTrainer{ + std::string_view map; + std::string_view battle; + std::string_view trainer; +}; +constexpr StoryTrainer STORY_TRAINERS[] = { + {.map = "PalletTown_ProfessorOaksLab", .battle = "rival_battle", .trainer = "TRAINER_RIVAL_OAKS_LAB_BULBASAUR"}, + {.map = "PewterCity_Gym", .battle = "camper_liam", .trainer = "TRAINER_CAMPER_LIAM"}, + {.map = "PewterCity_Gym", .battle = "brock", .trainer = "TRAINER_LEADER_BROCK"}, + {.map = "Route3", .battle = "bug_catcher_colton", .trainer = "TRAINER_BUG_CATCHER_COLTON"}, + {.map = "Route3", .battle = "bug_catcher_greg", .trainer = "TRAINER_BUG_CATCHER_GREG"}, + {.map = "Route3", .battle = "bug_catcher_james", .trainer = "TRAINER_BUG_CATCHER_JAMES"}, + // Grunt1 at (12, 20), MtMoon_B2F_EventScript_Grunt1. + {.map = "MtMoon_B2F", .battle = "rocket_grunt", .trainer = "TRAINER_TEAM_ROCKET_GRUNT"}, + {.map = "MtMoon_B2F", .battle = "super_nerd_miguel", .trainer = "TRAINER_SUPER_NERD_MIGUEL"}, + {.map = "CeruleanCity", .battle = "rival_cerulean", .trainer = "TRAINER_RIVAL_CERULEAN_BULBASAUR"}, + {.map = "Route24", .battle = "bug_catcher_cale", .trainer = "TRAINER_BUG_CATCHER_CALE"}, + {.map = "Route24", .battle = "lass_ali", .trainer = "TRAINER_LASS_ALI"}, + {.map = "Route24", .battle = "youngster_timmy", .trainer = "TRAINER_YOUNGSTER_TIMMY"}, + {.map = "Route24", .battle = "lass_reli", .trainer = "TRAINER_LASS_RELI"}, + {.map = "Route24", .battle = "camper_ethan", .trainer = "TRAINER_CAMPER_ETHAN"}, + // The Nugget Bridge Rocket, Route24_EventScript_Rocket. + {.map = "Route24", .battle = "rocket_grunt", .trainer = "TRAINER_TEAM_ROCKET_GRUNT_6"}, + {.map = "CeruleanCity_Gym", .battle = "misty", .trainer = "TRAINER_LEADER_MISTY"}, +}; + +using JsonTable = std::map>; + +const JsonValue& file_json(const std::string& name){ + static const JsonTable FILES = []{ + JsonTable files; + for (const auto& [file, text] : autostory_battle_json()){ + files.emplace(file, parse_json(text)); + } + return files; + }(); + const auto it = FILES.find(name); + if (it == FILES.end()){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "BattleData/" + name + ".json is not built into the program."); + } + return it->second; +} + +PokemonType type_of(const JsonValue& value){ + return Pokemon::POKEMON_TYPE_SLUGS().get_enum(value.to_string_throw(), PokemonType::NONE); +} + +uint8_t byte_of(const JsonValue& value){ + return static_cast(std::clamp(value.to_integer_throw(), 0, 255)); +} + +template +using Table = std::map>; + +const Table& moves(){ + static const Table MOVES = []{ + Table moves; + for (const auto& [name, value] : file_json("moves").to_object_throw()){ + const JsonArray& entry = value.to_array_throw(); + moves.emplace(name, MoveData{.power = byte_of(entry[0]), .type = type_of(entry[1]), .pp = byte_of(entry[2])}); + } + return moves; + }(); + return MOVES; +} + +const Table& species(){ + static const Table SPECIES = []{ + Table species; + for (const auto& [name, value] : file_json("species").to_object_throw()){ + const JsonArray& entry = value.to_array_throw(); + species.emplace(name, SpeciesData{ + .first = type_of(entry[0]), .second = type_of(entry[1]), + .attack = byte_of(entry[2]), .sp_attack = byte_of(entry[3]), + }); + } + return species; + }(); + return SPECIES; +} + +std::vector strings_of(const JsonValue& value){ + std::vector strings; + for (const JsonValue& item : value.to_array_throw()){ + strings.push_back(item.to_string_throw()); + } + return strings; +} + +TrainerMon trainer_mon(const JsonArray& entry){ + TrainerMon mon{.species = entry[0].to_string_throw(), .level = byte_of(entry[1]), .moves = {}}; + if (entry.size() > 2){ + mon.moves = strings_of(entry[2]); + } + return mon; +} + +} + + +const MoveData* move_data(std::string_view move){ + const auto it = moves().find(move); + return it == moves().end() ? nullptr : &it->second; +} + +const SpeciesData* species_data(std::string_view name){ + const auto it = species().find(name); + return it == species().end() ? nullptr : &it->second; +} + +const std::set& battle_species(){ + static const std::set NAMES = []{ + std::set names; + for (const auto& item : species()){ + names.insert(item.first); + } + return names; + }(); + return NAMES; +} + +std::vector wild_foes(std::string_view species){ + if (species_data(species) == nullptr){ + return {}; + } + return {std::string(species)}; +} + +std::vector read_wild_foes(Logger& logger, Language language, const ImageViewRGB32& screen){ + if (language == Language::None){ + return {}; + } + const std::string species = WildEncounterReader().read_encounter(logger, language, screen, battle_species()).name; + std::vector foes = wild_foes(species); + logger.log(foes.empty() + ? "Battle: the wild Pokemon wasn't read; attacks in the plan's order." + : "Battle: a wild " + species + "; attacks are chosen against it." + ); + return foes; +} + +size_t type_effectiveness(PokemonType attack, PokemonType defend){ + static const std::map, size_t> CHART = []{ + std::map, size_t> chart; + for (const JsonValue& value : file_json("type_chart").to_array_throw()){ + const JsonArray& entry = value.to_array_throw(); + chart[{type_of(entry[0]), type_of(entry[1])}] = static_cast(entry[2].to_integer_throw()); + } + return chart; + }(); + const auto it = CHART.find({attack, defend}); + return it == CHART.end() ? 10 : it->second; +} + +bool special_type(PokemonType type){ + switch (type){ + case PokemonType::FIRE: + case PokemonType::WATER: + case PokemonType::GRASS: + case PokemonType::ELECTRIC: + case PokemonType::PSYCHIC: + case PokemonType::ICE: + case PokemonType::DRAGON: + case PokemonType::DARK: + return true; + default: + return false; + } +} + +std::vector trainer_mons(std::string_view trainer){ + const JsonObject& trainers = file_json("trainers").to_object_throw(); + const auto it = trainers.find(std::string(trainer)); + std::vector party; + if (it == trainers.end()){ + return party; + } + for (const JsonValue& value : it->second.to_array_throw()){ + party.push_back(trainer_mon(value.to_array_throw())); + } + return party; +} + +std::vector map_trainers(std::string_view map){ + const JsonObject& maps = file_json("map_trainers").to_object_throw(); + const auto it = maps.find(std::string(map)); + return it == maps.end() ? std::vector{} : strings_of(it->second); +} + +std::optional story_trainer(std::string_view map, std::string_view battle){ + for (const StoryTrainer& entry : STORY_TRAINERS){ + if (entry.map == map && entry.battle == battle){ + return entry.trainer; + } + } + return std::nullopt; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h new file mode 100644 index 0000000000..3172f7cbc9 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h @@ -0,0 +1,111 @@ +/* AutoStory Battle Data + * + * From: https://github.com/PokemonAutomation/ + * + * The game's data the story's attacks are chosen from, generated from + * pret/pokefirered by devtools/maps/frlg_battle_data.py into BattleData/ + * and built into the program: the type chart, every species' types and + * base Attack and Sp. Atk, every move's power, type and PP, + * every trainer's party, and the trainers each map battles. Also which + * trainer each of the story's battle steps fights. + * + * Names are the program's slugs ("water-gun", "mr-mime"); trainers are + * pret's constants ("TRAINER_SUPER_NERD_MIGUEL"). + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattleData_H +#define PokemonAutomation_PokemonFRLG_AutoStoryBattleData_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" +#include "Pokemon/Pokemon_Types.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +using Pokemon::PokemonType; + +struct MoveData{ + // Moves whose damage doesn't come from their power (Flail, Dragon + // Rage) have 1; moves that do no damage 0. + uint8_t power = 0; + // NONE for Curse's "???". + PokemonType type = PokemonType::NONE; + uint8_t pp = 0; +}; + +struct SpeciesData{ + // The same type twice for a species with one. + PokemonType first = PokemonType::NONE; + PokemonType second = PokemonType::NONE; + uint8_t attack = 0; + uint8_t sp_attack = 0; +}; + +struct TrainerMon{ + std::string species; + uint8_t level = 0; + // The moves the party gives it; empty for its level-up moves. + std::vector moves; +}; + +// None for a move or species the data doesn't have. +const MoveData* move_data(std::string_view move); +const SpeciesData* species_data(std::string_view species); + +// Every species, for reading a wild Pokemon's name. +const std::set& battle_species(); + +// The foes of a wild battle whose Pokemon was read as `species`: it, or +// none when it wasn't read ("") or the data doesn't have it. +std::vector wild_foes(std::string_view species); + +// The foes of the wild battle on `screen`, a battle menu: the Pokemon its +// HP box names (WildEncounterReader, among battle_species()), as +// wild_foes() takes it. Logs what it read. +std::vector read_wild_foes(Logger& logger, Language language, const ImageViewRGB32& screen); + +// How well `attack` hits `defend`, in tenths: 20 is 2x, 5 is 0.5x. +size_t type_effectiveness(PokemonType attack, PokemonType defend); + +// Gen 3 splits physical and special by type: Fire, Water, Grass, +// Electric, Psychic, Ice, Dragon and Dark are special. +bool special_type(PokemonType type); + +// A trainer's party in order; empty for a trainer the data doesn't have. +std::vector trainer_mons(std::string_view trainer); + +// The trainers `map`'s scripts and objects battle. +std::vector map_trainers(std::string_view map); + +// The trainer the story's battle step `battle` fights on `map` (the map +// it leaves the player on). None for a battle the table doesn't name. +std::optional story_trainer(std::string_view map, std::string_view battle); + + +// (name, JSON text) of each file in BattleData/, sorted by name. +// Generated at build time (SerialPrograms/cmake/EmbedTextFiles.cmake). +const std::vector>& autostory_battle_json(); + + +void add_tests_AutoStoryBattleData(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp new file mode 100644 index 0000000000..8e61b63dc8 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp @@ -0,0 +1,202 @@ +/* AutoStory Battle Data Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The generated battle data, the trainer each story battle fights, and the + * attacks chosen against trainers' parties and wild Pokemon from it. + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryBattleData.h" +#include "PokemonFRLG_AutoStoryBattleDecisions.h" +#include "PokemonFRLG_AutoStoryParty.h" +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +class Test_AutoStoryBattleData : public UnitTest{ +public: + Test_AutoStoryBattleData(std::string name, std::function body) + : UnitTest("PokemonFRLG::AutoStoryBattleData - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + +const PartyStatus GREEN{.hp_seen = true, .hp_yellow = false, .hp_red = false, .status = StatusCondition::NONE}; + +// The story's Wartortle once Bite is in: Tackle, Bite, Water Gun, Withdraw. +constexpr size_t BITE = 1; +constexpr size_t WATER_GUN = BOTTOM_LEFT_MOVE; + +std::string slot_name(std::optional slot){ + return slot ? std::to_string(*slot) : "none"; +} + +// The slot a wild battle's first turn attacks with, against `species` as +// read off the screen. +size_t wild_turn(const PartyMember& lead, std::string_view species){ + Supplies supplies; + supplies.lead = lead; + supplies.potions = 5; + supplies.wild_foes = wild_foes(species); + BattleDecisions wild(supplies, BattleKind::WILD_FIGHT); + return wild.turn(GREEN).slot; +} + + +// Spot checks against pret: the type chart, Bite, and species' types and +// stats. +UnitTestResult test_data(){ + if (type_effectiveness(PokemonType::WATER, PokemonType::FIRE) != 20 + || type_effectiveness(PokemonType::DARK, PokemonType::PSYCHIC) != 20 + || type_effectiveness(PokemonType::NORMAL, PokemonType::GHOST) != 0 + || type_effectiveness(PokemonType::WATER, PokemonType::NORMAL) != 10 + ){ + return "Expected Water 2x on Fire, Dark 2x on Psychic, Normal 0x on Ghost, Water 1x on Normal."; + } + const MoveData* bite = move_data("bite"); + if (bite == nullptr || bite->power != 60 || bite->type != PokemonType::DARK || bite->pp != 25 || !special_type(bite->type)){ + return "Expected Bite: 60 power, Dark (special in Gen 3), 25 PP."; + } + const SpeciesData* starmie = species_data("starmie"); + if (starmie == nullptr || starmie->first != PokemonType::WATER || starmie->second != PokemonType::PSYCHIC || starmie->sp_attack != 100){ + return "Expected Starmie: Water, Psychic, base Sp. Atk 100."; + } + if (battle_species().size() != 386 || species_data("farfetch-d") == nullptr || species_data("missingno") != nullptr){ + return std::format("Expected the 386 species by the program's slugs, got {}.", battle_species().size()); + } + return true; +} + +// Every battle step in the table fights a trainer its map battles in +// pret's scripts, with a party. +UnitTestResult test_story_trainers(){ + size_t battles = 0; + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + for (const StoryStep& step : checkpoint.steps){ + if (step.kind != StoryStepKind::BATTLE){ + continue; + } + battles++; + const std::string map = step.pose_after ? step.pose_after->map : ""; + const std::optional trainer = story_trainer(map, step.name); + if (!trainer){ + return std::format("{}, {} on {}: no trainer.", checkpoint.id, step.name, map); + } + const std::vector on_map = map_trainers(map); + if (std::find(on_map.begin(), on_map.end(), *trainer) == on_map.end()){ + return std::format("{} on {}: {} isn't one of the map's trainers.", step.name, map, *trainer); + } + if (trainer_party(*trainer).empty()){ + return std::format("{} on {}: {} has no party.", step.name, map, *trainer); + } + } + } + if (battles == 0){ + return "Expected battle steps in the table."; + } + if (trainer_party(*story_trainer("CeruleanCity_Gym", "misty")) != std::vector{"staryu", "starmie"}){ + return "Expected Misty's Staryu and Starmie."; + } + return true; +} + +// Mt. Moon: Super Nerd Miguel's Grimer (Poison) takes Water Gun, with or +// without Bite known: Bite (60, Dark) ties Water Gun (40 x 1.5 STAB), both +// special, and the tie goes to the plan's Water Gun. +UnitTestResult test_miguel_grimer(){ + const std::optional miguel = story_trainer("MtMoon_B2F", "super_nerd_miguel"); + if (!miguel || trainer_party(*miguel) != std::vector{"grimer", "voltorb", "koffing"}){ + return "Expected Miguel's Grimer, Voltorb and Koffing (pret's sParty_SuperNerdMiguel)."; + } + const std::vector leads{grown_to(new_member("squirtle", 5), 17), grown_to(new_member("squirtle", 5), 20)}; + for (const PartyMember& lead : leads){ + for (const std::vector& foes : {std::vector{"grimer"}, trainer_party(*miguel)}){ + const std::optional slot = attack_slot_against(lead, foes); + if (slot != WATER_GUN){ + return std::format("{} against {} foes: expected Water Gun, got slot {}.", lead.species, foes.size(), slot_name(slot)); + } + } + } + return true; +} + +// Bite where it does more than Water Gun: on a Psychic or Ghost foe (2x), +// and on one that resists Water, where Bite's 1x beats Water Gun's +// 0.5 x 1.5 STAB. Against a wild Pokemon as read, and a trainer's party. +UnitTestResult test_bite_wins(){ + const PartyMember wartortle = grown_to(new_member("squirtle", 5), 20); + for (std::string_view foe : {"abra", "starmie", "gastly", "staryu", "oddish", "dratini"}){ + const size_t slot = wild_turn(wartortle, foe); + if (slot != BITE){ + return std::format("A wild {}: expected Bite, got slot {}.", foe, slot); + } + } + for (std::string_view foe : {"geodude", "pidgey", "rattata"}){ + const size_t slot = wild_turn(wartortle, foe); + if (slot != WATER_GUN){ + return std::format("A wild {}: expected Water Gun, got slot {}.", foe, slot); + } + } + if (attack_slot_against(wartortle, trainer_party(*story_trainer("CeruleanCity_Gym", "misty"))) != BITE){ + return "Expected Bite against Misty's party."; + } + return true; +} + +// A wild Pokemon that wasn't read, or a name the data doesn't have, gets +// the plan's order: Water Gun first. +UnitTestResult test_wild_fallback(){ + const PartyMember wartortle = grown_to(new_member("squirtle", 5), 20); + for (std::string_view read : {"", "missingno"}){ + if (!wild_foes(read).empty()){ + return std::format("Expected no foes for \"{}\".", read); + } + const size_t slot = wild_turn(wartortle, read); + if (slot != WATER_GUN || attack_slot(wartortle) != WATER_GUN){ + return std::format("A wild \"{}\": expected the plan's Water Gun, got slot {}.", read, slot); + } + } + return true; +} + +} + + +void add_tests_AutoStoryBattleData(UnitTestDatabase& database){ + database.add("type chart, moves and species from pret", test_data); + database.add("every story battle fights a trainer with a party", test_story_trainers); + database.add("Miguel's Grimer: Water Gun", test_miguel_grimer); + database.add("Bite on Psychic, Ghost and Water-resistant foes", test_bite_wins); + database.add("a wild Pokemon not read: the plan's order", test_wild_fallback); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp index 2ce9fb9725..758c006ccd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -105,8 +105,8 @@ TurnAction BattleDecisions::lead_turn(const PartyStatus& status){ return move_turn(); } -// The plan's attack with PP left, or against a trainer whose party is -// known, the one that does it most damage. While the story doesn't know +// The plan's attack with PP left, or against known foes (a trainer's +// party, the wild Pokemon read), the one that does them most damage. While the story doesn't know // all four moves, the bottom left one (Bubble from Lv7), which the cursor // can't reach while that slot is empty, so before Bubble it stays on // Tackle. @@ -117,9 +117,7 @@ TurnAction BattleDecisions::move_turn(){ usable.moves[refused.first].pp = 0; } } - const std::optional slot = m_kind == BattleKind::TRAINER - ? attack_slot_against(usable, m_supplies.foes) - : attack_slot(usable); + const std::optional slot = attack_slot_against(usable, m_kind == BattleKind::TRAINER ? m_supplies.foes : m_supplies.wild_foes); if (!slot){ return TurnAction{.choice = TurnChoice::MOVE, .slot = BOTTOM_LEFT_MOVE}; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index a5ef7c37c5..43f1310bce 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -15,6 +15,7 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStorySummary.h" @@ -153,9 +154,10 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ if (advance_text(env.console, env.context, BATTLE_TEXT_TIMEOUT, true) != TextEnd::BATTLE){ return Pokemon::outcome_failed("no_battle"); } - env.supplies.foes = trainer_party(step.name); + const std::optional trainer = step.pose_after ? story_trainer(step.pose_after->map, step.name) : std::nullopt; + env.supplies.foes = trainer ? trainer_party(*trainer) : std::vector{}; if (!env.supplies.foes.empty()){ - env.console.log("Story: " + step.name + "'s party is known; attacks are chosen against it."); + env.console.log("Story: " + step.name + " is " + std::string(*trainer) + "; attacks are chosen against the party."); } const BattleEnd end = fight_battle(env.console, env.context, env.supplies, BattleKind::TRAINER, env.checks, env.language); env.supplies.foes.clear(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp index 989e1c995e..8e474b2dd1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp @@ -5,7 +5,8 @@ */ #include -#include +#include +#include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryParty.h" namespace PokemonAutomation{ @@ -88,113 +89,6 @@ constexpr Evolution EVOLUTIONS[] = { {.species = "magikarp", .evolution = {.into = "gyarados", .level = 20}}, }; -// pret/pokefirered include/constants/pokemon.h TYPE_*, MYSTERY left out. -enum class Type{ - NORMAL, FIGHTING, FLYING, POISON, GROUND, ROCK, BUG, GHOST, STEEL, - FIRE, WATER, GRASS, ELECTRIC, PSYCHIC, ICE, DRAGON, DARK, -}; - -struct MoveData{ - std::string_view move; - uint8_t pp = 0; - // Flail's and Dragon Rage's damage doesn't come from their power, 1. - uint8_t power = 0; - Type type = Type::NORMAL; -}; - -// pret/pokefirered src/data/battle_moves.h. -constexpr MoveData MOVES[] = { - {.move = "tackle", .pp = 35, .power = 35, .type = Type::NORMAL}, - {.move = "tail-whip", .pp = 30, .power = 0, .type = Type::NORMAL}, - {.move = "bubble", .pp = 30, .power = 20, .type = Type::WATER}, - {.move = "withdraw", .pp = 40, .power = 0, .type = Type::WATER}, - {.move = "water-gun", .pp = 25, .power = 40, .type = Type::WATER}, - {.move = "bite", .pp = 25, .power = 60, .type = Type::DARK}, - {.move = "rapid-spin", .pp = 40, .power = 20, .type = Type::NORMAL}, - {.move = "protect", .pp = 10, .power = 0, .type = Type::NORMAL}, - {.move = "rain-dance", .pp = 5, .power = 0, .type = Type::WATER}, - {.move = "skull-bash", .pp = 15, .power = 100, .type = Type::NORMAL}, - {.move = "hydro-pump", .pp = 5, .power = 120, .type = Type::WATER}, - {.move = "splash", .pp = 40, .power = 0, .type = Type::NORMAL}, - {.move = "flail", .pp = 15, .power = 1, .type = Type::NORMAL}, - {.move = "thrash", .pp = 20, .power = 90, .type = Type::NORMAL}, - {.move = "dragon-rage", .pp = 10, .power = 1, .type = Type::DRAGON}, - {.move = "leer", .pp = 30, .power = 0, .type = Type::NORMAL}, - {.move = "twister", .pp = 20, .power = 40, .type = Type::DRAGON}, - {.move = "dragon-dance", .pp = 20, .power = 0, .type = Type::DRAGON}, - {.move = "hyper-beam", .pp = 5, .power = 150, .type = Type::NORMAL}, -}; - -// The types of the party's species and of the trainers' in -// TRAINER_PARTIES (pret/pokefirered src/data/pokemon/species_info.h). -struct SpeciesTypes{ - std::string_view species; - Type first; - Type second; -}; -constexpr SpeciesTypes SPECIES_TYPES[] = { - {.species = "squirtle", .first = Type::WATER, .second = Type::WATER}, - {.species = "wartortle", .first = Type::WATER, .second = Type::WATER}, - {.species = "blastoise", .first = Type::WATER, .second = Type::WATER}, - {.species = "magikarp", .first = Type::WATER, .second = Type::WATER}, - {.species = "gyarados", .first = Type::WATER, .second = Type::FLYING}, - {.species = "pidgeotto", .first = Type::NORMAL, .second = Type::FLYING}, - {.species = "abra", .first = Type::PSYCHIC, .second = Type::PSYCHIC}, - {.species = "rattata", .first = Type::NORMAL, .second = Type::NORMAL}, - {.species = "bulbasaur", .first = Type::GRASS, .second = Type::POISON}, - {.species = "staryu", .first = Type::WATER, .second = Type::WATER}, - {.species = "starmie", .first = Type::WATER, .second = Type::PSYCHIC}, -}; - -// pret/pokefirered src/battle_main.c gTypeEffectiveness, the rows of the -// types the party's moves have (Normal, Water, Dark, Dragon): every -// pairing not here is 1x. In tenths: 20 is 2x, 5 is 0.5x. -struct Effectiveness{ - Type attack; - Type defend; - uint8_t tenths; -}; -constexpr Effectiveness TYPE_CHART[] = { - {.attack = Type::NORMAL, .defend = Type::ROCK, .tenths = 5}, - {.attack = Type::NORMAL, .defend = Type::STEEL, .tenths = 5}, - {.attack = Type::NORMAL, .defend = Type::GHOST, .tenths = 0}, - {.attack = Type::WATER, .defend = Type::FIRE, .tenths = 20}, - {.attack = Type::WATER, .defend = Type::WATER, .tenths = 5}, - {.attack = Type::WATER, .defend = Type::GRASS, .tenths = 5}, - {.attack = Type::WATER, .defend = Type::GROUND, .tenths = 20}, - {.attack = Type::WATER, .defend = Type::ROCK, .tenths = 20}, - {.attack = Type::WATER, .defend = Type::DRAGON, .tenths = 5}, - {.attack = Type::DARK, .defend = Type::FIGHTING, .tenths = 5}, - {.attack = Type::DARK, .defend = Type::PSYCHIC, .tenths = 20}, - {.attack = Type::DARK, .defend = Type::GHOST, .tenths = 20}, - {.attack = Type::DARK, .defend = Type::DARK, .tenths = 5}, - {.attack = Type::DARK, .defend = Type::STEEL, .tenths = 5}, - {.attack = Type::DRAGON, .defend = Type::DRAGON, .tenths = 20}, - {.attack = Type::DRAGON, .defend = Type::STEEL, .tenths = 5}, -}; - -// The species of a trainer's party, by the table's battle step, from -// pret/pokefirered src/data/trainer_parties.h. -struct TrainerParty{ - std::string_view battle; - std::array species; -}; -constexpr TrainerParty TRAINER_PARTIES[] = { - // sParty_RivalCeruleanBulbasaur: Lv17, Lv16, Lv15, Lv18. - {.battle = "rival_cerulean", .species = {"pidgeotto", "abra", "rattata", "bulbasaur"}}, - // sParty_Misty: Lv18, Lv21. - {.battle = "misty", .species = {"staryu", "starmie"}}, -}; - -const MoveData* move_data(std::string_view move){ - for (const MoveData& entry : MOVES){ - if (entry.move == move){ - return &entry; - } - } - return nullptr; -} - // The story's plan per line (named by its first species): a level-up move // it learns over a full move list, and the move whose slot it takes. Any // other move offered over four is declined. Squirtle's is the speedrun's: @@ -299,47 +193,35 @@ void take_level(PartyMember& member, uint8_t level){ member.moves_through_level = level; } -const SpeciesTypes* species_types(std::string_view species){ - for (const SpeciesTypes& entry : SPECIES_TYPES){ - if (entry.species == species){ - return &entry; - } - } - return nullptr; +// The base stat `attacker` uses `move` with: Attack or Sp. Atk, by the +// move's type. +uint8_t attacking_stat(const SpeciesData& attacker, const MoveData& move){ + return special_type(move.type) ? attacker.sp_attack : attacker.attack; } -// In tenths; 10 for a species the table doesn't have. -size_t effectiveness(Type attack, std::string_view defender){ - const SpeciesTypes* types = species_types(defender); - if (types == nullptr){ - return 10; - } - size_t tenths = 10; - for (Type defend : {types->first, types->second}){ - for (const Effectiveness& entry : TYPE_CHART){ - if (entry.attack == attack && entry.defend == defend){ - tenths = tenths * entry.tenths / 10; - } - } - if (types->second == types->first){ - break; - } +// In tenths. +size_t effectiveness(const MoveData& move, const SpeciesData& defender){ + size_t tenths = type_effectiveness(move.type, defender.first); + if (defender.second != defender.first){ + tenths = tenths * type_effectiveness(move.type, defender.second) / 10; } return tenths; } -// `move`'s power times STAB times its effectiveness, summed over `foes`, -// in hundredths of a point. +// `move`'s expected damage, summed over `foes`: its power times STAB +// times its effectiveness times the lead's base attacking stat for it. +// The foe's Defense and Sp. Def, levels, IVs, EVs, natures and accuracy +// are left out. Each foe must be in species_data(). size_t expected_damage(const PartyMember& member, std::string_view move, const std::vector& foes){ const MoveData* data = move_data(move); - if (data == nullptr){ + const SpeciesData* own = species_data(member.species); + if (data == nullptr || own == nullptr){ return 0; } - const SpeciesTypes* own = species_types(member.species); - const bool stab = own != nullptr && (own->first == data->type || own->second == data->type); + const bool stab = own->first == data->type || own->second == data->type; size_t damage = 0; for (const std::string& foe : foes){ - damage += (size_t)data->power * (stab ? 15 : 10) * effectiveness(data->type, foe); + damage += (size_t)data->power * (stab ? 15 : 10) * effectiveness(*data, *species_data(foe)) * attacking_stat(*own, *data); } return damage; } @@ -485,30 +367,27 @@ std::optional attack_slot(const PartyMember& member){ return TOP_LEFT_MOVE; } -std::vector trainer_party(std::string_view battle){ +std::vector trainer_party(std::string_view trainer){ std::vector party; - for (const TrainerParty& trainer : TRAINER_PARTIES){ - if (trainer.battle != battle){ - continue; - } - for (std::string_view species : trainer.species){ - if (!species.empty()){ - party.emplace_back(species); - } - } + for (const TrainerMon& mon : trainer_mons(trainer)){ + party.push_back(mon.species); } return party; } std::optional attack_slot_against(const PartyMember& member, const std::vector& foes){ const std::optional plan = attack_slot(member); - if (foes.empty() || !plan){ + std::vector known; + std::ranges::copy_if(foes, std::back_inserter(known), [](const std::string& foe){ + return species_data(foe) != nullptr; + }); + if (known.empty() || !plan){ return plan; } std::optional best; size_t best_damage = 0; for (size_t slot : attack_order(member)){ - const size_t damage = expected_damage(member, member.moves[slot].move, foes); + const size_t damage = expected_damage(member, member.moves[slot].move, known); if (member.moves[slot].pp > 0 && damage > best_damage){ best = slot; best_damage = damage; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h index 468975f473..400d008dd1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h @@ -4,9 +4,10 @@ * * The lead's moves as the story knows them, and the data its choices come * from: level-up moves and evolutions (pret/pokefirered - * src/data/pokemon/level_up_learnsets.h, evolution.h), each move's PP - * (src/data/battle_moves.h), which new move takes which old one's slot, - * and which moves the lead attacks with first. + * src/data/pokemon/level_up_learnsets.h, evolution.h), which new move + * takes which old one's slot, and which moves the lead attacks with + * first. Moves' PP, power and type, species' types and trainers' parties + * are the generated battle data (PokemonFRLG_AutoStoryBattleData.h). * * The story starts from the moves read off the lead's summary when a run * loads a save (member_from_summary()), else from the moves a checkpoint's @@ -117,18 +118,22 @@ void evolve(PartyMember& member); // while the story doesn't know all its moves (fewer than four, not read). std::optional attack_slot(const PartyMember& member); -// The species of a trainer's party, by the table's name for the battle -// ("rival_cerulean"), from pret/pokefirered src/data/trainer_parties.h -// (the rival's for a player who took Squirtle). Empty for a battle whose -// party the story doesn't know. -std::vector trainer_party(std::string_view battle); - -// The slot to attack a trainer whose party is `foes` with, any of them -// as likely to be out: the move with PP left that does the most expected -// damage, its power times STAB times its type's effectiveness against -// each foe (pret's type chart), ties going to attack_slot()'s order. -// attack_slot() itself with no foes, or while the story doesn't know all -// its moves. +// The species of `trainer`'s party, in order: pret's constant +// ("TRAINER_LEADER_MISTY", see story_trainer()), from pret/pokefirered +// src/data/trainer_parties.h. Empty for a trainer the data doesn't have. +std::vector trainer_party(std::string_view trainer); + +// The slot to attack `foes` with, any of them as likely to be out: the +// move with PP left that does the most expected damage, ties going to +// attack_slot()'s order. Expected damage, summed over the foes, is power +// times STAB times the type chart, times the lead's base Attack or Sp. +// Atk, whichever the move's type uses (Gen 3: Fire, Water, Grass, +// Electric, Psychic, Ice, Dragon and Dark are special): Water Gun and Bite +// compare on Sp. Atk, Tackle on Attack. The foe's defenses are left out, +// so a frail foe's low Defense doesn't pull Tackle ahead of a type +// advantage. A foe the data doesn't +// have is left out; with none left, or while the story doesn't know all +// the lead's moves, attack_slot() itself (the plan's order). std::optional attack_slot_against(const PartyMember& member, const std::vector& foes); // The PP left in the damaging moves it knows. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp index 55cddac2e8..7d1c6b8ab8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp @@ -16,6 +16,7 @@ #include "Common/Cpp/Logging/AbstractLogger.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryBattleDecisions.h" #include "PokemonFRLG_AutoStoryParty.h" @@ -372,8 +373,9 @@ UnitTestResult test_summary_members(Logger&){ // #211: Bite, not Water Gun, against the trainers whose parties resist // Water Gun: the Cerulean rival's Bulbasaur, and Misty's Staryu and // Starmie (Water, Psychic: Bite does twice). Once Bite is out of PP, -// Tackle (35) over the resisted Water Gun (40 x 1.5 x 0.5); and the battle -// loop picks Bite against a known party, but not in a wild battle. +// Tackle (35, on Bulbasaur's lower Defense) over the resisted Water Gun +// (40 x 1.5 x 0.5); and the battle loop picks Bite against a known party, +// but not in a wild battle, which has its own foes (BattleData tests). UnitTestResult test_attack_by_matchup(Logger&){ PartyMember wartortle = grown_to(new_member("squirtle", 5), 20); const std::vector bulbasaur{"bulbasaur"}; @@ -388,8 +390,8 @@ UnitTestResult test_attack_by_matchup(Logger&){ }; const std::vector cases{ {.name = "the rival's Bulbasaur", .foes = bulbasaur}, - {.name = "the Cerulean rival's party", .foes = trainer_party("rival_cerulean")}, - {.name = "Misty's party", .foes = trainer_party("misty")}, + {.name = "the Cerulean rival's party", .foes = trainer_party("TRAINER_RIVAL_CERULEAN_BULBASAUR")}, + {.name = "Misty's party", .foes = trainer_party("TRAINER_LEADER_MISTY")}, }; for (const Case& c : cases){ const std::optional slot = attack_slot_against(wartortle, c.foes); @@ -397,8 +399,9 @@ UnitTestResult test_attack_by_matchup(Logger&){ return std::format("{} ({}): expected Bite (slot 1), got slot {}.", c.name, joined(c.foes), slot ? std::to_string(*slot) : "none"); } } - if (trainer_party("rival_cerulean") != std::vector{"pidgeotto", "abra", "rattata", "bulbasaur"}){ - return "Expected the Cerulean rival's party from pret's sParty_RivalCeruleanBulbasaur, got " + joined(trainer_party("rival_cerulean")) + "."; + const std::vector rival = trainer_party(story_trainer("CeruleanCity", "rival_cerulean").value_or("")); + if (rival != std::vector{"pidgeotto", "abra", "rattata", "bulbasaur"}){ + return "Expected the Cerulean rival's party from pret's sParty_RivalCeruleanBulbasaur, got " + joined(rival) + "."; } PartyMember no_bite = wartortle; @@ -417,19 +420,19 @@ UnitTestResult test_attack_by_matchup(Logger&){ BattleDecisions wild(supplies, BattleKind::WILD_FIGHT); supplies.potions = 5; if (wild.turn(GREEN).slot != *water_gun){ - return "Expected a wild battle to keep the plan's order (Water Gun), whatever foes are set."; + return "Expected a wild battle with nothing read to keep the plan's order (Water Gun), whatever foes are set."; } return true; } -// A trainer whose party the story doesn't know, and no foes at all, get -// the plan's order: Water Gun first. +// A trainer the data doesn't have, a species it doesn't have, and no foes +// at all get the plan's order: Water Gun first. UnitTestResult test_attack_unknown_foe(Logger&){ const PartyMember wartortle = grown_to(new_member("squirtle", 5), 20); - if (!trainer_party("bug_catcher_cale").empty()){ - return "Expected no party for a trainer the story doesn't know."; + if (!trainer_party("TRAINER_NOBODY").empty() || story_trainer("Route24", "nobody")){ + return "Expected no party for a trainer the data doesn't have."; } - const std::vector> unknown{{}, {"missingno"}, trainer_party("bug_catcher_cale")}; + const std::vector> unknown{{}, {"missingno"}, trainer_party("TRAINER_NOBODY")}; for (const std::vector& foes : unknown){ if (attack_slot_against(wartortle, foes) != attack_slot(wartortle) || attack_slot(wartortle) != BOTTOM_LEFT_MOVE){ return "Expected the plan's order (Water Gun) against " + joined(foes) + "."; @@ -737,6 +740,7 @@ void add_tests_AutoStoryParty(UnitTestDatabase& database){ database.add("a YES/NO with no move list after it changes no move", test_yes_no_without_move_list); database.add("a disabled move: left alone while Disable lasts, PP back", test_disabled_move); database.add("a move turned down: the move list, then the menu sooner than a turn", test_move_refusal_watch); + add_tests_AutoStoryBattleData(database); } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index f6e0827969..0c9470e880 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1839,6 +1839,9 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp diff --git a/devtools/maps/frlg_battle_data.py b/devtools/maps/frlg_battle_data.py new file mode 100644 index 0000000000..b56cabb61c --- /dev/null +++ b/devtools/maps/frlg_battle_data.py @@ -0,0 +1,195 @@ +"""Writes the FRLG battle data AutoStory chooses its attacks from, as JSON, from the pret/pokefirered decompilation. + +Usage: + python3 devtools/maps/frlg_battle_data.py --out SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData + python3 devtools/maps/frlg_battle_data.py --out --check + +Reads, at frlg_maps.COMMIT (cached in --cache like frlg_maps.py): +- src/battle_main.c gTypeEffectiveness: type_chart.json, each pairing that + isn't 1x, in tenths; +- src/data/pokemon/species_info.h: species.json, every species' two types + and base Attack and Sp. Atk; +- src/data/battle_moves.h: moves.json, every move's power, type and PP; +- src/data/trainers.h and src/data/trainer_parties.h: trainers.json, every + trainer's party: species, level, and the moves where the party gives them + (not the Ruby/Sapphire placeholders, DUMMY_TRAINER_MON); +- data/maps/*/scripts.inc, map.json and data/scripts/trainers.inc: + map_trainers.json, the trainers each map battles (trainerbattle_* + TRAINER_X in its scripts or its objects'). +Names are the program's slugs: SPECIES_MR_MIME is "mr-mime", MOVE_WATER_GUN +"water-gun", TYPE_WATER "water". One entry per line, so a change in pret +shows as a line in the diff. --check writes nothing: it regenerates the files +and fails if any differs. +""" +import argparse +import json +import os +import re +import sys +from concurrent.futures import ThreadPoolExecutor + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +import frlg_maps # noqa: E402 + +# Slugs the plain rule (lower case, '_' to '-') gets wrong: the program's +# names, from Resources/Pokemon/Pokedex/Pokedex-National.json and PokeAPI. +SPECIES_SLUGS = {'FARFETCHD': 'farfetch-d'} +MOVE_SLUGS = { + 'FAINT_ATTACK': 'feint-attack', + 'HI_JUMP_KICK': 'high-jump-kick', + 'SMELLING_SALT': 'smelling-salts', + 'VICE_GRIP': 'vise-grip', +} +# Not species a battle can show. +SKIPPED_SPECIES = re.compile(r'NONE$|EGG$|OLD_UNOWN_') +# gTypeEffectiveness's multipliers, in tenths. +MULTIPLIERS = {'TYPE_MUL_NO_EFFECT': 0, 'TYPE_MUL_NOT_EFFECTIVE': 5, 'TYPE_MUL_SUPER_EFFECTIVE': 20} + + +def slug(name, fixes=None): + return (fixes or {}).get(name) or name.lower().replace('_', '-') + + +def type_slug(name): + return name[len('TYPE_'):].lower() + + +def entries(text, prefix): + """(NAME, body) for each designated initializer `[PREFIX_NAME] = { body }`.""" + pattern = re.compile(r'\[' + prefix + r'_(\w+)\]\s*=\s*\{((?:(?!\n \[).)*?)\n \},', re.S) + return pattern.findall(text) + + +def field(body, name): + match = re.search(r'\.' + name + r'\s*=\s*([^,\n]+(?:\{[^}]*\})?)', body) + return match.group(1).strip() if match else None + + +def type_chart(text): + table = re.search(r'gTypeEffectiveness\[\d+\]\s*=\s*\{(.*?)\};', text, re.S).group(1) + chart = [] + for attack, defend, mul in re.findall(r'(TYPE_\w+),\s*(TYPE_\w+),\s*(TYPE_MUL_\w+)', table): + if attack in ('TYPE_FORESIGHT', 'TYPE_ENDTABLE'): + continue + chart.append([type_slug(attack), type_slug(defend), MULTIPLIERS[mul]]) + return chart + + +def species(text): + data = {} + for name, body in entries(text, 'SPECIES'): + if SKIPPED_SPECIES.search(name): + continue + types = re.search(r'\.types\s*=\s*\{(TYPE_\w+),\s*(TYPE_\w+)\}', body) + stats = [int(field(body, f)) for f in ('baseAttack', 'baseSpAttack')] + data[slug(name, SPECIES_SLUGS)] = [type_slug(types.group(1)), type_slug(types.group(2))] + stats + return data + + +def moves(text): + data = {} + for name, body in entries(text, 'MOVE'): + if name == 'NONE': + continue + data[slug(name, MOVE_SLUGS)] = [int(field(body, 'power')), type_slug(field(body, 'type')), int(field(body, 'pp'))] + return data + + +def parties(text): + """sParty_X: [[species, level, [moves]?], ...].""" + data = {} + # A placeholder's {DUMMY_TRAINER_MON} on one line doesn't match. + for name, body in re.findall(r'struct TrainerMon\w+ (sParty_\w+)\[\]\s*=\s*\{\n((?:(?!\nstatic ).)*?)\n\};', text, re.S): + party = [] + for mon in re.findall(r'\{(.*?)\n \}', body, re.S): + member = [slug(field(mon, 'species')[len('SPECIES_'):], SPECIES_SLUGS), int(field(mon, 'lvl'))] + given = re.search(r'\.moves\s*=\s*\{(.*?)\}', mon) + if given: + member.append([slug(m.strip()[len('MOVE_'):], MOVE_SLUGS) for m in given.group(1).split(',') if m.strip() != 'MOVE_NONE']) + party.append(member) + data[name] = party + return data + + +def trainers(text, party_text): + by_party = parties(party_text) + data = {} + for name, body in entries(text, 'TRAINER'): + if name == 'NONE': + continue + party = re.search(r'\.party\s*=\s*\w+\((sParty_\w+)\)', body) + # Left out: the Ruby/Sapphire placeholders (DUMMY_TRAINER_MON). + if party and party.group(1) in by_party: + data['TRAINER_' + name] = by_party[party.group(1)] + return data + + +def script_trainers(text): + """{label: TRAINER_X} for each script whose first line battles a trainer.""" + return dict(re.findall(r'^(\w+)::\n\s*trainerbattle\w* (TRAINER_\w+)', text, re.M)) + + +def map_trainers(decomp): + """The trainers each map battles: in its own scripts, and its objects' + scripts in data/scripts/trainers.inc (most trainers on routes).""" + groups = json.loads(decomp.read('data/maps/map_groups.json')) + names = sorted(m for group in groups['group_order'] for m in groups[group]) + shared = script_trainers(decomp.read('data/scripts/trainers.inc').decode()) + read = lambda m: (decomp.read(f'data/maps/{m}/scripts.inc').decode(), json.loads(decomp.read(f'data/maps/{m}/map.json'))) + with ThreadPoolExecutor(16) as pool: + sources = list(pool.map(read, names)) + data = {} + for name, (scripts, source) in zip(names, sources): + battled = set(re.findall(r'trainerbattle\w* (TRAINER_\w+)', scripts)) + battled |= {shared[o['script']] for o in source.get('object_events', []) if o.get('script') in shared} + if battled: + data[name] = sorted(battled) + return data + + +def json_lines(data): + """A JSON object (or a list), one entry per line.""" + if isinstance(data, list): + lines = [json.dumps(item) for item in data] + return '[\n' + ',\n'.join(lines) + '\n]\n' + lines = [f'{json.dumps(key)}: {json.dumps(value)}' for key, value in data.items()] + return '{\n' + ',\n'.join(lines) + '\n}\n' + + +def files(decomp): + read = lambda rel: decomp.read(rel).decode() + return { + 'type_chart': json_lines(type_chart(read('src/battle_main.c'))), + 'species': json_lines(species(read('src/data/pokemon/species_info.h'))), + 'moves': json_lines(moves(read('src/data/battle_moves.h'))), + 'trainers': json_lines(trainers(read('src/data/trainers.h'), read('src/data/trainer_parties.h'))), + 'map_trainers': json_lines(map_trainers(decomp)), + } + + +def main(): + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('--commit', default=frlg_maps.COMMIT) + parser.add_argument('--cache', default=os.path.expanduser('~/.cache/pokefirered')) + parser.add_argument('--out', required=True, help='folder of the .json files') + parser.add_argument('--check', action='store_true', help='check the files in --out instead of writing them') + args = parser.parse_args() + generated = files(frlg_maps.Decomp(args.commit, args.cache)) + if args.check: + differ = [] + for name, text in generated.items(): + path = os.path.join(args.out, name + '.json') + if not os.path.exists(path) or open(path, newline='').read() != text: + differ.append(name) + if differ: + sys.exit(f'Differ from the generator: {" ".join(differ)}. Regenerate them without --check.') + print(f'{len(generated)} files in {args.out} match the generator.') + return + os.makedirs(args.out, exist_ok=True) + for name, text in generated.items(): + with open(os.path.join(args.out, name + '.json'), 'w', newline='') as out: + out.write(text) + + +if __name__ == '__main__': + main() From fb4a70f9395eb9237bcc110e49e16b35e083b10f Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 05:04:15 -0800 Subject: [PATCH 70/75] FRLG AutoStory battle: the HP bar's share, the nurse for yellow HP, and move prompts out of step Console B, m48 (00.13 Mt. Moon, 2026-11-03): - The HP bar's share was counted over a 2-row box on the darker top row and one lighter row, so 17/55 HP read as 15% of the bar, and 2% with the box a pixel lower. A new reader (BattleHpBarReader) counts filled columns on the lighter rows in a 5-row box: within a pixel of the 48-pixel bar either way. - The story went into Miguel's battle with yellow HP and no Potion: the nurse was only for red HP. nurse_before_battle() sends it for any HP not green that no Potion healed. - The move list after YES to "Delete a move to make room for BITE?" closed with nothing forgotten; the game asked "Stop learning BITE?" where the story expected the next "Delete a move?", and NO/YES went round 13 times (75 s). A YES/NO right after the move list is now "Stop learning?" (YES, the lead keeps its moves), and past 4 move prompts since a turn the answer is a plain YES, which ends either one. Tests: AutoStoryBattle image tests on four console B frames (new in the CommandLineTests draft), AutoStoryParty tests for the nurse and the move prompts; all red before the fix. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG_BattleHpBarReader.cpp | 87 +++++++++++++++++++ .../Inference/PokemonFRLG_BattleHpBarReader.h | 43 +++++++++ .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 51 ++--------- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 15 ++-- .../PokemonFRLG_AutoStoryBattleDecisions.cpp | 23 +++++ .../PokemonFRLG_AutoStoryBattleDecisions.h | 11 ++- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 6 +- .../PokemonFRLG_AutoStoryItems_Tests.cpp | 38 ++++++++ .../PokemonFRLG_AutoStoryParty_Tests.cpp | 81 +++++++++++++++++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 10 files changed, 306 insertions(+), 51 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp new file mode 100644 index 0000000000..0d2c517a28 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp @@ -0,0 +1,87 @@ +/* Battle HP Bar Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "PokemonFRLG_BattleHpBarReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// As fractions of the 240x160 screen: the bar's fill, 48 pixels from its +// left end. The fill is 3 rows tall, a darker one over two lighter ones, +// and the box it is in bobs down by a pixel: these 5 rows hold both +// lighter rows either way (console B, 2026-11-03). The share filled is +// counted by columns, on the lighter colors: a 2-row box on the darker +// row and one lighter one, whose pixels were counted, read 17/55 HP as +// 15% of the bar, and as 2% with the box a pixel lower. +const ImageFloatBox HP_BAR_BOX(174.0 / 240, 90.0 / 160, 48.0 / 240, 5.0 / 160); + +// A column needs this many pixels of a fill color to count as filled: a +// lighter row is about 6 pixels tall at 1080p. +constexpr size_t MIN_COLUMN_PIXELS = 3; +// Filled columns for the bar to count as seen: about half a game pixel. +// At 1 HP a single pixel of red shows (console B, 2026-11-01, 1/25 HP). +constexpr size_t MIN_SEEN_COLUMNS = 3; + +// The lighter fill colors, measured on console B's captures (2026-11-01): +// green (100, 251, 171), yellow (255, 228, 23), red (255, 113, 68). +std::optional fill_color(uint32_t pixel){ + const int r = (pixel >> 16) & 0xff; + const int g = (pixel >> 8) & 0xff; + const int b = pixel & 0xff; + if (g > 200 && r < 160 && b > 120 && b < 210){ + return HpBarColor::GREEN; + } + if (r > 220 && g > 180 && b < 80){ + return HpBarColor::YELLOW; + } + if (r > 220 && g > 80 && g < 150 && b < 110){ + return HpBarColor::RED; + } + return std::nullopt; +} + +} + + +HpBarReading read_player_hp_bar(const ImageViewRGB32& game){ + const ImageViewRGB32 bar = extract_box_reference(game, HP_BAR_BOX); + size_t counts[3] = {}; + size_t filled = 0; + for (size_t x = 0; x < bar.width(); x++){ + size_t column = 0; + for (size_t y = 0; y < bar.height(); y++){ + const std::optional color = fill_color(bar.pixel(x, y)); + if (color){ + counts[(size_t)*color]++; + column++; + } + } + if (column >= MIN_COLUMN_PIXELS){ + filled++; + } + } + HpBarReading reading; + reading.seen = filled >= MIN_SEEN_COLUMNS; + reading.fill = bar.width() == 0 ? 0 : double(filled) / bar.width(); + const size_t* most = std::max_element(counts, counts + 3); + reading.color = HpBarColor(most - counts); + return reading; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h new file mode 100644 index 0000000000..0a34d8677e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h @@ -0,0 +1,43 @@ +/* Battle HP Bar Reader + * + * From: https://github.com/PokemonAutomation/ + * + * The HP bar in the player's box on a battle screen: its color and how + * much of it is filled. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_BattleHpBarReader_H +#define PokemonAutomation_PokemonFRLG_BattleHpBarReader_H + +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +enum class HpBarColor{ + GREEN, // over half + YELLOW, // over a fifth + RED, +}; + +struct HpBarReading{ + // Some of the bar is filled. + bool seen = false; + HpBarColor color = HpBarColor::GREEN; + // The filled share of the bar's width, 0 to 1: the HP to within a + // pixel of the 48-pixel bar. + double fill = 0; +}; + +// `game`: the game's screen, the Game Box of the video. +HpBarReading read_player_hp_bar(const ImageViewRGB32& game); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 5b0043d814..9aa194324b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -17,6 +17,7 @@ #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyMenuDetector.h" @@ -68,41 +69,11 @@ constexpr Milliseconds AFTER_BATTLE_TEXT = 60000ms; // The move list to fade in after "Delete a move?", and its cursor to move. constexpr Milliseconds MOVE_LIST_TIMEOUT = 5000ms; -// In the player's box, as fractions of the 240x160 screen: the HP bar's -// fill, which grows from its left end, and the status badge left of the -// HP numbers. The box bobs by a pixel; these keep a pixel inside. -const ImageFloatBox HP_BAR_BOX(174.0 / 240, 91.0 / 160, 48.0 / 240, 2.0 / 160); +// In the player's box, as a fraction of the 240x160 screen: the status +// badge left of the HP numbers. The box bobs by a pixel; this keeps a +// pixel inside. const ImageFloatBox STATUS_BADGE_BOX(146.0 / 240, 99.0 / 160, 12.0 / 240, 4.0 / 160); - -struct HpCounts{ - size_t green = 0; - size_t yellow = 0; - size_t red = 0; - size_t total = 0; -}; - -HpCounts count_hp_colors(const ImageViewRGB32& image){ - HpCounts counts; - for (size_t y = 0; y < image.height(); y++){ - for (size_t x = 0; x < image.width(); x++){ - const uint32_t pixel = image.pixel(x, y); - const int r = (pixel >> 16) & 0xff; - const int g = (pixel >> 8) & 0xff; - const int b = pixel & 0xff; - counts.total++; - if (g > 200 && r < 160 && b > 120 && b < 210){ - counts.green++; - }else if (r > 220 && g > 180 && b < 80){ - counts.yellow++; - }else if (r > 220 && g > 80 && g < 150 && b < 110){ - counts.red++; - } - } - } - return counts; -} - StatusCondition read_status_badge(const ImageViewRGB32& badge){ const ImageStats stats = image_stats(badge); const double r = stats.average.r; @@ -836,16 +807,12 @@ const char* status_name(StatusCondition status){ PartyStatus read_party_status(const ImageViewRGB32& screen){ const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); - const HpCounts counts = count_hp_colors(extract_box_reference(game, HP_BAR_BOX)); - // At 1 HP the red sliver was 32 of the box's 4000 pixels (console B, - // 2026-11-01, 1/25 HP). - const size_t seen = counts.total / 200 + 1; + const HpBarReading bar = read_player_hp_bar(game); PartyStatus status; - const size_t most = std::max({counts.green, counts.yellow, counts.red}); - status.hp_seen = most >= seen; - status.hp_yellow = status.hp_seen && counts.yellow == most; - status.hp_red = status.hp_seen && !status.hp_yellow && counts.red == most; - status.hp_fill = counts.total == 0 ? 0 : double(counts.green + counts.yellow + counts.red) / counts.total; + status.hp_seen = bar.seen; + status.hp_yellow = bar.seen && bar.color == HpBarColor::YELLOW; + status.hp_red = bar.seen && bar.color == HpBarColor::RED; + status.hp_fill = bar.fill; status.status = read_status_badge(extract_box_reference(game, STATUS_BADGE_BOX)); return status; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index 6536a174e3..1c074a07ad 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -87,6 +87,12 @@ void healed_by_nurse(Supplies& supplies); // The lead's attacks are low on PP: the nurse before a fight that needs them. bool attacks_low_on_pp(const Supplies& supplies); +// Before a trainer's battle, once the items are used: the nurse for HP +// not green (no Potion left to heal it), a status no item cured, or +// attacks low on PP. Yellow HP counts (console B, 2026-11-03: 17/55 HP +// and no Potion into Miguel's battle, which only red would have stopped). +bool nurse_before_battle(const Supplies& supplies); + enum class BattleKind{ WILD_RUN, // RUN, or fight after a few "Can't escape!" WILD_FIGHT, // fight for EXP with green HP, no status and 2 Potions, else RUN @@ -124,16 +130,15 @@ std::vector set_from_loaded_bag(Supplies& supplies, Supplies& saved std::vector read_items_pocket(ConsoleHandle& console, ProControllerContext& context, Language language); -// What the HP bar and the status badge of the player's Pokemon show, on a -// battle screen with its box. Colors measured on console B's captures -// (2026-11-01): the bar's fill green (100, 251, 171), yellow -// (255, 228, 23), red (255, 113, 68); the badge's place off-white +// What the HP bar (read_player_hp_bar()) and the status badge of the +// player's Pokemon show, on a battle screen with its box. The badge's +// place measured on console B's captures (2026-11-01): off-white // (255, 255, 217) with no status, (228, 168, 212) for PSN. struct PartyStatus{ bool hp_seen = false; bool hp_yellow = false; bool hp_red = false; - // The HP bar's colored share, 0 to 1, for the log. + // The HP bar's filled share of its width, 0 to 1, for the log. double hp_fill = 0; StatusCondition status = StatusCondition::NONE; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp index 758c006ccd..9c979d7590 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -45,6 +45,8 @@ constexpr Milliseconds REFUSED_WITHIN = std::chrono::milliseconds(7000); // Below this much PP left in the lead's attacks, the nurse before a fight // that needs them: about a trainer's worth of turns. constexpr size_t LOW_ATTACK_PP = 10; +// The move prompts a turn can bring: two moves offered, NO then YES each. +constexpr int MOVE_PROMPTS = 4; } @@ -60,6 +62,10 @@ bool attacks_low_on_pp(const Supplies& supplies){ return attack_slot(supplies.lead).has_value() && attack_pp(supplies.lead) < LOW_ATTACK_PP; } +bool nurse_before_battle(const Supplies& supplies){ + return supplies.hurt || supplies.status != StatusCondition::NONE || attacks_low_on_pp(supplies); +} + BattleDecisions::BattleDecisions(Supplies& supplies, BattleKind kind) : m_supplies(supplies) @@ -68,6 +74,8 @@ BattleDecisions::BattleDecisions(Supplies& supplies, BattleKind kind) TurnAction BattleDecisions::turn(const PartyStatus& status){ m_turns++; + m_move_prompts = 0; + m_before_forget.reset(); count_down_refused(); m_last_move_slot.reset(); if (!m_lost){ @@ -182,6 +190,20 @@ PromptAnswer BattleDecisions::prompt(bool lead_box_gone){ // NO tries to run; if that fails, the party list opens. return PromptAnswer{.answer = m_kind == BattleKind::TRAINER ? YesNo::YES : YesNo::NO}; } + m_move_prompts++; + if (m_before_forget){ + // A YES/NO right after the move list: it closed with no move + // forgotten, and this is "Stop learning ?" (console B, + // 2026-11-03, Miguel's battle). The lead keeps its moves. + m_supplies.lead = std::move(*m_before_forget); + m_before_forget.reset(); + return PromptAnswer{.answer = YesNo::YES}; + } + if (m_move_prompts > MOVE_PROMPTS){ + // More than the move prompts can be: YES ends either one, as + // "Delete a move?" opens the move list, which the loop's B closes. + return PromptAnswer{.answer = YesNo::YES}; + } if (m_declined_delete){ // "Stop learning ?" YES; NO would ask "Delete a move?" again. m_declined_delete = false; @@ -190,6 +212,7 @@ PromptAnswer BattleDecisions::prompt(bool lead_box_gone){ PartyMember learning = m_supplies.lead; const LearnDecision decision = learn_move(learning); if (decision.forget_slot){ + m_before_forget = m_supplies.lead; return PromptAnswer{.answer = YesNo::YES, .forget_slot = decision.forget_slot, .learned = std::move(learning)}; } m_supplies.lead = std::move(learning); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h index 3df8ef806c..7505efae52 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h @@ -101,7 +101,11 @@ class BattleDecisions{ // A YES/NO in or after the battle. With the lead's box gone and the // opponent's there, it is "Use next POKEMON?"; else the move prompts: - // "Delete a move to make room?", then "Stop learning?" after a NO. + // "Delete a move to make room?", then "Stop learning?" after a NO, or + // after YES and a move list closed with nothing forgotten. Past + // MOVE_PROMPTS since the last turn, a plain YES, which ends them + // either way (console B, 2026-11-03: NO and YES out of step with the + // game went round for 75 s). PromptAnswer prompt(bool lead_box_gone); // The party list opened with the lead fainted: the slot to send in, @@ -131,6 +135,11 @@ class BattleDecisions{ bool m_lost = false; // NO was answered to "Delete a move?": "Stop learning?" comes next. bool m_declined_delete = false; + // The move prompts since the last turn. + int m_move_prompts = 0; + // YES was answered to "Delete a move?": the lead as it was before. + // A YES/NO before the next turn means nothing was forgotten. + std::optional m_before_forget; std::optional m_last_move_slot; // The slots the game turned down, and the turns until they are tried again. std::map m_refused; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 43f1310bce..6afda3f039 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -169,8 +169,8 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ } // HP and status are the battle loop's last reading. Items first (an -// Antidote, a Parlyz Heal, a Potion); the nurse only for red HP with no -// Potion left, a status no item here cures, or attacks low on PP. +// Antidote, a Parlyz Heal, a Potion); then the nurse as +// nurse_before_battle() says. Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ Supplies& supplies = env.supplies; env.console.log(std::format( @@ -178,7 +178,7 @@ Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ supplies.hp_red ? "red" : supplies.hurt ? "yellow" : "green", status_name(supplies.status), supplies.potions )); recover_after_battle(env.console, env.context, supplies, env.checks, env.language); - if (!supplies.hp_red && supplies.status == StatusCondition::NONE && !attacks_low_on_pp(supplies)){ + if (!nurse_before_battle(supplies)){ return Pokemon::outcome_ok(); } Outcome walked = walk_route(env, state, step); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index 380b03db46..e568269e39 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -6,8 +6,10 @@ * */ +#include #include #include +#include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Logging/AbstractLogger.h" #include "Common/Cpp/TestRunners/UnitTest.h" @@ -194,6 +196,38 @@ class Test_BattleShows : public ImageUnitTest{ bool m_expected; }; +// read_party_status() on console B's captures: the bar's color, and its +// colored share within a pixel of the 48-pixel bar of `hp` / `max_hp`. +// Console B, 2026-11-03, before Miguel: 17/55 HP read as 15% of the bar, +// then 2% with the box a pixel lower. +class Test_PartyHp : public ImageUnitTest{ +public: + Test_PartyHp(const std::string& image, std::string_view color, int hp, int max_hp) + : ImageUnitTest("PokemonFRLG::AutoStoryBattle - " + image, {image}) + , m_color(color) + , m_share(double(hp) / max_hp) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const PartyStatus status = read_party_status(images[0]); + const std::string_view color = !status.hp_seen ? "none" : status.hp_red ? "red" : status.hp_yellow ? "yellow" : "green"; + if (color != m_color){ + return std::format("Expected an HP bar read as {}, got {}.", m_color, color); + } + if (std::abs(status.hp_fill - m_share) > 1.0 / 48){ + return std::format("Expected {:.0f}% of the bar, got {:.0f}%.", 100 * m_share, 100 * status.hp_fill); + } + return true; + } + +private: + std::string_view m_color; + double m_share; +}; + } @@ -209,6 +243,10 @@ void add_tests_AutoStoryItems(UnitTestDatabase& database){ // text box (console B, 2026-11-03: 9 minutes of A and B there). database.add("PokemonFRLG/WildEncounterReader/eng_chansey.jpg", true); database.add("PokemonFRLG/AutoStoryBattle/MtMoonB2F_AfterRun_False.png", false); + database.add("PokemonFRLG/AutoStoryBattle/MtMoon1F_HpGreen_Full.png", "green", 45, 45); + database.add("PokemonFRLG/AutoStoryBattle/MtMoon1F_HpGreen_27of45.png", "green", 27, 45); + database.add("PokemonFRLG/AutoStoryBattle/MtMoonB2F_HpYellow_17of55.png", "yellow", 17, 55); + database.add("PokemonFRLG/AutoStoryBattle/MtMoonB2F_HpYellow_17of55_BarLow.png", "yellow", 17, 55); // The battle's choices, registered here to keep add_tests() within its size. add_tests_AutoStoryParty(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp index 7d1c6b8ab8..1b5388de98 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp @@ -723,6 +723,84 @@ UnitTestResult test_move_refusal_watch(Logger&){ return true; } +// Regression, console B 2026-11-03, Miguel's battle (m48): the move list +// opened after YES to "Delete a move to make room for BITE?", and closed +// with no move forgotten, so the game asked "Stop learning BITE?" where +// the story expected the next move's "Delete a move?". NO there and YES +// at "Delete a move?" went round 13 times (75 s), until presses by time +// ended it. A YES/NO right after the move list is "Stop learning?": YES, +// and the lead keeps its moves. +UnitTestResult test_move_list_closed(Logger&){ + enum class Prompt{DELETE, STOP}; + Supplies supplies; + supplies.lead = squirtle_before_miguel(); + BattleDecisions decisions(supplies, BattleKind::TRAINER); + decisions.turn(GREEN); + Prompt prompt = Prompt::DELETE; + for (int answers = 1; answers <= 8; answers++){ + const PromptAnswer answer = decisions.prompt(false); + if (answer.learned){ + // The move list showed, as the loop saw it. + supplies.lead = *answer.learned; + } + if (prompt == Prompt::STOP && answer.answer == YesNo::YES){ + const std::vector before{"water-gun", "tail-whip", "bubble", "withdraw"}; + if (move_names(supplies.lead) != before){ + return "Expected the moves as before Bite was offered, got " + joined(move_names(supplies.lead)) + "."; + } + return true; + } + // The move list closes with nothing forgotten: "Stop learning?", + // as after NO; NO there asks "Delete a move?" again. + prompt = prompt == Prompt::DELETE ? Prompt::STOP : Prompt::DELETE; + } + return "Expected the move prompts to end within 8 answers."; +} + +// However the YES/NOs come, a few after a turn are all the move prompts +// can be (two moves offered, NO then YES each); after those, YES only, +// which ends either prompt ("Delete a move?": the move list, which the +// loop's B closes; "Stop learning?": done), and the moves stay as they are. +UnitTestResult test_move_prompts_bounded(Logger&){ + Supplies supplies; + supplies.lead = with_moves("wartortle", {"tackle", "bite", "water-gun", "withdraw"}, 19); + BattleDecisions decisions(supplies, BattleKind::TRAINER); + decisions.turn(GREEN); + for (int answers = 1; answers <= 12; answers++){ + const PromptAnswer answer = decisions.prompt(false); + if (answers > 4 && (answer.answer != YesNo::YES || answer.forget_slot)){ + return std::format("Expected a plain YES at the move prompt {} after a turn.", answers); + } + } + const std::vector moves{"tackle", "bite", "water-gun", "withdraw"}; + if (move_names(supplies.lead) != moves){ + return "Expected the moves unchanged, got " + joined(move_names(supplies.lead)) + "."; + } + return true; +} + +// Regression, console B 2026-11-03, before Miguel (m48): yellow HP +// (17/55) and no Potion left, and the story went into the battle, as the +// nurse was only for red HP. After the items, the nurse for any HP not +// green, a status, or attacks low on PP. +UnitTestResult test_nurse_before_battle(Logger&){ + Supplies supplies; + supplies.lead = squirtle_before_miguel(); + if (nurse_before_battle(supplies)){ + return "Expected no nurse with green HP, no status and full PP."; + } + supplies.hurt = true; + if (!nurse_before_battle(supplies)){ + return "Expected the nurse for yellow HP that no Potion healed."; + } + supplies.hurt = false; + supplies.status = StatusCondition::OTHER; + if (!nurse_before_battle(supplies)){ + return "Expected the nurse for a status no item cured."; + } + return true; +} + void add_tests_AutoStoryParty(UnitTestDatabase& database){ database.add("movesets the game gives and the story plays", test_movesets); database.add("move offered and slot forgotten", test_learn_prompts); @@ -740,6 +818,9 @@ void add_tests_AutoStoryParty(UnitTestDatabase& database){ database.add("a YES/NO with no move list after it changes no move", test_yes_no_without_move_list); database.add("a disabled move: left alone while Disable lasts, PP back", test_disabled_move); database.add("a move turned down: the move list, then the menu sooner than a turn", test_move_refusal_watch); + database.add("the move list closed with nothing forgotten: YES to \"Stop learning?\"", test_move_list_closed); + database.add("move prompts after a turn: a plain YES after the first few", test_move_prompts_bounded); + database.add("the nurse before a battle for HP not green with no Potion", test_nurse_before_battle); add_tests_AutoStoryBattleData(database); } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 0c9470e880..3ef0ca6a55 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1773,6 +1773,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleLevelUpReader.h Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.cpp Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h + Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.cpp + Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.cpp Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.h Source/VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.cpp From c3edf46ffd46264f04626344de195c522d6458dd Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 05:19:15 -0800 Subject: [PATCH 71/75] FRLG AutoStory: verify mode, the start checkpoint N runs from its save With the story run options' verify mode on, AutoStory loads the start checkpoint's save and runs it as verify_checkpoint() does: a set number of runs, a soft reset to the save between them, no save at its end. It finishes when enough runs pass and fails the program otherwise. A checkpoint that starts a new game has no save to reload and is refused. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStory.cpp | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 7995396f60..856aba2734 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -5,6 +5,7 @@ */ #include +#include #include "Common/Cpp/Exceptions.h" #include "CommonFramework/Exceptions/OperationFailedException.h" #include "CommonFramework/Notifications/ProgramNotifications.h" @@ -121,10 +122,61 @@ Pokemon::SegmentHooks story_hooks(SingleSwitchProgramEnvironment& env, StoryEnv& return hooks; } +// The game on the save checkpoint `checkpoint` starts from, with the +// supplies and moves read from it. +void load_verify_save( + SingleSwitchProgramEnvironment& env, ProControllerContext& context, StoryEnv& story, const StoryCheckpoint& checkpoint +){ + if (!checkpoint.start){ + throw UserSetupError(env.console, + "Verify mode reloads the checkpoint's save between runs: " + checkpoint.id + " starts a new game and has none." + ); + } + env.console.log("Verify mode: loading the save for " + checkpoint.id + "."); + soft_reset(env.console, context); + story.has_save = true; + check_start_save(env, story, checkpoint); + read_lead_moves(story, checkpoint.menu); + read_bag_supplies(story, checkpoint.menu); +} + +// Verify mode: the start checkpoint run from its save as `policy` says, +// never saving at its end, so every run starts from the same save. +// Throws unless enough runs pass. +void verify_story_checkpoint( + SingleSwitchProgramEnvironment& env, ProControllerContext& context, + const Pokemon::StoryRunOptions& run, const Pokemon::VerifyPolicy& policy, EventNotificationOption& finished +){ + const std::vector& checkpoints = story_checkpoints(); + const StoryCheckpoint& checkpoint = checkpoints[run.start_index()]; + StoryEnv story{env.console, context, checkpoint.supplies, checkpoint.supplies, false, run.checks()}; + load_verify_save(env, context, story, checkpoint); + StoryExecutor executor(story); + executor.set_checks(run.checks()); + executor.set_language(run.language()); + Pokemon::Segment segment = make_story_segment(checkpoints, executor); + Pokemon::SegmentHooks hooks = story_hooks(env, story); + + Pokemon::RunState state; + const Pokemon::VerifyReport report = Pokemon::verify_checkpoint(state, segment, checkpoint.id, policy, hooks); + const std::string summary = std::format( + "AutoStory verify: {} {}/{} passed, {} needed.", checkpoint.id, report.passes, policy.runs, policy.passes_needed + ); + if (!report.verified){ + throw OperationFailedException(ErrorReportMode::NO_ERROR_REPORT, summary); + } + env.console.log(summary); + send_program_finished_notification(env, finished, summary); +} + } void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ + if (const std::optional verify = RUN.VERIFY.policy()){ + verify_story_checkpoint(env, context, RUN, *verify, NOTIFICATION_PROGRAM_FINISH); + return; + } const std::vector& checkpoints = story_checkpoints(); const size_t first = RUN.start_index(); const size_t last = RUN.end_index(); From cb51ddf86b4b17c65ae8192c99d7520927b4ad09 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 06:09:42 -0800 Subject: [PATCH 72/75] FRLG AutoStory battle: a Gen 3 damage calculator, the foe out, and a battle sim for big fights The battle data from pret now carries every base stat, each move's accuracy, priority and effect, and each trainer's AI flags, items, IVs, natures and moves. A Gen 3 damage calculator (CalculateBaseDamage, crit, STAB, type chart in order, random roll) checks out against hand-worked numbers and the Elite Four Farmer's Starmie table. Trainer battles now track the foe out: its name at each battle menu, else the game's own send-out rule after a faint. LOW risk steps use the best expected damage against it; HIGH risk steps (rival, gym leaders, bosses, Elite Four) use a battle sim's move and Potion choices, and refuse the fight before it starts when the sim's win chance is under 70%. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/AutoStory/BattleData/moves.json | 708 ++++----- .../AutoStory/BattleData/species.json | 772 +++++----- .../AutoStory/BattleData/trainers.json | 1278 ++++++++--------- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 8 + .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 13 +- .../PokemonFRLG_AutoStoryBattleData.cpp | 115 +- .../PokemonFRLG_AutoStoryBattleData.h | 78 +- .../PokemonFRLG_AutoStoryBattleData_Tests.cpp | 4 +- .../PokemonFRLG_AutoStoryBattleDecisions.cpp | 47 +- .../PokemonFRLG_AutoStoryBattleSim.cpp | 523 +++++++ .../PokemonFRLG_AutoStoryBattleSim.h | 172 +++ .../PokemonFRLG_AutoStoryBattleSim_Tests.cpp | 310 ++++ .../AutoStory/PokemonFRLG_AutoStoryDamage.cpp | 175 +++ .../AutoStory/PokemonFRLG_AutoStoryDamage.h | 123 ++ .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 37 +- .../PokemonFRLG_AutoStoryFoeTracker.cpp | 77 + .../PokemonFRLG_AutoStoryFoeTracker.h | 72 + .../AutoStory/PokemonFRLG_AutoStoryParty.cpp | 2 +- .../PokemonFRLG_AutoStoryWinChance.cpp | 388 +++++ .../PokemonFRLG_AutoStoryWinChance.h | 63 + SerialPrograms/cmake/SourceFiles.cmake | 9 + devtools/maps/frlg_battle_data.py | 115 +- 22 files changed, 3669 insertions(+), 1420 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json index e619c049fb..64425be1f6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json @@ -1,356 +1,356 @@ { -"pound": [40, "normal", 35], -"karate-chop": [50, "fighting", 25], -"double-slap": [15, "normal", 10], -"comet-punch": [18, "normal", 15], -"mega-punch": [80, "normal", 20], -"pay-day": [40, "normal", 20], -"fire-punch": [75, "fire", 15], -"ice-punch": [75, "ice", 15], -"thunder-punch": [75, "electric", 15], -"scratch": [40, "normal", 35], -"vise-grip": [55, "normal", 30], -"guillotine": [1, "normal", 5], -"razor-wind": [80, "normal", 10], -"swords-dance": [0, "normal", 30], -"cut": [50, "normal", 30], -"gust": [40, "flying", 35], -"wing-attack": [60, "flying", 35], -"whirlwind": [0, "normal", 20], -"fly": [70, "flying", 15], -"bind": [15, "normal", 20], -"slam": [80, "normal", 20], -"vine-whip": [35, "grass", 10], -"stomp": [65, "normal", 20], -"double-kick": [30, "fighting", 30], -"mega-kick": [120, "normal", 5], -"jump-kick": [70, "fighting", 25], -"rolling-kick": [60, "fighting", 15], -"sand-attack": [0, "ground", 15], -"headbutt": [70, "normal", 15], -"horn-attack": [65, "normal", 25], -"fury-attack": [15, "normal", 20], -"horn-drill": [1, "normal", 5], -"tackle": [35, "normal", 35], -"body-slam": [85, "normal", 15], -"wrap": [15, "normal", 20], -"take-down": [90, "normal", 20], -"thrash": [90, "normal", 20], -"double-edge": [120, "normal", 15], -"tail-whip": [0, "normal", 30], -"poison-sting": [15, "poison", 35], -"twineedle": [25, "bug", 20], -"pin-missile": [14, "bug", 20], -"leer": [0, "normal", 30], -"bite": [60, "dark", 25], -"growl": [0, "normal", 40], -"roar": [0, "normal", 20], -"sing": [0, "normal", 15], -"supersonic": [0, "normal", 20], -"sonic-boom": [1, "normal", 20], -"disable": [0, "normal", 20], -"acid": [40, "poison", 30], -"ember": [40, "fire", 25], -"flamethrower": [95, "fire", 15], -"mist": [0, "ice", 30], -"water-gun": [40, "water", 25], -"hydro-pump": [120, "water", 5], -"surf": [95, "water", 15], -"ice-beam": [95, "ice", 10], -"blizzard": [120, "ice", 5], -"psybeam": [65, "psychic", 20], -"bubble-beam": [65, "water", 20], -"aurora-beam": [65, "ice", 20], -"hyper-beam": [150, "normal", 5], -"peck": [35, "flying", 35], -"drill-peck": [80, "flying", 20], -"submission": [80, "fighting", 25], -"low-kick": [1, "fighting", 20], -"counter": [1, "fighting", 20], -"seismic-toss": [1, "fighting", 20], -"strength": [80, "normal", 15], -"absorb": [20, "grass", 20], -"mega-drain": [40, "grass", 10], -"leech-seed": [0, "grass", 10], -"growth": [0, "normal", 40], -"razor-leaf": [55, "grass", 25], -"solar-beam": [120, "grass", 10], -"poison-powder": [0, "poison", 35], -"stun-spore": [0, "grass", 30], -"sleep-powder": [0, "grass", 15], -"petal-dance": [70, "grass", 20], -"string-shot": [0, "bug", 40], -"dragon-rage": [1, "dragon", 10], -"fire-spin": [15, "fire", 15], -"thunder-shock": [40, "electric", 30], -"thunderbolt": [95, "electric", 15], -"thunder-wave": [0, "electric", 20], -"thunder": [120, "electric", 10], -"rock-throw": [50, "rock", 15], -"earthquake": [100, "ground", 10], -"fissure": [1, "ground", 5], -"dig": [60, "ground", 10], -"toxic": [0, "poison", 10], -"confusion": [50, "psychic", 25], -"psychic": [90, "psychic", 10], -"hypnosis": [0, "psychic", 20], -"meditate": [0, "psychic", 40], -"agility": [0, "psychic", 30], -"quick-attack": [40, "normal", 30], -"rage": [20, "normal", 20], -"teleport": [0, "psychic", 20], -"night-shade": [1, "ghost", 15], -"mimic": [0, "normal", 10], -"screech": [0, "normal", 40], -"double-team": [0, "normal", 15], -"recover": [0, "normal", 20], -"harden": [0, "normal", 30], -"minimize": [0, "normal", 20], -"smokescreen": [0, "normal", 20], -"confuse-ray": [0, "ghost", 10], -"withdraw": [0, "water", 40], -"defense-curl": [0, "normal", 40], -"barrier": [0, "psychic", 30], -"light-screen": [0, "psychic", 30], -"haze": [0, "ice", 30], -"reflect": [0, "psychic", 20], -"focus-energy": [0, "normal", 30], -"bide": [1, "normal", 10], -"metronome": [0, "normal", 10], -"mirror-move": [0, "flying", 20], -"self-destruct": [200, "normal", 5], -"egg-bomb": [100, "normal", 10], -"lick": [20, "ghost", 30], -"smog": [20, "poison", 20], -"sludge": [65, "poison", 20], -"bone-club": [65, "ground", 20], -"fire-blast": [120, "fire", 5], -"waterfall": [80, "water", 15], -"clamp": [35, "water", 10], -"swift": [60, "normal", 20], -"skull-bash": [100, "normal", 15], -"spike-cannon": [20, "normal", 15], -"constrict": [10, "normal", 35], -"amnesia": [0, "psychic", 20], -"kinesis": [0, "psychic", 15], -"soft-boiled": [0, "normal", 10], -"high-jump-kick": [85, "fighting", 20], -"glare": [0, "normal", 30], -"dream-eater": [100, "psychic", 15], -"poison-gas": [0, "poison", 40], -"barrage": [15, "normal", 20], -"leech-life": [20, "bug", 15], -"lovely-kiss": [0, "normal", 10], -"sky-attack": [140, "flying", 5], -"transform": [0, "normal", 10], -"bubble": [20, "water", 30], -"dizzy-punch": [70, "normal", 10], -"spore": [0, "grass", 15], -"flash": [0, "normal", 20], -"psywave": [1, "psychic", 15], -"splash": [0, "normal", 40], -"acid-armor": [0, "poison", 40], -"crabhammer": [90, "water", 10], -"explosion": [250, "normal", 5], -"fury-swipes": [18, "normal", 15], -"bonemerang": [50, "ground", 10], -"rest": [0, "psychic", 10], -"rock-slide": [75, "rock", 10], -"hyper-fang": [80, "normal", 15], -"sharpen": [0, "normal", 30], -"conversion": [0, "normal", 30], -"tri-attack": [80, "normal", 10], -"super-fang": [1, "normal", 10], -"slash": [70, "normal", 20], -"substitute": [0, "normal", 10], -"struggle": [50, "normal", 1], -"sketch": [0, "normal", 1], -"triple-kick": [10, "fighting", 10], -"thief": [40, "dark", 10], -"spider-web": [0, "bug", 10], -"mind-reader": [0, "normal", 5], -"nightmare": [0, "ghost", 15], -"flame-wheel": [60, "fire", 25], -"snore": [40, "normal", 15], -"curse": [0, "mystery", 10], -"flail": [1, "normal", 15], -"conversion-2": [0, "normal", 30], -"aeroblast": [100, "flying", 5], -"cotton-spore": [0, "grass", 40], -"reversal": [1, "fighting", 15], -"spite": [0, "ghost", 10], -"powder-snow": [40, "ice", 25], -"protect": [0, "normal", 10], -"mach-punch": [40, "fighting", 30], -"scary-face": [0, "normal", 10], -"feint-attack": [60, "dark", 20], -"sweet-kiss": [0, "normal", 10], -"belly-drum": [0, "normal", 10], -"sludge-bomb": [90, "poison", 10], -"mud-slap": [20, "ground", 10], -"octazooka": [65, "water", 10], -"spikes": [0, "ground", 20], -"zap-cannon": [100, "electric", 5], -"foresight": [0, "normal", 40], -"destiny-bond": [0, "ghost", 5], -"perish-song": [0, "normal", 5], -"icy-wind": [55, "ice", 15], -"detect": [0, "fighting", 5], -"bone-rush": [25, "ground", 10], -"lock-on": [0, "normal", 5], -"outrage": [90, "dragon", 15], -"sandstorm": [0, "rock", 10], -"giga-drain": [60, "grass", 5], -"endure": [0, "normal", 10], -"charm": [0, "normal", 20], -"rollout": [30, "rock", 20], -"false-swipe": [40, "normal", 40], -"swagger": [0, "normal", 15], -"milk-drink": [0, "normal", 10], -"spark": [65, "electric", 20], -"fury-cutter": [10, "bug", 20], -"steel-wing": [70, "steel", 25], -"mean-look": [0, "normal", 5], -"attract": [0, "normal", 15], -"sleep-talk": [0, "normal", 10], -"heal-bell": [0, "normal", 5], -"return": [1, "normal", 20], -"present": [1, "normal", 15], -"frustration": [1, "normal", 20], -"safeguard": [0, "normal", 25], -"pain-split": [0, "normal", 20], -"sacred-fire": [100, "fire", 5], -"magnitude": [1, "ground", 30], -"dynamic-punch": [100, "fighting", 5], -"megahorn": [120, "bug", 10], -"dragon-breath": [60, "dragon", 20], -"baton-pass": [0, "normal", 40], -"encore": [0, "normal", 5], -"pursuit": [40, "dark", 20], -"rapid-spin": [20, "normal", 40], -"sweet-scent": [0, "normal", 20], -"iron-tail": [100, "steel", 15], -"metal-claw": [50, "steel", 35], -"vital-throw": [70, "fighting", 10], -"morning-sun": [0, "normal", 5], -"synthesis": [0, "grass", 5], -"moonlight": [0, "normal", 5], -"hidden-power": [1, "normal", 15], -"cross-chop": [100, "fighting", 5], -"twister": [40, "dragon", 20], -"rain-dance": [0, "water", 5], -"sunny-day": [0, "fire", 5], -"crunch": [80, "dark", 15], -"mirror-coat": [1, "psychic", 20], -"psych-up": [0, "normal", 10], -"extreme-speed": [80, "normal", 5], -"ancient-power": [60, "rock", 5], -"shadow-ball": [80, "ghost", 15], -"future-sight": [80, "psychic", 15], -"rock-smash": [20, "fighting", 15], -"whirlpool": [15, "water", 15], -"beat-up": [10, "dark", 10], -"fake-out": [40, "normal", 10], -"uproar": [50, "normal", 10], -"stockpile": [0, "normal", 10], -"spit-up": [100, "normal", 10], -"swallow": [0, "normal", 10], -"heat-wave": [100, "fire", 10], -"hail": [0, "ice", 10], -"torment": [0, "dark", 15], -"flatter": [0, "dark", 15], -"will-o-wisp": [0, "fire", 15], -"memento": [0, "dark", 10], -"facade": [70, "normal", 20], -"focus-punch": [150, "fighting", 20], -"smelling-salts": [60, "normal", 10], -"follow-me": [0, "normal", 20], -"nature-power": [0, "normal", 20], -"charge": [0, "electric", 20], -"taunt": [0, "dark", 20], -"helping-hand": [0, "normal", 20], -"trick": [0, "psychic", 10], -"role-play": [0, "psychic", 10], -"wish": [0, "normal", 10], -"assist": [0, "normal", 20], -"ingrain": [0, "grass", 20], -"superpower": [120, "fighting", 5], -"magic-coat": [0, "psychic", 15], -"recycle": [0, "normal", 10], -"revenge": [60, "fighting", 10], -"brick-break": [75, "fighting", 15], -"yawn": [0, "normal", 10], -"knock-off": [20, "dark", 20], -"endeavor": [1, "normal", 5], -"eruption": [150, "fire", 5], -"skill-swap": [0, "psychic", 10], -"imprison": [0, "psychic", 10], -"refresh": [0, "normal", 20], -"grudge": [0, "ghost", 5], -"snatch": [0, "dark", 10], -"secret-power": [70, "normal", 20], -"dive": [60, "water", 10], -"arm-thrust": [15, "fighting", 20], -"camouflage": [0, "normal", 20], -"tail-glow": [0, "bug", 20], -"luster-purge": [70, "psychic", 5], -"mist-ball": [70, "psychic", 5], -"feather-dance": [0, "flying", 15], -"teeter-dance": [0, "normal", 20], -"blaze-kick": [85, "fire", 10], -"mud-sport": [0, "ground", 15], -"ice-ball": [30, "ice", 20], -"needle-arm": [60, "grass", 15], -"slack-off": [0, "normal", 10], -"hyper-voice": [90, "normal", 10], -"poison-fang": [50, "poison", 15], -"crush-claw": [75, "normal", 10], -"blast-burn": [150, "fire", 5], -"hydro-cannon": [150, "water", 5], -"meteor-mash": [100, "steel", 10], -"astonish": [30, "ghost", 15], -"weather-ball": [50, "normal", 10], -"aromatherapy": [0, "grass", 5], -"fake-tears": [0, "dark", 20], -"air-cutter": [55, "flying", 25], -"overheat": [140, "fire", 5], -"odor-sleuth": [0, "normal", 40], -"rock-tomb": [50, "rock", 10], -"silver-wind": [60, "bug", 5], -"metal-sound": [0, "steel", 40], -"grass-whistle": [0, "grass", 15], -"tickle": [0, "normal", 20], -"cosmic-power": [0, "psychic", 20], -"water-spout": [150, "water", 5], -"signal-beam": [75, "bug", 15], -"shadow-punch": [60, "ghost", 20], -"extrasensory": [80, "psychic", 30], -"sky-uppercut": [85, "fighting", 15], -"sand-tomb": [15, "ground", 15], -"sheer-cold": [1, "ice", 5], -"muddy-water": [95, "water", 10], -"bullet-seed": [10, "grass", 30], -"aerial-ace": [60, "flying", 20], -"icicle-spear": [10, "ice", 30], -"iron-defense": [0, "steel", 15], -"block": [0, "normal", 5], -"howl": [0, "normal", 40], -"dragon-claw": [80, "dragon", 15], -"frenzy-plant": [150, "grass", 5], -"bulk-up": [0, "fighting", 20], -"bounce": [85, "flying", 5], -"mud-shot": [55, "ground", 15], -"poison-tail": [50, "poison", 25], -"covet": [40, "normal", 40], -"volt-tackle": [120, "electric", 15], -"magical-leaf": [60, "grass", 20], -"water-sport": [0, "water", 15], -"calm-mind": [0, "psychic", 20], -"leaf-blade": [70, "grass", 15], -"dragon-dance": [0, "dragon", 20], -"rock-blast": [25, "rock", 10], -"shock-wave": [60, "electric", 20], -"water-pulse": [60, "water", 20], -"doom-desire": [120, "steel", 5], -"psycho-boost": [140, "psychic", 5] +"pound": [40, "normal", 35, 100, 0, "hit", 0], +"karate-chop": [50, "fighting", 25, 100, 0, "high-critical", 0], +"double-slap": [15, "normal", 10, 85, 0, "multi-hit", 0], +"comet-punch": [18, "normal", 15, 85, 0, "multi-hit", 0], +"mega-punch": [80, "normal", 20, 85, 0, "hit", 0], +"pay-day": [40, "normal", 20, 100, 0, "pay-day", 100], +"fire-punch": [75, "fire", 15, 100, 0, "burn-hit", 10], +"ice-punch": [75, "ice", 15, 100, 0, "freeze-hit", 10], +"thunder-punch": [75, "electric", 15, 100, 0, "paralyze-hit", 10], +"scratch": [40, "normal", 35, 100, 0, "hit", 0], +"vise-grip": [55, "normal", 30, 100, 0, "hit", 0], +"guillotine": [1, "normal", 5, 30, 0, "ohko", 0], +"razor-wind": [80, "normal", 10, 100, 0, "razor-wind", 0], +"swords-dance": [0, "normal", 30, 0, 0, "attack-up-2", 0], +"cut": [50, "normal", 30, 95, 0, "hit", 0], +"gust": [40, "flying", 35, 100, 0, "gust", 0], +"wing-attack": [60, "flying", 35, 100, 0, "hit", 0], +"whirlwind": [0, "normal", 20, 100, -6, "roar", 0], +"fly": [70, "flying", 15, 95, 0, "semi-invulnerable", 0], +"bind": [15, "normal", 20, 75, 0, "trap", 100], +"slam": [80, "normal", 20, 75, 0, "hit", 0], +"vine-whip": [35, "grass", 10, 100, 0, "hit", 0], +"stomp": [65, "normal", 20, 100, 0, "flinch-minimize-hit", 30], +"double-kick": [30, "fighting", 30, 100, 0, "double-hit", 0], +"mega-kick": [120, "normal", 5, 75, 0, "hit", 0], +"jump-kick": [70, "fighting", 25, 95, 0, "recoil-if-miss", 0], +"rolling-kick": [60, "fighting", 15, 85, 0, "flinch-hit", 30], +"sand-attack": [0, "ground", 15, 100, 0, "accuracy-down", 0], +"headbutt": [70, "normal", 15, 100, 0, "flinch-hit", 30], +"horn-attack": [65, "normal", 25, 100, 0, "hit", 0], +"fury-attack": [15, "normal", 20, 85, 0, "multi-hit", 0], +"horn-drill": [1, "normal", 5, 30, 0, "ohko", 0], +"tackle": [35, "normal", 35, 95, 0, "hit", 0], +"body-slam": [85, "normal", 15, 100, 0, "paralyze-hit", 30], +"wrap": [15, "normal", 20, 85, 0, "trap", 100], +"take-down": [90, "normal", 20, 85, 0, "recoil", 0], +"thrash": [90, "normal", 20, 100, 0, "rampage", 100], +"double-edge": [120, "normal", 15, 100, 0, "double-edge", 0], +"tail-whip": [0, "normal", 30, 100, 0, "defense-down", 0], +"poison-sting": [15, "poison", 35, 100, 0, "poison-hit", 30], +"twineedle": [25, "bug", 20, 100, 0, "twineedle", 20], +"pin-missile": [14, "bug", 20, 85, 0, "multi-hit", 0], +"leer": [0, "normal", 30, 100, 0, "defense-down", 0], +"bite": [60, "dark", 25, 100, 0, "flinch-hit", 30], +"growl": [0, "normal", 40, 100, 0, "attack-down", 0], +"roar": [0, "normal", 20, 100, -6, "roar", 0], +"sing": [0, "normal", 15, 55, 0, "sleep", 0], +"supersonic": [0, "normal", 20, 55, 0, "confuse", 0], +"sonic-boom": [1, "normal", 20, 90, 0, "sonicboom", 0], +"disable": [0, "normal", 20, 55, 0, "disable", 0], +"acid": [40, "poison", 30, 100, 0, "defense-down-hit", 10], +"ember": [40, "fire", 25, 100, 0, "burn-hit", 10], +"flamethrower": [95, "fire", 15, 100, 0, "burn-hit", 10], +"mist": [0, "ice", 30, 0, 0, "mist", 0], +"water-gun": [40, "water", 25, 100, 0, "hit", 0], +"hydro-pump": [120, "water", 5, 80, 0, "hit", 0], +"surf": [95, "water", 15, 100, 0, "hit", 0], +"ice-beam": [95, "ice", 10, 100, 0, "freeze-hit", 10], +"blizzard": [120, "ice", 5, 70, 0, "freeze-hit", 10], +"psybeam": [65, "psychic", 20, 100, 0, "confuse-hit", 10], +"bubble-beam": [65, "water", 20, 100, 0, "speed-down-hit", 10], +"aurora-beam": [65, "ice", 20, 100, 0, "attack-down-hit", 10], +"hyper-beam": [150, "normal", 5, 90, 0, "recharge", 0], +"peck": [35, "flying", 35, 100, 0, "hit", 0], +"drill-peck": [80, "flying", 20, 100, 0, "hit", 0], +"submission": [80, "fighting", 25, 80, 0, "recoil", 0], +"low-kick": [1, "fighting", 20, 100, 0, "low-kick", 0], +"counter": [1, "fighting", 20, 100, -5, "counter", 0], +"seismic-toss": [1, "fighting", 20, 100, 0, "level-damage", 0], +"strength": [80, "normal", 15, 100, 0, "hit", 0], +"absorb": [20, "grass", 20, 100, 0, "absorb", 0], +"mega-drain": [40, "grass", 10, 100, 0, "absorb", 0], +"leech-seed": [0, "grass", 10, 90, 0, "leech-seed", 0], +"growth": [0, "normal", 40, 0, 0, "special-attack-up", 0], +"razor-leaf": [55, "grass", 25, 95, 0, "high-critical", 0], +"solar-beam": [120, "grass", 10, 100, 0, "solar-beam", 0], +"poison-powder": [0, "poison", 35, 75, 0, "poison", 0], +"stun-spore": [0, "grass", 30, 75, 0, "paralyze", 0], +"sleep-powder": [0, "grass", 15, 75, 0, "sleep", 0], +"petal-dance": [70, "grass", 20, 100, 0, "rampage", 100], +"string-shot": [0, "bug", 40, 95, 0, "speed-down", 0], +"dragon-rage": [1, "dragon", 10, 100, 0, "dragon-rage", 0], +"fire-spin": [15, "fire", 15, 70, 0, "trap", 100], +"thunder-shock": [40, "electric", 30, 100, 0, "paralyze-hit", 10], +"thunderbolt": [95, "electric", 15, 100, 0, "paralyze-hit", 10], +"thunder-wave": [0, "electric", 20, 100, 0, "paralyze", 0], +"thunder": [120, "electric", 10, 70, 0, "thunder", 30], +"rock-throw": [50, "rock", 15, 90, 0, "hit", 0], +"earthquake": [100, "ground", 10, 100, 0, "earthquake", 0], +"fissure": [1, "ground", 5, 30, 0, "ohko", 0], +"dig": [60, "ground", 10, 100, 0, "semi-invulnerable", 0], +"toxic": [0, "poison", 10, 85, 0, "toxic", 100], +"confusion": [50, "psychic", 25, 100, 0, "confuse-hit", 10], +"psychic": [90, "psychic", 10, 100, 0, "special-defense-down-hit", 10], +"hypnosis": [0, "psychic", 20, 60, 0, "sleep", 0], +"meditate": [0, "psychic", 40, 0, 0, "attack-up", 0], +"agility": [0, "psychic", 30, 0, 0, "speed-up-2", 0], +"quick-attack": [40, "normal", 30, 100, 1, "quick-attack", 0], +"rage": [20, "normal", 20, 100, 0, "rage", 0], +"teleport": [0, "psychic", 20, 0, 0, "teleport", 0], +"night-shade": [1, "ghost", 15, 100, 0, "level-damage", 0], +"mimic": [0, "normal", 10, 100, 0, "mimic", 0], +"screech": [0, "normal", 40, 85, 0, "defense-down-2", 0], +"double-team": [0, "normal", 15, 0, 0, "evasion-up", 0], +"recover": [0, "normal", 20, 0, 0, "restore-hp", 0], +"harden": [0, "normal", 30, 0, 0, "defense-up", 0], +"minimize": [0, "normal", 20, 0, 0, "minimize", 0], +"smokescreen": [0, "normal", 20, 100, 0, "accuracy-down", 0], +"confuse-ray": [0, "ghost", 10, 100, 0, "confuse", 0], +"withdraw": [0, "water", 40, 0, 0, "defense-up", 0], +"defense-curl": [0, "normal", 40, 0, 0, "defense-curl", 0], +"barrier": [0, "psychic", 30, 0, 0, "defense-up-2", 0], +"light-screen": [0, "psychic", 30, 0, 0, "light-screen", 0], +"haze": [0, "ice", 30, 0, 0, "haze", 0], +"reflect": [0, "psychic", 20, 0, 0, "reflect", 0], +"focus-energy": [0, "normal", 30, 0, 0, "focus-energy", 0], +"bide": [1, "normal", 10, 100, 0, "bide", 0], +"metronome": [0, "normal", 10, 0, 0, "metronome", 0], +"mirror-move": [0, "flying", 20, 0, 0, "mirror-move", 0], +"self-destruct": [200, "normal", 5, 100, 0, "explosion", 0], +"egg-bomb": [100, "normal", 10, 75, 0, "hit", 0], +"lick": [20, "ghost", 30, 100, 0, "paralyze-hit", 30], +"smog": [20, "poison", 20, 70, 0, "poison-hit", 40], +"sludge": [65, "poison", 20, 100, 0, "poison-hit", 30], +"bone-club": [65, "ground", 20, 85, 0, "flinch-hit", 10], +"fire-blast": [120, "fire", 5, 85, 0, "burn-hit", 10], +"waterfall": [80, "water", 15, 100, 0, "hit", 0], +"clamp": [35, "water", 10, 75, 0, "trap", 100], +"swift": [60, "normal", 20, 0, 0, "always-hit", 0], +"skull-bash": [100, "normal", 15, 100, 0, "skull-bash", 0], +"spike-cannon": [20, "normal", 15, 100, 0, "multi-hit", 0], +"constrict": [10, "normal", 35, 100, 0, "speed-down-hit", 10], +"amnesia": [0, "psychic", 20, 0, 0, "special-defense-up-2", 0], +"kinesis": [0, "psychic", 15, 80, 0, "accuracy-down", 0], +"soft-boiled": [0, "normal", 10, 100, 0, "softboiled", 0], +"high-jump-kick": [85, "fighting", 20, 90, 0, "recoil-if-miss", 0], +"glare": [0, "normal", 30, 75, 0, "paralyze", 0], +"dream-eater": [100, "psychic", 15, 100, 0, "dream-eater", 0], +"poison-gas": [0, "poison", 40, 55, 0, "poison", 0], +"barrage": [15, "normal", 20, 85, 0, "multi-hit", 0], +"leech-life": [20, "bug", 15, 100, 0, "absorb", 0], +"lovely-kiss": [0, "normal", 10, 75, 0, "sleep", 0], +"sky-attack": [140, "flying", 5, 90, 0, "sky-attack", 30], +"transform": [0, "normal", 10, 0, 0, "transform", 0], +"bubble": [20, "water", 30, 100, 0, "speed-down-hit", 10], +"dizzy-punch": [70, "normal", 10, 100, 0, "confuse-hit", 20], +"spore": [0, "grass", 15, 100, 0, "sleep", 0], +"flash": [0, "normal", 20, 70, 0, "accuracy-down", 0], +"psywave": [1, "psychic", 15, 80, 0, "psywave", 0], +"splash": [0, "normal", 40, 0, 0, "splash", 0], +"acid-armor": [0, "poison", 40, 0, 0, "defense-up-2", 0], +"crabhammer": [90, "water", 10, 85, 0, "high-critical", 0], +"explosion": [250, "normal", 5, 100, 0, "explosion", 0], +"fury-swipes": [18, "normal", 15, 80, 0, "multi-hit", 0], +"bonemerang": [50, "ground", 10, 90, 0, "double-hit", 0], +"rest": [0, "psychic", 10, 0, 0, "rest", 0], +"rock-slide": [75, "rock", 10, 90, 0, "flinch-hit", 30], +"hyper-fang": [80, "normal", 15, 90, 0, "flinch-hit", 10], +"sharpen": [0, "normal", 30, 0, 0, "attack-up", 0], +"conversion": [0, "normal", 30, 0, 0, "conversion", 0], +"tri-attack": [80, "normal", 10, 100, 0, "tri-attack", 20], +"super-fang": [1, "normal", 10, 90, 0, "super-fang", 0], +"slash": [70, "normal", 20, 100, 0, "high-critical", 0], +"substitute": [0, "normal", 10, 0, 0, "substitute", 0], +"struggle": [50, "normal", 1, 100, 0, "recoil", 0], +"sketch": [0, "normal", 1, 0, 0, "sketch", 0], +"triple-kick": [10, "fighting", 10, 90, 0, "triple-kick", 0], +"thief": [40, "dark", 10, 100, 0, "thief", 100], +"spider-web": [0, "bug", 10, 100, 0, "mean-look", 0], +"mind-reader": [0, "normal", 5, 100, 0, "lock-on", 0], +"nightmare": [0, "ghost", 15, 100, 0, "nightmare", 0], +"flame-wheel": [60, "fire", 25, 100, 0, "thaw-hit", 10], +"snore": [40, "normal", 15, 100, 0, "snore", 30], +"curse": [0, "mystery", 10, 0, 0, "curse", 0], +"flail": [1, "normal", 15, 100, 0, "flail", 0], +"conversion-2": [0, "normal", 30, 100, 0, "conversion-2", 0], +"aeroblast": [100, "flying", 5, 95, 0, "high-critical", 0], +"cotton-spore": [0, "grass", 40, 85, 0, "speed-down-2", 0], +"reversal": [1, "fighting", 15, 100, 0, "flail", 0], +"spite": [0, "ghost", 10, 100, 0, "spite", 0], +"powder-snow": [40, "ice", 25, 100, 0, "freeze-hit", 10], +"protect": [0, "normal", 10, 0, 3, "protect", 0], +"mach-punch": [40, "fighting", 30, 100, 1, "quick-attack", 0], +"scary-face": [0, "normal", 10, 90, 0, "speed-down-2", 0], +"feint-attack": [60, "dark", 20, 0, 0, "always-hit", 0], +"sweet-kiss": [0, "normal", 10, 75, 0, "confuse", 0], +"belly-drum": [0, "normal", 10, 0, 0, "belly-drum", 0], +"sludge-bomb": [90, "poison", 10, 100, 0, "poison-hit", 30], +"mud-slap": [20, "ground", 10, 100, 0, "accuracy-down-hit", 100], +"octazooka": [65, "water", 10, 85, 0, "accuracy-down-hit", 50], +"spikes": [0, "ground", 20, 0, 0, "spikes", 0], +"zap-cannon": [100, "electric", 5, 50, 0, "paralyze-hit", 100], +"foresight": [0, "normal", 40, 100, 0, "foresight", 0], +"destiny-bond": [0, "ghost", 5, 0, 0, "destiny-bond", 0], +"perish-song": [0, "normal", 5, 0, 0, "perish-song", 0], +"icy-wind": [55, "ice", 15, 95, 0, "speed-down-hit", 100], +"detect": [0, "fighting", 5, 0, 3, "protect", 0], +"bone-rush": [25, "ground", 10, 80, 0, "multi-hit", 0], +"lock-on": [0, "normal", 5, 100, 0, "lock-on", 0], +"outrage": [90, "dragon", 15, 100, 0, "rampage", 100], +"sandstorm": [0, "rock", 10, 0, 0, "sandstorm", 0], +"giga-drain": [60, "grass", 5, 100, 0, "absorb", 0], +"endure": [0, "normal", 10, 0, 3, "endure", 0], +"charm": [0, "normal", 20, 100, 0, "attack-down-2", 0], +"rollout": [30, "rock", 20, 90, 0, "rollout", 0], +"false-swipe": [40, "normal", 40, 100, 0, "false-swipe", 0], +"swagger": [0, "normal", 15, 90, 0, "swagger", 100], +"milk-drink": [0, "normal", 10, 0, 0, "softboiled", 0], +"spark": [65, "electric", 20, 100, 0, "paralyze-hit", 30], +"fury-cutter": [10, "bug", 20, 95, 0, "fury-cutter", 0], +"steel-wing": [70, "steel", 25, 90, 0, "defense-up-hit", 10], +"mean-look": [0, "normal", 5, 100, 0, "mean-look", 0], +"attract": [0, "normal", 15, 100, 0, "attract", 0], +"sleep-talk": [0, "normal", 10, 0, 0, "sleep-talk", 0], +"heal-bell": [0, "normal", 5, 0, 0, "heal-bell", 0], +"return": [1, "normal", 20, 100, 0, "return", 0], +"present": [1, "normal", 15, 90, 0, "present", 0], +"frustration": [1, "normal", 20, 100, 0, "frustration", 0], +"safeguard": [0, "normal", 25, 0, 0, "safeguard", 0], +"pain-split": [0, "normal", 20, 100, 0, "pain-split", 0], +"sacred-fire": [100, "fire", 5, 95, 0, "thaw-hit", 50], +"magnitude": [1, "ground", 30, 100, 0, "magnitude", 0], +"dynamic-punch": [100, "fighting", 5, 50, 0, "confuse-hit", 100], +"megahorn": [120, "bug", 10, 85, 0, "hit", 0], +"dragon-breath": [60, "dragon", 20, 100, 0, "paralyze-hit", 30], +"baton-pass": [0, "normal", 40, 0, 0, "baton-pass", 0], +"encore": [0, "normal", 5, 100, 0, "encore", 0], +"pursuit": [40, "dark", 20, 100, 0, "pursuit", 0], +"rapid-spin": [20, "normal", 40, 100, 0, "rapid-spin", 0], +"sweet-scent": [0, "normal", 20, 100, 0, "evasion-down", 0], +"iron-tail": [100, "steel", 15, 75, 0, "defense-down-hit", 30], +"metal-claw": [50, "steel", 35, 95, 0, "attack-up-hit", 10], +"vital-throw": [70, "fighting", 10, 100, -1, "vital-throw", 0], +"morning-sun": [0, "normal", 5, 0, 0, "morning-sun", 0], +"synthesis": [0, "grass", 5, 0, 0, "synthesis", 0], +"moonlight": [0, "normal", 5, 0, 0, "moonlight", 0], +"hidden-power": [1, "normal", 15, 100, 0, "hidden-power", 0], +"cross-chop": [100, "fighting", 5, 80, 0, "high-critical", 0], +"twister": [40, "dragon", 20, 100, 0, "twister", 20], +"rain-dance": [0, "water", 5, 0, 0, "rain-dance", 0], +"sunny-day": [0, "fire", 5, 0, 0, "sunny-day", 0], +"crunch": [80, "dark", 15, 100, 0, "special-defense-down-hit", 20], +"mirror-coat": [1, "psychic", 20, 100, -5, "mirror-coat", 0], +"psych-up": [0, "normal", 10, 0, 0, "psych-up", 0], +"extreme-speed": [80, "normal", 5, 100, 1, "quick-attack", 0], +"ancient-power": [60, "rock", 5, 100, 0, "all-stats-up-hit", 10], +"shadow-ball": [80, "ghost", 15, 100, 0, "special-defense-down-hit", 20], +"future-sight": [80, "psychic", 15, 90, 0, "future-sight", 0], +"rock-smash": [20, "fighting", 15, 100, 0, "defense-down-hit", 50], +"whirlpool": [15, "water", 15, 70, 0, "trap", 100], +"beat-up": [10, "dark", 10, 100, 0, "beat-up", 0], +"fake-out": [40, "normal", 10, 100, 1, "fake-out", 0], +"uproar": [50, "normal", 10, 100, 0, "uproar", 100], +"stockpile": [0, "normal", 10, 0, 0, "stockpile", 0], +"spit-up": [100, "normal", 10, 100, 0, "spit-up", 0], +"swallow": [0, "normal", 10, 0, 0, "swallow", 0], +"heat-wave": [100, "fire", 10, 90, 0, "burn-hit", 10], +"hail": [0, "ice", 10, 0, 0, "hail", 0], +"torment": [0, "dark", 15, 100, 0, "torment", 0], +"flatter": [0, "dark", 15, 100, 0, "flatter", 0], +"will-o-wisp": [0, "fire", 15, 75, 0, "will-o-wisp", 0], +"memento": [0, "dark", 10, 100, 0, "memento", 0], +"facade": [70, "normal", 20, 100, 0, "facade", 0], +"focus-punch": [150, "fighting", 20, 100, -3, "focus-punch", 0], +"smelling-salts": [60, "normal", 10, 100, 0, "smellingsalt", 0], +"follow-me": [0, "normal", 20, 100, 3, "follow-me", 0], +"nature-power": [0, "normal", 20, 0, 0, "nature-power", 0], +"charge": [0, "electric", 20, 100, 0, "charge", 0], +"taunt": [0, "dark", 20, 100, 0, "taunt", 0], +"helping-hand": [0, "normal", 20, 100, 5, "helping-hand", 0], +"trick": [0, "psychic", 10, 100, 0, "trick", 0], +"role-play": [0, "psychic", 10, 100, 0, "role-play", 0], +"wish": [0, "normal", 10, 100, 0, "wish", 0], +"assist": [0, "normal", 20, 100, 0, "assist", 0], +"ingrain": [0, "grass", 20, 100, 0, "ingrain", 0], +"superpower": [120, "fighting", 5, 100, 0, "superpower", 0], +"magic-coat": [0, "psychic", 15, 100, 4, "magic-coat", 0], +"recycle": [0, "normal", 10, 100, 0, "recycle", 0], +"revenge": [60, "fighting", 10, 100, -4, "revenge", 0], +"brick-break": [75, "fighting", 15, 100, 0, "brick-break", 0], +"yawn": [0, "normal", 10, 100, 0, "yawn", 0], +"knock-off": [20, "dark", 20, 100, 0, "knock-off", 100], +"endeavor": [1, "normal", 5, 100, 0, "endeavor", 0], +"eruption": [150, "fire", 5, 100, 0, "eruption", 0], +"skill-swap": [0, "psychic", 10, 100, 0, "skill-swap", 0], +"imprison": [0, "psychic", 10, 100, 0, "imprison", 0], +"refresh": [0, "normal", 20, 100, 0, "refresh", 0], +"grudge": [0, "ghost", 5, 100, 0, "grudge", 0], +"snatch": [0, "dark", 10, 100, 4, "snatch", 0], +"secret-power": [70, "normal", 20, 100, 0, "secret-power", 30], +"dive": [60, "water", 10, 100, 0, "semi-invulnerable", 0], +"arm-thrust": [15, "fighting", 20, 100, 0, "multi-hit", 0], +"camouflage": [0, "normal", 20, 100, 0, "camouflage", 0], +"tail-glow": [0, "bug", 20, 100, 0, "special-attack-up-2", 0], +"luster-purge": [70, "psychic", 5, 100, 0, "special-defense-down-hit", 50], +"mist-ball": [70, "psychic", 5, 100, 0, "special-attack-down-hit", 50], +"feather-dance": [0, "flying", 15, 100, 0, "attack-down-2", 0], +"teeter-dance": [0, "normal", 20, 100, 0, "teeter-dance", 0], +"blaze-kick": [85, "fire", 10, 90, 0, "blaze-kick", 10], +"mud-sport": [0, "ground", 15, 100, 0, "mud-sport", 0], +"ice-ball": [30, "ice", 20, 90, 0, "rollout", 0], +"needle-arm": [60, "grass", 15, 100, 0, "flinch-minimize-hit", 30], +"slack-off": [0, "normal", 10, 100, 0, "restore-hp", 0], +"hyper-voice": [90, "normal", 10, 100, 0, "hit", 0], +"poison-fang": [50, "poison", 15, 100, 0, "poison-fang", 30], +"crush-claw": [75, "normal", 10, 95, 0, "defense-down-hit", 50], +"blast-burn": [150, "fire", 5, 90, 0, "recharge", 0], +"hydro-cannon": [150, "water", 5, 90, 0, "recharge", 0], +"meteor-mash": [100, "steel", 10, 85, 0, "attack-up-hit", 20], +"astonish": [30, "ghost", 15, 100, 0, "flinch-minimize-hit", 30], +"weather-ball": [50, "normal", 10, 100, 0, "weather-ball", 0], +"aromatherapy": [0, "grass", 5, 0, 0, "heal-bell", 0], +"fake-tears": [0, "dark", 20, 100, 0, "special-defense-down-2", 0], +"air-cutter": [55, "flying", 25, 95, 0, "high-critical", 0], +"overheat": [140, "fire", 5, 90, 0, "overheat", 100], +"odor-sleuth": [0, "normal", 40, 100, 0, "foresight", 0], +"rock-tomb": [50, "rock", 10, 80, 0, "speed-down-hit", 100], +"silver-wind": [60, "bug", 5, 100, 0, "all-stats-up-hit", 10], +"metal-sound": [0, "steel", 40, 85, 0, "special-defense-down-2", 0], +"grass-whistle": [0, "grass", 15, 55, 0, "sleep", 0], +"tickle": [0, "normal", 20, 100, 0, "tickle", 0], +"cosmic-power": [0, "psychic", 20, 0, 0, "cosmic-power", 0], +"water-spout": [150, "water", 5, 100, 0, "eruption", 0], +"signal-beam": [75, "bug", 15, 100, 0, "confuse-hit", 10], +"shadow-punch": [60, "ghost", 20, 0, 0, "always-hit", 0], +"extrasensory": [80, "psychic", 30, 100, 0, "flinch-minimize-hit", 10], +"sky-uppercut": [85, "fighting", 15, 90, 0, "sky-uppercut", 0], +"sand-tomb": [15, "ground", 15, 70, 0, "trap", 100], +"sheer-cold": [1, "ice", 5, 30, 0, "ohko", 0], +"muddy-water": [95, "water", 10, 85, 0, "accuracy-down-hit", 30], +"bullet-seed": [10, "grass", 30, 100, 0, "multi-hit", 0], +"aerial-ace": [60, "flying", 20, 0, 0, "always-hit", 0], +"icicle-spear": [10, "ice", 30, 100, 0, "multi-hit", 0], +"iron-defense": [0, "steel", 15, 0, 0, "defense-up-2", 0], +"block": [0, "normal", 5, 100, 0, "mean-look", 0], +"howl": [0, "normal", 40, 0, 0, "attack-up", 0], +"dragon-claw": [80, "dragon", 15, 100, 0, "hit", 0], +"frenzy-plant": [150, "grass", 5, 90, 0, "recharge", 0], +"bulk-up": [0, "fighting", 20, 0, 0, "bulk-up", 0], +"bounce": [85, "flying", 5, 85, 0, "semi-invulnerable", 30], +"mud-shot": [55, "ground", 15, 95, 0, "speed-down-hit", 100], +"poison-tail": [50, "poison", 25, 100, 0, "poison-tail", 10], +"covet": [40, "normal", 40, 100, 0, "thief", 100], +"volt-tackle": [120, "electric", 15, 100, 0, "double-edge", 0], +"magical-leaf": [60, "grass", 20, 0, 0, "always-hit", 0], +"water-sport": [0, "water", 15, 100, 0, "water-sport", 0], +"calm-mind": [0, "psychic", 20, 0, 0, "calm-mind", 0], +"leaf-blade": [70, "grass", 15, 100, 0, "high-critical", 0], +"dragon-dance": [0, "dragon", 20, 0, 0, "dragon-dance", 0], +"rock-blast": [25, "rock", 10, 80, 0, "multi-hit", 0], +"shock-wave": [60, "electric", 20, 0, 0, "always-hit", 0], +"water-pulse": [60, "water", 20, 100, 0, "confuse-hit", 20], +"doom-desire": [120, "steel", 5, 85, 0, "future-sight", 0], +"psycho-boost": [140, "psychic", 5, 90, 0, "overheat", 100] } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json index bbbc54e80e..5393e90c95 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json @@ -1,388 +1,388 @@ { -"bulbasaur": ["grass", "poison", 49, 65], -"ivysaur": ["grass", "poison", 62, 80], -"venusaur": ["grass", "poison", 82, 100], -"charmander": ["fire", "fire", 52, 60], -"charmeleon": ["fire", "fire", 64, 80], -"charizard": ["fire", "flying", 84, 109], -"squirtle": ["water", "water", 48, 50], -"wartortle": ["water", "water", 63, 65], -"blastoise": ["water", "water", 83, 85], -"caterpie": ["bug", "bug", 30, 20], -"metapod": ["bug", "bug", 20, 25], -"butterfree": ["bug", "flying", 45, 80], -"weedle": ["bug", "poison", 35, 20], -"kakuna": ["bug", "poison", 25, 25], -"beedrill": ["bug", "poison", 80, 45], -"pidgey": ["normal", "flying", 45, 35], -"pidgeotto": ["normal", "flying", 60, 50], -"pidgeot": ["normal", "flying", 80, 70], -"rattata": ["normal", "normal", 56, 25], -"raticate": ["normal", "normal", 81, 50], -"spearow": ["normal", "flying", 60, 31], -"fearow": ["normal", "flying", 90, 61], -"ekans": ["poison", "poison", 60, 40], -"arbok": ["poison", "poison", 85, 65], -"pikachu": ["electric", "electric", 55, 50], -"raichu": ["electric", "electric", 90, 90], -"sandshrew": ["ground", "ground", 75, 20], -"sandslash": ["ground", "ground", 100, 45], -"nidoran-f": ["poison", "poison", 47, 40], -"nidorina": ["poison", "poison", 62, 55], -"nidoqueen": ["poison", "ground", 82, 75], -"nidoran-m": ["poison", "poison", 57, 40], -"nidorino": ["poison", "poison", 72, 55], -"nidoking": ["poison", "ground", 92, 85], -"clefairy": ["normal", "normal", 45, 60], -"clefable": ["normal", "normal", 70, 85], -"vulpix": ["fire", "fire", 41, 50], -"ninetales": ["fire", "fire", 76, 81], -"jigglypuff": ["normal", "normal", 45, 45], -"wigglytuff": ["normal", "normal", 70, 75], -"zubat": ["poison", "flying", 45, 30], -"golbat": ["poison", "flying", 80, 65], -"oddish": ["grass", "poison", 50, 75], -"gloom": ["grass", "poison", 65, 85], -"vileplume": ["grass", "poison", 80, 100], -"paras": ["bug", "grass", 70, 45], -"parasect": ["bug", "grass", 95, 60], -"venonat": ["bug", "poison", 55, 40], -"venomoth": ["bug", "poison", 65, 90], -"diglett": ["ground", "ground", 55, 35], -"dugtrio": ["ground", "ground", 80, 50], -"meowth": ["normal", "normal", 45, 40], -"persian": ["normal", "normal", 70, 65], -"psyduck": ["water", "water", 52, 65], -"golduck": ["water", "water", 82, 95], -"mankey": ["fighting", "fighting", 80, 35], -"primeape": ["fighting", "fighting", 105, 60], -"growlithe": ["fire", "fire", 70, 70], -"arcanine": ["fire", "fire", 110, 100], -"poliwag": ["water", "water", 50, 40], -"poliwhirl": ["water", "water", 65, 50], -"poliwrath": ["water", "fighting", 85, 70], -"abra": ["psychic", "psychic", 20, 105], -"kadabra": ["psychic", "psychic", 35, 120], -"alakazam": ["psychic", "psychic", 50, 135], -"machop": ["fighting", "fighting", 80, 35], -"machoke": ["fighting", "fighting", 100, 50], -"machamp": ["fighting", "fighting", 130, 65], -"bellsprout": ["grass", "poison", 75, 70], -"weepinbell": ["grass", "poison", 90, 85], -"victreebel": ["grass", "poison", 105, 100], -"tentacool": ["water", "poison", 40, 50], -"tentacruel": ["water", "poison", 70, 80], -"geodude": ["rock", "ground", 80, 30], -"graveler": ["rock", "ground", 95, 45], -"golem": ["rock", "ground", 110, 55], -"ponyta": ["fire", "fire", 85, 65], -"rapidash": ["fire", "fire", 100, 80], -"slowpoke": ["water", "psychic", 65, 40], -"slowbro": ["water", "psychic", 75, 100], -"magnemite": ["electric", "steel", 35, 95], -"magneton": ["electric", "steel", 60, 120], -"farfetch-d": ["normal", "flying", 65, 58], -"doduo": ["normal", "flying", 85, 35], -"dodrio": ["normal", "flying", 110, 60], -"seel": ["water", "water", 45, 45], -"dewgong": ["water", "ice", 70, 70], -"grimer": ["poison", "poison", 80, 40], -"muk": ["poison", "poison", 105, 65], -"shellder": ["water", "water", 65, 45], -"cloyster": ["water", "ice", 95, 85], -"gastly": ["ghost", "poison", 35, 100], -"haunter": ["ghost", "poison", 50, 115], -"gengar": ["ghost", "poison", 65, 130], -"onix": ["rock", "ground", 45, 30], -"drowzee": ["psychic", "psychic", 48, 43], -"hypno": ["psychic", "psychic", 73, 73], -"krabby": ["water", "water", 105, 25], -"kingler": ["water", "water", 130, 50], -"voltorb": ["electric", "electric", 30, 55], -"electrode": ["electric", "electric", 50, 80], -"exeggcute": ["grass", "psychic", 40, 60], -"exeggutor": ["grass", "psychic", 95, 125], -"cubone": ["ground", "ground", 50, 40], -"marowak": ["ground", "ground", 80, 50], -"hitmonlee": ["fighting", "fighting", 120, 35], -"hitmonchan": ["fighting", "fighting", 105, 35], -"lickitung": ["normal", "normal", 55, 60], -"koffing": ["poison", "poison", 65, 60], -"weezing": ["poison", "poison", 90, 85], -"rhyhorn": ["ground", "rock", 85, 30], -"rhydon": ["ground", "rock", 130, 45], -"chansey": ["normal", "normal", 5, 35], -"tangela": ["grass", "grass", 55, 100], -"kangaskhan": ["normal", "normal", 95, 40], -"horsea": ["water", "water", 40, 70], -"seadra": ["water", "water", 65, 95], -"goldeen": ["water", "water", 67, 35], -"seaking": ["water", "water", 92, 65], -"staryu": ["water", "water", 45, 70], -"starmie": ["water", "psychic", 75, 100], -"mr-mime": ["psychic", "psychic", 45, 100], -"scyther": ["bug", "flying", 110, 55], -"jynx": ["ice", "psychic", 50, 115], -"electabuzz": ["electric", "electric", 83, 95], -"magmar": ["fire", "fire", 95, 100], -"pinsir": ["bug", "bug", 125, 55], -"tauros": ["normal", "normal", 100, 40], -"magikarp": ["water", "water", 10, 15], -"gyarados": ["water", "flying", 125, 60], -"lapras": ["water", "ice", 85, 85], -"ditto": ["normal", "normal", 48, 48], -"eevee": ["normal", "normal", 55, 45], -"vaporeon": ["water", "water", 65, 110], -"jolteon": ["electric", "electric", 65, 110], -"flareon": ["fire", "fire", 130, 95], -"porygon": ["normal", "normal", 60, 85], -"omanyte": ["rock", "water", 40, 90], -"omastar": ["rock", "water", 60, 115], -"kabuto": ["rock", "water", 80, 55], -"kabutops": ["rock", "water", 115, 65], -"aerodactyl": ["rock", "flying", 105, 60], -"snorlax": ["normal", "normal", 110, 65], -"articuno": ["ice", "flying", 85, 95], -"zapdos": ["electric", "flying", 90, 125], -"moltres": ["fire", "flying", 100, 125], -"dratini": ["dragon", "dragon", 64, 50], -"dragonair": ["dragon", "dragon", 84, 70], -"dragonite": ["dragon", "flying", 134, 100], -"mewtwo": ["psychic", "psychic", 110, 154], -"mew": ["psychic", "psychic", 100, 100], -"chikorita": ["grass", "grass", 49, 49], -"bayleef": ["grass", "grass", 62, 63], -"meganium": ["grass", "grass", 82, 83], -"cyndaquil": ["fire", "fire", 52, 60], -"quilava": ["fire", "fire", 64, 80], -"typhlosion": ["fire", "fire", 84, 109], -"totodile": ["water", "water", 65, 44], -"croconaw": ["water", "water", 80, 59], -"feraligatr": ["water", "water", 105, 79], -"sentret": ["normal", "normal", 46, 35], -"furret": ["normal", "normal", 76, 45], -"hoothoot": ["normal", "flying", 30, 36], -"noctowl": ["normal", "flying", 50, 76], -"ledyba": ["bug", "flying", 20, 40], -"ledian": ["bug", "flying", 35, 55], -"spinarak": ["bug", "poison", 60, 40], -"ariados": ["bug", "poison", 90, 60], -"crobat": ["poison", "flying", 90, 70], -"chinchou": ["water", "electric", 38, 56], -"lanturn": ["water", "electric", 58, 76], -"pichu": ["electric", "electric", 40, 35], -"cleffa": ["normal", "normal", 25, 45], -"igglybuff": ["normal", "normal", 30, 40], -"togepi": ["normal", "normal", 20, 40], -"togetic": ["normal", "flying", 40, 80], -"natu": ["psychic", "flying", 50, 70], -"xatu": ["psychic", "flying", 75, 95], -"mareep": ["electric", "electric", 40, 65], -"flaaffy": ["electric", "electric", 55, 80], -"ampharos": ["electric", "electric", 75, 115], -"bellossom": ["grass", "grass", 80, 90], -"marill": ["water", "water", 20, 20], -"azumarill": ["water", "water", 50, 50], -"sudowoodo": ["rock", "rock", 100, 30], -"politoed": ["water", "water", 75, 90], -"hoppip": ["grass", "flying", 35, 35], -"skiploom": ["grass", "flying", 45, 45], -"jumpluff": ["grass", "flying", 55, 55], -"aipom": ["normal", "normal", 70, 40], -"sunkern": ["grass", "grass", 30, 30], -"sunflora": ["grass", "grass", 75, 105], -"yanma": ["bug", "flying", 65, 75], -"wooper": ["water", "ground", 45, 25], -"quagsire": ["water", "ground", 85, 65], -"espeon": ["psychic", "psychic", 65, 130], -"umbreon": ["dark", "dark", 65, 60], -"murkrow": ["dark", "flying", 85, 85], -"slowking": ["water", "psychic", 75, 100], -"misdreavus": ["ghost", "ghost", 60, 85], -"unown": ["psychic", "psychic", 72, 72], -"wobbuffet": ["psychic", "psychic", 33, 33], -"girafarig": ["normal", "psychic", 80, 90], -"pineco": ["bug", "bug", 65, 35], -"forretress": ["bug", "steel", 90, 60], -"dunsparce": ["normal", "normal", 70, 65], -"gligar": ["ground", "flying", 75, 35], -"steelix": ["steel", "ground", 85, 55], -"snubbull": ["normal", "normal", 80, 40], -"granbull": ["normal", "normal", 120, 60], -"qwilfish": ["water", "poison", 95, 55], -"scizor": ["bug", "steel", 130, 55], -"shuckle": ["bug", "rock", 10, 10], -"heracross": ["bug", "fighting", 125, 40], -"sneasel": ["dark", "ice", 95, 35], -"teddiursa": ["normal", "normal", 80, 50], -"ursaring": ["normal", "normal", 130, 75], -"slugma": ["fire", "fire", 40, 70], -"magcargo": ["fire", "rock", 50, 80], -"swinub": ["ice", "ground", 50, 30], -"piloswine": ["ice", "ground", 100, 60], -"corsola": ["water", "rock", 55, 65], -"remoraid": ["water", "water", 65, 65], -"octillery": ["water", "water", 105, 105], -"delibird": ["ice", "flying", 55, 65], -"mantine": ["water", "flying", 40, 80], -"skarmory": ["steel", "flying", 80, 40], -"houndour": ["dark", "fire", 60, 80], -"houndoom": ["dark", "fire", 90, 110], -"kingdra": ["water", "dragon", 95, 95], -"phanpy": ["ground", "ground", 60, 40], -"donphan": ["ground", "ground", 120, 60], -"porygon2": ["normal", "normal", 80, 105], -"stantler": ["normal", "normal", 95, 85], -"smeargle": ["normal", "normal", 20, 20], -"tyrogue": ["fighting", "fighting", 35, 35], -"hitmontop": ["fighting", "fighting", 95, 35], -"smoochum": ["ice", "psychic", 30, 85], -"elekid": ["electric", "electric", 63, 65], -"magby": ["fire", "fire", 75, 70], -"miltank": ["normal", "normal", 80, 40], -"blissey": ["normal", "normal", 10, 75], -"raikou": ["electric", "electric", 85, 115], -"entei": ["fire", "fire", 115, 90], -"suicune": ["water", "water", 75, 90], -"larvitar": ["rock", "ground", 64, 45], -"pupitar": ["rock", "ground", 84, 65], -"tyranitar": ["rock", "dark", 134, 95], -"lugia": ["psychic", "flying", 90, 90], -"ho-oh": ["fire", "flying", 130, 110], -"celebi": ["psychic", "grass", 100, 100], -"treecko": ["grass", "grass", 45, 65], -"grovyle": ["grass", "grass", 65, 85], -"sceptile": ["grass", "grass", 85, 105], -"torchic": ["fire", "fire", 60, 70], -"combusken": ["fire", "fighting", 85, 85], -"blaziken": ["fire", "fighting", 120, 110], -"mudkip": ["water", "water", 70, 50], -"marshtomp": ["water", "ground", 85, 60], -"swampert": ["water", "ground", 110, 85], -"poochyena": ["dark", "dark", 55, 30], -"mightyena": ["dark", "dark", 90, 60], -"zigzagoon": ["normal", "normal", 30, 30], -"linoone": ["normal", "normal", 70, 50], -"wurmple": ["bug", "bug", 45, 20], -"silcoon": ["bug", "bug", 35, 25], -"beautifly": ["bug", "flying", 70, 90], -"cascoon": ["bug", "bug", 35, 25], -"dustox": ["bug", "poison", 50, 50], -"lotad": ["water", "grass", 30, 40], -"lombre": ["water", "grass", 50, 60], -"ludicolo": ["water", "grass", 70, 90], -"seedot": ["grass", "grass", 40, 30], -"nuzleaf": ["grass", "dark", 70, 60], -"shiftry": ["grass", "dark", 100, 90], -"nincada": ["bug", "ground", 45, 30], -"ninjask": ["bug", "flying", 90, 50], -"shedinja": ["bug", "ghost", 90, 30], -"taillow": ["normal", "flying", 55, 30], -"swellow": ["normal", "flying", 85, 50], -"shroomish": ["grass", "grass", 40, 40], -"breloom": ["grass", "fighting", 130, 60], -"spinda": ["normal", "normal", 60, 60], -"wingull": ["water", "flying", 30, 55], -"pelipper": ["water", "flying", 50, 85], -"surskit": ["bug", "water", 30, 50], -"masquerain": ["bug", "flying", 60, 80], -"wailmer": ["water", "water", 70, 70], -"wailord": ["water", "water", 90, 90], -"skitty": ["normal", "normal", 45, 35], -"delcatty": ["normal", "normal", 65, 55], -"kecleon": ["normal", "normal", 90, 60], -"baltoy": ["ground", "psychic", 40, 40], -"claydol": ["ground", "psychic", 70, 70], -"nosepass": ["rock", "rock", 45, 45], -"torkoal": ["fire", "fire", 85, 85], -"sableye": ["dark", "ghost", 75, 65], -"barboach": ["water", "ground", 48, 46], -"whiscash": ["water", "ground", 78, 76], -"luvdisc": ["water", "water", 30, 40], -"corphish": ["water", "water", 80, 50], -"crawdaunt": ["water", "dark", 120, 90], -"feebas": ["water", "water", 15, 10], -"milotic": ["water", "water", 60, 100], -"carvanha": ["water", "dark", 90, 65], -"sharpedo": ["water", "dark", 120, 95], -"trapinch": ["ground", "ground", 100, 45], -"vibrava": ["ground", "dragon", 70, 50], -"flygon": ["ground", "dragon", 100, 80], -"makuhita": ["fighting", "fighting", 60, 20], -"hariyama": ["fighting", "fighting", 120, 40], -"electrike": ["electric", "electric", 45, 65], -"manectric": ["electric", "electric", 75, 105], -"numel": ["fire", "ground", 60, 65], -"camerupt": ["fire", "ground", 100, 105], -"spheal": ["ice", "water", 40, 55], -"sealeo": ["ice", "water", 60, 75], -"walrein": ["ice", "water", 80, 95], -"cacnea": ["grass", "grass", 85, 85], -"cacturne": ["grass", "dark", 115, 115], -"snorunt": ["ice", "ice", 50, 50], -"glalie": ["ice", "ice", 80, 80], -"lunatone": ["rock", "psychic", 55, 95], -"solrock": ["rock", "psychic", 95, 55], -"azurill": ["normal", "normal", 20, 20], -"spoink": ["psychic", "psychic", 25, 70], -"grumpig": ["psychic", "psychic", 45, 90], -"plusle": ["electric", "electric", 50, 85], -"minun": ["electric", "electric", 40, 75], -"mawile": ["steel", "steel", 85, 55], -"meditite": ["fighting", "psychic", 40, 40], -"medicham": ["fighting", "psychic", 60, 60], -"swablu": ["normal", "flying", 40, 40], -"altaria": ["dragon", "flying", 70, 70], -"wynaut": ["psychic", "psychic", 23, 23], -"duskull": ["ghost", "ghost", 40, 30], -"dusclops": ["ghost", "ghost", 70, 60], -"roselia": ["grass", "poison", 60, 100], -"slakoth": ["normal", "normal", 60, 35], -"vigoroth": ["normal", "normal", 80, 55], -"slaking": ["normal", "normal", 160, 95], -"gulpin": ["poison", "poison", 43, 43], -"swalot": ["poison", "poison", 73, 73], -"tropius": ["grass", "flying", 68, 72], -"whismur": ["normal", "normal", 51, 51], -"loudred": ["normal", "normal", 71, 71], -"exploud": ["normal", "normal", 91, 91], -"clamperl": ["water", "water", 64, 74], -"huntail": ["water", "water", 104, 94], -"gorebyss": ["water", "water", 84, 114], -"absol": ["dark", "dark", 130, 75], -"shuppet": ["ghost", "ghost", 75, 63], -"banette": ["ghost", "ghost", 115, 83], -"seviper": ["poison", "poison", 100, 100], -"zangoose": ["normal", "normal", 115, 60], -"relicanth": ["water", "rock", 90, 45], -"aron": ["steel", "rock", 70, 40], -"lairon": ["steel", "rock", 90, 50], -"aggron": ["steel", "rock", 110, 60], -"castform": ["normal", "normal", 70, 70], -"volbeat": ["bug", "bug", 73, 47], -"illumise": ["bug", "bug", 47, 73], -"lileep": ["rock", "grass", 41, 61], -"cradily": ["rock", "grass", 81, 81], -"anorith": ["rock", "bug", 95, 40], -"armaldo": ["rock", "bug", 125, 70], -"ralts": ["psychic", "psychic", 25, 45], -"kirlia": ["psychic", "psychic", 35, 65], -"gardevoir": ["psychic", "psychic", 65, 125], -"bagon": ["dragon", "dragon", 75, 40], -"shelgon": ["dragon", "dragon", 95, 60], -"salamence": ["dragon", "flying", 135, 110], -"beldum": ["steel", "psychic", 55, 35], -"metang": ["steel", "psychic", 75, 55], -"metagross": ["steel", "psychic", 135, 95], -"regirock": ["rock", "rock", 100, 50], -"regice": ["ice", "ice", 50, 100], -"registeel": ["steel", "steel", 75, 75], -"kyogre": ["water", "water", 100, 150], -"groudon": ["ground", "ground", 150, 100], -"rayquaza": ["dragon", "flying", 150, 150], -"latias": ["dragon", "psychic", 80, 110], -"latios": ["dragon", "psychic", 90, 130], -"jirachi": ["steel", "psychic", 100, 100], -"deoxys": ["psychic", "psychic", 150, 150], -"chimecho": ["psychic", "psychic", 50, 95] +"bulbasaur": ["grass", "poison", 45, 49, 49, 65, 65, 45], +"ivysaur": ["grass", "poison", 60, 62, 63, 80, 80, 60], +"venusaur": ["grass", "poison", 80, 82, 83, 100, 100, 80], +"charmander": ["fire", "fire", 39, 52, 43, 60, 50, 65], +"charmeleon": ["fire", "fire", 58, 64, 58, 80, 65, 80], +"charizard": ["fire", "flying", 78, 84, 78, 109, 85, 100], +"squirtle": ["water", "water", 44, 48, 65, 50, 64, 43], +"wartortle": ["water", "water", 59, 63, 80, 65, 80, 58], +"blastoise": ["water", "water", 79, 83, 100, 85, 105, 78], +"caterpie": ["bug", "bug", 45, 30, 35, 20, 20, 45], +"metapod": ["bug", "bug", 50, 20, 55, 25, 25, 30], +"butterfree": ["bug", "flying", 60, 45, 50, 80, 80, 70], +"weedle": ["bug", "poison", 40, 35, 30, 20, 20, 50], +"kakuna": ["bug", "poison", 45, 25, 50, 25, 25, 35], +"beedrill": ["bug", "poison", 65, 80, 40, 45, 80, 75], +"pidgey": ["normal", "flying", 40, 45, 40, 35, 35, 56], +"pidgeotto": ["normal", "flying", 63, 60, 55, 50, 50, 71], +"pidgeot": ["normal", "flying", 83, 80, 75, 70, 70, 91], +"rattata": ["normal", "normal", 30, 56, 35, 25, 35, 72], +"raticate": ["normal", "normal", 55, 81, 60, 50, 70, 97], +"spearow": ["normal", "flying", 40, 60, 30, 31, 31, 70], +"fearow": ["normal", "flying", 65, 90, 65, 61, 61, 100], +"ekans": ["poison", "poison", 35, 60, 44, 40, 54, 55], +"arbok": ["poison", "poison", 60, 85, 69, 65, 79, 80], +"pikachu": ["electric", "electric", 35, 55, 30, 50, 40, 90], +"raichu": ["electric", "electric", 60, 90, 55, 90, 80, 100], +"sandshrew": ["ground", "ground", 50, 75, 85, 20, 30, 40], +"sandslash": ["ground", "ground", 75, 100, 110, 45, 55, 65], +"nidoran-f": ["poison", "poison", 55, 47, 52, 40, 40, 41], +"nidorina": ["poison", "poison", 70, 62, 67, 55, 55, 56], +"nidoqueen": ["poison", "ground", 90, 82, 87, 75, 85, 76], +"nidoran-m": ["poison", "poison", 46, 57, 40, 40, 40, 50], +"nidorino": ["poison", "poison", 61, 72, 57, 55, 55, 65], +"nidoking": ["poison", "ground", 81, 92, 77, 85, 75, 85], +"clefairy": ["normal", "normal", 70, 45, 48, 60, 65, 35], +"clefable": ["normal", "normal", 95, 70, 73, 85, 90, 60], +"vulpix": ["fire", "fire", 38, 41, 40, 50, 65, 65], +"ninetales": ["fire", "fire", 73, 76, 75, 81, 100, 100], +"jigglypuff": ["normal", "normal", 115, 45, 20, 45, 25, 20], +"wigglytuff": ["normal", "normal", 140, 70, 45, 75, 50, 45], +"zubat": ["poison", "flying", 40, 45, 35, 30, 40, 55], +"golbat": ["poison", "flying", 75, 80, 70, 65, 75, 90], +"oddish": ["grass", "poison", 45, 50, 55, 75, 65, 30], +"gloom": ["grass", "poison", 60, 65, 70, 85, 75, 40], +"vileplume": ["grass", "poison", 75, 80, 85, 100, 90, 50], +"paras": ["bug", "grass", 35, 70, 55, 45, 55, 25], +"parasect": ["bug", "grass", 60, 95, 80, 60, 80, 30], +"venonat": ["bug", "poison", 60, 55, 50, 40, 55, 45], +"venomoth": ["bug", "poison", 70, 65, 60, 90, 75, 90], +"diglett": ["ground", "ground", 10, 55, 25, 35, 45, 95], +"dugtrio": ["ground", "ground", 35, 80, 50, 50, 70, 120], +"meowth": ["normal", "normal", 40, 45, 35, 40, 40, 90], +"persian": ["normal", "normal", 65, 70, 60, 65, 65, 115], +"psyduck": ["water", "water", 50, 52, 48, 65, 50, 55], +"golduck": ["water", "water", 80, 82, 78, 95, 80, 85], +"mankey": ["fighting", "fighting", 40, 80, 35, 35, 45, 70], +"primeape": ["fighting", "fighting", 65, 105, 60, 60, 70, 95], +"growlithe": ["fire", "fire", 55, 70, 45, 70, 50, 60], +"arcanine": ["fire", "fire", 90, 110, 80, 100, 80, 95], +"poliwag": ["water", "water", 40, 50, 40, 40, 40, 90], +"poliwhirl": ["water", "water", 65, 65, 65, 50, 50, 90], +"poliwrath": ["water", "fighting", 90, 85, 95, 70, 90, 70], +"abra": ["psychic", "psychic", 25, 20, 15, 105, 55, 90], +"kadabra": ["psychic", "psychic", 40, 35, 30, 120, 70, 105], +"alakazam": ["psychic", "psychic", 55, 50, 45, 135, 85, 120], +"machop": ["fighting", "fighting", 70, 80, 50, 35, 35, 35], +"machoke": ["fighting", "fighting", 80, 100, 70, 50, 60, 45], +"machamp": ["fighting", "fighting", 90, 130, 80, 65, 85, 55], +"bellsprout": ["grass", "poison", 50, 75, 35, 70, 30, 40], +"weepinbell": ["grass", "poison", 65, 90, 50, 85, 45, 55], +"victreebel": ["grass", "poison", 80, 105, 65, 100, 60, 70], +"tentacool": ["water", "poison", 40, 40, 35, 50, 100, 70], +"tentacruel": ["water", "poison", 80, 70, 65, 80, 120, 100], +"geodude": ["rock", "ground", 40, 80, 100, 30, 30, 20], +"graveler": ["rock", "ground", 55, 95, 115, 45, 45, 35], +"golem": ["rock", "ground", 80, 110, 130, 55, 65, 45], +"ponyta": ["fire", "fire", 50, 85, 55, 65, 65, 90], +"rapidash": ["fire", "fire", 65, 100, 70, 80, 80, 105], +"slowpoke": ["water", "psychic", 90, 65, 65, 40, 40, 15], +"slowbro": ["water", "psychic", 95, 75, 110, 100, 80, 30], +"magnemite": ["electric", "steel", 25, 35, 70, 95, 55, 45], +"magneton": ["electric", "steel", 50, 60, 95, 120, 70, 70], +"farfetch-d": ["normal", "flying", 52, 65, 55, 58, 62, 60], +"doduo": ["normal", "flying", 35, 85, 45, 35, 35, 75], +"dodrio": ["normal", "flying", 60, 110, 70, 60, 60, 100], +"seel": ["water", "water", 65, 45, 55, 45, 70, 45], +"dewgong": ["water", "ice", 90, 70, 80, 70, 95, 70], +"grimer": ["poison", "poison", 80, 80, 50, 40, 50, 25], +"muk": ["poison", "poison", 105, 105, 75, 65, 100, 50], +"shellder": ["water", "water", 30, 65, 100, 45, 25, 40], +"cloyster": ["water", "ice", 50, 95, 180, 85, 45, 70], +"gastly": ["ghost", "poison", 30, 35, 30, 100, 35, 80], +"haunter": ["ghost", "poison", 45, 50, 45, 115, 55, 95], +"gengar": ["ghost", "poison", 60, 65, 60, 130, 75, 110], +"onix": ["rock", "ground", 35, 45, 160, 30, 45, 70], +"drowzee": ["psychic", "psychic", 60, 48, 45, 43, 90, 42], +"hypno": ["psychic", "psychic", 85, 73, 70, 73, 115, 67], +"krabby": ["water", "water", 30, 105, 90, 25, 25, 50], +"kingler": ["water", "water", 55, 130, 115, 50, 50, 75], +"voltorb": ["electric", "electric", 40, 30, 50, 55, 55, 100], +"electrode": ["electric", "electric", 60, 50, 70, 80, 80, 140], +"exeggcute": ["grass", "psychic", 60, 40, 80, 60, 45, 40], +"exeggutor": ["grass", "psychic", 95, 95, 85, 125, 65, 55], +"cubone": ["ground", "ground", 50, 50, 95, 40, 50, 35], +"marowak": ["ground", "ground", 60, 80, 110, 50, 80, 45], +"hitmonlee": ["fighting", "fighting", 50, 120, 53, 35, 110, 87], +"hitmonchan": ["fighting", "fighting", 50, 105, 79, 35, 110, 76], +"lickitung": ["normal", "normal", 90, 55, 75, 60, 75, 30], +"koffing": ["poison", "poison", 40, 65, 95, 60, 45, 35], +"weezing": ["poison", "poison", 65, 90, 120, 85, 70, 60], +"rhyhorn": ["ground", "rock", 80, 85, 95, 30, 30, 25], +"rhydon": ["ground", "rock", 105, 130, 120, 45, 45, 40], +"chansey": ["normal", "normal", 250, 5, 5, 35, 105, 50], +"tangela": ["grass", "grass", 65, 55, 115, 100, 40, 60], +"kangaskhan": ["normal", "normal", 105, 95, 80, 40, 80, 90], +"horsea": ["water", "water", 30, 40, 70, 70, 25, 60], +"seadra": ["water", "water", 55, 65, 95, 95, 45, 85], +"goldeen": ["water", "water", 45, 67, 60, 35, 50, 63], +"seaking": ["water", "water", 80, 92, 65, 65, 80, 68], +"staryu": ["water", "water", 30, 45, 55, 70, 55, 85], +"starmie": ["water", "psychic", 60, 75, 85, 100, 85, 115], +"mr-mime": ["psychic", "psychic", 40, 45, 65, 100, 120, 90], +"scyther": ["bug", "flying", 70, 110, 80, 55, 80, 105], +"jynx": ["ice", "psychic", 65, 50, 35, 115, 95, 95], +"electabuzz": ["electric", "electric", 65, 83, 57, 95, 85, 105], +"magmar": ["fire", "fire", 65, 95, 57, 100, 85, 93], +"pinsir": ["bug", "bug", 65, 125, 100, 55, 70, 85], +"tauros": ["normal", "normal", 75, 100, 95, 40, 70, 110], +"magikarp": ["water", "water", 20, 10, 55, 15, 20, 80], +"gyarados": ["water", "flying", 95, 125, 79, 60, 100, 81], +"lapras": ["water", "ice", 130, 85, 80, 85, 95, 60], +"ditto": ["normal", "normal", 48, 48, 48, 48, 48, 48], +"eevee": ["normal", "normal", 55, 55, 50, 45, 65, 55], +"vaporeon": ["water", "water", 130, 65, 60, 110, 95, 65], +"jolteon": ["electric", "electric", 65, 65, 60, 110, 95, 130], +"flareon": ["fire", "fire", 65, 130, 60, 95, 110, 65], +"porygon": ["normal", "normal", 65, 60, 70, 85, 75, 40], +"omanyte": ["rock", "water", 35, 40, 100, 90, 55, 35], +"omastar": ["rock", "water", 70, 60, 125, 115, 70, 55], +"kabuto": ["rock", "water", 30, 80, 90, 55, 45, 55], +"kabutops": ["rock", "water", 60, 115, 105, 65, 70, 80], +"aerodactyl": ["rock", "flying", 80, 105, 65, 60, 75, 130], +"snorlax": ["normal", "normal", 160, 110, 65, 65, 110, 30], +"articuno": ["ice", "flying", 90, 85, 100, 95, 125, 85], +"zapdos": ["electric", "flying", 90, 90, 85, 125, 90, 100], +"moltres": ["fire", "flying", 90, 100, 90, 125, 85, 90], +"dratini": ["dragon", "dragon", 41, 64, 45, 50, 50, 50], +"dragonair": ["dragon", "dragon", 61, 84, 65, 70, 70, 70], +"dragonite": ["dragon", "flying", 91, 134, 95, 100, 100, 80], +"mewtwo": ["psychic", "psychic", 106, 110, 90, 154, 90, 130], +"mew": ["psychic", "psychic", 100, 100, 100, 100, 100, 100], +"chikorita": ["grass", "grass", 45, 49, 65, 49, 65, 45], +"bayleef": ["grass", "grass", 60, 62, 80, 63, 80, 60], +"meganium": ["grass", "grass", 80, 82, 100, 83, 100, 80], +"cyndaquil": ["fire", "fire", 39, 52, 43, 60, 50, 65], +"quilava": ["fire", "fire", 58, 64, 58, 80, 65, 80], +"typhlosion": ["fire", "fire", 78, 84, 78, 109, 85, 100], +"totodile": ["water", "water", 50, 65, 64, 44, 48, 43], +"croconaw": ["water", "water", 65, 80, 80, 59, 63, 58], +"feraligatr": ["water", "water", 85, 105, 100, 79, 83, 78], +"sentret": ["normal", "normal", 35, 46, 34, 35, 45, 20], +"furret": ["normal", "normal", 85, 76, 64, 45, 55, 90], +"hoothoot": ["normal", "flying", 60, 30, 30, 36, 56, 50], +"noctowl": ["normal", "flying", 100, 50, 50, 76, 96, 70], +"ledyba": ["bug", "flying", 40, 20, 30, 40, 80, 55], +"ledian": ["bug", "flying", 55, 35, 50, 55, 110, 85], +"spinarak": ["bug", "poison", 40, 60, 40, 40, 40, 30], +"ariados": ["bug", "poison", 70, 90, 70, 60, 60, 40], +"crobat": ["poison", "flying", 85, 90, 80, 70, 80, 130], +"chinchou": ["water", "electric", 75, 38, 38, 56, 56, 67], +"lanturn": ["water", "electric", 125, 58, 58, 76, 76, 67], +"pichu": ["electric", "electric", 20, 40, 15, 35, 35, 60], +"cleffa": ["normal", "normal", 50, 25, 28, 45, 55, 15], +"igglybuff": ["normal", "normal", 90, 30, 15, 40, 20, 15], +"togepi": ["normal", "normal", 35, 20, 65, 40, 65, 20], +"togetic": ["normal", "flying", 55, 40, 85, 80, 105, 40], +"natu": ["psychic", "flying", 40, 50, 45, 70, 45, 70], +"xatu": ["psychic", "flying", 65, 75, 70, 95, 70, 95], +"mareep": ["electric", "electric", 55, 40, 40, 65, 45, 35], +"flaaffy": ["electric", "electric", 70, 55, 55, 80, 60, 45], +"ampharos": ["electric", "electric", 90, 75, 75, 115, 90, 55], +"bellossom": ["grass", "grass", 75, 80, 85, 90, 100, 50], +"marill": ["water", "water", 70, 20, 50, 20, 50, 40], +"azumarill": ["water", "water", 100, 50, 80, 50, 80, 50], +"sudowoodo": ["rock", "rock", 70, 100, 115, 30, 65, 30], +"politoed": ["water", "water", 90, 75, 75, 90, 100, 70], +"hoppip": ["grass", "flying", 35, 35, 40, 35, 55, 50], +"skiploom": ["grass", "flying", 55, 45, 50, 45, 65, 80], +"jumpluff": ["grass", "flying", 75, 55, 70, 55, 85, 110], +"aipom": ["normal", "normal", 55, 70, 55, 40, 55, 85], +"sunkern": ["grass", "grass", 30, 30, 30, 30, 30, 30], +"sunflora": ["grass", "grass", 75, 75, 55, 105, 85, 30], +"yanma": ["bug", "flying", 65, 65, 45, 75, 45, 95], +"wooper": ["water", "ground", 55, 45, 45, 25, 25, 15], +"quagsire": ["water", "ground", 95, 85, 85, 65, 65, 35], +"espeon": ["psychic", "psychic", 65, 65, 60, 130, 95, 110], +"umbreon": ["dark", "dark", 95, 65, 110, 60, 130, 65], +"murkrow": ["dark", "flying", 60, 85, 42, 85, 42, 91], +"slowking": ["water", "psychic", 95, 75, 80, 100, 110, 30], +"misdreavus": ["ghost", "ghost", 60, 60, 60, 85, 85, 85], +"unown": ["psychic", "psychic", 48, 72, 48, 72, 48, 48], +"wobbuffet": ["psychic", "psychic", 190, 33, 58, 33, 58, 33], +"girafarig": ["normal", "psychic", 70, 80, 65, 90, 65, 85], +"pineco": ["bug", "bug", 50, 65, 90, 35, 35, 15], +"forretress": ["bug", "steel", 75, 90, 140, 60, 60, 40], +"dunsparce": ["normal", "normal", 100, 70, 70, 65, 65, 45], +"gligar": ["ground", "flying", 65, 75, 105, 35, 65, 85], +"steelix": ["steel", "ground", 75, 85, 200, 55, 65, 30], +"snubbull": ["normal", "normal", 60, 80, 50, 40, 40, 30], +"granbull": ["normal", "normal", 90, 120, 75, 60, 60, 45], +"qwilfish": ["water", "poison", 65, 95, 75, 55, 55, 85], +"scizor": ["bug", "steel", 70, 130, 100, 55, 80, 65], +"shuckle": ["bug", "rock", 20, 10, 230, 10, 230, 5], +"heracross": ["bug", "fighting", 80, 125, 75, 40, 95, 85], +"sneasel": ["dark", "ice", 55, 95, 55, 35, 75, 115], +"teddiursa": ["normal", "normal", 60, 80, 50, 50, 50, 40], +"ursaring": ["normal", "normal", 90, 130, 75, 75, 75, 55], +"slugma": ["fire", "fire", 40, 40, 40, 70, 40, 20], +"magcargo": ["fire", "rock", 50, 50, 120, 80, 80, 30], +"swinub": ["ice", "ground", 50, 50, 40, 30, 30, 50], +"piloswine": ["ice", "ground", 100, 100, 80, 60, 60, 50], +"corsola": ["water", "rock", 55, 55, 85, 65, 85, 35], +"remoraid": ["water", "water", 35, 65, 35, 65, 35, 65], +"octillery": ["water", "water", 75, 105, 75, 105, 75, 45], +"delibird": ["ice", "flying", 45, 55, 45, 65, 45, 75], +"mantine": ["water", "flying", 65, 40, 70, 80, 140, 70], +"skarmory": ["steel", "flying", 65, 80, 140, 40, 70, 70], +"houndour": ["dark", "fire", 45, 60, 30, 80, 50, 65], +"houndoom": ["dark", "fire", 75, 90, 50, 110, 80, 95], +"kingdra": ["water", "dragon", 75, 95, 95, 95, 95, 85], +"phanpy": ["ground", "ground", 90, 60, 60, 40, 40, 40], +"donphan": ["ground", "ground", 90, 120, 120, 60, 60, 50], +"porygon2": ["normal", "normal", 85, 80, 90, 105, 95, 60], +"stantler": ["normal", "normal", 73, 95, 62, 85, 65, 85], +"smeargle": ["normal", "normal", 55, 20, 35, 20, 45, 75], +"tyrogue": ["fighting", "fighting", 35, 35, 35, 35, 35, 35], +"hitmontop": ["fighting", "fighting", 50, 95, 95, 35, 110, 70], +"smoochum": ["ice", "psychic", 45, 30, 15, 85, 65, 65], +"elekid": ["electric", "electric", 45, 63, 37, 65, 55, 95], +"magby": ["fire", "fire", 45, 75, 37, 70, 55, 83], +"miltank": ["normal", "normal", 95, 80, 105, 40, 70, 100], +"blissey": ["normal", "normal", 255, 10, 10, 75, 135, 55], +"raikou": ["electric", "electric", 90, 85, 75, 115, 100, 115], +"entei": ["fire", "fire", 115, 115, 85, 90, 75, 100], +"suicune": ["water", "water", 100, 75, 115, 90, 115, 85], +"larvitar": ["rock", "ground", 50, 64, 50, 45, 50, 41], +"pupitar": ["rock", "ground", 70, 84, 70, 65, 70, 51], +"tyranitar": ["rock", "dark", 100, 134, 110, 95, 100, 61], +"lugia": ["psychic", "flying", 106, 90, 130, 90, 154, 110], +"ho-oh": ["fire", "flying", 106, 130, 90, 110, 154, 90], +"celebi": ["psychic", "grass", 100, 100, 100, 100, 100, 100], +"treecko": ["grass", "grass", 40, 45, 35, 65, 55, 70], +"grovyle": ["grass", "grass", 50, 65, 45, 85, 65, 95], +"sceptile": ["grass", "grass", 70, 85, 65, 105, 85, 120], +"torchic": ["fire", "fire", 45, 60, 40, 70, 50, 45], +"combusken": ["fire", "fighting", 60, 85, 60, 85, 60, 55], +"blaziken": ["fire", "fighting", 80, 120, 70, 110, 70, 80], +"mudkip": ["water", "water", 50, 70, 50, 50, 50, 40], +"marshtomp": ["water", "ground", 70, 85, 70, 60, 70, 50], +"swampert": ["water", "ground", 100, 110, 90, 85, 90, 60], +"poochyena": ["dark", "dark", 35, 55, 35, 30, 30, 35], +"mightyena": ["dark", "dark", 70, 90, 70, 60, 60, 70], +"zigzagoon": ["normal", "normal", 38, 30, 41, 30, 41, 60], +"linoone": ["normal", "normal", 78, 70, 61, 50, 61, 100], +"wurmple": ["bug", "bug", 45, 45, 35, 20, 30, 20], +"silcoon": ["bug", "bug", 50, 35, 55, 25, 25, 15], +"beautifly": ["bug", "flying", 60, 70, 50, 90, 50, 65], +"cascoon": ["bug", "bug", 50, 35, 55, 25, 25, 15], +"dustox": ["bug", "poison", 60, 50, 70, 50, 90, 65], +"lotad": ["water", "grass", 40, 30, 30, 40, 50, 30], +"lombre": ["water", "grass", 60, 50, 50, 60, 70, 50], +"ludicolo": ["water", "grass", 80, 70, 70, 90, 100, 70], +"seedot": ["grass", "grass", 40, 40, 50, 30, 30, 30], +"nuzleaf": ["grass", "dark", 70, 70, 40, 60, 40, 60], +"shiftry": ["grass", "dark", 90, 100, 60, 90, 60, 80], +"nincada": ["bug", "ground", 31, 45, 90, 30, 30, 40], +"ninjask": ["bug", "flying", 61, 90, 45, 50, 50, 160], +"shedinja": ["bug", "ghost", 1, 90, 45, 30, 30, 40], +"taillow": ["normal", "flying", 40, 55, 30, 30, 30, 85], +"swellow": ["normal", "flying", 60, 85, 60, 50, 50, 125], +"shroomish": ["grass", "grass", 60, 40, 60, 40, 60, 35], +"breloom": ["grass", "fighting", 60, 130, 80, 60, 60, 70], +"spinda": ["normal", "normal", 60, 60, 60, 60, 60, 60], +"wingull": ["water", "flying", 40, 30, 30, 55, 30, 85], +"pelipper": ["water", "flying", 60, 50, 100, 85, 70, 65], +"surskit": ["bug", "water", 40, 30, 32, 50, 52, 65], +"masquerain": ["bug", "flying", 70, 60, 62, 80, 82, 60], +"wailmer": ["water", "water", 130, 70, 35, 70, 35, 60], +"wailord": ["water", "water", 170, 90, 45, 90, 45, 60], +"skitty": ["normal", "normal", 50, 45, 45, 35, 35, 50], +"delcatty": ["normal", "normal", 70, 65, 65, 55, 55, 70], +"kecleon": ["normal", "normal", 60, 90, 70, 60, 120, 40], +"baltoy": ["ground", "psychic", 40, 40, 55, 40, 70, 55], +"claydol": ["ground", "psychic", 60, 70, 105, 70, 120, 75], +"nosepass": ["rock", "rock", 30, 45, 135, 45, 90, 30], +"torkoal": ["fire", "fire", 70, 85, 140, 85, 70, 20], +"sableye": ["dark", "ghost", 50, 75, 75, 65, 65, 50], +"barboach": ["water", "ground", 50, 48, 43, 46, 41, 60], +"whiscash": ["water", "ground", 110, 78, 73, 76, 71, 60], +"luvdisc": ["water", "water", 43, 30, 55, 40, 65, 97], +"corphish": ["water", "water", 43, 80, 65, 50, 35, 35], +"crawdaunt": ["water", "dark", 63, 120, 85, 90, 55, 55], +"feebas": ["water", "water", 20, 15, 20, 10, 55, 80], +"milotic": ["water", "water", 95, 60, 79, 100, 125, 81], +"carvanha": ["water", "dark", 45, 90, 20, 65, 20, 65], +"sharpedo": ["water", "dark", 70, 120, 40, 95, 40, 95], +"trapinch": ["ground", "ground", 45, 100, 45, 45, 45, 10], +"vibrava": ["ground", "dragon", 50, 70, 50, 50, 50, 70], +"flygon": ["ground", "dragon", 80, 100, 80, 80, 80, 100], +"makuhita": ["fighting", "fighting", 72, 60, 30, 20, 30, 25], +"hariyama": ["fighting", "fighting", 144, 120, 60, 40, 60, 50], +"electrike": ["electric", "electric", 40, 45, 40, 65, 40, 65], +"manectric": ["electric", "electric", 70, 75, 60, 105, 60, 105], +"numel": ["fire", "ground", 60, 60, 40, 65, 45, 35], +"camerupt": ["fire", "ground", 70, 100, 70, 105, 75, 40], +"spheal": ["ice", "water", 70, 40, 50, 55, 50, 25], +"sealeo": ["ice", "water", 90, 60, 70, 75, 70, 45], +"walrein": ["ice", "water", 110, 80, 90, 95, 90, 65], +"cacnea": ["grass", "grass", 50, 85, 40, 85, 40, 35], +"cacturne": ["grass", "dark", 70, 115, 60, 115, 60, 55], +"snorunt": ["ice", "ice", 50, 50, 50, 50, 50, 50], +"glalie": ["ice", "ice", 80, 80, 80, 80, 80, 80], +"lunatone": ["rock", "psychic", 70, 55, 65, 95, 85, 70], +"solrock": ["rock", "psychic", 70, 95, 85, 55, 65, 70], +"azurill": ["normal", "normal", 50, 20, 40, 20, 40, 20], +"spoink": ["psychic", "psychic", 60, 25, 35, 70, 80, 60], +"grumpig": ["psychic", "psychic", 80, 45, 65, 90, 110, 80], +"plusle": ["electric", "electric", 60, 50, 40, 85, 75, 95], +"minun": ["electric", "electric", 60, 40, 50, 75, 85, 95], +"mawile": ["steel", "steel", 50, 85, 85, 55, 55, 50], +"meditite": ["fighting", "psychic", 30, 40, 55, 40, 55, 60], +"medicham": ["fighting", "psychic", 60, 60, 75, 60, 75, 80], +"swablu": ["normal", "flying", 45, 40, 60, 40, 75, 50], +"altaria": ["dragon", "flying", 75, 70, 90, 70, 105, 80], +"wynaut": ["psychic", "psychic", 95, 23, 48, 23, 48, 23], +"duskull": ["ghost", "ghost", 20, 40, 90, 30, 90, 25], +"dusclops": ["ghost", "ghost", 40, 70, 130, 60, 130, 25], +"roselia": ["grass", "poison", 50, 60, 45, 100, 80, 65], +"slakoth": ["normal", "normal", 60, 60, 60, 35, 35, 30], +"vigoroth": ["normal", "normal", 80, 80, 80, 55, 55, 90], +"slaking": ["normal", "normal", 150, 160, 100, 95, 65, 100], +"gulpin": ["poison", "poison", 70, 43, 53, 43, 53, 40], +"swalot": ["poison", "poison", 100, 73, 83, 73, 83, 55], +"tropius": ["grass", "flying", 99, 68, 83, 72, 87, 51], +"whismur": ["normal", "normal", 64, 51, 23, 51, 23, 28], +"loudred": ["normal", "normal", 84, 71, 43, 71, 43, 48], +"exploud": ["normal", "normal", 104, 91, 63, 91, 63, 68], +"clamperl": ["water", "water", 35, 64, 85, 74, 55, 32], +"huntail": ["water", "water", 55, 104, 105, 94, 75, 52], +"gorebyss": ["water", "water", 55, 84, 105, 114, 75, 52], +"absol": ["dark", "dark", 65, 130, 60, 75, 60, 75], +"shuppet": ["ghost", "ghost", 44, 75, 35, 63, 33, 45], +"banette": ["ghost", "ghost", 64, 115, 65, 83, 63, 65], +"seviper": ["poison", "poison", 73, 100, 60, 100, 60, 65], +"zangoose": ["normal", "normal", 73, 115, 60, 60, 60, 90], +"relicanth": ["water", "rock", 100, 90, 130, 45, 65, 55], +"aron": ["steel", "rock", 50, 70, 100, 40, 40, 30], +"lairon": ["steel", "rock", 60, 90, 140, 50, 50, 40], +"aggron": ["steel", "rock", 70, 110, 180, 60, 60, 50], +"castform": ["normal", "normal", 70, 70, 70, 70, 70, 70], +"volbeat": ["bug", "bug", 65, 73, 55, 47, 75, 85], +"illumise": ["bug", "bug", 65, 47, 55, 73, 75, 85], +"lileep": ["rock", "grass", 66, 41, 77, 61, 87, 23], +"cradily": ["rock", "grass", 86, 81, 97, 81, 107, 43], +"anorith": ["rock", "bug", 45, 95, 50, 40, 50, 75], +"armaldo": ["rock", "bug", 75, 125, 100, 70, 80, 45], +"ralts": ["psychic", "psychic", 28, 25, 25, 45, 35, 40], +"kirlia": ["psychic", "psychic", 38, 35, 35, 65, 55, 50], +"gardevoir": ["psychic", "psychic", 68, 65, 65, 125, 115, 80], +"bagon": ["dragon", "dragon", 45, 75, 60, 40, 30, 50], +"shelgon": ["dragon", "dragon", 65, 95, 100, 60, 50, 50], +"salamence": ["dragon", "flying", 95, 135, 80, 110, 80, 100], +"beldum": ["steel", "psychic", 40, 55, 80, 35, 60, 30], +"metang": ["steel", "psychic", 60, 75, 100, 55, 80, 50], +"metagross": ["steel", "psychic", 80, 135, 130, 95, 90, 70], +"regirock": ["rock", "rock", 80, 100, 200, 50, 100, 50], +"regice": ["ice", "ice", 80, 50, 100, 100, 200, 50], +"registeel": ["steel", "steel", 80, 75, 150, 75, 150, 50], +"kyogre": ["water", "water", 100, 100, 90, 150, 140, 90], +"groudon": ["ground", "ground", 100, 150, 140, 100, 90, 90], +"rayquaza": ["dragon", "flying", 105, 150, 90, 150, 90, 95], +"latias": ["dragon", "psychic", 80, 80, 90, 110, 130, 110], +"latios": ["dragon", "psychic", 80, 90, 80, 130, 110, 110], +"jirachi": ["steel", "psychic", 100, 100, 100, 100, 100, 100], +"deoxys": ["psychic", "psychic", 50, 150, 50, 150, 50, 150], +"chimecho": ["psychic", "psychic", 65, 50, 70, 95, 80, 65] } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json index 82880e1d31..3877817c87 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json @@ -1,641 +1,641 @@ { -"TRAINER_YOUNGSTER_BEN": [["rattata", 11], ["ekans", 11]], -"TRAINER_YOUNGSTER_CALVIN": [["spearow", 14]], -"TRAINER_YOUNGSTER_JOSH": [["rattata", 10], ["rattata", 10], ["zubat", 10]], -"TRAINER_YOUNGSTER_TIMMY": [["sandshrew", 14], ["ekans", 14]], -"TRAINER_YOUNGSTER_JOEY": [["rattata", 15], ["spearow", 15]], -"TRAINER_YOUNGSTER_DAN": [["slowpoke", 17]], -"TRAINER_YOUNGSTER_CHAD": [["ekans", 14], ["sandshrew", 14]], -"TRAINER_YOUNGSTER_TYLER": [["nidoran-m", 21]], -"TRAINER_YOUNGSTER_EDDIE": [["ekans", 21]], -"TRAINER_YOUNGSTER_DILLON": [["sandshrew", 19], ["zubat", 19]], -"TRAINER_YOUNGSTER_YASU": [["rattata", 17], ["rattata", 17], ["raticate", 17]], -"TRAINER_YOUNGSTER_DAVE": [["nidoran-m", 18], ["nidorino", 18]], -"TRAINER_YOUNGSTER_BEN_2": [["rattata", 17], ["ekans", 17]], -"TRAINER_BUG_CATCHER_RICK": [["weedle", 6], ["caterpie", 6]], -"TRAINER_BUG_CATCHER_DOUG": [["weedle", 7], ["kakuna", 7], ["weedle", 7]], -"TRAINER_BUG_CATCHER_SAMMY": [["weedle", 9]], -"TRAINER_BUG_CATCHER_COLTON": [["caterpie", 10], ["weedle", 10], ["caterpie", 10]], -"TRAINER_BUG_CATCHER_GREG": [["weedle", 9], ["kakuna", 9], ["caterpie", 9], ["metapod", 9]], -"TRAINER_BUG_CATCHER_JAMES": [["caterpie", 11], ["metapod", 11]], -"TRAINER_BUG_CATCHER_KENT": [["weedle", 11], ["kakuna", 11]], -"TRAINER_BUG_CATCHER_ROBBY": [["caterpie", 10], ["metapod", 10], ["caterpie", 10]], -"TRAINER_BUG_CATCHER_CALE": [["caterpie", 10], ["weedle", 10], ["metapod", 10], ["kakuna", 10]], -"TRAINER_BUG_CATCHER_KEIGO": [["weedle", 16], ["caterpie", 16], ["weedle", 16]], -"TRAINER_BUG_CATCHER_ELIJAH": [["butterfree", 20]], -"TRAINER_BUG_CATCHER_2": [["metapod", 18], ["caterpie", 18], ["venonat", 18]], -"TRAINER_BUG_CATCHER_BRENT": [["beedrill", 19], ["beedrill", 19]], -"TRAINER_BUG_CATCHER_CONNER": [["caterpie", 20], ["weedle", 20], ["venonat", 20]], -"TRAINER_LASS_JANICE": [["pidgey", 9], ["pidgey", 9]], -"TRAINER_LASS_SALLY": [["rattata", 10], ["nidoran-f", 10]], -"TRAINER_LASS_ROBIN": [["jigglypuff", 14]], -"TRAINER_LASS_CRISSY": [["paras", 31], ["paras", 31], ["parasect", 31]], -"TRAINER_LASS_MIRIAM": [["oddish", 11], ["bellsprout", 11]], -"TRAINER_LASS_IRIS": [["clefairy", 14]], -"TRAINER_LASS_RELI": [["nidoran-m", 16], ["nidoran-f", 16]], -"TRAINER_LASS_ALI": [["pidgey", 12], ["oddish", 12], ["bellsprout", 12]], -"TRAINER_LASS_2": [["nidoran-m", 15], ["nidoran-f", 15]], -"TRAINER_LASS_HALEY": [["oddish", 13], ["pidgey", 13], ["oddish", 13]], -"TRAINER_LASS_ANN": [["pidgey", 18], ["nidoran-f", 18]], -"TRAINER_LASS_DAWN": [["rattata", 18], ["pikachu", 18]], -"TRAINER_LASS_PAIGE": [["nidoran-f", 23], ["nidorina", 23]], -"TRAINER_LASS_ANDREA": [["meowth", 24], ["meowth", 24], ["meowth", 24]], -"TRAINER_LASS_MEGAN": [["pidgey", 19], ["rattata", 19], ["nidoran-m", 19], ["meowth", 19], ["pikachu", 19]], -"TRAINER_LASS_JULIA": [["clefairy", 22], ["clefairy", 22]], -"TRAINER_LASS_KAY": [["bellsprout", 23], ["weepinbell", 23]], -"TRAINER_LASS_LISA": [["oddish", 23], ["gloom", 23]], -"TRAINER_SAILOR_EDMOND": [["machop", 18], ["shellder", 18]], -"TRAINER_SAILOR_TREVOR": [["machop", 17], ["tentacool", 17]], -"TRAINER_SAILOR_LEONARD": [["shellder", 21]], -"TRAINER_SAILOR_DUNCAN": [["horsea", 17], ["shellder", 17], ["tentacool", 17]], -"TRAINER_SAILOR_HUEY": [["tentacool", 18], ["staryu", 18]], -"TRAINER_SAILOR_DYLAN": [["horsea", 17], ["horsea", 17], ["horsea", 17]], -"TRAINER_SAILOR_PHILLIP": [["machop", 20]], -"TRAINER_SAILOR_DWAYNE": [["pikachu", 21], ["pikachu", 21]], -"TRAINER_CAMPER_LIAM": [["geodude", 10, ["tackle", "defense-curl"]], ["sandshrew", 11, ["scratch", "defense-curl", "sand-attack"]]], -"TRAINER_CAMPER_SHANE": [["rattata", 14], ["ekans", 14]], -"TRAINER_CAMPER_ETHAN": [["mankey", 18]], -"TRAINER_CAMPER_RICKY": [["squirtle", 20]], -"TRAINER_CAMPER_JEFF": [["spearow", 16], ["raticate", 16]], -"TRAINER_CAMPER_CHRIS": [["growlithe", 21], ["charmander", 21]], -"TRAINER_CAMPER_DREW": [["rattata", 19], ["sandshrew", 19], ["ekans", 19], ["sandshrew", 19]], -"TRAINER_PICNICKER_DIANA": [["goldeen", 19]], -"TRAINER_PICNICKER_NANCY": [["rattata", 16], ["pikachu", 16]], -"TRAINER_PICNICKER_ISABELLE": [["pidgey", 16], ["pidgey", 16], ["pidgey", 16]], -"TRAINER_PICNICKER_KELSEY": [["nidoran-m", 15], ["nidoran-f", 15]], -"TRAINER_PICNICKER_ALICIA": [["oddish", 18], ["bellsprout", 18], ["oddish", 18], ["bellsprout", 18]], -"TRAINER_PICNICKER_CAITLIN": [["meowth", 23]], -"TRAINER_PICNICKER_HEIDI": [["pikachu", 20], ["clefairy", 20]], -"TRAINER_PICNICKER_CAROL": [["pidgey", 21], ["pidgeotto", 21]], -"TRAINER_PICNICKER_SOFIA": [["jigglypuff", 21], ["pidgey", 21], ["meowth", 21]], -"TRAINER_PICNICKER_MARTHA": [["oddish", 22], ["bulbasaur", 22]], -"TRAINER_PICNICKER_TINA": [["bulbasaur", 24], ["ivysaur", 24]], -"TRAINER_PICNICKER_HANNAH": [["pidgey", 24], ["meowth", 24], ["rattata", 24], ["pikachu", 24], ["meowth", 24]], -"TRAINER_POKEMANIAC_MARK": [["rhyhorn", 29], ["lickitung", 29]], -"TRAINER_POKEMANIAC_HERMAN": [["cubone", 20], ["slowpoke", 20]], -"TRAINER_POKEMANIAC_COOPER": [["slowpoke", 20], ["slowpoke", 20], ["slowpoke", 20]], -"TRAINER_POKEMANIAC_STEVE": [["charmander", 22], ["cubone", 22]], -"TRAINER_POKEMANIAC_WINSTON": [["slowpoke", 25]], -"TRAINER_POKEMANIAC_DAWSON": [["charmeleon", 40], ["lapras", 40], ["lickitung", 40]], -"TRAINER_POKEMANIAC_ASHTON": [["cubone", 23], ["slowpoke", 23]], -"TRAINER_SUPER_NERD_JOVAN": [["magnemite", 11], ["voltorb", 11]], -"TRAINER_SUPER_NERD_MIGUEL": [["grimer", 12], ["voltorb", 12], ["koffing", 12]], -"TRAINER_SUPER_NERD_AIDAN": [["voltorb", 20, ["sonic-boom", "screech", "tackle", "charge"]], ["koffing", 20, ["sludge", "smog", "tackle", "poison-gas"]], ["voltorb", 20, ["sonic-boom", "screech", "tackle", "charge"]], ["magnemite", 20, ["sonic-boom", "supersonic", "thunder-shock", "tackle"]]], -"TRAINER_SUPER_NERD_GLENN": [["grimer", 22], ["muk", 22], ["grimer", 22]], -"TRAINER_SUPER_NERD_LESLIE": [["koffing", 26, ["sludge", "smokescreen", "smog", "self-destruct"]]], -"TRAINER_SUPER_NERD_1": [["koffing", 22], ["magnemite", 22], ["weezing", 22]], -"TRAINER_SUPER_NERD_2": [["magnemite", 20], ["magnemite", 20], ["koffing", 20], ["magnemite", 20]], -"TRAINER_SUPER_NERD_3": [["magnemite", 24], ["voltorb", 24]], -"TRAINER_SUPER_NERD_ERIK": [["vulpix", 36], ["vulpix", 36], ["ninetales", 36]], -"TRAINER_SUPER_NERD_AVERY": [["ponyta", 34], ["charmander", 34], ["vulpix", 34], ["growlithe", 34]], -"TRAINER_SUPER_NERD_DEREK": [["rapidash", 41]], -"TRAINER_SUPER_NERD_ZAC": [["growlithe", 37], ["vulpix", 37]], -"TRAINER_HIKER_MARCOS": [["geodude", 10], ["geodude", 10], ["onix", 10]], -"TRAINER_HIKER_FRANKLIN": [["machop", 15], ["geodude", 15]], -"TRAINER_HIKER_NOB": [["geodude", 13], ["geodude", 13], ["machop", 13], ["geodude", 13]], -"TRAINER_HIKER_WAYNE": [["onix", 17]], -"TRAINER_HIKER_ALAN": [["geodude", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["onix", 21, ["harden", "rock-throw", "bind", "screech"]]], -"TRAINER_HIKER_BRICE": [["geodude", 20], ["machop", 20], ["geodude", 20]], -"TRAINER_HIKER_CLARK": [["geodude", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["onix", 21, ["harden", "rock-throw", "bind", "screech"]]], -"TRAINER_HIKER_TRENT": [["onix", 19], ["graveler", 19]], -"TRAINER_HIKER_DUDLEY": [["geodude", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["geodude", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["graveler", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]], -"TRAINER_HIKER_ALLEN": [["geodude", 25, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]], -"TRAINER_HIKER_ERIC": [["machop", 20], ["onix", 20]], -"TRAINER_HIKER_LENNY": [["geodude", 19], ["machop", 19], ["geodude", 19], ["geodude", 19]], -"TRAINER_HIKER_OLIVER": [["onix", 20], ["onix", 20], ["geodude", 20]], -"TRAINER_HIKER_LUCAS": [["geodude", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["graveler", 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]], -"TRAINER_BIKER_JARED": [["koffing", 28, ["smokescreen", "sludge", "smog", "poison-gas"]], ["koffing", 28, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, ["smokescreen", "sludge", "smog", "tackle"]]], -"TRAINER_BIKER_MALIK": [["koffing", 29, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 29, ["screech", "minimize", "sludge", "disable"]]], -"TRAINER_BIKER_ERNEST": [["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 25, ["minimize", "sludge", "disable", "pound"]]], -"TRAINER_BIKER_ALEX": [["koffing", 28, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 28, ["screech", "minimize", "sludge", "disable"]], ["weezing", 28, ["smokescreen", "sludge", "smog", "tackle"]]], -"TRAINER_BIKER_LAO": [["grimer", 29, ["screech", "minimize", "sludge", "disable"]], ["koffing", 29, ["smokescreen", "sludge", "smog", "tackle"]]], -"TRAINER_BIKER_HIDEO": [["weezing", 33]], -"TRAINER_BIKER_RUBEN": [["weezing", 28, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 28, ["smokescreen", "sludge", "smog", "tackle"]]], -"TRAINER_BIKER_BILLY": [["muk", 33]], -"TRAINER_BIKER_NIKOLAS": [["voltorb", 29, ["spark", "sonic-boom", "screech", "charge"]], ["voltorb", 29, ["spark", "sonic-boom", "screech", "charge"]]], -"TRAINER_BIKER_JAXON": [["weezing", 29, ["sludge", "smokescreen", "smog", "tackle"]], ["muk", 29, ["screech", "minimize", "sludge", "disable"]]], -"TRAINER_BIKER_WILLIAM": [["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, ["smokescreen", "sludge", "self-destruct", "tackle"]]], -"TRAINER_BIKER_LUKAS": [["koffing", 26, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 26, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 26, ["screech", "minimize", "sludge", "disable"]], ["koffing", 26, ["smokescreen", "sludge", "smog", "tackle"]]], -"TRAINER_BIKER_ISAAC": [["grimer", 28, ["screech", "minimize", "sludge", "disable"]], ["grimer", 28, ["screech", "minimize", "sludge", "disable"]], ["koffing", 28, ["smokescreen", "sludge", "smog", "tackle"]]], -"TRAINER_BIKER_GERALD": [["koffing", 29, ["smokescreen", "sludge", "smog", "tackle"]], ["muk", 29, ["screech", "minimize", "sludge", "disable"]]], -"TRAINER_BURGLAR_1": [["growlithe", 29], ["vulpix", 29]], -"TRAINER_BURGLAR_2": [["growlithe", 33]], -"TRAINER_BURGLAR_3": [["vulpix", 28], ["charmander", 28], ["ponyta", 28]], -"TRAINER_BURGLAR_QUINN": [["growlithe", 36], ["vulpix", 36], ["ninetales", 36]], -"TRAINER_BURGLAR_RAMON": [["ponyta", 41]], -"TRAINER_BURGLAR_DUSTY": [["vulpix", 37], ["growlithe", 37]], -"TRAINER_BURGLAR_ARNIE": [["charmander", 34], ["charmeleon", 34]], -"TRAINER_BURGLAR_4": [["charmander", 34], ["charmeleon", 34]], -"TRAINER_BURGLAR_SIMON": [["ninetales", 38]], -"TRAINER_BURGLAR_LEWIS": [["growlithe", 34], ["ponyta", 34]], -"TRAINER_ENGINEER_BAILY": [["voltorb", 21], ["magnemite", 21]], -"TRAINER_ENGINEER_BRAXTON": [["magnemite", 21]], -"TRAINER_ENGINEER_BERNIE": [["magnemite", 18], ["magnemite", 18], ["magneton", 18]], -"TRAINER_FISHERMAN_DALE": [["goldeen", 17], ["tentacool", 17], ["goldeen", 17]], -"TRAINER_FISHERMAN_BARNY": [["tentacool", 17], ["staryu", 17], ["shellder", 17]], -"TRAINER_FISHERMAN_NED": [["goldeen", 22], ["poliwag", 22], ["goldeen", 22]], -"TRAINER_FISHERMAN_CHIP": [["tentacool", 24], ["goldeen", 24]], -"TRAINER_FISHERMAN_HANK": [["goldeen", 27]], -"TRAINER_FISHERMAN_ELLIOT": [["poliwag", 21], ["shellder", 21], ["goldeen", 21], ["horsea", 21]], -"TRAINER_FISHERMAN_RONALD": [["seaking", 28], ["goldeen", 28], ["seaking", 28], ["seaking", 28]], -"TRAINER_FISHERMAN_CLAUDE": [["shellder", 31], ["cloyster", 31]], -"TRAINER_FISHERMAN_WADE": [["magikarp", 27], ["magikarp", 27], ["magikarp", 27], ["magikarp", 27], ["magikarp", 27], ["magikarp", 27]], -"TRAINER_FISHERMAN_NOLAN": [["seaking", 33], ["goldeen", 33]], -"TRAINER_FISHERMAN_ANDREW": [["magikarp", 24], ["magikarp", 24]], -"TRAINER_SWIMMER_MALE_LUIS": [["horsea", 16], ["shellder", 16]], -"TRAINER_SWIMMER_MALE_RICHARD": [["tentacool", 30], ["shellder", 30]], -"TRAINER_SWIMMER_MALE_REECE": [["goldeen", 29], ["horsea", 29], ["staryu", 29]], -"TRAINER_SWIMMER_MALE_MATTHEW": [["poliwag", 30], ["poliwhirl", 30]], -"TRAINER_SWIMMER_MALE_DOUGLAS": [["horsea", 27], ["tentacool", 27], ["tentacool", 27], ["goldeen", 27]], -"TRAINER_SWIMMER_MALE_DAVID": [["goldeen", 29], ["shellder", 29], ["seaking", 29]], -"TRAINER_SWIMMER_MALE_TONY": [["horsea", 30], ["horsea", 30]], -"TRAINER_SWIMMER_MALE_AXLE": [["tentacool", 27], ["tentacool", 27], ["staryu", 27], ["horsea", 27], ["tentacruel", 27]], -"TRAINER_SWIMMER_MALE_BARRY": [["shellder", 31], ["cloyster", 31]], -"TRAINER_SWIMMER_MALE_DEAN": [["staryu", 35]], -"TRAINER_SWIMMER_MALE_DARRIN": [["horsea", 28], ["horsea", 28], ["seadra", 28], ["horsea", 28]], -"TRAINER_SWIMMER_MALE_SPENCER": [["seadra", 33], ["tentacruel", 33]], -"TRAINER_SWIMMER_MALE_JACK": [["starmie", 37]], -"TRAINER_SWIMMER_MALE_JEROME": [["staryu", 33], ["wartortle", 33]], -"TRAINER_SWIMMER_MALE_ROLAND": [["poliwhirl", 32], ["tentacool", 32], ["seadra", 32]], -"TRAINER_CUE_BALL_KOJI": [["machop", 28], ["mankey", 28], ["machop", 28]], -"TRAINER_CUE_BALL_LUKE": [["mankey", 29], ["machop", 29]], -"TRAINER_CUE_BALL_CAMRON": [["mankey", 29], ["machop", 29]], -"TRAINER_CUE_BALL_RAUL": [["mankey", 29], ["primeape", 29]], -"TRAINER_CUE_BALL_ISAIAH": [["machop", 29], ["machamp", 29]], -"TRAINER_CUE_BALL_ZEEK": [["machoke", 33]], -"TRAINER_CUE_BALL_JAMAL": [["mankey", 26], ["mankey", 26], ["machamp", 26], ["machop", 26]], -"TRAINER_CUE_BALL_COREY": [["primeape", 29], ["machoke", 29]], -"TRAINER_CUE_BALL_CHASE": [["tentacool", 31], ["tentacool", 31], ["tentacruel", 31]], -"TRAINER_GAMER_HUGO": [["poliwag", 18], ["horsea", 18]], -"TRAINER_GAMER_JASPER": [["bellsprout", 18], ["oddish", 18]], -"TRAINER_GAMER_DIRK": [["voltorb", 18], ["magnemite", 18]], -"TRAINER_GAMER_DARIAN": [["growlithe", 18], ["vulpix", 18]], -"TRAINER_GAMER_STAN": [["poliwag", 22], ["poliwag", 22], ["poliwhirl", 22]], -"TRAINER_GAMER_RICH": [["growlithe", 24], ["vulpix", 24]], -"TRAINER_BEAUTY_BRIDGET": [["oddish", 21], ["bellsprout", 21], ["oddish", 21], ["bellsprout", 21]], -"TRAINER_BEAUTY_TAMIA": [["bellsprout", 24], ["bellsprout", 24]], -"TRAINER_BEAUTY_LORI": [["exeggcute", 24]], -"TRAINER_BEAUTY_LOLA": [["rattata", 27], ["pikachu", 27], ["rattata", 27]], -"TRAINER_BEAUTY_SHEILA": [["clefairy", 29], ["meowth", 29]], -"TRAINER_SWIMMER_FEMALE_TIFFANY": [["seaking", 35]], -"TRAINER_SWIMMER_FEMALE_NORA": [["shellder", 30], ["shellder", 30], ["cloyster", 30]], -"TRAINER_SWIMMER_FEMALE_MELISSA": [["poliwag", 31], ["seaking", 31]], -"TRAINER_BEAUTY_GRACE": [["pidgeotto", 29], ["wigglytuff", 29]], -"TRAINER_BEAUTY_OLIVIA": [["bulbasaur", 29], ["ivysaur", 29]], -"TRAINER_BEAUTY_LAUREN": [["weepinbell", 33], ["bellsprout", 33], ["weepinbell", 33]], -"TRAINER_SWIMMER_FEMALE_ANYA": [["poliwag", 27], ["goldeen", 27], ["seaking", 27], ["goldeen", 27], ["poliwag", 27]], -"TRAINER_SWIMMER_FEMALE_ALICE": [["goldeen", 30], ["seaking", 30]], -"TRAINER_SWIMMER_FEMALE_CONNIE": [["staryu", 29], ["staryu", 29], ["staryu", 29]], -"TRAINER_SWIMMER_FEMALE_SHIRLEY": [["seadra", 30], ["horsea", 30], ["seadra", 30]], -"TRAINER_PSYCHIC_JOHAN": [["kadabra", 31], ["slowpoke", 31], ["mr-mime", 31], ["kadabra", 31]], -"TRAINER_PSYCHIC_TYRON": [["mr-mime", 34], ["kadabra", 34]], -"TRAINER_PSYCHIC_CAMERON": [["slowpoke", 33], ["slowpoke", 33], ["slowbro", 33]], -"TRAINER_PSYCHIC_PRESTON": [["slowbro", 38]], -"TRAINER_ROCKER_RANDALL": [["voltorb", 20], ["magnemite", 20], ["voltorb", 20]], -"TRAINER_ROCKER_LUCA": [["voltorb", 29], ["electrode", 29]], -"TRAINER_JUGGLER_DALTON": [["kadabra", 29], ["mr-mime", 29]], -"TRAINER_JUGGLER_NELSON": [["drowzee", 41], ["hypno", 41], ["kadabra", 41], ["kadabra", 41]], -"TRAINER_JUGGLER_KIRK": [["drowzee", 31], ["drowzee", 31], ["kadabra", 31], ["drowzee", 31]], -"TRAINER_JUGGLER_SHAWN": [["drowzee", 34], ["hypno", 34]], -"TRAINER_JUGGLER_GREGORY": [["mr-mime", 48, ["psychic", "role-play", "double-slap", "encore"]]], -"TRAINER_JUGGLER_EDWARD": [["voltorb", 46, ["swift", "light-screen", "spark", "sonic-boom"]], ["voltorb", 46, ["swift", "light-screen", "spark", "sonic-boom"]], ["electrode", 47, ["swift", "spark", "self-destruct", "sonic-boom"]], ["mr-mime", 48, ["psychic", "role-play", "reflect", "encore"]]], -"TRAINER_JUGGLER_KAYDEN": [["hypno", 38]], -"TRAINER_JUGGLER_NATE": [["drowzee", 34], ["kadabra", 34]], -"TRAINER_TAMER_PHIL": [["sandslash", 34], ["arbok", 34]], -"TRAINER_TAMER_EDGAR": [["arbok", 33], ["sandslash", 33], ["arbok", 33]], -"TRAINER_TAMER_JASON": [["rhyhorn", 43]], -"TRAINER_TAMER_COLE": [["arbok", 39], ["tauros", 39]], -"TRAINER_TAMER_VINCENT": [["persian", 44], ["golduck", 44]], -"TRAINER_TAMER_JOHN": [["rhyhorn", 42], ["primeape", 42], ["arbok", 42], ["tauros", 42]], -"TRAINER_BIRD_KEEPER_SEBASTIAN": [["pidgey", 29], ["pidgeotto", 29]], -"TRAINER_BIRD_KEEPER_PERRY": [["spearow", 25], ["pidgey", 25], ["pidgey", 25], ["spearow", 25], ["spearow", 25]], -"TRAINER_BIRD_KEEPER_ROBERT": [["pidgey", 26], ["pidgeotto", 26], ["spearow", 26], ["fearow", 26]], -"TRAINER_BIRD_KEEPER_DONALD": [["farfetch-d", 33]], -"TRAINER_BIRD_KEEPER_BENNY": [["spearow", 29], ["fearow", 29]], -"TRAINER_BIRD_KEEPER_EDWIN": [["pidgeotto", 26], ["farfetch-d", 26], ["doduo", 26], ["pidgey", 26]], -"TRAINER_BIRD_KEEPER_CHESTER": [["dodrio", 28], ["doduo", 28], ["doduo", 28]], -"TRAINER_BIRD_KEEPER_WILTON": [["spearow", 29], ["fearow", 29]], -"TRAINER_BIRD_KEEPER_RAMIRO": [["dodrio", 34]], -"TRAINER_BIRD_KEEPER_JACOB": [["spearow", 26], ["spearow", 26], ["fearow", 26], ["spearow", 26]], -"TRAINER_BIRD_KEEPER_ROGER": [["fearow", 30], ["fearow", 30], ["pidgeotto", 30]], -"TRAINER_BIRD_KEEPER_REED": [["pidgeotto", 39], ["pidgeotto", 39], ["pidgey", 39], ["pidgeotto", 39]], -"TRAINER_BIRD_KEEPER_KEITH": [["farfetch-d", 39], ["fearow", 39]], -"TRAINER_BIRD_KEEPER_CARTER": [["pidgey", 28], ["doduo", 28], ["pidgeotto", 28]], -"TRAINER_BIRD_KEEPER_MITCH": [["pidgey", 26], ["spearow", 26], ["pidgey", 26], ["fearow", 26]], -"TRAINER_BIRD_KEEPER_BECK": [["pidgeotto", 29], ["fearow", 29]], -"TRAINER_BIRD_KEEPER_MARLON": [["spearow", 28], ["doduo", 28], ["fearow", 28]], -"TRAINER_BLACK_BELT_KOICHI": [["hitmonlee", 37], ["hitmonchan", 37]], -"TRAINER_BLACK_BELT_MIKE": [["mankey", 31], ["mankey", 31], ["primeape", 31]], -"TRAINER_BLACK_BELT_HIDEKI": [["machop", 32], ["machoke", 32]], -"TRAINER_BLACK_BELT_AARON": [["primeape", 36]], -"TRAINER_BLACK_BELT_HITOSHI": [["machop", 31], ["mankey", 31], ["primeape", 31]], -"TRAINER_BLACK_BELT_ATSUSHI": [["machop", 40], ["machoke", 40]], -"TRAINER_BLACK_BELT_KIYO": [["machoke", 43]], -"TRAINER_BLACK_BELT_TAKASHI": [["machoke", 38], ["machop", 38], ["machoke", 38]], -"TRAINER_BLACK_BELT_DAISUKE": [["machoke", 43], ["machop", 43], ["machoke", 43]], -"TRAINER_RIVAL_OAKS_LAB_SQUIRTLE": [["squirtle", 5]], -"TRAINER_RIVAL_OAKS_LAB_BULBASAUR": [["bulbasaur", 5]], -"TRAINER_RIVAL_OAKS_LAB_CHARMANDER": [["charmander", 5]], -"TRAINER_RIVAL_ROUTE22_EARLY_SQUIRTLE": [["pidgey", 9, ["tackle", "sand-attack"]], ["squirtle", 9, ["tackle", "tail-whip"]]], -"TRAINER_RIVAL_ROUTE22_EARLY_BULBASAUR": [["pidgey", 9, ["tackle", "sand-attack"]], ["bulbasaur", 9, ["tackle", "growl"]]], -"TRAINER_RIVAL_ROUTE22_EARLY_CHARMANDER": [["pidgey", 9, ["tackle", "sand-attack"]], ["charmander", 9, ["scratch", "growl"]]], -"TRAINER_RIVAL_CERULEAN_SQUIRTLE": [["pidgeotto", 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, ["teleport"]], ["rattata", 15, ["tackle", "tail-whip", "quick-attack"]], ["squirtle", 18, ["tackle", "tail-whip", "withdraw", "water-gun"]]], -"TRAINER_RIVAL_CERULEAN_BULBASAUR": [["pidgeotto", 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, ["teleport"]], ["rattata", 15, ["tackle", "tail-whip", "quick-attack"]], ["bulbasaur", 18, ["sleep-powder", "poison-powder", "vine-whip", "leech-seed"]]], -"TRAINER_RIVAL_CERULEAN_CHARMANDER": [["pidgeotto", 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, ["teleport"]], ["rattata", 15, ["tackle", "tail-whip", "quick-attack"]], ["charmander", 18, ["metal-claw", "ember", "growl", "scratch"]]], -"TRAINER_SCIENTIST_TED": [["electrode", 29], ["weezing", 29]], -"TRAINER_SCIENTIST_CONNOR": [["grimer", 26, ["screech", "minimize", "sludge", "disable"]], ["weezing", 26, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 26, ["smokescreen", "sludge", "smog", "self-destruct"]], ["weezing", 26, ["smokescreen", "sludge", "smog", "tackle"]]], -"TRAINER_SCIENTIST_JERRY": [["magnemite", 28], ["voltorb", 28], ["magneton", 28]], -"TRAINER_SCIENTIST_JOSE": [["electrode", 29, ["spark", "sonic-boom", "screech", "tackle"]], ["weezing", 29, ["smokescreen", "sludge", "smog", "tackle"]]], -"TRAINER_SCIENTIST_RODNEY": [["electrode", 33]], -"TRAINER_SCIENTIST_BEAU": [["magneton", 26, ["spark", "thunder-wave", "sonic-boom", "supersonic"]], ["koffing", 26, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 26, ["smokescreen", "sludge", "smog", "tackle"]], ["magnemite", 26, ["spark", "thunder-wave", "sonic-boom", "supersonic"]]], -"TRAINER_SCIENTIST_TAYLOR": [["voltorb", 25, ["spark", "sonic-boom", "screech", "tackle"]], ["koffing", 25, ["smokescreen", "sludge", "smog", "tackle"]], ["magneton", 25, ["thunder-wave", "sonic-boom", "supersonic", "thunder-shock"]], ["magnemite", 25, ["thunder-wave", "sonic-boom", "supersonic", "thunder-shock"]], ["koffing", 25, ["smokescreen", "sludge", "smog", "self-destruct"]]], -"TRAINER_SCIENTIST_JOSHUA": [["electrode", 29], ["muk", 29]], -"TRAINER_SCIENTIST_PARKER": [["grimer", 29], ["electrode", 29]], -"TRAINER_SCIENTIST_ED": [["voltorb", 28, ["spark", "sonic-boom", "screech", "tackle"]], ["koffing", 28, ["smokescreen", "sludge", "tackle", "smog"]], ["magneton", 28, ["spark", "thunder-wave", "sonic-boom", "supersonic"]]], -"TRAINER_SCIENTIST_TRAVIS": [["magnemite", 29], ["koffing", 29]], -"TRAINER_SCIENTIST_BRAYDON": [["magnemite", 33], ["magneton", 33], ["voltorb", 33]], -"TRAINER_SCIENTIST_IVAN": [["magnemite", 34], ["electrode", 34]], -"TRAINER_BOSS_GIOVANNI": [["onix", 25], ["rhyhorn", 24], ["kangaskhan", 29]], -"TRAINER_BOSS_GIOVANNI_2": [["nidorino", 37], ["kangaskhan", 35], ["rhyhorn", 37], ["nidoqueen", 41]], -"TRAINER_LEADER_GIOVANNI": [["rhyhorn", 45, ["take-down", "rock-blast", "scary-face", "earthquake"]], ["dugtrio", 42, ["slash", "sand-tomb", "mud-slap", "earthquake"]], ["nidoqueen", 44, ["body-slam", "double-kick", "poison-sting", "earthquake"]], ["nidoking", 45, ["thrash", "double-kick", "poison-sting", "earthquake"]], ["rhyhorn", 50, ["take-down", "rock-blast", "scary-face", "earthquake"]]], -"TRAINER_TEAM_ROCKET_GRUNT": [["rattata", 13], ["zubat", 13]], -"TRAINER_TEAM_ROCKET_GRUNT_2": [["sandshrew", 11], ["rattata", 11], ["zubat", 11]], -"TRAINER_TEAM_ROCKET_GRUNT_3": [["zubat", 11], ["ekans", 11]], -"TRAINER_TEAM_ROCKET_GRUNT_4": [["rattata", 13], ["sandshrew", 13]], -"TRAINER_TEAM_ROCKET_GRUNT_5": [["machop", 17], ["drowzee", 17]], -"TRAINER_TEAM_ROCKET_GRUNT_6": [["ekans", 15], ["zubat", 15]], -"TRAINER_TEAM_ROCKET_GRUNT_7": [["raticate", 20], ["zubat", 20]], -"TRAINER_TEAM_ROCKET_GRUNT_8": [["drowzee", 21], ["machop", 21]], -"TRAINER_TEAM_ROCKET_GRUNT_9": [["raticate", 21], ["raticate", 21]], -"TRAINER_TEAM_ROCKET_GRUNT_10": [["grimer", 20, ["minimize", "sludge", "disable", "harden"]], ["koffing", 20, ["smog", "tackle", "poison-gas"]], ["koffing", 20, ["smog", "tackle", "poison-gas"]]], -"TRAINER_TEAM_ROCKET_GRUNT_11": [["rattata", 19], ["raticate", 19], ["raticate", 19], ["rattata", 19]], -"TRAINER_TEAM_ROCKET_GRUNT_12": [["grimer", 22, ["minimize", "sludge", "disable", "harden"]], ["koffing", 22, ["sludge", "smog", "tackle", "poison-gas"]]], -"TRAINER_TEAM_ROCKET_GRUNT_13": [["zubat", 17, ["bite", "astonish", "supersonic", "leech-life"]], ["koffing", 17, ["smog", "tackle", "poison-gas"]], ["grimer", 17, ["sludge", "disable", "harden", "pound"]], ["zubat", 17, ["bite", "astonish", "supersonic", "leech-life"]], ["raticate", 17, ["hyper-fang", "quick-attack", "tail-whip", "tackle"]]], -"TRAINER_TEAM_ROCKET_GRUNT_14": [["rattata", 20], ["raticate", 20], ["drowzee", 20]], -"TRAINER_TEAM_ROCKET_GRUNT_15": [["machop", 21], ["machop", 21]], -"TRAINER_TEAM_ROCKET_GRUNT_16": [["sandshrew", 23], ["ekans", 23], ["sandslash", 23]], -"TRAINER_TEAM_ROCKET_GRUNT_17": [["ekans", 23], ["sandshrew", 23], ["arbok", 23]], -"TRAINER_TEAM_ROCKET_GRUNT_18": [["koffing", 21], ["zubat", 21]], -"TRAINER_TEAM_ROCKET_GRUNT_19": [["zubat", 25], ["zubat", 25], ["golbat", 25]], -"TRAINER_TEAM_ROCKET_GRUNT_20": [["koffing", 26], ["drowzee", 26]], -"TRAINER_TEAM_ROCKET_GRUNT_21": [["zubat", 23], ["rattata", 23], ["raticate", 23], ["zubat", 23]], -"TRAINER_TEAM_ROCKET_GRUNT_22": [["drowzee", 26], ["koffing", 26]], -"TRAINER_TEAM_ROCKET_GRUNT_23": [["cubone", 29], ["zubat", 29]], -"TRAINER_TEAM_ROCKET_GRUNT_24": [["golbat", 25], ["zubat", 25], ["zubat", 25], ["raticate", 25], ["zubat", 25]], -"TRAINER_TEAM_ROCKET_GRUNT_25": [["raticate", 28], ["hypno", 28], ["raticate", 28]], -"TRAINER_TEAM_ROCKET_GRUNT_26": [["machop", 29], ["drowzee", 29]], -"TRAINER_TEAM_ROCKET_GRUNT_27": [["ekans", 28], ["zubat", 28], ["cubone", 28]], -"TRAINER_TEAM_ROCKET_GRUNT_28": [["arbok", 33]], -"TRAINER_TEAM_ROCKET_GRUNT_29": [["hypno", 33]], -"TRAINER_TEAM_ROCKET_GRUNT_30": [["machop", 29], ["machoke", 29]], -"TRAINER_TEAM_ROCKET_GRUNT_31": [["zubat", 28], ["zubat", 28], ["golbat", 28]], -"TRAINER_TEAM_ROCKET_GRUNT_32": [["raticate", 26, ["scary-face", "hyper-fang", "quick-attack", "tail-whip"]], ["arbok", 26, ["glare", "bite", "poison-sting", "leer"]], ["koffing", 26, ["smokescreen", "sludge", "smog", "tackle"]], ["golbat", 26, ["wing-attack", "bite", "astonish", "supersonic"]]], -"TRAINER_TEAM_ROCKET_GRUNT_33": [["cubone", 29], ["cubone", 29]], -"TRAINER_TEAM_ROCKET_GRUNT_34": [["sandshrew", 29], ["sandslash", 29]], -"TRAINER_TEAM_ROCKET_GRUNT_35": [["raticate", 26], ["zubat", 26], ["golbat", 26], ["rattata", 26]], -"TRAINER_TEAM_ROCKET_GRUNT_36": [["weezing", 28], ["golbat", 28], ["koffing", 28]], -"TRAINER_TEAM_ROCKET_GRUNT_37": [["drowzee", 28], ["grimer", 28], ["machop", 28]], -"TRAINER_TEAM_ROCKET_GRUNT_38": [["golbat", 28], ["drowzee", 28], ["hypno", 28]], -"TRAINER_TEAM_ROCKET_GRUNT_39": [["machoke", 33]], -"TRAINER_TEAM_ROCKET_GRUNT_40": [["rattata", 25], ["rattata", 25], ["zubat", 25], ["rattata", 25], ["ekans", 25]], -"TRAINER_TEAM_ROCKET_GRUNT_41": [["cubone", 32], ["drowzee", 32], ["marowak", 32]], -"TRAINER_COOLTRAINER_SAMUEL": [["sandslash", 37, ["slash", "swift", "sand-attack", "poison-sting"]], ["sandslash", 37, ["slash", "swift", "sand-attack", "poison-sting"]], ["rhyhorn", 38, ["take-down", "rock-blast", "fury-attack", "scary-face"]], ["nidorino", 39, ["fury-attack", "horn-attack", "poison-sting", "double-kick"]], ["nidoking", 39, ["thrash", "double-kick", "poison-sting", "focus-energy"]]], -"TRAINER_COOLTRAINER_GEORGE": [["exeggutor", 42, ["egg-bomb", "confusion", "stun-spore", "sleep-powder"]], ["sandslash", 42, ["fury-swipes", "swift", "poison-sting", "sand-attack"]], ["cloyster", 42, ["spike-cannon", "spikes", "aurora-beam", "supersonic"]], ["electrode", 42, ["spark", "sonic-boom", "screech", "light-screen"]], ["arcanine", 42, ["flame-wheel", "roar", "bite", "take-down"]]], -"TRAINER_COOLTRAINER_COLBY": [["kingler", 41, ["guillotine", "stomp", "mud-shot", "bubble"]], ["poliwhirl", 42, ["body-slam", "double-slap", "water-gun", "hypnosis"]], ["tentacruel", 42, ["barrier", "wrap", "bubble-beam", "acid"]], ["seadra", 42, ["water-gun", "smokescreen", "twister", "leer"]], ["blastoise", 43, ["water-gun", "bite", "rapid-spin", "rain-dance"]]], -"TRAINER_COOLTRAINER_PAUL": [["slowpoke", 42, ["headbutt", "confusion", "water-gun", "disable"]], ["shellder", 42, ["aurora-beam", "clamp", "supersonic", "leer"]], ["kingler", 42, ["guillotine", "stomp", "mud-shot", "bubble"]], ["starmie", 42, ["bubble-beam", "swift", "recover", "rapid-spin"]], ["golduck", 42, ["confusion", "scratch", "screech", "disable"]]], -"TRAINER_COOLTRAINER_ROLANDO": [["raticate", 42, ["super-fang", "pursuit", "scary-face", "quick-attack"]], ["ivysaur", 42, ["razor-leaf", "sleep-powder", "sweet-scent", "synthesis"]], ["wartortle", 42, ["water-gun", "bite", "rapid-spin", "tail-whip"]], ["charmeleon", 42, ["flamethrower", "slash", "smokescreen", "scary-face"]], ["charizard", 42, ["flamethrower", "wing-attack", "smokescreen", "scary-face"]]], -"TRAINER_COOLTRAINER_GILBERT": [["pidgeotto", 42, ["wing-attack", "feather-dance", "whirlwind", "quick-attack"]], ["fearow", 42, ["drill-peck", "mirror-move", "pursuit", "leer"]], ["persian", 42, ["pay-day", "feint-attack", "screech", "bite"]], ["lickitung", 42, ["slam", "disable", "wrap", "supersonic"]], ["tauros", 42, ["horn-attack", "scary-face", "swagger", "tail-whip"]]], -"TRAINER_COOLTRAINER_OWEN": [["nidorino", 42, ["scratch", "poison-sting", "double-kick", "bite"]], ["nidorina", 42, ["horn-attack", "poison-sting", "double-kick", "leer"]], ["raticate", 42, ["super-fang", "pursuit", "scary-face", "quick-attack"]], ["sandslash", 42, ["fury-swipes", "swift", "slash", "poison-sting"]], ["rhyhorn", 42, ["rock-blast", "scary-face", "stomp", "tail-whip"]]], -"TRAINER_COOLTRAINER_BERKE": [["seel", 42, ["take-down", "aurora-beam", "icy-wind", "growl"]], ["graveler", 42, ["rock-blast", "magnitude", "rock-throw", "mud-sport"]], ["kingler", 42, ["guillotine", "stomp", "mud-shot", "bubble"]], ["onix", 42, ["slam", "sandstorm", "dragon-breath", "rock-throw"]], ["cloyster", 42, ["spike-cannon", "aurora-beam", "supersonic", "protect"]]], -"TRAINER_COOLTRAINER_YUJI": [["sandslash", 38, ["slash", "swift", "sand-attack", "poison-sting"]], ["graveler", 38, ["rock-blast", "magnitude", "mud-sport", "defense-curl"]], ["onix", 38, ["dragon-breath", "sandstorm", "rock-throw", "bind"]], ["graveler", 38, ["rock-blast", "magnitude", "rollout", "defense-curl"]], ["marowak", 38, ["bonemerang", "headbutt", "leer", "growl"]]], -"TRAINER_COOLTRAINER_WARREN": [["marowak", 37, ["bonemerang", "headbutt", "leer", "growl"]], ["marowak", 37, ["bonemerang", "headbutt", "leer", "growl"]], ["rhyhorn", 38, ["take-down", "rock-blast", "fury-attack", "scary-face"]], ["nidorina", 39, ["fury-swipes", "bite", "poison-sting", "double-kick"]], ["nidoqueen", 39, ["body-slam", "bite", "poison-sting", "double-kick"]]], -"TRAINER_COOLTRAINER_MARY": [["bellsprout", 22, ["wrap", "stun-spore", "poison-powder", "growth"]], ["oddish", 22, ["poison-powder", "stun-spore", "absorb", "sweet-scent"]], ["weepinbell", 22, ["vine-whip", "stun-spore", "poison-powder", "growth"]], ["gloom", 22, ["absorb", "stun-spore", "poison-powder", "sweet-scent"]], ["ivysaur", 22, ["razor-leaf", "sleep-powder", "vine-whip", "leech-seed"]]], -"TRAINER_COOLTRAINER_CAROLINE": [["bellsprout", 42, ["razor-leaf", "acid", "stun-spore", "poison-powder"]], ["weepinbell", 42, ["razor-leaf", "acid", "sleep-powder", "poison-powder"]], ["victreebel", 42, ["razor-leaf", "acid", "stun-spore", "sleep-powder"]], ["paras", 42, ["growth", "slash", "leech-life", "stun-spore"]], ["parasect", 42, ["spore", "slash", "leech-life", "poison-powder"]]], -"TRAINER_COOLTRAINER_ALEXA": [["clefairy", 42, ["light-screen", "cosmic-power", "double-slap", "encore"]], ["jigglypuff", 42, ["sing", "body-slam", "rollout", "disable"]], ["persian", 42, ["pay-day", "feint-attack", "bite", "screech"]], ["dewgong", 42, ["sheer-cold", "take-down", "rest", "aurora-beam"]], ["chansey", 42, ["sing", "egg-bomb", "soft-boiled", "minimize"]]], -"TRAINER_COOLTRAINER_SHANNON": [["beedrill", 42, ["pin-missile", "twineedle", "agility", "pursuit"]], ["butterfree", 42, ["safeguard", "psybeam", "gust", "supersonic"]], ["parasect", 42, ["spore", "leech-life", "slash", "growth"]], ["venonat", 42, ["psybeam", "stun-spore", "leech-life", "disable"]], ["venomoth", 42, ["psybeam", "gust", "supersonic", "leech-life"]]], -"TRAINER_COOLTRAINER_NAOMI": [["persian", 42, ["fury-swipes", "screech", "feint-attack", "pay-day"]], ["ponyta", 42, ["agility", "take-down", "fire-spin", "stomp"]], ["rapidash", 42, ["fury-attack", "fire-spin", "stomp", "growl"]], ["vulpix", 42, ["flamethrower", "confuse-ray", "quick-attack", "imprison"]], ["ninetales", 42, ["safeguard", "will-o-wisp", "confuse-ray", "fire-spin"]]], -"TRAINER_COOLTRAINER_BROOKE": [["tangela", 42, ["slam", "bind", "mega-drain", "ingrain"]], ["gloom", 42, ["acid", "moonlight", "sleep-powder", "stun-spore"]], ["vileplume", 42, ["mega-drain", "acid", "stun-spore", "aromatherapy"]], ["ivysaur", 42, ["razor-leaf", "sweet-scent", "growl", "leech-seed"]], ["venusaur", 42, ["razor-leaf", "growth", "sleep-powder", "poison-powder"]]], -"TRAINER_COOLTRAINER_AUSTINA": [["rhyhorn", 42, ["horn-drill", "rock-blast", "scary-face", "stomp"]], ["nidorina", 42, ["double-kick", "fury-swipes", "bite", "flatter"]], ["nidoqueen", 42, ["body-slam", "double-kick", "bite", "growl"]], ["nidorino", 42, ["horn-attack", "poison-sting", "focus-energy", "leer"]], ["nidoking", 42, ["thrash", "double-kick", "poison-sting", "peck"]]], -"TRAINER_COOLTRAINER_JULIE": [["persian", 42, ["fury-swipes", "bite", "screech", "feint-attack"]], ["ninetales", 42, ["flamethrower", "will-o-wisp", "confuse-ray", "grudge"]], ["rapidash", 42, ["fury-attack", "fire-spin", "take-down", "agility"]], ["pikachu", 42, ["thunderbolt", "thunder-wave", "double-team", "quick-attack"]], ["raichu", 42, ["thunder", "thunder-wave", "slam", "double-team"]]], -"TRAINER_ELITE_FOUR_LORELEI": [["dewgong", 52, ["ice-beam", "surf", "hail", "safeguard"]], ["cloyster", 51, ["spikes", "protect", "hail", "dive"]], ["slowbro", 52, ["ice-beam", "surf", "amnesia", "yawn"]], ["jynx", 54, ["ice-punch", "double-slap", "lovely-kiss", "attract"]], ["lapras", 54, ["confuse-ray", "ice-beam", "surf", "body-slam"]]], -"TRAINER_ELITE_FOUR_BRUNO": [["onix", 51, ["earthquake", "rock-tomb", "iron-tail", "roar"]], ["hitmonchan", 53, ["sky-uppercut", "mach-punch", "rock-tomb", "counter"]], ["hitmonlee", 53, ["mega-kick", "foresight", "brick-break", "facade"]], ["onix", 54, ["double-edge", "earthquake", "iron-tail", "sand-tomb"]], ["machamp", 56, ["cross-chop", "bulk-up", "scary-face", "rock-tomb"]]], -"TRAINER_ELITE_FOUR_AGATHA": [["gengar", 54, ["shadow-punch", "confuse-ray", "toxic", "double-team"]], ["golbat", 54, ["confuse-ray", "poison-fang", "air-cutter", "bite"]], ["haunter", 53, ["hypnosis", "dream-eater", "curse", "mean-look"]], ["arbok", 56, ["sludge-bomb", "screech", "iron-tail", "bite"]], ["gengar", 58, ["shadow-ball", "sludge-bomb", "hypnosis", "nightmare"]]], -"TRAINER_ELITE_FOUR_LANCE": [["gyarados", 56, ["hyper-beam", "dragon-rage", "twister", "bite"]], ["dragonair", 54, ["hyper-beam", "safeguard", "dragon-rage", "outrage"]], ["dragonair", 54, ["hyper-beam", "safeguard", "thunder-wave", "outrage"]], ["aerodactyl", 58, ["hyper-beam", "ancient-power", "wing-attack", "scary-face"]], ["dragonite", 60, ["hyper-beam", "safeguard", "outrage", "wing-attack"]]], -"TRAINER_LEADER_BROCK": [["geodude", 12, ["tackle", "defense-curl"]], ["onix", 14, ["tackle", "bind", "rock-tomb"]]], -"TRAINER_LEADER_MISTY": [["staryu", 18, ["tackle", "harden", "recover", "water-pulse"]], ["starmie", 21, ["swift", "recover", "rapid-spin", "water-pulse"]]], -"TRAINER_LEADER_LT_SURGE": [["voltorb", 21, ["sonic-boom", "tackle", "screech", "shock-wave"]], ["pikachu", 18, ["quick-attack", "thunder-wave", "double-team", "shock-wave"]], ["raichu", 24, ["quick-attack", "thunder-wave", "double-team", "shock-wave"]]], -"TRAINER_LEADER_ERIKA": [["victreebel", 29, ["stun-spore", "acid", "poison-powder", "giga-drain"]], ["tangela", 24, ["poison-powder", "constrict", "ingrain", "giga-drain"]], ["vileplume", 29, ["sleep-powder", "acid", "stun-spore", "giga-drain"]]], -"TRAINER_LEADER_KOGA": [["koffing", 37, ["self-destruct", "sludge", "smokescreen", "toxic"]], ["muk", 39, ["minimize", "sludge", "acid-armor", "toxic"]], ["koffing", 37, ["self-destruct", "sludge", "smokescreen", "toxic"]], ["weezing", 43, ["tackle", "sludge", "smokescreen", "toxic"]]], -"TRAINER_LEADER_BLAINE": [["growlithe", 42, ["bite", "roar", "take-down", "fire-blast"]], ["ponyta", 40, ["stomp", "bounce", "fire-spin", "fire-blast"]], ["rapidash", 42, ["stomp", "bounce", "fire-spin", "fire-blast"]], ["arcanine", 47, ["bite", "roar", "take-down", "fire-blast"]]], -"TRAINER_LEADER_SABRINA": [["kadabra", 38, ["psybeam", "reflect", "future-sight", "calm-mind"]], ["mr-mime", 37, ["barrier", "psybeam", "baton-pass", "calm-mind"]], ["venomoth", 38, ["psybeam", "gust", "leech-life", "supersonic"]], ["alakazam", 43, ["psychic", "recover", "future-sight", "calm-mind"]]], -"TRAINER_GENTLEMAN_THOMAS": [["growlithe", 18], ["growlithe", 18]], -"TRAINER_GENTLEMAN_ARTHUR": [["nidoran-m", 19], ["nidoran-f", 19]], -"TRAINER_GENTLEMAN_TUCKER": [["pikachu", 23]], -"TRAINER_GENTLEMAN_NORTON": [["persian", 48]], -"TRAINER_GENTLEMAN_WALTER": [["growlithe", 17], ["ponyta", 17]], -"TRAINER_RIVAL_SS_ANNE_SQUIRTLE": [["pidgeotto", 19], ["raticate", 16], ["kadabra", 18], ["wartortle", 20]], -"TRAINER_RIVAL_SS_ANNE_BULBASAUR": [["pidgeotto", 19], ["raticate", 16], ["kadabra", 18], ["ivysaur", 20]], -"TRAINER_RIVAL_SS_ANNE_CHARMANDER": [["pidgeotto", 19], ["raticate", 16], ["kadabra", 18], ["charmeleon", 20]], -"TRAINER_RIVAL_POKEMON_TOWER_SQUIRTLE": [["pidgeotto", 25], ["growlithe", 23], ["exeggcute", 22], ["kadabra", 20], ["wartortle", 25]], -"TRAINER_RIVAL_POKEMON_TOWER_BULBASAUR": [["pidgeotto", 25], ["gyarados", 23], ["growlithe", 22], ["kadabra", 20], ["ivysaur", 25]], -"TRAINER_RIVAL_POKEMON_TOWER_CHARMANDER": [["pidgeotto", 25], ["exeggcute", 23], ["gyarados", 22], ["kadabra", 20], ["charmeleon", 25]], -"TRAINER_RIVAL_SILPH_SQUIRTLE": [["pidgeot", 37], ["growlithe", 38], ["exeggcute", 35], ["alakazam", 35], ["blastoise", 40]], -"TRAINER_RIVAL_SILPH_BULBASAUR": [["pidgeot", 37], ["gyarados", 38], ["growlithe", 35], ["alakazam", 35], ["venusaur", 40]], -"TRAINER_RIVAL_SILPH_CHARMANDER": [["pidgeot", 37], ["exeggcute", 38], ["gyarados", 35], ["alakazam", 35], ["charizard", 40]], -"TRAINER_RIVAL_ROUTE22_LATE_SQUIRTLE": [["pidgeot", 47, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["growlithe", 45, ["flame-wheel", "take-down", "leer", "agility"]], ["exeggcute", 45, ["solar-beam", "sleep-powder", "poison-powder", "stun-spore"]], ["alakazam", 47, ["psychic", "calm-mind", "future-sight", "disable"]], ["blastoise", 53, ["water-gun", "rain-dance", "bite", "rapid-spin"]]], -"TRAINER_RIVAL_ROUTE22_LATE_BULBASAUR": [["pidgeot", 47, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["gyarados", 45, ["hydro-pump", "twister", "leer", "rain-dance"]], ["growlithe", 45, ["flame-wheel", "take-down", "leer", "agility"]], ["alakazam", 47, ["psychic", "calm-mind", "future-sight", "disable"]], ["venusaur", 53, ["razor-leaf", "sweet-scent", "growth", "synthesis"]]], -"TRAINER_RIVAL_ROUTE22_LATE_CHARMANDER": [["pidgeot", 47, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["exeggcute", 45, ["solar-beam", "sleep-powder", "poison-powder", "stun-spore"]], ["gyarados", 45, ["hydro-pump", "twister", "leer", "rain-dance"]], ["alakazam", 47, ["psychic", "calm-mind", "future-sight", "disable"]], ["charizard", 53, ["flamethrower", "wing-attack", "slash", "scary-face"]]], -"TRAINER_CHAMPION_FIRST_SQUIRTLE": [["pidgeot", 59, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["arcanine", 59, ["extreme-speed", "flamethrower", "roar", "bite"]], ["exeggutor", 61, ["giga-drain", "egg-bomb", "sleep-powder", "light-screen"]], ["blastoise", 63, ["hydro-pump", "rain-dance", "skull-bash", "bite"]]], -"TRAINER_CHAMPION_FIRST_BULBASAUR": [["pidgeot", 59, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["gyarados", 59, ["hydro-pump", "dragon-rage", "bite", "thrash"]], ["arcanine", 61, ["extreme-speed", "flamethrower", "roar", "bite"]], ["venusaur", 63, ["solar-beam", "synthesis", "sunny-day", "growth"]]], -"TRAINER_CHAMPION_FIRST_CHARMANDER": [["pidgeot", 59, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["exeggutor", 59, ["giga-drain", "egg-bomb", "sleep-powder", "light-screen"]], ["gyarados", 61, ["hydro-pump", "dragon-rage", "bite", "thrash"]], ["charizard", 63, ["fire-blast", "aerial-ace", "slash", "fire-spin"]]], -"TRAINER_CHANNELER_PATRICIA": [["gastly", 22]], -"TRAINER_CHANNELER_CARLY": [["gastly", 24]], -"TRAINER_CHANNELER_HOPE": [["gastly", 23]], -"TRAINER_CHANNELER_PAULA": [["gastly", 24]], -"TRAINER_CHANNELER_LAUREL": [["gastly", 23], ["gastly", 23]], -"TRAINER_CHANNELER_JODY": [["gastly", 22]], -"TRAINER_CHANNELER_TAMMY": [["haunter", 23]], -"TRAINER_CHANNELER_RUTH": [["gastly", 22]], -"TRAINER_CHANNELER_KARINA": [["gastly", 24]], -"TRAINER_CHANNELER_JANAE": [["gastly", 22]], -"TRAINER_CHANNELER_ANGELICA": [["gastly", 22], ["gastly", 22], ["gastly", 22]], -"TRAINER_CHANNELER_EMILIA": [["gastly", 24]], -"TRAINER_CHANNELER_JENNIFER": [["gastly", 24]], -"TRAINER_CHANNELER_1": [["haunter", 23]], -"TRAINER_CHANNELER_2": [["gastly", 24]], -"TRAINER_CHANNELER_3": [["gastly", 22]], -"TRAINER_CHANNELER_4": [["gastly", 24]], -"TRAINER_CHANNELER_5": [["haunter", 22]], -"TRAINER_CHANNELER_6": [["gastly", 22], ["gastly", 22], ["gastly", 22]], -"TRAINER_CHANNELER_7": [["gastly", 24]], -"TRAINER_CHANNELER_8": [["gastly", 24]], -"TRAINER_CHANNELER_AMANDA": [["gastly", 34], ["haunter", 34]], -"TRAINER_CHANNELER_STACY": [["haunter", 38]], -"TRAINER_CHANNELER_TASHA": [["gastly", 33], ["gastly", 33], ["haunter", 33]], -"TRAINER_HIKER_JEREMY": [["machop", 20], ["onix", 20]], -"TRAINER_PICNICKER_ALMA": [["goldeen", 28], ["poliwag", 28], ["horsea", 28]], -"TRAINER_PICNICKER_SUSIE": [["pidgey", 24], ["meowth", 24], ["rattata", 24], ["pikachu", 24], ["meowth", 24]], -"TRAINER_PICNICKER_VALERIE": [["poliwag", 30], ["poliwag", 30]], -"TRAINER_PICNICKER_GWEN": [["pidgey", 27], ["meowth", 27], ["pidgey", 27], ["pidgeotto", 27]], -"TRAINER_BIKER_VIRGIL": [["weezing", 28, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 28, ["smokescreen", "sludge", "smog", "tackle"]]], -"TRAINER_CAMPER_FLINT": [["rattata", 14], ["ekans", 14]], -"TRAINER_PICNICKER_MISSY": [["goldeen", 31], ["seaking", 31]], -"TRAINER_PICNICKER_IRENE": [["tentacool", 30], ["horsea", 30], ["seel", 30]], -"TRAINER_PICNICKER_DANA": [["meowth", 20], ["oddish", 20], ["pidgey", 20]], -"TRAINER_PICNICKER_ARIANA": [["pidgey", 19], ["rattata", 19], ["rattata", 19], ["bellsprout", 19]], -"TRAINER_PICNICKER_LEAH": [["bellsprout", 22], ["clefairy", 22]], -"TRAINER_CAMPER_JUSTIN": [["nidoran-m", 29], ["nidorino", 29]], -"TRAINER_PICNICKER_YAZMIN": [["bellsprout", 29], ["oddish", 29], ["tangela", 29]], -"TRAINER_PICNICKER_KINDRA": [["gloom", 28], ["oddish", 28], ["oddish", 28]], -"TRAINER_PICNICKER_BECKY": [["pikachu", 29], ["raichu", 29]], -"TRAINER_PICNICKER_CELIA": [["clefairy", 33]], -"TRAINER_GENTLEMAN_BROOKS": [["pikachu", 23]], -"TRAINER_GENTLEMAN_LAMAR": [["growlithe", 17], ["ponyta", 17]], -"TRAINER_TWINS_ELI_ANNE": [["clefairy", 22], ["jigglypuff", 22]], -"TRAINER_COOL_COUPLE_RAY_TYRA": [["nidoqueen", 45, ["superpower", "body-slam", "double-kick", "poison-sting"]], ["nidoking", 45, ["megahorn", "thrash", "double-kick", "poison-sting"]]], -"TRAINER_YOUNG_COUPLE_GIA_JES": [["nidoran-m", 24], ["nidoran-f", 24]], -"TRAINER_TWINS_KIRI_JAN": [["charmander", 29], ["squirtle", 29]], -"TRAINER_CRUSH_KIN_RON_MYA": [["hitmonchan", 29], ["hitmonlee", 29]], -"TRAINER_YOUNG_COUPLE_LEA_JED": [["rapidash", 29], ["ninetales", 29]], -"TRAINER_SIS_AND_BRO_LIA_LUC": [["goldeen", 30], ["seaking", 30]], -"TRAINER_SIS_AND_BRO_LIL_IAN": [["seadra", 33], ["starmie", 33]], -"TRAINER_YOUNGSTER_BEN_3": [["raticate", 28], ["ekans", 28]], -"TRAINER_YOUNGSTER_BEN_4": [["raticate", 48], ["arbok", 48]], -"TRAINER_YOUNGSTER_CHAD_2": [["ekans", 20], ["sandshrew", 20]], -"TRAINER_LASS_RELI_2": [["pidgey", 20], ["nidoran-f", 20]], -"TRAINER_LASS_RELI_3": [["pidgeotto", 28], ["nidorina", 28]], -"TRAINER_YOUNGSTER_TIMMY_2": [["raticate", 19], ["ekans", 19], ["zubat", 19]], -"TRAINER_YOUNGSTER_TIMMY_3": [["raticate", 27], ["ekans", 27], ["golbat", 27]], -"TRAINER_YOUNGSTER_TIMMY_4": [["raticate", 52], ["arbok", 52], ["golbat", 52]], -"TRAINER_YOUNGSTER_CHAD_3": [["arbok", 28], ["sandshrew", 28]], -"TRAINER_LASS_JANICE_2": [["pidgeotto", 20], ["pidgeotto", 20]], -"TRAINER_LASS_JANICE_3": [["pidgeotto", 28], ["pidgeotto", 28]], -"TRAINER_YOUNGSTER_CHAD_4": [["arbok", 48], ["sandslash", 48]], -"TRAINER_HIKER_FRANKLIN_2": [["machoke", 25], ["graveler", 25]], -"TRAINER_TEAM_ROCKET_GRUNT_42": [["houndour", 49], ["houndour", 49]], -"TRAINER_PSYCHIC_JACLYN": [["natu", 48, ["night-shade", "confuse-ray", "future-sight", "wish"]], ["slowbro", 48, ["psychic", "headbutt", "amnesia", "yawn"]], ["kadabra", 49, ["psychic", "future-sight", "recover", "reflect"]]], -"TRAINER_CRUSH_GIRL_SHARON": [["mankey", 37], ["primeape", 37]], -"TRAINER_TUBER_AMIRA": [["poliwag", 34], ["poliwhirl", 35], ["poliwag", 34]], -"TRAINER_PKMN_BREEDER_ALIZE": [["pikachu", 48], ["clefairy", 48], ["marill", 48]], -"TRAINER_PKMN_RANGER_NICOLAS": [["weepinbell", 51, ["razor-leaf", "acid", "sweet-scent", "wrap"]], ["victreebel", 51, ["razor-leaf", "acid", "sleep-powder", "stun-spore"]]], -"TRAINER_PKMN_RANGER_MADELINE": [["gloom", 51, ["petal-dance", "acid", "sweet-scent", "poison-powder"]], ["vileplume", 51, ["petal-dance", "moonlight", "acid", "stun-spore"]]], -"TRAINER_AROMA_LADY_NIKKI": [["bellsprout", 37], ["weepinbell", 37]], -"TRAINER_RUIN_MANIAC_STANLY": [["graveler", 48], ["onix", 48], ["graveler", 48]], -"TRAINER_LADY_JACKI": [["hoppip", 48], ["skiploom", 50]], -"TRAINER_PAINTER_DAISY": [["smeargle", 50, ["dynamic-punch", "dizzy-punch", "focus-punch", "mega-punch"]]], -"TRAINER_BIKER_GOON": [["koffing", 37, ["haze", "smokescreen", "sludge", "tackle"]], ["grimer", 37, ["acid-armor", "screech", "minimize", "sludge"]]], -"TRAINER_BIKER_GOON_2": [["koffing", 38, ["haze", "smokescreen", "sludge", "tackle"]]], -"TRAINER_BIKER_GOON_3": [["grimer", 38]], -"TRAINER_BUG_CATCHER_ANTHONY": [["caterpie", 7], ["caterpie", 8]], -"TRAINER_BUG_CATCHER_CHARLIE": [["metapod", 7], ["caterpie", 7], ["metapod", 7]], -"TRAINER_TWINS_ELI_ANNE_2": [["clefairy", 28], ["jigglypuff", 28]], -"TRAINER_YOUNGSTER_JOHNSON": [["ekans", 33], ["ekans", 33], ["raticate", 34]], -"TRAINER_BIKER_RICARDO": [["koffing", 22, ["sludge", "smog", "tackle", "poison-gas"]], ["koffing", 22, ["sludge", "smog", "tackle", "poison-gas"]], ["grimer", 23, ["minimize", "sludge", "disable", "pound"]]], -"TRAINER_BIKER_JAREN": [["grimer", 24], ["grimer", 24]], -"TRAINER_TEAM_ROCKET_GRUNT_43": [["cubone", 37], ["marowak", 37]], -"TRAINER_TEAM_ROCKET_GRUNT_44": [["rattata", 35], ["raticate", 35], ["sandshrew", 35], ["sandslash", 35]], -"TRAINER_TEAM_ROCKET_GRUNT_45": [["zubat", 38], ["zubat", 38], ["golbat", 38]], -"TRAINER_TEAM_ROCKET_GRUNT_46": [["muk", 48], ["golbat", 48], ["raticate", 48]], -"TRAINER_TEAM_ROCKET_GRUNT_47": [["machop", 48], ["machop", 48], ["machoke", 48]], -"TRAINER_TEAM_ROCKET_GRUNT_48": [["hypno", 49], ["hypno", 49]], -"TRAINER_TEAM_ROCKET_ADMIN": [["muk", 52, ["sludge-bomb", "screech", "minimize", "rock-tomb"]], ["arbok", 53, ["sludge-bomb", "bite", "earthquake", "iron-tail"]], ["vileplume", 54, ["sludge-bomb", "giga-drain", "sleep-powder", "stun-spore"]]], -"TRAINER_TEAM_ROCKET_ADMIN_2": [["golbat", 53, ["confuse-ray", "sludge-bomb", "air-cutter", "shadow-ball"]], ["weezing", 54, ["sludge-bomb", "thunderbolt", "explosion", "shadow-ball"]], ["houndoom", 55, ["flamethrower", "crunch", "iron-tail", "shadow-ball"]]], -"TRAINER_SCIENTIST_GIDEON": [["voltorb", 46, ["swift", "screech", "spark", "sonic-boom"]], ["electrode", 46, ["spark", "sonic-boom", "screech", "charge"]], ["magnemite", 46, ["screech", "swift", "spark", "thunder-wave"]], ["magneton", 46, ["tri-attack", "spark", "thunder-wave", "sonic-boom"]], ["porygon", 46, ["tri-attack", "conversion", "recover", "psybeam"]]], -"TRAINER_SWIMMER_FEMALE_AMARA": [["seel", 36], ["seel", 36], ["dewgong", 36]], -"TRAINER_SWIMMER_FEMALE_MARIA": [["seadra", 37], ["seadra", 37]], -"TRAINER_SWIMMER_FEMALE_ABIGAIL": [["psyduck", 35], ["psyduck", 36], ["golduck", 37]], -"TRAINER_SWIMMER_MALE_FINN": [["starmie", 38]], -"TRAINER_SWIMMER_MALE_GARRETT": [["shellder", 35], ["cloyster", 35], ["wartortle", 38]], -"TRAINER_FISHERMAN_TOMMY": [["goldeen", 33], ["goldeen", 33], ["seaking", 35], ["seaking", 35], ["seaking", 35]], -"TRAINER_CRUSH_GIRL_TANYA": [["hitmonlee", 38], ["hitmonchan", 38]], -"TRAINER_BLACK_BELT_SHEA": [["machop", 38], ["machoke", 38]], -"TRAINER_BLACK_BELT_HUGH": [["machop", 37], ["machoke", 37]], -"TRAINER_CAMPER_BRYCE": [["nidorino", 36], ["raticate", 36], ["sandslash", 36]], -"TRAINER_PICNICKER_CLAIRE": [["meowth", 35], ["meowth", 35], ["pikachu", 35], ["clefairy", 35]], -"TRAINER_CRUSH_KIN_MIK_KIA": [["machoke", 39], ["primeape", 39]], -"TRAINER_AROMA_LADY_VIOLET": [["bulbasaur", 36], ["ivysaur", 36], ["ivysaur", 36]], -"TRAINER_TUBER_ALEXIS": [["staryu", 34], ["staryu", 34], ["krabby", 34], ["krabby", 34]], -"TRAINER_TWINS_JOY_MEG": [["clefairy", 37], ["clefairy", 37]], -"TRAINER_SWIMMER_FEMALE_TISHA": [["kingler", 38]], -"TRAINER_PAINTER_CELINA": [["smeargle", 50, ["fly", "dig", "dive", "bounce"]]], -"TRAINER_PAINTER_RAYNA": [["smeargle", 50, ["cross-chop", "megahorn", "double-edge", "self-destruct"]]], -"TRAINER_LADY_GILLIAN": [["mareep", 47], ["mareep", 48], ["flaaffy", 49]], -"TRAINER_YOUNGSTER_DESTIN": [["raticate", 48], ["pidgeotto", 48]], -"TRAINER_SWIMMER_MALE_TOBY": [["poliwhirl", 48], ["tentacool", 48], ["tentacruel", 48]], -"TRAINER_TEAM_ROCKET_GRUNT_49": [["rattata", 48], ["grimer", 48], ["muk", 48]], -"TRAINER_TEAM_ROCKET_GRUNT_50": [["koffing", 49, ["memento", "haze", "smokescreen", "sludge"]], ["weezing", 49, ["haze", "smokescreen", "sludge", "self-destruct"]]], -"TRAINER_TEAM_ROCKET_GRUNT_51": [["ekans", 48], ["gloom", 48], ["gloom", 48]], -"TRAINER_BIRD_KEEPER_MILO": [["pidgey", 47], ["pidgeotto", 49]], -"TRAINER_BIRD_KEEPER_CHAZ": [["spearow", 47], ["fearow", 49]], -"TRAINER_BIRD_KEEPER_HAROLD": [["hoothoot", 47], ["noctowl", 49]], -"TRAINER_FISHERMAN_TYLOR": [["qwilfish", 49], ["qwilfish", 49]], -"TRAINER_SWIMMER_MALE_MYMO": [["kingler", 49], ["wartortle", 49]], -"TRAINER_SWIMMER_FEMALE_NICOLE": [["marill", 50]], -"TRAINER_SIS_AND_BRO_AVA_GEB": [["poliwhirl", 50], ["starmie", 50]], -"TRAINER_AROMA_LADY_ROSE": [["sunkern", 49], ["sunflora", 49]], -"TRAINER_SWIMMER_MALE_SAMIR": [["gyarados", 50]], -"TRAINER_SWIMMER_FEMALE_DENISE": [["chinchou", 49], ["lanturn", 49]], -"TRAINER_TWINS_MIU_MIA": [["pikachu", 50], ["pikachu", 50]], -"TRAINER_HIKER_EARL": [["onix", 49], ["machoke", 49]], -"TRAINER_RUIN_MANIAC_FOSTER": [["golem", 50]], -"TRAINER_RUIN_MANIAC_LARRY": [["machoke", 49], ["machoke", 49]], -"TRAINER_HIKER_DARYL": [["sudowoodo", 50]], -"TRAINER_POKEMANIAC_HECTOR": [["rhyhorn", 49], ["kangaskhan", 49]], -"TRAINER_PSYCHIC_DARIO": [["girafarig", 52, ["crunch", "psybeam", "odor-sleuth", "agility"]]], -"TRAINER_PSYCHIC_RODETTE": [["natu", 48, ["night-shade", "confuse-ray", "wish", "future-sight"]], ["drowzee", 48, ["psychic", "disable", "psych-up", "future-sight"]], ["hypno", 50, ["psychic", "hypnosis", "psych-up", "future-sight"]]], -"TRAINER_AROMA_LADY_MIAH": [["bellossom", 50], ["bellossom", 50]], -"TRAINER_YOUNG_COUPLE_EVE_JON": [["golduck", 50], ["psyduck", 50]], -"TRAINER_JUGGLER_MASON": [["voltorb", 47, ["swift", "light-screen", "spark", "sonic-boom"]], ["pineco", 47, ["spikes", "bide", "rapid-spin", "take-down"]], ["voltorb", 47, ["swift", "light-screen", "spark", "sonic-boom"]], ["pineco", 47, ["spikes", "bide", "rapid-spin", "explosion"]]], -"TRAINER_CRUSH_GIRL_CYNDY": [["primeape", 48], ["hitmontop", 48], ["machoke", 48]], -"TRAINER_CRUSH_GIRL_JOCELYN": [["hitmonchan", 38], ["hitmonchan", 38]], -"TRAINER_TAMER_EVAN": [["sandslash", 48], ["lickitung", 48], ["ursaring", 49]], -"TRAINER_POKEMANIAC_MARK_2": [["rhyhorn", 33], ["lickitung", 33]], -"TRAINER_PKMN_RANGER_LOGAN": [["exeggcute", 37, ["sleep-powder", "poison-powder", "stun-spore", "confusion"]], ["exeggutor", 40, ["egg-bomb", "stomp", "confusion", "hypnosis"]]], -"TRAINER_PKMN_RANGER_JACKSON": [["tangela", 49, ["slam", "mega-drain", "bind", "ingrain"]], ["exeggcute", 49, ["confusion", "poison-powder", "barrage", "reflect"]], ["exeggutor", 49, ["confusion", "egg-bomb", "sleep-powder", "stomp"]]], -"TRAINER_PKMN_RANGER_BETH": [["bellsprout", 38], ["gloom", 38], ["gloom", 38]], -"TRAINER_PKMN_RANGER_KATELYN": [["chansey", 52, ["egg-bomb", "defense-curl", "minimize", "soft-boiled"]]], -"TRAINER_COOLTRAINER_LEROY": [["rhydon", 47, ["take-down", "horn-drill", "rock-blast", "scary-face"]], ["slowbro", 48, ["psychic", "headbutt", "amnesia", "disable"]], ["kangaskhan", 47, ["dizzy-punch", "bite", "endure", "reversal"]], ["machoke", 48, ["cross-chop", "vital-throw", "revenge", "seismic-toss"]], ["ursaring", 50, ["slash", "feint-attack", "snore", "rest"]]], -"TRAINER_COOLTRAINER_MICHELLE": [["persian", 47, ["slash", "screech", "feint-attack", "bite"]], ["dewgong", 47, ["ice-beam", "take-down", "icy-wind", "growl"]], ["ninetales", 48, ["flamethrower", "confuse-ray", "will-o-wisp", "grudge"]], ["rapidash", 48, ["bounce", "agility", "fire-spin", "take-down"]], ["girafarig", 50, ["crunch", "psybeam", "stomp", "odor-sleuth"]]], -"TRAINER_COOL_COUPLE_LEX_NYA": [["miltank", 52, ["body-slam", "milk-drink", "growl", "defense-curl"]], ["tauros", 52, ["thrash", "horn-attack", "pursuit", "swagger"]]], -"TRAINER_RUIN_MANIAC_BRANDON": [["onix", 50]], -"TRAINER_RUIN_MANIAC_BENJAMIN": [["geodude", 48, ["earthquake", "rock-blast", "rollout", "self-destruct"]], ["graveler", 48, ["earthquake", "rock-blast", "rock-throw", "self-destruct"]], ["graveler", 48, ["earthquake", "rock-blast", "rock-throw", "self-destruct"]]], -"TRAINER_PAINTER_EDNA": [["smeargle", 50, ["fake-out", "extreme-speed", "protect", "quick-attack"]]], -"TRAINER_GENTLEMAN_CLIFFORD": [["marowak", 49], ["golduck", 49]], -"TRAINER_LADY_SELPHY": [["persian", 49, ["pay-day", "bite", "taunt", "torment"]], ["persian", 49, ["pay-day", "scratch", "torment", "taunt"]]], -"TRAINER_RUIN_MANIAC_LAWSON": [["onix", 47], ["graveler", 48], ["marowak", 49]], -"TRAINER_PSYCHIC_LAURA": [["natu", 48], ["natu", 48], ["xatu", 49]], -"TRAINER_PKMN_BREEDER_BETHANY": [["chansey", 50]], -"TRAINER_PKMN_BREEDER_ALLISON": [["clefairy", 48], ["clefairy", 48], ["clefable", 48]], -"TRAINER_BUG_CATCHER_GARRET": [["heracross", 49]], -"TRAINER_BUG_CATCHER_JONAH": [["yanma", 45], ["beedrill", 45], ["yanma", 46], ["beedrill", 47]], -"TRAINER_BUG_CATCHER_VANCE": [["venonat", 48], ["venomoth", 48]], -"TRAINER_YOUNGSTER_NASH": [["weepinbell", 47], ["weepinbell", 47], ["victreebel", 49]], -"TRAINER_YOUNGSTER_CORDELL": [["farfetch-d", 48], ["farfetch-d", 48]], -"TRAINER_LASS_DALIA": [["hoppip", 46], ["hoppip", 47], ["skiploom", 47], ["skiploom", 48]], -"TRAINER_LASS_JOANA": [["snubbull", 49]], -"TRAINER_CAMPER_RILEY": [["pinsir", 49], ["heracross", 50]], -"TRAINER_PICNICKER_MARCY": [["paras", 48], ["paras", 48], ["parasect", 49]], -"TRAINER_RUIN_MANIAC_LAYTON": [["sandslash", 48], ["onix", 48], ["sandslash", 48]], -"TRAINER_PICNICKER_KELSEY_2": [["nidoran-m", 21], ["nidoran-f", 21]], -"TRAINER_PICNICKER_KELSEY_3": [["nidorino", 29], ["nidorina", 29]], -"TRAINER_PICNICKER_KELSEY_4": [["nidorino", 49], ["nidorina", 49]], -"TRAINER_CAMPER_RICKY_2": [["squirtle", 22]], -"TRAINER_CAMPER_RICKY_3": [["wartortle", 30]], -"TRAINER_CAMPER_RICKY_4": [["wartortle", 55]], -"TRAINER_CAMPER_JEFF_2": [["spearow", 21], ["raticate", 21]], -"TRAINER_CAMPER_JEFF_3": [["fearow", 29], ["raticate", 29]], -"TRAINER_CAMPER_JEFF_4": [["fearow", 54], ["raticate", 54]], -"TRAINER_PICNICKER_ISABELLE_2": [["pidgeotto", 21], ["pidgeotto", 21], ["pidgey", 18]], -"TRAINER_PICNICKER_ISABELLE_3": [["pidgeotto", 29], ["pidgeotto", 29], ["pidgeotto", 26]], -"TRAINER_PICNICKER_ISABELLE_4": [["pidgeotto", 47], ["pidgeotto", 47], ["pidgeot", 50]], -"TRAINER_YOUNGSTER_YASU_2": [["rattata", 22], ["raticate", 22], ["raticate", 22]], -"TRAINER_YOUNGSTER_YASU_3": [["raticate", 47], ["raticate", 47], ["raticate", 47]], -"TRAINER_ENGINEER_BERNIE_2": [["magneton", 28], ["magneton", 28], ["magneton", 28]], -"TRAINER_GAMER_DARIAN_2": [["growlithe", 29], ["vulpix", 29]], -"TRAINER_CAMPER_CHRIS_2": [["growlithe", 24], ["charmander", 24]], -"TRAINER_CAMPER_CHRIS_3": [["growlithe", 29], ["charmeleon", 29]], -"TRAINER_CAMPER_CHRIS_4": [["arcanine", 54], ["charmeleon", 54]], -"TRAINER_PICNICKER_ALICIA_2": [["meowth", 25]], -"TRAINER_PICNICKER_ALICIA_3": [["persian", 30]], -"TRAINER_PICNICKER_ALICIA_4": [["persian", 55]], -"TRAINER_HIKER_JEREMY_2": [["machoke", 30], ["onix", 28]], -"TRAINER_POKEMANIAC_MARK_3": [["rhydon", 54], ["lickitung", 54]], -"TRAINER_POKEMANIAC_HERMAN_2": [["marowak", 29], ["slowbro", 29]], -"TRAINER_POKEMANIAC_HERMAN_3": [["marowak", 54], ["slowbro", 54]], -"TRAINER_HIKER_TRENT_2": [["onix", 31], ["graveler", 31]], -"TRAINER_LASS_MEGAN_2": [["pidgeotto", 22], ["raticate", 22], ["nidoran-m", 23], ["meowth", 21], ["pikachu", 22]], -"TRAINER_LASS_MEGAN_3": [["pidgeot", 46], ["raticate", 47], ["nidorino", 47], ["persian", 47], ["raichu", 48]], -"TRAINER_SUPER_NERD_GLENN_2": [["muk", 28], ["muk", 28], ["muk", 28]], -"TRAINER_GAMER_RICH_2": [["growlithe", 30], ["vulpix", 30]], -"TRAINER_BIKER_JAREN_2": [["muk", 28], ["muk", 30]], -"TRAINER_FISHERMAN_ELLIOT_2": [["poliwhirl", 28], ["cloyster", 28], ["seaking", 28], ["seadra", 28]], -"TRAINER_ROCKER_LUCA_2": [["electrode", 33], ["electrode", 33]], -"TRAINER_BEAUTY_SHEILA_2": [["clefairy", 49], ["persian", 49]], -"TRAINER_BIRD_KEEPER_ROBERT_2": [["pidgeotto", 28], ["pidgeotto", 28], ["fearow", 28], ["fearow", 28]], -"TRAINER_BIRD_KEEPER_ROBERT_3": [["pidgeot", 47], ["pidgeot", 47], ["fearow", 47], ["fearow", 47]], -"TRAINER_PICNICKER_SUSIE_2": [["pidgeotto", 27], ["meowth", 27], ["raticate", 27], ["pikachu", 27], ["meowth", 27]], -"TRAINER_PICNICKER_SUSIE_3": [["pidgeotto", 47], ["persian", 47], ["raticate", 47], ["pikachu", 47], ["persian", 47]], -"TRAINER_PICNICKER_SUSIE_4": [["pidgeot", 52], ["persian", 52], ["raticate", 52], ["raichu", 52], ["persian", 52]], -"TRAINER_BIKER_LUKAS_2": [["koffing", 47], ["koffing", 47], ["muk", 47], ["weezing", 47]], -"TRAINER_BIRD_KEEPER_BENNY_2": [["fearow", 32], ["fearow", 32]], -"TRAINER_BIRD_KEEPER_BENNY_3": [["fearow", 49], ["fearow", 49]], -"TRAINER_BIRD_KEEPER_MARLON_2": [["fearow", 30], ["doduo", 30], ["fearow", 30]], -"TRAINER_BIRD_KEEPER_MARLON_3": [["fearow", 48], ["dodrio", 48], ["fearow", 48]], -"TRAINER_BEAUTY_GRACE_2": [["pidgeot", 49], ["wigglytuff", 49]], -"TRAINER_BIRD_KEEPER_CHESTER_2": [["dodrio", 30], ["dodrio", 30], ["doduo", 30]], -"TRAINER_BIRD_KEEPER_CHESTER_3": [["dodrio", 48], ["dodrio", 48], ["dodrio", 48]], -"TRAINER_PICNICKER_BECKY_2": [["pikachu", 32], ["raichu", 32]], -"TRAINER_PICNICKER_BECKY_3": [["pikachu", 49], ["raichu", 49]], -"TRAINER_PICNICKER_BECKY_4": [["raichu", 54], ["raichu", 54]], -"TRAINER_CRUSH_KIN_RON_MYA_2": [["hitmonchan", 33], ["hitmonlee", 33]], -"TRAINER_CRUSH_KIN_RON_MYA_3": [["hitmonchan", 51], ["hitmonlee", 51]], -"TRAINER_CRUSH_KIN_RON_MYA_4": [["hitmonchan", 56], ["hitmonlee", 56]], -"TRAINER_BIKER_RUBEN_2": [["weezing", 48], ["weezing", 48], ["weezing", 48]], -"TRAINER_CUE_BALL_CAMRON_2": [["primeape", 49], ["machoke", 49]], -"TRAINER_BIKER_JAXON_2": [["weezing", 49], ["muk", 49]], -"TRAINER_CUE_BALL_ISAIAH_2": [["machoke", 49], ["machamp", 49]], -"TRAINER_CUE_BALL_COREY_2": [["primeape", 49], ["machamp", 49]], -"TRAINER_BIRD_KEEPER_JACOB_2": [["fearow", 28], ["spearow", 28], ["fearow", 28], ["spearow", 28]], -"TRAINER_BIRD_KEEPER_JACOB_3": [["fearow", 47], ["fearow", 47], ["fearow", 47], ["fearow", 47]], -"TRAINER_SWIMMER_FEMALE_ALICE_2": [["seaking", 49], ["seaking", 49]], -"TRAINER_SWIMMER_MALE_DARRIN_2": [["seadra", 52], ["seadra", 52], ["seadra", 52], ["seadra", 52]], -"TRAINER_PICNICKER_MISSY_2": [["seaking", 49], ["seaking", 49]], -"TRAINER_PICNICKER_MISSY_3": [["seaking", 54], ["seaking", 54]], -"TRAINER_FISHERMAN_WADE_2": [["magikarp", 47], ["magikarp", 47], ["magikarp", 47], ["magikarp", 47], ["magikarp", 47], ["magikarp", 47]], -"TRAINER_SWIMMER_MALE_JACK_2": [["starmie", 50]], -"TRAINER_SIS_AND_BRO_LIL_IAN_2": [["seadra", 50], ["starmie", 50]], -"TRAINER_SIS_AND_BRO_LIL_IAN_3": [["seadra", 55], ["starmie", 55]], -"TRAINER_SWIMMER_MALE_FINN_2": [["starmie", 50]], -"TRAINER_CRUSH_GIRL_SHARON_2": [["mankey", 50], ["primeape", 50]], -"TRAINER_CRUSH_GIRL_SHARON_3": [["primeape", 55], ["primeape", 55]], -"TRAINER_CRUSH_GIRL_TANYA_2": [["hitmonlee", 50], ["hitmonchan", 50]], -"TRAINER_CRUSH_GIRL_TANYA_3": [["hitmonlee", 55], ["hitmonchan", 55]], -"TRAINER_BLACK_BELT_SHEA_2": [["machoke", 50], ["machoke", 50]], -"TRAINER_BLACK_BELT_SHEA_3": [["machoke", 55], ["machamp", 55]], -"TRAINER_BLACK_BELT_HUGH_2": [["machoke", 50], ["machoke", 50]], -"TRAINER_BLACK_BELT_HUGH_3": [["machoke", 55], ["machamp", 55]], -"TRAINER_CRUSH_KIN_MIK_KIA_2": [["machoke", 51], ["primeape", 51]], -"TRAINER_CRUSH_KIN_MIK_KIA_3": [["machamp", 56], ["primeape", 56]], -"TRAINER_TUBER_AMIRA_2": [["poliwhirl", 47], ["poliwhirl", 47], ["poliwhirl", 47]], -"TRAINER_TWINS_JOY_MEG_2": [["clefairy", 49], ["clefairy", 49]], -"TRAINER_PAINTER_RAYNA_2": [["smeargle", 54, ["cross-chop", "megahorn", "double-edge", "self-destruct"]]], -"TRAINER_YOUNGSTER_DESTIN_2": [["raticate", 53], ["pidgeot", 53]], -"TRAINER_PKMN_BREEDER_ALIZE_2": [["pikachu", 53], ["clefairy", 53], ["marill", 53]], -"TRAINER_YOUNG_COUPLE_GIA_JES_2": [["nidorina", 30], ["nidorino", 30]], -"TRAINER_YOUNG_COUPLE_GIA_JES_3": [["nidoking", 55], ["nidoqueen", 55]], -"TRAINER_BIRD_KEEPER_MILO_2": [["pidgeotto", 53], ["pidgeot", 55]], -"TRAINER_BIRD_KEEPER_CHAZ_2": [["fearow", 53], ["fearow", 55]], -"TRAINER_BIRD_KEEPER_HAROLD_2": [["noctowl", 53], ["noctowl", 55]], -"TRAINER_SWIMMER_FEMALE_NICOLE_2": [["marill", 54]], -"TRAINER_PSYCHIC_JACLYN_2": [["natu", 52, ["psychic", "confuse-ray", "future-sight", "wish"]], ["slowbro", 52, ["psychic", "headbutt", "amnesia", "yawn"]], ["kadabra", 54, ["psychic", "future-sight", "recover", "reflect"]]], -"TRAINER_SWIMMER_MALE_SAMIR_2": [["gyarados", 55]], -"TRAINER_HIKER_EARL_2": [["onix", 54], ["machamp", 54]], -"TRAINER_RUIN_MANIAC_LARRY_2": [["machoke", 54], ["machoke", 54]], -"TRAINER_POKEMANIAC_HECTOR_2": [["rhydon", 55], ["kangaskhan", 55]], -"TRAINER_PSYCHIC_DARIO_2": [["girafarig", 56, ["crunch", "psybeam", "odor-sleuth", "agility"]]], -"TRAINER_PSYCHIC_RODETTE_2": [["natu", 53, ["psychic", "confuse-ray", "wish", "future-sight"]], ["hypno", 53, ["psychic", "disable", "psych-up", "future-sight"]], ["hypno", 53, ["psychic", "hypnosis", "psych-up", "future-sight"]]], -"TRAINER_JUGGLER_MASON_2": [["electrode", 52], ["pineco", 52], ["electrode", 52], ["pineco", 52]], -"TRAINER_PKMN_RANGER_NICOLAS_2": [["victreebel", 55, ["razor-leaf", "acid", "stun-spore", "wrap"]], ["victreebel", 55, ["razor-leaf", "acid", "sleep-powder", "slam"]]], -"TRAINER_PKMN_RANGER_MADELINE_2": [["vileplume", 55, ["petal-dance", "moonlight", "acid", "sleep-powder"]], ["vileplume", 55, ["petal-dance", "moonlight", "acid", "stun-spore"]]], -"TRAINER_CRUSH_GIRL_CYNDY_2": [["primeape", 54], ["hitmontop", 54], ["machamp", 54]], -"TRAINER_TAMER_EVAN_2": [["sandslash", 52], ["lickitung", 52], ["ursaring", 55]], -"TRAINER_PKMN_RANGER_JACKSON_2": [["tangela", 53, ["slam", "mega-drain", "bind", "ingrain"]], ["exeggutor", 54, ["confusion", "egg-bomb", "stun-spore", "reflect"]], ["exeggutor", 55, ["confusion", "egg-bomb", "sleep-powder", "stomp"]]], -"TRAINER_PKMN_RANGER_KATELYN_2": [["chansey", 56, ["egg-bomb", "defense-curl", "minimize", "soft-boiled"]]], -"TRAINER_COOLTRAINER_LEROY_2": [["rhydon", 52, ["earthquake", "horn-drill", "rock-blast", "scary-face"]], ["slowbro", 54, ["psychic", "headbutt", "amnesia", "disable"]], ["kangaskhan", 52, ["dizzy-punch", "bite", "endure", "reversal"]], ["machamp", 52, ["cross-chop", "vital-throw", "revenge", "seismic-toss"]], ["ursaring", 55, ["slash", "feint-attack", "snore", "rest"]]], -"TRAINER_COOLTRAINER_MICHELLE_2": [["persian", 53, ["slash", "screech", "feint-attack", "bite"]], ["dewgong", 53, ["ice-beam", "take-down", "icy-wind", "sheer-cold"]], ["ninetales", 54, ["flamethrower", "confuse-ray", "will-o-wisp", "grudge"]], ["rapidash", 54, ["bounce", "agility", "fire-spin", "take-down"]], ["girafarig", 56, ["crunch", "psybeam", "stomp", "odor-sleuth"]]], -"TRAINER_COOL_COUPLE_LEX_NYA_2": [["miltank", 57, ["body-slam", "milk-drink", "growl", "defense-curl"]], ["tauros", 57, ["take-down", "scary-face", "pursuit", "swagger"]]], -"TRAINER_BUG_CATCHER_COLTON_2": [["metapod", 19], ["weedle", 19], ["metapod", 19]], -"TRAINER_BUG_CATCHER_COLTON_3": [["butterfree", 27], ["kakuna", 27], ["butterfree", 27]], -"TRAINER_BUG_CATCHER_COLTON_4": [["butterfree", 51], ["beedrill", 54], ["butterfree", 51]], -"TRAINER_SWIMMER_MALE_MATTHEW_2": [["poliwhirl", 49], ["poliwrath", 49]], -"TRAINER_SWIMMER_MALE_TONY_2": [["seadra", 49], ["seadra", 49]], -"TRAINER_SWIMMER_FEMALE_MELISSA_2": [["poliwhirl", 49], ["seaking", 49]], -"TRAINER_ELITE_FOUR_LORELEI_2": [["dewgong", 64, ["ice-beam", "surf", "signal-beam", "double-team"]], ["cloyster", 63, ["ice-beam", "surf", "supersonic", "rain-dance"]], ["piloswine", 63, ["blizzard", "earthquake", "double-edge", "rock-slide"]], ["jynx", 66, ["ice-beam", "psychic", "lovely-kiss", "attract"]], ["lapras", 66, ["ice-beam", "surf", "psychic", "thunder"]]], -"TRAINER_ELITE_FOUR_BRUNO_2": [["steelix", 65, ["earthquake", "iron-tail", "crunch", "rock-tomb"]], ["hitmonchan", 65, ["sky-uppercut", "mach-punch", "rock-slide", "counter"]], ["hitmonlee", 65, ["mega-kick", "foresight", "earthquake", "rock-slide"]], ["steelix", 66, ["earthquake", "iron-tail", "crunch", "dragon-breath"]], ["machamp", 68, ["cross-chop", "earthquake", "brick-break", "rock-slide"]]], -"TRAINER_ELITE_FOUR_AGATHA_2": [["gengar", 66, ["shadow-ball", "psychic", "confuse-ray", "hypnosis"]], ["crobat", 66, ["sludge-bomb", "air-cutter", "shadow-ball", "confuse-ray"]], ["misdreavus", 65, ["shadow-ball", "psychic", "thunderbolt", "attract"]], ["arbok", 68, ["sludge-bomb", "earthquake", "giga-drain", "double-team"]], ["gengar", 70, ["shadow-ball", "psychic", "thunderbolt", "sludge-bomb"]]], -"TRAINER_ELITE_FOUR_LANCE_2": [["gyarados", 68, ["hyper-beam", "dragon-dance", "earthquake", "thunder-wave"]], ["dragonite", 66, ["hyper-beam", "earthquake", "dragon-claw", "flamethrower"]], ["kingdra", 66, ["hyper-beam", "dragon-dance", "surf", "ice-beam"]], ["aerodactyl", 70, ["hyper-beam", "ancient-power", "aerial-ace", "earthquake"]], ["dragonite", 72, ["hyper-beam", "outrage", "thunderbolt", "ice-beam"]]], -"TRAINER_CHAMPION_REMATCH_SQUIRTLE": [["heracross", 72, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["arcanine", 73, ["extreme-speed", "overheat", "aerial-ace", "iron-tail"]], ["exeggutor", 73, ["giga-drain", "psychic", "sleep-powder", "light-screen"]], ["blastoise", 75, ["hydro-pump", "ice-beam", "earthquake", "rain-dance"]]], -"TRAINER_CHAMPION_REMATCH_BULBASAUR": [["heracross", 72, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["gyarados", 73, ["hydro-pump", "dragon-dance", "earthquake", "hyper-beam"]], ["arcanine", 73, ["extreme-speed", "overheat", "aerial-ace", "iron-tail"]], ["venusaur", 75, ["solar-beam", "sludge-bomb", "earthquake", "sunny-day"]]], -"TRAINER_CHAMPION_REMATCH_CHARMANDER": [["heracross", 72, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["exeggutor", 73, ["giga-drain", "psychic", "sleep-powder", "light-screen"]], ["gyarados", 73, ["hydro-pump", "dragon-dance", "earthquake", "hyper-beam"]], ["charizard", 75, ["fire-blast", "dragon-claw", "aerial-ace", "earthquake"]]], -"TRAINER_CUE_BALL_PAXTON": [["weezing", 39], ["muk", 39]] +"TRAINER_YOUNGSTER_BEN": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 11, 0, 8, ["tackle", "tail-whip", "quick-attack"]], ["ekans", 11, 0, 12, ["wrap", "leer", "poison-sting"]]]}, +"TRAINER_YOUNGSTER_CALVIN": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 14, 0, 17, ["peck", "growl", "leer", "fury-attack"]]]}, +"TRAINER_YOUNGSTER_JOSH": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 10, 0, 10, ["tackle", "tail-whip", "quick-attack"]], ["rattata", 10, 0, 9, ["tackle", "tail-whip", "quick-attack"]], ["zubat", 10, 0, 10, ["leech-life", "astonish"]]]}, +"TRAINER_YOUNGSTER_TIMMY": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 14, 0, 6, ["scratch", "defense-curl", "sand-attack"]], ["ekans", 14, 0, 21, ["wrap", "leer", "poison-sting", "bite"]]]}, +"TRAINER_YOUNGSTER_JOEY": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 15, 0, 3, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["spearow", 15, 0, 16, ["peck", "growl", "leer", "fury-attack"]]]}, +"TRAINER_YOUNGSTER_DAN": {"ai": ["check-bad-move"], "items": [], "party": [["slowpoke", 17, 0, 22, ["tackle", "growl", "water-gun", "confusion"]]]}, +"TRAINER_YOUNGSTER_CHAD": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 14, 0, 1, ["wrap", "leer", "poison-sting", "bite"]], ["sandshrew", 14, 0, 21, ["scratch", "defense-curl", "sand-attack"]]]}, +"TRAINER_YOUNGSTER_TYLER": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 21, 0, 19, ["focus-energy", "double-kick", "poison-sting", "horn-attack"]]]}, +"TRAINER_YOUNGSTER_EDDIE": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 21, 0, 8, ["leer", "poison-sting", "bite", "glare"]]]}, +"TRAINER_YOUNGSTER_DILLON": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 19, 0, 13, ["scratch", "defense-curl", "sand-attack", "poison-sting"]], ["zubat", 19, 0, 5, ["leech-life", "astonish", "supersonic", "bite"]]]}, +"TRAINER_YOUNGSTER_YASU": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 17, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["rattata", 17, 0, 2, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["raticate", 17, 0, 2, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]]]}, +"TRAINER_YOUNGSTER_DAVE": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 18, 0, 15, ["peck", "focus-energy", "double-kick", "poison-sting"]], ["nidorino", 18, 0, 12, ["peck", "focus-energy", "double-kick", "poison-sting"]]]}, +"TRAINER_YOUNGSTER_BEN_2": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 17, 20, 8, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["ekans", 17, 20, 12, ["wrap", "leer", "poison-sting", "bite"]]]}, +"TRAINER_BUG_CATCHER_RICK": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 6, 0, 16, ["poison-sting", "string-shot"]], ["caterpie", 6, 0, 16, ["tackle", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_DOUG": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 7, 0, 2, ["poison-sting", "string-shot"]], ["kakuna", 7, 0, 23, ["harden"]], ["weedle", 7, 0, 14, ["poison-sting", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_SAMMY": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 9, 0, 12, ["poison-sting", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_COLTON": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 10, 0, 21, ["tackle", "string-shot"]], ["weedle", 10, 0, 11, ["poison-sting", "string-shot"]], ["caterpie", 10, 0, 21, ["tackle", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_GREG": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 9, 0, 17, ["poison-sting", "string-shot"]], ["kakuna", 9, 0, 3, ["harden"]], ["caterpie", 9, 0, 4, ["tackle", "string-shot"]], ["metapod", 9, 0, 21, ["harden"]]]}, +"TRAINER_BUG_CATCHER_JAMES": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 11, 0, 19, ["tackle", "string-shot"]], ["metapod", 11, 0, 18, ["harden"]]]}, +"TRAINER_BUG_CATCHER_KENT": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 11, 0, 20, ["poison-sting", "string-shot"]], ["kakuna", 11, 0, 9, ["harden"]]]}, +"TRAINER_BUG_CATCHER_ROBBY": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 10, 0, 3, ["tackle", "string-shot"]], ["metapod", 10, 0, 11, ["harden"]], ["caterpie", 10, 0, 3, ["tackle", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_CALE": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 10, 0, 16, ["tackle", "string-shot"]], ["weedle", 10, 0, 1, ["poison-sting", "string-shot"]], ["metapod", 10, 0, 22, ["harden"]], ["kakuna", 10, 0, 12, ["harden"]]]}, +"TRAINER_BUG_CATCHER_KEIGO": {"ai": ["check-bad-move"], "items": [], "party": [["weedle", 16, 0, 18, ["poison-sting", "string-shot"]], ["caterpie", 16, 0, 20, ["tackle", "string-shot"]], ["weedle", 16, 0, 2, ["poison-sting", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_ELIJAH": {"ai": ["check-bad-move"], "items": [], "party": [["butterfree", 20, 0, 7, ["poison-powder", "stun-spore", "sleep-powder", "supersonic"]]]}, +"TRAINER_BUG_CATCHER_2": {"ai": ["check-bad-move"], "items": [], "party": [["metapod", 18, 0, 17, ["harden"]], ["caterpie", 18, 0, 7, ["tackle", "string-shot"]], ["venonat", 18, 0, 15, ["disable", "foresight", "supersonic", "confusion"]]]}, +"TRAINER_BUG_CATCHER_BRENT": {"ai": ["check-bad-move"], "items": [], "party": [["beedrill", 19, 0, 0, ["fury-attack", "focus-energy"]], ["beedrill", 19, 0, 14, ["fury-attack", "focus-energy"]]]}, +"TRAINER_BUG_CATCHER_CONNER": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 20, 0, 11, ["tackle", "string-shot"]], ["weedle", 20, 0, 16, ["poison-sting", "string-shot"]], ["venonat", 20, 0, 9, ["foresight", "supersonic", "confusion", "poison-powder"]]]}, +"TRAINER_LASS_JANICE": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 9, 0, 10, ["tackle", "sand-attack", "gust"]], ["pidgey", 9, 0, 0, ["tackle", "sand-attack", "gust"]]]}, +"TRAINER_LASS_SALLY": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 10, 0, 12, ["tackle", "tail-whip", "quick-attack"]], ["nidoran-f", 10, 0, 10, ["growl", "scratch", "tail-whip"]]]}, +"TRAINER_LASS_ROBIN": {"ai": ["check-bad-move"], "items": [], "party": [["jigglypuff", 14, 0, 22, ["sing", "defense-curl", "pound", "disable"]]]}, +"TRAINER_LASS_CRISSY": {"ai": ["check-bad-move"], "items": [], "party": [["paras", 31, 0, 9, ["poison-powder", "leech-life", "spore", "slash"]], ["paras", 31, 0, 23, ["poison-powder", "leech-life", "spore", "slash"]], ["parasect", 31, 0, 3, ["stun-spore", "poison-powder", "leech-life", "spore"]]]}, +"TRAINER_LASS_MIRIAM": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 11, 0, 19, ["absorb", "sweet-scent"]], ["bellsprout", 11, 0, 18, ["vine-whip", "growth", "wrap"]]]}, +"TRAINER_LASS_IRIS": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 14, 0, 16, ["growl", "encore", "sing", "double-slap"]]]}, +"TRAINER_LASS_RELI": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 16, 0, 21, ["leer", "peck", "focus-energy", "double-kick"]], ["nidoran-f", 16, 0, 3, ["growl", "scratch", "tail-whip", "double-kick"]]]}, +"TRAINER_LASS_ALI": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 12, 0, 17, ["tackle", "sand-attack", "gust"]], ["oddish", 12, 0, 22, ["absorb", "sweet-scent"]], ["bellsprout", 12, 0, 2, ["vine-whip", "growth", "wrap"]]]}, +"TRAINER_LASS_2": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 15, 0, 18, ["leer", "peck", "focus-energy", "double-kick"]], ["nidoran-f", 15, 0, 22, ["growl", "scratch", "tail-whip", "double-kick"]]]}, +"TRAINER_LASS_HALEY": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 13, 0, 6, ["absorb", "sweet-scent"]], ["pidgey", 13, 0, 9, ["tackle", "sand-attack", "gust", "quick-attack"]], ["oddish", 13, 0, 20, ["absorb", "sweet-scent"]]]}, +"TRAINER_LASS_ANN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 18, 0, 9, ["tackle", "sand-attack", "gust", "quick-attack"]], ["nidoran-f", 18, 0, 10, ["scratch", "tail-whip", "double-kick", "poison-sting"]]]}, +"TRAINER_LASS_DAWN": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 18, 0, 9, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["pikachu", 18, 0, 1, ["tail-whip", "thunder-wave", "quick-attack", "double-team"]]]}, +"TRAINER_LASS_PAIGE": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-f", 23, 0, 7, ["double-kick", "poison-sting", "bite", "helping-hand"]], ["nidorina", 23, 0, 22, ["tail-whip", "double-kick", "poison-sting", "bite"]]]}, +"TRAINER_LASS_ANDREA": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 24, 0, 24, ["scratch", "growl", "bite", "pay-day"]], ["meowth", 24, 0, 3, ["scratch", "growl", "bite", "pay-day"]], ["meowth", 24, 0, 7, ["scratch", "growl", "bite", "pay-day"]]]}, +"TRAINER_LASS_MEGAN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 19, 0, 7, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["rattata", 19, 0, 0, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["nidoran-m", 19, 0, 18, ["peck", "focus-energy", "double-kick", "poison-sting"]], ["meowth", 19, 0, 13, ["scratch", "growl", "bite", "pay-day"]], ["pikachu", 19, 0, 9, ["tail-whip", "thunder-wave", "quick-attack", "double-team"]]]}, +"TRAINER_LASS_JULIA": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 22, 0, 20, ["sing", "double-slap", "follow-me", "minimize"]], ["clefairy", 22, 0, 20, ["sing", "double-slap", "follow-me", "minimize"]]]}, +"TRAINER_LASS_KAY": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 23, 0, 15, ["sleep-powder", "poison-powder", "stun-spore", "acid"]], ["weepinbell", 23, 0, 13, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]]]}, +"TRAINER_LASS_LISA": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 23, 0, 5, ["poison-powder", "stun-spore", "sleep-powder", "acid"]], ["gloom", 23, 0, 17, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]]]}, +"TRAINER_SAILOR_EDMOND": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 18, 0, 19, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["shellder", 18, 0, 21, ["tackle", "withdraw", "icicle-spear", "supersonic"]]]}, +"TRAINER_SAILOR_TREVOR": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 17, 0, 2, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["tentacool", 17, 0, 10, ["poison-sting", "supersonic", "constrict"]]]}, +"TRAINER_SAILOR_LEONARD": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 21, 0, 13, ["tackle", "withdraw", "icicle-spear", "supersonic"]]]}, +"TRAINER_SAILOR_DUNCAN": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 17, 0, 16, ["bubble", "smokescreen", "leer"]], ["shellder", 17, 0, 5, ["tackle", "withdraw", "icicle-spear", "supersonic"]], ["tentacool", 17, 0, 17, ["poison-sting", "supersonic", "constrict"]]]}, +"TRAINER_SAILOR_HUEY": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 18, 0, 3, ["poison-sting", "supersonic", "constrict"]], ["staryu", 18, 0, 16, ["harden", "water-gun", "rapid-spin", "recover"]]]}, +"TRAINER_SAILOR_DYLAN": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 17, 0, 19, ["bubble", "smokescreen", "leer"]], ["horsea", 17, 0, 2, ["bubble", "smokescreen", "leer"]], ["horsea", 17, 0, 10, ["bubble", "smokescreen", "leer"]]]}, +"TRAINER_SAILOR_PHILLIP": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 20, 0, 22, ["leer", "focus-energy", "karate-chop", "seismic-toss"]]]}, +"TRAINER_SAILOR_DWAYNE": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 21, 0, 15, ["thunder-wave", "quick-attack", "double-team", "slam"]], ["pikachu", 21, 0, 19, ["thunder-wave", "quick-attack", "double-team", "slam"]]]}, +"TRAINER_CAMPER_LIAM": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 10, 0, 13, ["tackle", "defense-curl"]], ["sandshrew", 11, 0, 22, ["scratch", "defense-curl", "sand-attack"]]]}, +"TRAINER_CAMPER_SHANE": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 14, 0, 21, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["ekans", 14, 0, 13, ["wrap", "leer", "poison-sting", "bite"]]]}, +"TRAINER_CAMPER_ETHAN": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 18, 0, 14, ["leer", "low-kick", "karate-chop", "fury-swipes"]]]}, +"TRAINER_CAMPER_RICKY": {"ai": ["check-bad-move"], "items": [], "party": [["squirtle", 20, 0, 16, ["bubble", "withdraw", "water-gun", "bite"]]]}, +"TRAINER_CAMPER_JEFF": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 16, 0, 6, ["peck", "growl", "leer", "fury-attack"]], ["raticate", 16, 0, 22, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]]]}, +"TRAINER_CAMPER_CHRIS": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 21, 0, 4, ["roar", "ember", "leer", "odor-sleuth"]], ["charmander", 21, 0, 21, ["growl", "ember", "metal-claw", "smokescreen"]]]}, +"TRAINER_CAMPER_DREW": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 19, 0, 23, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["sandshrew", 19, 0, 22, ["scratch", "defense-curl", "sand-attack", "poison-sting"]], ["ekans", 19, 0, 16, ["wrap", "leer", "poison-sting", "bite"]], ["sandshrew", 19, 0, 15, ["scratch", "defense-curl", "sand-attack", "poison-sting"]]]}, +"TRAINER_PICNICKER_DIANA": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 19, 0, 8, ["tail-whip", "water-sport", "supersonic", "horn-attack"]]]}, +"TRAINER_PICNICKER_NANCY": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 16, 0, 15, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["pikachu", 16, 0, 13, ["tail-whip", "thunder-wave", "quick-attack", "double-team"]]]}, +"TRAINER_PICNICKER_ISABELLE": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 16, 0, 5, ["tackle", "sand-attack", "gust", "quick-attack"]], ["pidgey", 16, 0, 15, ["tackle", "sand-attack", "gust", "quick-attack"]], ["pidgey", 16, 0, 0, ["tackle", "sand-attack", "gust", "quick-attack"]]]}, +"TRAINER_PICNICKER_KELSEY": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 15, 0, 1, ["leer", "peck", "focus-energy", "double-kick"]], ["nidoran-f", 15, 0, 13, ["growl", "scratch", "tail-whip", "double-kick"]]]}, +"TRAINER_PICNICKER_ALICIA": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 18, 0, 1, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bellsprout", 18, 0, 7, ["growth", "wrap", "sleep-powder", "poison-powder"]], ["oddish", 18, 0, 13, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bellsprout", 18, 0, 19, ["growth", "wrap", "sleep-powder", "poison-powder"]]]}, +"TRAINER_PICNICKER_CAITLIN": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 23, 0, 15, ["scratch", "growl", "bite", "pay-day"]]]}, +"TRAINER_PICNICKER_HEIDI": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 20, 0, 11, ["thunder-wave", "quick-attack", "double-team", "slam"]], ["clefairy", 20, 0, 3, ["encore", "sing", "double-slap", "follow-me"]]]}, +"TRAINER_PICNICKER_CAROL": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 21, 0, 11, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["pidgeotto", 21, 0, 20, ["sand-attack", "gust", "quick-attack", "whirlwind"]]]}, +"TRAINER_PICNICKER_SOFIA": {"ai": ["check-bad-move"], "items": [], "party": [["jigglypuff", 21, 0, 24, ["defense-curl", "pound", "disable", "rollout"]], ["pidgey", 21, 0, 21, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["meowth", 21, 0, 1, ["scratch", "growl", "bite", "pay-day"]]]}, +"TRAINER_PICNICKER_MARTHA": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 22, 0, 7, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bulbasaur", 22, 0, 20, ["vine-whip", "poison-powder", "sleep-powder", "razor-leaf"]]]}, +"TRAINER_PICNICKER_TINA": {"ai": ["check-bad-move"], "items": [], "party": [["bulbasaur", 24, 0, 24, ["vine-whip", "poison-powder", "sleep-powder", "razor-leaf"]], ["ivysaur", 24, 0, 4, ["vine-whip", "poison-powder", "sleep-powder", "razor-leaf"]]]}, +"TRAINER_PICNICKER_HANNAH": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 24, 0, 9, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["meowth", 24, 0, 6, ["scratch", "growl", "bite", "pay-day"]], ["rattata", 24, 0, 1, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["pikachu", 24, 0, 24, ["thunder-wave", "quick-attack", "double-team", "slam"]], ["meowth", 24, 0, 21, ["scratch", "growl", "bite", "pay-day"]]]}, +"TRAINER_POKEMANIAC_MARK": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 29, 30, 6, ["stomp", "fury-attack", "scary-face", "rock-blast"]], ["lickitung", 29, 30, 8, ["defense-curl", "knock-off", "stomp", "wrap"]]]}, +"TRAINER_POKEMANIAC_HERMAN": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 20, 30, 17, ["tail-whip", "bone-club", "headbutt", "leer"]], ["slowpoke", 20, 30, 16, ["tackle", "growl", "water-gun", "confusion"]]]}, +"TRAINER_POKEMANIAC_COOPER": {"ai": ["check-bad-move"], "items": [], "party": [["slowpoke", 20, 30, 13, ["tackle", "growl", "water-gun", "confusion"]], ["slowpoke", 20, 30, 15, ["tackle", "growl", "water-gun", "confusion"]], ["slowpoke", 20, 30, 17, ["tackle", "growl", "water-gun", "confusion"]]]}, +"TRAINER_POKEMANIAC_STEVE": {"ai": ["check-bad-move"], "items": [], "party": [["charmander", 22, 30, 12, ["growl", "ember", "metal-claw", "smokescreen"]], ["cubone", 22, 30, 24, ["bone-club", "headbutt", "leer", "focus-energy"]]]}, +"TRAINER_POKEMANIAC_WINSTON": {"ai": ["check-bad-move"], "items": [], "party": [["slowpoke", 25, 30, 6, ["growl", "water-gun", "confusion", "disable"]]]}, +"TRAINER_POKEMANIAC_DAWSON": {"ai": ["check-bad-move"], "items": [], "party": [["charmeleon", 40, 30, 12, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]], ["lapras", 40, 30, 12, ["confuse-ray", "perish-song", "ice-beam", "rain-dance"]], ["lickitung", 40, 30, 19, ["stomp", "wrap", "disable", "slam"]]]}, +"TRAINER_POKEMANIAC_ASHTON": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 23, 30, 0, ["bone-club", "headbutt", "leer", "focus-energy"]], ["slowpoke", 23, 30, 7, ["tackle", "growl", "water-gun", "confusion"]]]}, +"TRAINER_SUPER_NERD_JOVAN": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 11, 0, 4, ["metal-sound", "tackle", "thunder-shock", "supersonic"]], ["voltorb", 11, 0, 17, ["charge", "tackle", "screech"]]]}, +"TRAINER_SUPER_NERD_MIGUEL": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 12, 0, 0, ["poison-gas", "pound", "harden", "disable"]], ["voltorb", 12, 0, 9, ["charge", "tackle", "screech"]], ["koffing", 12, 0, 2, ["poison-gas", "tackle", "smog"]]]}, +"TRAINER_SUPER_NERD_AIDAN": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 20, 0, 1, ["sonic-boom", "screech", "tackle", "charge"]], ["koffing", 20, 0, 0, ["sludge", "smog", "tackle", "poison-gas"]], ["voltorb", 20, 0, 15, ["sonic-boom", "screech", "tackle", "charge"]], ["magnemite", 20, 0, 10, ["sonic-boom", "supersonic", "thunder-shock", "tackle"]]]}, +"TRAINER_SUPER_NERD_GLENN": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 22, 0, 19, ["harden", "disable", "sludge", "minimize"]], ["muk", 22, 0, 4, ["harden", "disable", "sludge", "minimize"]], ["grimer", 22, 0, 12, ["harden", "disable", "sludge", "minimize"]]]}, +"TRAINER_SUPER_NERD_LESLIE": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 26, 0, 24, ["sludge", "smokescreen", "smog", "self-destruct"]]]}, +"TRAINER_SUPER_NERD_1": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 22, 0, 6, ["tackle", "smog", "self-destruct", "sludge"]], ["magnemite", 22, 0, 22, ["thunder-shock", "supersonic", "sonic-boom", "thunder-wave"]], ["weezing", 22, 0, 18, ["tackle", "smog", "self-destruct", "sludge"]]]}, +"TRAINER_SUPER_NERD_2": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 20, 0, 2, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["magnemite", 20, 0, 18, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["koffing", 20, 0, 13, ["poison-gas", "tackle", "smog", "self-destruct"]], ["magnemite", 20, 0, 4, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]]]}, +"TRAINER_SUPER_NERD_3": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 24, 0, 2, ["thunder-shock", "supersonic", "sonic-boom", "thunder-wave"]], ["voltorb", 24, 0, 13, ["tackle", "screech", "sonic-boom", "spark"]]]}, +"TRAINER_SUPER_NERD_ERIK": {"ai": ["check-bad-move"], "items": [], "party": [["vulpix", 36, 0, 3, ["confuse-ray", "imprison", "flamethrower", "safeguard"]], ["vulpix", 36, 0, 20, ["confuse-ray", "imprison", "flamethrower", "safeguard"]], ["ninetales", 36, 0, 5, ["ember", "quick-attack", "confuse-ray", "safeguard"]]]}, +"TRAINER_SUPER_NERD_AVERY": {"ai": ["check-bad-move"], "items": [], "party": [["ponyta", 34, 0, 9, ["ember", "stomp", "fire-spin", "take-down"]], ["charmander", 34, 0, 10, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]], ["vulpix", 34, 0, 11, ["confuse-ray", "imprison", "flamethrower", "safeguard"]], ["growlithe", 34, 0, 13, ["leer", "odor-sleuth", "take-down", "flame-wheel"]]]}, +"TRAINER_SUPER_NERD_DEREK": {"ai": ["check-bad-move"], "items": [], "party": [["rapidash", 41, 0, 8, ["fire-spin", "take-down", "agility", "fury-attack"]]]}, +"TRAINER_SUPER_NERD_ZAC": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 37, 0, 10, ["odor-sleuth", "take-down", "flame-wheel", "helping-hand"]], ["vulpix", 37, 0, 8, ["imprison", "flamethrower", "safeguard", "grudge"]]]}, +"TRAINER_HIKER_MARCOS": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 10, 0, 24, ["tackle", "defense-curl", "mud-sport"]], ["geodude", 10, 0, 12, ["tackle", "defense-curl", "mud-sport"]], ["onix", 10, 0, 8, ["tackle", "screech", "bind"]]]}, +"TRAINER_HIKER_FRANKLIN": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 15, 0, 6, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["geodude", 15, 0, 22, ["tackle", "defense-curl", "mud-sport", "rock-throw"]]]}, +"TRAINER_HIKER_NOB": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 13, 0, 23, ["tackle", "defense-curl", "mud-sport", "rock-throw"]], ["geodude", 13, 0, 10, ["tackle", "defense-curl", "mud-sport", "rock-throw"]], ["machop", 13, 0, 1, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["geodude", 13, 0, 13, ["tackle", "defense-curl", "mud-sport", "rock-throw"]]]}, +"TRAINER_HIKER_WAYNE": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 17, 0, 10, ["tackle", "screech", "bind", "rock-throw"]]]}, +"TRAINER_HIKER_ALAN": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 21, 0, 21, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["onix", 21, 0, 14, ["harden", "rock-throw", "bind", "screech"]]]}, +"TRAINER_HIKER_BRICE": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 20, 0, 16, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]], ["machop", 20, 0, 0, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["geodude", 20, 0, 5, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]]]}, +"TRAINER_HIKER_CLARK": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 21, 0, 14, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["onix", 21, 0, 0, ["harden", "rock-throw", "bind", "screech"]]]}, +"TRAINER_HIKER_TRENT": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 19, 0, 14, ["screech", "bind", "rock-throw", "harden"]], ["graveler", 19, 0, 12, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]]]}, +"TRAINER_HIKER_DUDLEY": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 21, 0, 11, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["geodude", 21, 0, 11, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["graveler", 21, 0, 14, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]]}, +"TRAINER_HIKER_ALLEN": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 25, 0, 8, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]]}, +"TRAINER_HIKER_ERIC": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 20, 0, 17, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["onix", 20, 0, 2, ["screech", "bind", "rock-throw", "harden"]]]}, +"TRAINER_HIKER_LENNY": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 19, 0, 14, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]], ["machop", 19, 0, 21, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["geodude", 19, 0, 24, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]], ["geodude", 19, 0, 2, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]]]}, +"TRAINER_HIKER_OLIVER": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 20, 0, 4, ["screech", "bind", "rock-throw", "harden"]], ["onix", 20, 0, 22, ["screech", "bind", "rock-throw", "harden"]], ["geodude", 20, 0, 7, ["defense-curl", "mud-sport", "rock-throw", "magnitude"]]]}, +"TRAINER_HIKER_LUCAS": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 21, 0, 5, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]], ["graveler", 21, 0, 2, ["magnitude", "rock-throw", "mud-sport", "defense-curl"]]]}, +"TRAINER_BIKER_JARED": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 28, 0, 14, ["smokescreen", "sludge", "smog", "poison-gas"]], ["koffing", 28, 0, 17, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, 0, 20, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_BIKER_MALIK": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 29, 0, 12, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 29, 0, 9, ["screech", "minimize", "sludge", "disable"]]]}, +"TRAINER_BIKER_ERNEST": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 25, 0, 13, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, 0, 15, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, 0, 18, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, 0, 20, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 25, 0, 18, ["minimize", "sludge", "disable", "pound"]]]}, +"TRAINER_BIKER_ALEX": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 28, 0, 22, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 28, 0, 4, ["screech", "minimize", "sludge", "disable"]], ["weezing", 28, 0, 16, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_BIKER_LAO": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 29, 0, 18, ["screech", "minimize", "sludge", "disable"]], ["koffing", 29, 0, 4, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_BIKER_HIDEO": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 33, 0, 8, ["self-destruct", "sludge", "smokescreen", "haze"]]]}, +"TRAINER_BIKER_RUBEN": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 28, 0, 22, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, 0, 7, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 28, 0, 18, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_BIKER_BILLY": {"ai": ["check-bad-move"], "items": [], "party": [["muk", 33, 0, 19, ["disable", "sludge", "minimize", "screech"]]]}, +"TRAINER_BIKER_NIKOLAS": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 29, 0, 20, ["spark", "sonic-boom", "screech", "charge"]], ["voltorb", 29, 0, 4, ["spark", "sonic-boom", "screech", "charge"]]]}, +"TRAINER_BIKER_JAXON": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 29, 0, 21, ["sludge", "smokescreen", "smog", "tackle"]], ["muk", 29, 0, 3, ["screech", "minimize", "sludge", "disable"]]]}, +"TRAINER_BIKER_WILLIAM": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 25, 0, 17, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, 0, 24, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, 0, 5, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 25, 0, 11, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 25, 0, 18, ["smokescreen", "sludge", "self-destruct", "tackle"]]]}, +"TRAINER_BIKER_LUKAS": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 26, 0, 20, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 26, 0, 4, ["smokescreen", "sludge", "smog", "tackle"]], ["grimer", 26, 0, 9, ["screech", "minimize", "sludge", "disable"]], ["koffing", 26, 0, 18, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_BIKER_ISAAC": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 28, 0, 5, ["screech", "minimize", "sludge", "disable"]], ["grimer", 28, 0, 24, ["screech", "minimize", "sludge", "disable"]], ["koffing", 28, 0, 22, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_BIKER_GERALD": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 29, 0, 9, ["smokescreen", "sludge", "smog", "tackle"]], ["muk", 29, 0, 5, ["screech", "minimize", "sludge", "disable"]]]}, +"TRAINER_BURGLAR_1": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 29, 0, 7, ["ember", "leer", "odor-sleuth", "take-down"]], ["vulpix", 29, 0, 2, ["will-o-wisp", "confuse-ray", "imprison", "flamethrower"]]]}, +"TRAINER_BURGLAR_2": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 33, 0, 7, ["leer", "odor-sleuth", "take-down", "flame-wheel"]]]}, +"TRAINER_BURGLAR_3": {"ai": ["check-bad-move"], "items": [], "party": [["vulpix", 28, 0, 6, ["quick-attack", "will-o-wisp", "confuse-ray", "imprison"]], ["charmander", 28, 0, 1, ["ember", "metal-claw", "smokescreen", "scary-face"]], ["ponyta", 28, 0, 18, ["tail-whip", "ember", "stomp", "fire-spin"]]]}, +"TRAINER_BURGLAR_QUINN": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 36, 0, 12, ["leer", "odor-sleuth", "take-down", "flame-wheel"]], ["vulpix", 36, 0, 12, ["confuse-ray", "imprison", "flamethrower", "safeguard"]], ["ninetales", 36, 0, 5, ["ember", "quick-attack", "confuse-ray", "safeguard"]]]}, +"TRAINER_BURGLAR_RAMON": {"ai": ["check-bad-move"], "items": [], "party": [["ponyta", 41, 0, 24, ["stomp", "fire-spin", "take-down", "agility"]]]}, +"TRAINER_BURGLAR_DUSTY": {"ai": ["check-bad-move"], "items": [], "party": [["vulpix", 37, 0, 20, ["imprison", "flamethrower", "safeguard", "grudge"]], ["growlithe", 37, 0, 5, ["odor-sleuth", "take-down", "flame-wheel", "helping-hand"]]]}, +"TRAINER_BURGLAR_ARNIE": {"ai": ["check-bad-move"], "items": [], "party": [["charmander", 34, 0, 18, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]], ["charmeleon", 34, 0, 4, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]]]}, +"TRAINER_BURGLAR_4": {"ai": ["check-bad-move"], "items": [], "party": [["charmander", 34, 0, 6, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]], ["charmeleon", 34, 0, 5, ["metal-claw", "smokescreen", "scary-face", "flamethrower"]]]}, +"TRAINER_BURGLAR_SIMON": {"ai": ["check-bad-move"], "items": [], "party": [["ninetales", 38, 0, 24, ["ember", "quick-attack", "confuse-ray", "safeguard"]]]}, +"TRAINER_BURGLAR_LEWIS": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 34, 0, 20, ["leer", "odor-sleuth", "take-down", "flame-wheel"]], ["ponyta", 34, 0, 0, ["ember", "stomp", "fire-spin", "take-down"]]]}, +"TRAINER_ENGINEER_BAILY": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 21, 0, 21, ["tackle", "screech", "sonic-boom", "spark"]], ["magnemite", 21, 0, 11, ["thunder-shock", "supersonic", "sonic-boom", "thunder-wave"]]]}, +"TRAINER_ENGINEER_BRAXTON": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 21, 0, 3, ["thunder-shock", "supersonic", "sonic-boom", "thunder-wave"]]]}, +"TRAINER_ENGINEER_BERNIE": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 18, 0, 16, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["magnemite", 18, 0, 21, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["magneton", 18, 0, 22, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]]]}, +"TRAINER_FISHERMAN_DALE": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 17, 0, 16, ["tail-whip", "water-sport", "supersonic", "horn-attack"]], ["tentacool", 17, 0, 11, ["poison-sting", "supersonic", "constrict"]], ["goldeen", 17, 0, 16, ["tail-whip", "water-sport", "supersonic", "horn-attack"]]]}, +"TRAINER_FISHERMAN_BARNY": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 17, 0, 0, ["poison-sting", "supersonic", "constrict"]], ["staryu", 17, 0, 10, ["harden", "water-gun", "rapid-spin", "recover"]], ["shellder", 17, 0, 1, ["tackle", "withdraw", "icicle-spear", "supersonic"]]]}, +"TRAINER_FISHERMAN_NED": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 22, 0, 6, ["tail-whip", "water-sport", "supersonic", "horn-attack"]], ["poliwag", 22, 0, 2, ["bubble", "hypnosis", "water-gun", "double-slap"]], ["goldeen", 22, 0, 22, ["tail-whip", "water-sport", "supersonic", "horn-attack"]]]}, +"TRAINER_FISHERMAN_CHIP": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 24, 0, 15, ["poison-sting", "supersonic", "constrict", "acid"]], ["goldeen", 24, 0, 4, ["water-sport", "supersonic", "horn-attack", "flail"]]]}, +"TRAINER_FISHERMAN_HANK": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 27, 0, 13, ["water-sport", "supersonic", "horn-attack", "flail"]]]}, +"TRAINER_FISHERMAN_ELLIOT": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 21, 0, 5, ["bubble", "hypnosis", "water-gun", "double-slap"]], ["shellder", 21, 0, 15, ["tackle", "withdraw", "icicle-spear", "supersonic"]], ["goldeen", 21, 0, 8, ["tail-whip", "water-sport", "supersonic", "horn-attack"]], ["horsea", 21, 0, 9, ["bubble", "smokescreen", "leer"]]]}, +"TRAINER_FISHERMAN_RONALD": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 28, 0, 24, ["water-sport", "supersonic", "horn-attack", "flail"]], ["goldeen", 28, 0, 13, ["water-sport", "supersonic", "horn-attack", "flail"]], ["seaking", 28, 0, 1, ["water-sport", "supersonic", "horn-attack", "flail"]], ["seaking", 28, 0, 14, ["water-sport", "supersonic", "horn-attack", "flail"]]]}, +"TRAINER_FISHERMAN_CLAUDE": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 31, 0, 9, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["cloyster", 31, 0, 11, ["withdraw", "supersonic", "aurora-beam", "protect"]]]}, +"TRAINER_FISHERMAN_WADE": {"ai": ["check-bad-move"], "items": [], "party": [["magikarp", 27, 0, 7, ["splash", "tackle"]], ["magikarp", 27, 0, 3, ["splash", "tackle"]], ["magikarp", 27, 0, 24, ["splash", "tackle"]], ["magikarp", 27, 0, 20, ["splash", "tackle"]], ["magikarp", 27, 0, 16, ["splash", "tackle"]], ["magikarp", 27, 0, 12, ["splash", "tackle"]]]}, +"TRAINER_FISHERMAN_NOLAN": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 33, 0, 10, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["goldeen", 33, 0, 10, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_FISHERMAN_ANDREW": {"ai": ["check-bad-move"], "items": [], "party": [["magikarp", 24, 0, 6, ["splash", "tackle"]], ["magikarp", 24, 0, 1, ["splash", "tackle"]]]}, +"TRAINER_SWIMMER_MALE_LUIS": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 16, 0, 8, ["bubble", "smokescreen", "leer"]], ["shellder", 16, 0, 14, ["tackle", "withdraw", "icicle-spear", "supersonic"]]]}, +"TRAINER_SWIMMER_MALE_RICHARD": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 30, 0, 13, ["constrict", "acid", "bubble-beam", "wrap"]], ["shellder", 30, 0, 17, ["icicle-spear", "supersonic", "aurora-beam", "protect"]]]}, +"TRAINER_SWIMMER_MALE_REECE": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 29, 0, 16, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["horsea", 29, 0, 4, ["smokescreen", "leer", "water-gun", "twister"]], ["staryu", 29, 0, 20, ["recover", "camouflage", "swift", "bubble-beam"]]]}, +"TRAINER_SWIMMER_MALE_MATTHEW": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 30, 0, 23, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["poliwhirl", 30, 0, 1, ["hypnosis", "water-gun", "double-slap", "rain-dance"]]]}, +"TRAINER_SWIMMER_MALE_DOUGLAS": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 27, 0, 14, ["bubble", "smokescreen", "leer", "water-gun"]], ["tentacool", 27, 0, 24, ["supersonic", "constrict", "acid", "bubble-beam"]], ["tentacool", 27, 0, 9, ["supersonic", "constrict", "acid", "bubble-beam"]], ["goldeen", 27, 0, 4, ["water-sport", "supersonic", "horn-attack", "flail"]]]}, +"TRAINER_SWIMMER_MALE_DAVID": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 29, 0, 15, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["shellder", 29, 0, 11, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["seaking", 29, 0, 14, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_SWIMMER_MALE_TONY": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 30, 0, 11, ["smokescreen", "leer", "water-gun", "twister"]], ["horsea", 30, 0, 11, ["smokescreen", "leer", "water-gun", "twister"]]]}, +"TRAINER_SWIMMER_MALE_AXLE": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 27, 0, 1, ["supersonic", "constrict", "acid", "bubble-beam"]], ["tentacool", 27, 0, 16, ["supersonic", "constrict", "acid", "bubble-beam"]], ["staryu", 27, 0, 2, ["rapid-spin", "recover", "camouflage", "swift"]], ["horsea", 27, 0, 10, ["bubble", "smokescreen", "leer", "water-gun"]], ["tentacruel", 27, 0, 0, ["supersonic", "constrict", "acid", "bubble-beam"]]]}, +"TRAINER_SWIMMER_MALE_BARRY": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 31, 0, 1, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["cloyster", 31, 0, 20, ["withdraw", "supersonic", "aurora-beam", "protect"]]]}, +"TRAINER_SWIMMER_MALE_DEAN": {"ai": ["check-bad-move"], "items": [], "party": [["staryu", 35, 0, 14, ["camouflage", "swift", "bubble-beam", "minimize"]]]}, +"TRAINER_SWIMMER_MALE_DARRIN": {"ai": ["check-bad-move"], "items": [], "party": [["horsea", 28, 0, 8, ["bubble", "smokescreen", "leer", "water-gun"]], ["horsea", 28, 0, 5, ["bubble", "smokescreen", "leer", "water-gun"]], ["seadra", 28, 0, 19, ["bubble", "smokescreen", "leer", "water-gun"]], ["horsea", 28, 0, 16, ["bubble", "smokescreen", "leer", "water-gun"]]]}, +"TRAINER_SWIMMER_MALE_SPENCER": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 33, 0, 12, ["smokescreen", "leer", "water-gun", "twister"]], ["tentacruel", 33, 0, 3, ["constrict", "acid", "bubble-beam", "wrap"]]]}, +"TRAINER_SWIMMER_MALE_JACK": {"ai": ["check-bad-move"], "items": [], "party": [["starmie", 37, 0, 22, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_SWIMMER_MALE_JEROME": {"ai": ["check-bad-move"], "items": [], "party": [["staryu", 33, 0, 23, ["camouflage", "swift", "bubble-beam", "minimize"]], ["wartortle", 33, 0, 1, ["water-gun", "bite", "rapid-spin", "protect"]]]}, +"TRAINER_SWIMMER_MALE_ROLAND": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 32, 0, 17, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["tentacool", 32, 0, 21, ["constrict", "acid", "bubble-beam", "wrap"]], ["seadra", 32, 0, 10, ["smokescreen", "leer", "water-gun", "twister"]]]}, +"TRAINER_CUE_BALL_KOJI": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 28, 0, 2, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["mankey", 28, 0, 21, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["machop", 28, 0, 12, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_CUE_BALL_LUKE": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 29, 0, 4, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["machop", 29, 0, 19, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_CUE_BALL_CAMRON": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 29, 0, 1, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["machop", 29, 0, 13, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_CUE_BALL_RAUL": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 29, 0, 22, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["primeape", 29, 0, 24, ["fury-swipes", "focus-energy", "seismic-toss", "rage"]]]}, +"TRAINER_CUE_BALL_ISAIAH": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 29, 0, 21, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["machamp", 29, 0, 16, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_CUE_BALL_ZEEK": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 33, 0, 5, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, +"TRAINER_CUE_BALL_JAMAL": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 26, 0, 23, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["mankey", 26, 0, 10, ["karate-chop", "fury-swipes", "focus-energy", "seismic-toss"]], ["machamp", 26, 0, 4, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["machop", 26, 0, 13, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_CUE_BALL_COREY": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 29, 0, 13, ["fury-swipes", "focus-energy", "seismic-toss", "rage"]], ["machoke", 29, 0, 12, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_CUE_BALL_CHASE": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 31, 0, 6, ["constrict", "acid", "bubble-beam", "wrap"]], ["tentacool", 31, 0, 1, ["constrict", "acid", "bubble-beam", "wrap"]], ["tentacruel", 31, 0, 21, ["constrict", "acid", "bubble-beam", "wrap"]]]}, +"TRAINER_GAMER_HUGO": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 18, 0, 16, ["bubble", "hypnosis", "water-gun"]], ["horsea", 18, 0, 3, ["bubble", "smokescreen", "leer"]]]}, +"TRAINER_GAMER_JASPER": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 18, 0, 21, ["growth", "wrap", "sleep-powder", "poison-powder"]], ["oddish", 18, 0, 6, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]]]}, +"TRAINER_GAMER_DIRK": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 18, 0, 13, ["charge", "tackle", "screech", "sonic-boom"]], ["magnemite", 18, 0, 20, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]]]}, +"TRAINER_GAMER_DARIAN": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 18, 0, 10, ["bite", "roar", "ember", "leer"]], ["vulpix", 18, 0, 8, ["tail-whip", "roar", "quick-attack", "will-o-wisp"]]]}, +"TRAINER_GAMER_STAN": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 22, 0, 9, ["bubble", "hypnosis", "water-gun", "double-slap"]], ["poliwag", 22, 0, 7, ["bubble", "hypnosis", "water-gun", "double-slap"]], ["poliwhirl", 22, 0, 21, ["bubble", "hypnosis", "water-gun", "double-slap"]]]}, +"TRAINER_GAMER_RICH": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 24, 0, 24, ["roar", "ember", "leer", "odor-sleuth"]], ["vulpix", 24, 0, 11, ["roar", "quick-attack", "will-o-wisp", "confuse-ray"]]]}, +"TRAINER_BEAUTY_BRIDGET": {"ai": ["check-bad-move"], "items": [], "party": [["oddish", 21, 0, 22, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bellsprout", 21, 0, 24, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]], ["oddish", 21, 0, 1, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["bellsprout", 21, 0, 3, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]]]}, +"TRAINER_BEAUTY_TAMIA": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 24, 0, 14, ["sleep-powder", "poison-powder", "stun-spore", "acid"]], ["bellsprout", 24, 0, 8, ["sleep-powder", "poison-powder", "stun-spore", "acid"]]]}, +"TRAINER_BEAUTY_LORI": {"ai": ["check-bad-move"], "items": [], "party": [["exeggcute", 24, 0, 9, ["hypnosis", "reflect", "leech-seed", "confusion"]]]}, +"TRAINER_BEAUTY_LOLA": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 27, 0, 22, ["quick-attack", "hyper-fang", "focus-energy", "pursuit"]], ["pikachu", 27, 0, 2, ["quick-attack", "double-team", "slam", "thunderbolt"]], ["rattata", 27, 0, 4, ["quick-attack", "hyper-fang", "focus-energy", "pursuit"]]]}, +"TRAINER_BEAUTY_SHEILA": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 29, 0, 17, ["follow-me", "minimize", "defense-curl", "metronome"]], ["meowth", 29, 0, 12, ["growl", "bite", "pay-day", "feint-attack"]]]}, +"TRAINER_SWIMMER_FEMALE_TIFFANY": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 35, 0, 1, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_SWIMMER_FEMALE_NORA": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 30, 0, 23, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["shellder", 30, 0, 1, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["cloyster", 30, 0, 8, ["withdraw", "supersonic", "aurora-beam", "protect"]]]}, +"TRAINER_SWIMMER_FEMALE_MELISSA": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 31, 0, 10, ["water-gun", "double-slap", "rain-dance", "body-slam"]], ["seaking", 31, 0, 23, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_BEAUTY_GRACE": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 29, 0, 14, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["wigglytuff", 29, 0, 24, ["sing", "disable", "defense-curl", "double-slap"]]]}, +"TRAINER_BEAUTY_OLIVIA": {"ai": ["check-bad-move"], "items": [], "party": [["bulbasaur", 29, 0, 0, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]], ["ivysaur", 29, 0, 6, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]]]}, +"TRAINER_BEAUTY_LAUREN": {"ai": ["check-bad-move"], "items": [], "party": [["weepinbell", 33, 0, 20, ["poison-powder", "stun-spore", "acid", "sweet-scent"]], ["bellsprout", 33, 0, 17, ["poison-powder", "stun-spore", "acid", "sweet-scent"]], ["weepinbell", 33, 0, 17, ["poison-powder", "stun-spore", "acid", "sweet-scent"]]]}, +"TRAINER_SWIMMER_FEMALE_ANYA": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 27, 0, 15, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["goldeen", 27, 0, 9, ["water-sport", "supersonic", "horn-attack", "flail"]], ["seaking", 27, 0, 2, ["water-sport", "supersonic", "horn-attack", "flail"]], ["goldeen", 27, 0, 21, ["water-sport", "supersonic", "horn-attack", "flail"]], ["poliwag", 27, 0, 16, ["hypnosis", "water-gun", "double-slap", "rain-dance"]]]}, +"TRAINER_SWIMMER_FEMALE_ALICE": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 30, 0, 14, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 30, 0, 7, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_SWIMMER_FEMALE_CONNIE": {"ai": ["check-bad-move"], "items": [], "party": [["staryu", 29, 0, 21, ["recover", "camouflage", "swift", "bubble-beam"]], ["staryu", 29, 0, 22, ["recover", "camouflage", "swift", "bubble-beam"]], ["staryu", 29, 0, 23, ["recover", "camouflage", "swift", "bubble-beam"]]]}, +"TRAINER_SWIMMER_FEMALE_SHIRLEY": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 30, 0, 17, ["smokescreen", "leer", "water-gun", "twister"]], ["horsea", 30, 0, 22, ["smokescreen", "leer", "water-gun", "twister"]], ["seadra", 30, 0, 19, ["smokescreen", "leer", "water-gun", "twister"]]]}, +"TRAINER_PSYCHIC_JOHAN": {"ai": ["check-bad-move"], "items": [], "party": [["kadabra", 31, 50, 19, ["psybeam", "reflect", "recover", "future-sight"]], ["slowpoke", 31, 50, 11, ["water-gun", "confusion", "disable", "headbutt"]], ["mr-mime", 31, 50, 14, ["reflect", "magical-leaf", "encore", "psybeam"]], ["kadabra", 31, 50, 22, ["psybeam", "reflect", "recover", "future-sight"]]]}, +"TRAINER_PSYCHIC_TYRON": {"ai": ["check-bad-move"], "items": [], "party": [["mr-mime", 34, 50, 3, ["magical-leaf", "encore", "psybeam", "recycle"]], ["kadabra", 34, 50, 0, ["reflect", "recover", "future-sight", "role-play"]]]}, +"TRAINER_PSYCHIC_CAMERON": {"ai": ["check-bad-move"], "items": [], "party": [["slowpoke", 33, 50, 11, ["water-gun", "confusion", "disable", "headbutt"]], ["slowpoke", 33, 50, 11, ["water-gun", "confusion", "disable", "headbutt"]], ["slowbro", 33, 50, 23, ["water-gun", "confusion", "disable", "headbutt"]]]}, +"TRAINER_PSYCHIC_PRESTON": {"ai": ["check-bad-move"], "items": [], "party": [["slowbro", 38, 50, 1, ["disable", "headbutt", "amnesia", "withdraw"]]]}, +"TRAINER_ROCKER_RANDALL": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 20, 0, 6, ["charge", "tackle", "screech", "sonic-boom"]], ["magnemite", 20, 0, 6, ["tackle", "thunder-shock", "supersonic", "sonic-boom"]], ["voltorb", 20, 0, 1, ["charge", "tackle", "screech", "sonic-boom"]]]}, +"TRAINER_ROCKER_LUCA": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 29, 0, 8, ["screech", "sonic-boom", "spark", "self-destruct"]], ["electrode", 29, 0, 10, ["screech", "sonic-boom", "spark", "self-destruct"]]]}, +"TRAINER_JUGGLER_DALTON": {"ai": ["check-bad-move"], "items": [], "party": [["kadabra", 29, 0, 18, ["disable", "psybeam", "reflect", "recover"]], ["mr-mime", 29, 0, 20, ["reflect", "magical-leaf", "encore", "psybeam"]]]}, +"TRAINER_JUGGLER_NELSON": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 41, 0, 19, ["meditate", "psychic", "psych-up", "swagger"]], ["hypno", 41, 0, 12, ["headbutt", "poison-gas", "meditate", "psychic"]], ["kadabra", 41, 0, 22, ["recover", "future-sight", "role-play", "psychic"]], ["kadabra", 41, 0, 7, ["recover", "future-sight", "role-play", "psychic"]]]}, +"TRAINER_JUGGLER_KIRK": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 31, 0, 7, ["headbutt", "poison-gas", "meditate", "psychic"]], ["drowzee", 31, 0, 3, ["headbutt", "poison-gas", "meditate", "psychic"]], ["kadabra", 31, 0, 1, ["psybeam", "reflect", "recover", "future-sight"]], ["drowzee", 31, 0, 22, ["headbutt", "poison-gas", "meditate", "psychic"]]]}, +"TRAINER_JUGGLER_SHAWN": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 34, 0, 19, ["headbutt", "poison-gas", "meditate", "psychic"]], ["hypno", 34, 0, 12, ["confusion", "headbutt", "poison-gas", "meditate"]]]}, +"TRAINER_JUGGLER_GREGORY": {"ai": ["check-bad-move"], "items": [], "party": [["mr-mime", 48, 0, 3, ["psychic", "role-play", "double-slap", "encore"]]]}, +"TRAINER_JUGGLER_EDWARD": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 46, 0, 23, ["swift", "light-screen", "spark", "sonic-boom"]], ["voltorb", 46, 0, 10, ["swift", "light-screen", "spark", "sonic-boom"]], ["electrode", 47, 0, 2, ["swift", "spark", "self-destruct", "sonic-boom"]], ["mr-mime", 48, 0, 13, ["psychic", "role-play", "reflect", "encore"]]]}, +"TRAINER_JUGGLER_KAYDEN": {"ai": ["check-bad-move"], "items": [], "party": [["hypno", 38, 0, 15, ["headbutt", "poison-gas", "meditate", "psychic"]]]}, +"TRAINER_JUGGLER_NATE": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 34, 0, 3, ["headbutt", "poison-gas", "meditate", "psychic"]], ["kadabra", 34, 0, 22, ["reflect", "recover", "future-sight", "role-play"]]]}, +"TRAINER_TAMER_PHIL": {"ai": ["check-bad-move"], "items": [], "party": [["sandslash", 34, 40, 21, ["sand-attack", "poison-sting", "slash", "swift"]], ["arbok", 34, 40, 17, ["poison-sting", "bite", "glare", "screech"]]]}, +"TRAINER_TAMER_EDGAR": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 33, 40, 13, ["poison-sting", "bite", "glare", "screech"]], ["sandslash", 33, 40, 4, ["sand-attack", "poison-sting", "slash", "swift"]], ["arbok", 33, 40, 6, ["poison-sting", "bite", "glare", "screech"]]]}, +"TRAINER_TAMER_JASON": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 43, 40, 18, ["scary-face", "rock-blast", "horn-drill", "take-down"]]]}, +"TRAINER_TAMER_COLE": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 39, 40, 22, ["bite", "glare", "screech", "acid"]], ["tauros", 39, 40, 6, ["scary-face", "pursuit", "swagger", "rest"]]]}, +"TRAINER_TAMER_VINCENT": {"ai": ["check-bad-move"], "items": [], "party": [["persian", 44, 40, 24, ["pay-day", "feint-attack", "screech", "fury-swipes"]], ["golduck", 44, 40, 8, ["confusion", "screech", "psych-up", "fury-swipes"]]]}, +"TRAINER_TAMER_JOHN": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 42, 40, 5, ["fury-attack", "scary-face", "rock-blast", "horn-drill"]], ["primeape", 42, 40, 2, ["focus-energy", "seismic-toss", "rage", "cross-chop"]], ["arbok", 42, 40, 10, ["bite", "glare", "screech", "acid"]], ["tauros", 42, 40, 16, ["scary-face", "pursuit", "swagger", "rest"]]]}, +"TRAINER_BIRD_KEEPER_SEBASTIAN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 29, 0, 12, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 29, 0, 6, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, +"TRAINER_BIRD_KEEPER_PERRY": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 25, 0, 2, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["pidgey", 25, 0, 16, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgey", 25, 0, 5, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["spearow", 25, 0, 21, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["spearow", 25, 0, 12, ["leer", "fury-attack", "pursuit", "aerial-ace"]]]}, +"TRAINER_BIRD_KEEPER_ROBERT": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 26, 0, 17, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 26, 0, 16, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["spearow", 26, 0, 24, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 26, 0, 17, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_DONALD": {"ai": ["check-bad-move"], "items": [], "party": [["farfetch-d", 33, 0, 7, ["fury-attack", "knock-off", "fury-cutter", "swords-dance"]]]}, +"TRAINER_BIRD_KEEPER_BENNY": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 29, 0, 20, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 29, 0, 14, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_EDWIN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 26, 0, 6, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["farfetch-d", 26, 0, 16, ["leer", "fury-attack", "knock-off", "fury-cutter"]], ["doduo", 26, 0, 10, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["pidgey", 26, 0, 12, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, +"TRAINER_BIRD_KEEPER_CHESTER": {"ai": ["check-bad-move"], "items": [], "party": [["dodrio", 28, 0, 2, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["doduo", 28, 0, 16, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["doduo", 28, 0, 5, ["pursuit", "fury-attack", "tri-attack", "rage"]]]}, +"TRAINER_BIRD_KEEPER_WILTON": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 29, 0, 9, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 29, 0, 17, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_RAMIRO": {"ai": ["check-bad-move"], "items": [], "party": [["dodrio", 34, 0, 12, ["pursuit", "fury-attack", "tri-attack", "rage"]]]}, +"TRAINER_BIRD_KEEPER_JACOB": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 26, 0, 21, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["spearow", 26, 0, 6, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 26, 0, 1, ["growl", "leer", "fury-attack", "pursuit"]], ["spearow", 26, 0, 11, ["leer", "fury-attack", "pursuit", "aerial-ace"]]]}, +"TRAINER_BIRD_KEEPER_ROGER": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 30, 0, 23, ["growl", "leer", "fury-attack", "pursuit"]], ["fearow", 30, 0, 10, ["growl", "leer", "fury-attack", "pursuit"]], ["pidgeotto", 30, 0, 3, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, +"TRAINER_BIRD_KEEPER_REED": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 39, 0, 2, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["pidgeotto", 39, 0, 18, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["pidgey", 39, 0, 16, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["pidgeotto", 39, 0, 7, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]]]}, +"TRAINER_BIRD_KEEPER_KEITH": {"ai": ["check-bad-move"], "items": [], "party": [["farfetch-d", 39, 0, 9, ["knock-off", "fury-cutter", "swords-dance", "agility"]], ["fearow", 39, 0, 11, ["leer", "fury-attack", "pursuit", "mirror-move"]]]}, +"TRAINER_BIRD_KEEPER_CARTER": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 28, 0, 14, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["doduo", 28, 0, 9, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["pidgeotto", 28, 0, 5, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, +"TRAINER_BIRD_KEEPER_MITCH": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 26, 0, 1, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["spearow", 26, 0, 18, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["pidgey", 26, 0, 8, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["fearow", 26, 0, 10, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_BECK": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 29, 0, 11, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["fearow", 29, 0, 5, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_MARLON": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 28, 0, 14, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["doduo", 28, 0, 7, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["fearow", 28, 0, 20, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BLACK_BELT_KOICHI": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonlee", 37, 100, 12, ["focus-energy", "high-jump-kick", "mind-reader", "foresight"]], ["hitmonchan", 37, 100, 3, ["thunder-punch", "ice-punch", "fire-punch", "sky-uppercut"]]]}, +"TRAINER_BLACK_BELT_MIKE": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 31, 100, 13, ["fury-swipes", "focus-energy", "seismic-toss", "cross-chop"]], ["mankey", 31, 100, 15, ["fury-swipes", "focus-energy", "seismic-toss", "cross-chop"]], ["primeape", 31, 100, 8, ["fury-swipes", "focus-energy", "seismic-toss", "rage"]]]}, +"TRAINER_BLACK_BELT_HIDEKI": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 32, 100, 15, ["seismic-toss", "foresight", "revenge", "vital-throw"]], ["machoke", 32, 100, 10, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_BLACK_BELT_AARON": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 36, 100, 11, ["focus-energy", "seismic-toss", "rage", "cross-chop"]]]}, +"TRAINER_BLACK_BELT_HITOSHI": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 31, 100, 8, ["seismic-toss", "foresight", "revenge", "vital-throw"]], ["mankey", 31, 100, 8, ["fury-swipes", "focus-energy", "seismic-toss", "cross-chop"]], ["primeape", 31, 100, 24, ["fury-swipes", "focus-energy", "seismic-toss", "rage"]]]}, +"TRAINER_BLACK_BELT_ATSUSHI": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 40, 100, 12, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machoke", 40, 100, 4, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, +"TRAINER_BLACK_BELT_KIYO": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 43, 100, 8, ["foresight", "revenge", "vital-throw", "submission"]]]}, +"TRAINER_BLACK_BELT_TAKASHI": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 38, 100, 10, ["seismic-toss", "foresight", "revenge", "vital-throw"]], ["machop", 38, 100, 18, ["foresight", "revenge", "vital-throw", "submission"]], ["machoke", 38, 100, 17, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, +"TRAINER_BLACK_BELT_DAISUKE": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 43, 100, 16, ["foresight", "revenge", "vital-throw", "submission"]], ["machop", 43, 100, 5, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machoke", 43, 100, 10, ["foresight", "revenge", "vital-throw", "submission"]]]}, +"TRAINER_RIVAL_OAKS_LAB_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["squirtle", 5, 0, 11, ["tackle", "tail-whip"]]]}, +"TRAINER_RIVAL_OAKS_LAB_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["bulbasaur", 5, 0, 8, ["tackle", "growl"]]]}, +"TRAINER_RIVAL_OAKS_LAB_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["charmander", 5, 0, 2, ["scratch", "growl"]]]}, +"TRAINER_RIVAL_ROUTE22_EARLY_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgey", 9, 50, 24, ["tackle", "sand-attack"]], ["squirtle", 9, 50, 24, ["tackle", "tail-whip"]]]}, +"TRAINER_RIVAL_ROUTE22_EARLY_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgey", 9, 50, 24, ["tackle", "sand-attack"]], ["bulbasaur", 9, 50, 21, ["tackle", "growl"]]]}, +"TRAINER_RIVAL_ROUTE22_EARLY_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgey", 9, 50, 24, ["tackle", "sand-attack"]], ["charmander", 9, 50, 15, ["scratch", "growl"]]]}, +"TRAINER_RIVAL_CERULEAN_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 17, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, 50, 9, ["teleport"]], ["rattata", 15, 50, 3, ["tackle", "tail-whip", "quick-attack"]], ["squirtle", 18, 100, 3, ["tackle", "tail-whip", "withdraw", "water-gun"]]]}, +"TRAINER_RIVAL_CERULEAN_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 17, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, 50, 9, ["teleport"]], ["rattata", 15, 50, 3, ["tackle", "tail-whip", "quick-attack"]], ["bulbasaur", 18, 100, 0, ["sleep-powder", "poison-powder", "vine-whip", "leech-seed"]]]}, +"TRAINER_RIVAL_CERULEAN_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 17, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["abra", 16, 50, 9, ["teleport"]], ["rattata", 15, 50, 3, ["tackle", "tail-whip", "quick-attack"]], ["charmander", 18, 100, 19, ["metal-claw", "ember", "growl", "scratch"]]]}, +"TRAINER_SCIENTIST_TED": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 29, 0, 24, ["screech", "sonic-boom", "spark", "self-destruct"]], ["weezing", 29, 0, 17, ["smog", "self-destruct", "sludge", "smokescreen"]]]}, +"TRAINER_SCIENTIST_CONNOR": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 26, 0, 22, ["screech", "minimize", "sludge", "disable"]], ["weezing", 26, 0, 13, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 26, 0, 3, ["smokescreen", "sludge", "smog", "self-destruct"]], ["weezing", 26, 0, 19, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_SCIENTIST_JERRY": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 28, 0, 13, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["voltorb", 28, 0, 10, ["screech", "sonic-boom", "spark", "self-destruct"]], ["magneton", 28, 0, 8, ["supersonic", "sonic-boom", "thunder-wave", "spark"]]]}, +"TRAINER_SCIENTIST_JOSE": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 29, 0, 10, ["spark", "sonic-boom", "screech", "tackle"]], ["weezing", 29, 0, 14, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_SCIENTIST_RODNEY": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 33, 0, 9, ["screech", "sonic-boom", "spark", "self-destruct"]]]}, +"TRAINER_SCIENTIST_BEAU": {"ai": ["check-bad-move"], "items": [], "party": [["magneton", 26, 0, 11, ["spark", "thunder-wave", "sonic-boom", "supersonic"]], ["koffing", 26, 0, 19, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 26, 0, 3, ["smokescreen", "sludge", "smog", "tackle"]], ["magnemite", 26, 0, 7, ["spark", "thunder-wave", "sonic-boom", "supersonic"]]]}, +"TRAINER_SCIENTIST_TAYLOR": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 25, 0, 14, ["spark", "sonic-boom", "screech", "tackle"]], ["koffing", 25, 0, 1, ["smokescreen", "sludge", "smog", "tackle"]], ["magneton", 25, 0, 5, ["thunder-wave", "sonic-boom", "supersonic", "thunder-shock"]], ["magnemite", 25, 0, 13, ["thunder-wave", "sonic-boom", "supersonic", "thunder-shock"]], ["koffing", 25, 0, 0, ["smokescreen", "sludge", "smog", "self-destruct"]]]}, +"TRAINER_SCIENTIST_JOSHUA": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 29, 0, 17, ["screech", "sonic-boom", "spark", "self-destruct"]], ["muk", 29, 0, 0, ["disable", "sludge", "minimize", "screech"]]]}, +"TRAINER_SCIENTIST_PARKER": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 29, 0, 12, ["disable", "sludge", "minimize", "screech"]], ["electrode", 29, 0, 13, ["screech", "sonic-boom", "spark", "self-destruct"]]]}, +"TRAINER_SCIENTIST_ED": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 28, 0, 8, ["spark", "sonic-boom", "screech", "tackle"]], ["koffing", 28, 0, 14, ["smokescreen", "sludge", "tackle", "smog"]], ["magneton", 28, 0, 12, ["spark", "thunder-wave", "sonic-boom", "supersonic"]]]}, +"TRAINER_SCIENTIST_TRAVIS": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 29, 0, 7, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["koffing", 29, 0, 7, ["smog", "self-destruct", "sludge", "smokescreen"]]]}, +"TRAINER_SCIENTIST_BRAYDON": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 33, 0, 13, ["sonic-boom", "thunder-wave", "spark", "lock-on"]], ["magneton", 33, 0, 11, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["voltorb", 33, 0, 8, ["sonic-boom", "spark", "self-destruct", "rollout"]]]}, +"TRAINER_SCIENTIST_IVAN": {"ai": ["check-bad-move"], "items": [], "party": [["magnemite", 34, 0, 17, ["sonic-boom", "thunder-wave", "spark", "lock-on"]], ["electrode", 34, 0, 23, ["sonic-boom", "spark", "self-destruct", "rollout"]]]}, +"TRAINER_BOSS_GIOVANNI": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 25, 250, 21, ["bind", "rock-throw", "harden", "rage"]], ["rhyhorn", 24, 250, 18, ["tail-whip", "stomp", "fury-attack", "scary-face"]], ["kangaskhan", 29, 250, 24, ["bite", "tail-whip", "fake-out", "mega-punch"]]]}, +"TRAINER_BOSS_GIOVANNI_2": {"ai": ["check-bad-move"], "items": [], "party": [["nidorino", 37, 250, 1, ["poison-sting", "horn-attack", "helping-hand", "fury-attack"]], ["kangaskhan", 35, 250, 7, ["tail-whip", "fake-out", "mega-punch", "rage"]], ["rhyhorn", 37, 250, 4, ["stomp", "fury-attack", "scary-face", "rock-blast"]], ["nidoqueen", 41, 250, 21, ["tail-whip", "double-kick", "poison-sting", "body-slam"]]]}, +"TRAINER_LEADER_GIOVANNI": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "hyper-potion", "full-heal"], "party": [["rhyhorn", 45, 0, 8, ["take-down", "rock-blast", "scary-face", "earthquake"]], ["dugtrio", 42, 0, 8, ["slash", "sand-tomb", "mud-slap", "earthquake"]], ["nidoqueen", 44, 0, 0, ["body-slam", "double-kick", "poison-sting", "earthquake"]], ["nidoking", 45, 0, 0, ["thrash", "double-kick", "poison-sting", "earthquake"]], ["rhyhorn", 50, 0, 22, ["take-down", "rock-blast", "scary-face", "earthquake"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 13, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["zubat", 13, 0, 4, ["leech-life", "astonish", "supersonic"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_2": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 11, 0, 6, ["scratch", "defense-curl", "sand-attack"]], ["rattata", 11, 0, 14, ["tackle", "tail-whip", "quick-attack"]], ["zubat", 11, 0, 24, ["leech-life", "astonish", "supersonic"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_3": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 11, 0, 21, ["leech-life", "astonish", "supersonic"]], ["ekans", 11, 0, 11, ["wrap", "leer", "poison-sting"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_4": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 13, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["sandshrew", 13, 0, 14, ["scratch", "defense-curl", "sand-attack"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_5": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 17, 0, 3, ["low-kick", "leer", "focus-energy", "karate-chop"]], ["drowzee", 17, 0, 1, ["hypnosis", "disable", "confusion", "headbutt"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_6": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 15, 0, 1, ["wrap", "leer", "poison-sting", "bite"]], ["zubat", 15, 0, 11, ["leech-life", "astonish", "supersonic"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_7": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 20, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["zubat", 20, 0, 21, ["leech-life", "astonish", "supersonic", "bite"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_8": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 21, 0, 9, ["disable", "confusion", "headbutt", "poison-gas"]], ["machop", 21, 0, 1, ["leer", "focus-energy", "karate-chop", "seismic-toss"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_9": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 21, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["raticate", 21, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_10": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 20, 0, 12, ["minimize", "sludge", "disable", "harden"]], ["koffing", 20, 0, 17, ["smog", "tackle", "poison-gas"]], ["koffing", 20, 0, 22, ["smog", "tackle", "poison-gas"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_11": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 19, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["raticate", 19, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["raticate", 19, 0, 19, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["rattata", 19, 0, 2, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_12": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 22, 0, 12, ["minimize", "sludge", "disable", "harden"]], ["koffing", 22, 0, 17, ["sludge", "smog", "tackle", "poison-gas"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_13": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 17, 0, 21, ["bite", "astonish", "supersonic", "leech-life"]], ["koffing", 17, 0, 1, ["smog", "tackle", "poison-gas"]], ["grimer", 17, 0, 2, ["sludge", "disable", "harden", "pound"]], ["zubat", 17, 0, 12, ["bite", "astonish", "supersonic", "leech-life"]], ["raticate", 17, 0, 12, ["hyper-fang", "quick-attack", "tail-whip", "tackle"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_14": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 20, 0, 19, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["raticate", 20, 0, 19, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["drowzee", 20, 0, 17, ["hypnosis", "disable", "confusion", "headbutt"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_15": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 21, 0, 3, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["machop", 21, 0, 20, ["leer", "focus-energy", "karate-chop", "seismic-toss"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_16": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 23, 0, 6, ["defense-curl", "sand-attack", "poison-sting", "slash"]], ["ekans", 23, 0, 21, ["leer", "poison-sting", "bite", "glare"]], ["sandslash", 23, 0, 7, ["scratch", "defense-curl", "sand-attack", "poison-sting"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_17": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 23, 0, 1, ["leer", "poison-sting", "bite", "glare"]], ["sandshrew", 23, 0, 21, ["defense-curl", "sand-attack", "poison-sting", "slash"]], ["arbok", 23, 0, 18, ["leer", "poison-sting", "bite", "glare"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_18": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 21, 0, 16, ["tackle", "smog", "self-destruct", "sludge"]], ["zubat", 21, 0, 1, ["astonish", "supersonic", "bite", "wing-attack"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_19": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 25, 0, 21, ["astonish", "supersonic", "bite", "wing-attack"]], ["zubat", 25, 0, 6, ["astonish", "supersonic", "bite", "wing-attack"]], ["golbat", 25, 0, 4, ["astonish", "supersonic", "bite", "wing-attack"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_20": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 26, 0, 16, ["smog", "self-destruct", "sludge", "smokescreen"]], ["drowzee", 26, 0, 14, ["disable", "confusion", "headbutt", "poison-gas"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_21": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 23, 0, 21, ["astonish", "supersonic", "bite", "wing-attack"]], ["rattata", 23, 0, 4, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["raticate", 23, 0, 4, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["zubat", 23, 0, 14, ["astonish", "supersonic", "bite", "wing-attack"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_22": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 26, 0, 9, ["disable", "confusion", "headbutt", "poison-gas"]], ["koffing", 26, 0, 14, ["smog", "self-destruct", "sludge", "smokescreen"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_23": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 29, 0, 2, ["leer", "focus-energy", "bonemerang", "rage"]], ["zubat", 29, 0, 12, ["supersonic", "bite", "wing-attack", "confuse-ray"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_24": {"ai": ["check-bad-move"], "items": [], "party": [["golbat", 25, 0, 9, ["astonish", "supersonic", "bite", "wing-attack"]], ["zubat", 25, 0, 19, ["astonish", "supersonic", "bite", "wing-attack"]], ["zubat", 25, 0, 4, ["astonish", "supersonic", "bite", "wing-attack"]], ["raticate", 25, 0, 4, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["zubat", 25, 0, 14, ["astonish", "supersonic", "bite", "wing-attack"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_25": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 28, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["hypno", 28, 0, 19, ["disable", "confusion", "headbutt", "poison-gas"]], ["raticate", 28, 0, 19, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_26": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 29, 0, 3, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["drowzee", 29, 0, 1, ["confusion", "headbutt", "poison-gas", "meditate"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_27": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 28, 0, 1, ["poison-sting", "bite", "glare", "screech"]], ["zubat", 28, 0, 11, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["cubone", 28, 0, 2, ["headbutt", "leer", "focus-energy", "bonemerang"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_28": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 33, 0, 8, ["poison-sting", "bite", "glare", "screech"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_29": {"ai": ["check-bad-move"], "items": [], "party": [["hypno", 33, 0, 19, ["confusion", "headbutt", "poison-gas", "meditate"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_30": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 29, 0, 3, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["machoke", 29, 0, 11, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_31": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 28, 0, 21, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["zubat", 28, 0, 6, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["golbat", 28, 0, 4, ["supersonic", "bite", "wing-attack", "confuse-ray"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_32": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 26, 0, 11, ["scary-face", "hyper-fang", "quick-attack", "tail-whip"]], ["arbok", 26, 0, 8, ["glare", "bite", "poison-sting", "leer"]], ["koffing", 26, 0, 13, ["smokescreen", "sludge", "smog", "tackle"]], ["golbat", 26, 0, 11, ["wing-attack", "bite", "astonish", "supersonic"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_33": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 29, 0, 2, ["leer", "focus-energy", "bonemerang", "rage"]], ["cubone", 29, 0, 18, ["leer", "focus-energy", "bonemerang", "rage"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_34": {"ai": ["check-bad-move"], "items": [], "party": [["sandshrew", 29, 0, 6, ["defense-curl", "sand-attack", "poison-sting", "slash"]], ["sandslash", 29, 0, 17, ["defense-curl", "sand-attack", "poison-sting", "slash"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_35": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 26, 0, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["zubat", 26, 0, 21, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["golbat", 26, 0, 19, ["astonish", "supersonic", "bite", "wing-attack"]], ["rattata", 26, 0, 2, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_36": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 28, 0, 17, ["smog", "self-destruct", "sludge", "smokescreen"]], ["golbat", 28, 0, 15, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["koffing", 28, 0, 20, ["smog", "self-destruct", "sludge", "smokescreen"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_37": {"ai": ["check-bad-move"], "items": [], "party": [["drowzee", 28, 0, 9, ["confusion", "headbutt", "poison-gas", "meditate"]], ["grimer", 28, 0, 10, ["disable", "sludge", "minimize", "screech"]], ["machop", 28, 0, 2, ["karate-chop", "seismic-toss", "foresight", "revenge"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_38": {"ai": ["check-bad-move"], "items": [], "party": [["golbat", 28, 0, 9, ["supersonic", "bite", "wing-attack", "confuse-ray"]], ["drowzee", 28, 0, 7, ["confusion", "headbutt", "poison-gas", "meditate"]], ["hypno", 28, 0, 15, ["disable", "confusion", "headbutt", "poison-gas"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_39": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 33, 0, 19, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_40": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 25, 0, 19, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["rattata", 25, 0, 2, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["zubat", 25, 0, 12, ["astonish", "supersonic", "bite", "wing-attack"]], ["rattata", 25, 0, 20, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["ekans", 25, 0, 10, ["poison-sting", "bite", "glare", "screech"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_41": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 32, 0, 2, ["leer", "focus-energy", "bonemerang", "rage"]], ["drowzee", 32, 0, 0, ["headbutt", "poison-gas", "meditate", "psychic"]], ["marowak", 32, 0, 14, ["leer", "focus-energy", "bonemerang", "rage"]]]}, +"TRAINER_COOLTRAINER_SAMUEL": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["super-potion"], "party": [["sandslash", 37, 100, 9, ["slash", "swift", "sand-attack", "poison-sting"]], ["sandslash", 37, 100, 7, ["slash", "swift", "sand-attack", "poison-sting"]], ["rhyhorn", 38, 100, 2, ["take-down", "rock-blast", "fury-attack", "scary-face"]], ["nidorino", 39, 100, 15, ["fury-attack", "horn-attack", "poison-sting", "double-kick"]], ["nidoking", 39, 100, 13, ["thrash", "double-kick", "poison-sting", "focus-energy"]]]}, +"TRAINER_COOLTRAINER_GEORGE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["exeggutor", 42, 100, 0, ["egg-bomb", "confusion", "stun-spore", "sleep-powder"]], ["sandslash", 42, 100, 14, ["fury-swipes", "swift", "poison-sting", "sand-attack"]], ["cloyster", 42, 100, 7, ["spike-cannon", "spikes", "aurora-beam", "supersonic"]], ["electrode", 42, 100, 11, ["spark", "sonic-boom", "screech", "light-screen"]], ["arcanine", 42, 100, 17, ["flame-wheel", "roar", "bite", "take-down"]]]}, +"TRAINER_COOLTRAINER_COLBY": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["kingler", 41, 100, 1, ["guillotine", "stomp", "mud-shot", "bubble"]], ["poliwhirl", 42, 100, 24, ["body-slam", "double-slap", "water-gun", "hypnosis"]], ["tentacruel", 42, 100, 20, ["barrier", "wrap", "bubble-beam", "acid"]], ["seadra", 42, 100, 1, ["water-gun", "smokescreen", "twister", "leer"]], ["blastoise", 43, 100, 4, ["water-gun", "bite", "rapid-spin", "rain-dance"]]]}, +"TRAINER_COOLTRAINER_PAUL": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["slowpoke", 42, 100, 24, ["headbutt", "confusion", "water-gun", "disable"]], ["shellder", 42, 100, 14, ["aurora-beam", "clamp", "supersonic", "leer"]], ["kingler", 42, 100, 21, ["guillotine", "stomp", "mud-shot", "bubble"]], ["starmie", 42, 100, 7, ["bubble-beam", "swift", "recover", "rapid-spin"]], ["golduck", 42, 100, 21, ["confusion", "scratch", "screech", "disable"]]]}, +"TRAINER_COOLTRAINER_ROLANDO": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["raticate", 42, 100, 12, ["super-fang", "pursuit", "scary-face", "quick-attack"]], ["ivysaur", 42, 100, 0, ["razor-leaf", "sleep-powder", "sweet-scent", "synthesis"]], ["wartortle", 42, 100, 22, ["water-gun", "bite", "rapid-spin", "tail-whip"]], ["charmeleon", 42, 100, 7, ["flamethrower", "slash", "smokescreen", "scary-face"]], ["charizard", 42, 100, 15, ["flamethrower", "wing-attack", "smokescreen", "scary-face"]]]}, +"TRAINER_COOLTRAINER_GILBERT": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["pidgeotto", 42, 100, 21, ["wing-attack", "feather-dance", "whirlwind", "quick-attack"]], ["fearow", 42, 100, 0, ["drill-peck", "mirror-move", "pursuit", "leer"]], ["persian", 42, 100, 4, ["pay-day", "feint-attack", "screech", "bite"]], ["lickitung", 42, 100, 9, ["slam", "disable", "wrap", "supersonic"]], ["tauros", 42, 100, 19, ["horn-attack", "scary-face", "swagger", "tail-whip"]]]}, +"TRAINER_COOLTRAINER_OWEN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["nidorino", 42, 100, 8, ["scratch", "poison-sting", "double-kick", "bite"]], ["nidorina", 42, 100, 21, ["horn-attack", "poison-sting", "double-kick", "leer"]], ["raticate", 42, 100, 17, ["super-fang", "pursuit", "scary-face", "quick-attack"]], ["sandslash", 42, 100, 24, ["fury-swipes", "swift", "slash", "poison-sting"]], ["rhyhorn", 42, 100, 3, ["rock-blast", "scary-face", "stomp", "tail-whip"]]]}, +"TRAINER_COOLTRAINER_BERKE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["seel", 42, 100, 22, ["take-down", "aurora-beam", "icy-wind", "growl"]], ["graveler", 42, 100, 4, ["rock-blast", "magnitude", "rock-throw", "mud-sport"]], ["kingler", 42, 100, 23, ["guillotine", "stomp", "mud-shot", "bubble"]], ["onix", 42, 100, 10, ["slam", "sandstorm", "dragon-breath", "rock-throw"]], ["cloyster", 42, 100, 16, ["spike-cannon", "aurora-beam", "supersonic", "protect"]]]}, +"TRAINER_COOLTRAINER_YUJI": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["sandslash", 38, 100, 16, ["slash", "swift", "sand-attack", "poison-sting"]], ["graveler", 38, 100, 1, ["rock-blast", "magnitude", "mud-sport", "defense-curl"]], ["onix", 38, 100, 16, ["dragon-breath", "sandstorm", "rock-throw", "bind"]], ["graveler", 38, 100, 1, ["rock-blast", "magnitude", "rollout", "defense-curl"]], ["marowak", 38, 100, 9, ["bonemerang", "headbutt", "leer", "growl"]]]}, +"TRAINER_COOLTRAINER_WARREN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["marowak", 37, 100, 10, ["bonemerang", "headbutt", "leer", "growl"]], ["marowak", 37, 100, 9, ["bonemerang", "headbutt", "leer", "growl"]], ["rhyhorn", 38, 100, 2, ["take-down", "rock-blast", "fury-attack", "scary-face"]], ["nidorina", 39, 100, 4, ["fury-swipes", "bite", "poison-sting", "double-kick"]], ["nidoqueen", 39, 100, 17, ["body-slam", "bite", "poison-sting", "double-kick"]]]}, +"TRAINER_COOLTRAINER_MARY": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["super-potion"], "party": [["bellsprout", 22, 100, 1, ["wrap", "stun-spore", "poison-powder", "growth"]], ["oddish", 22, 100, 7, ["poison-powder", "stun-spore", "absorb", "sweet-scent"]], ["weepinbell", 22, 100, 16, ["vine-whip", "stun-spore", "poison-powder", "growth"]], ["gloom", 22, 100, 24, ["absorb", "stun-spore", "poison-powder", "sweet-scent"]], ["ivysaur", 22, 100, 7, ["razor-leaf", "sleep-powder", "vine-whip", "leech-seed"]]]}, +"TRAINER_COOLTRAINER_CAROLINE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["bellsprout", 42, 100, 10, ["razor-leaf", "acid", "stun-spore", "poison-powder"]], ["weepinbell", 42, 100, 3, ["razor-leaf", "acid", "sleep-powder", "poison-powder"]], ["victreebel", 42, 100, 9, ["razor-leaf", "acid", "stun-spore", "sleep-powder"]], ["paras", 42, 100, 9, ["growth", "slash", "leech-life", "stun-spore"]], ["parasect", 42, 100, 0, ["spore", "slash", "leech-life", "poison-powder"]]]}, +"TRAINER_COOLTRAINER_ALEXA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["clefairy", 42, 100, 10, ["light-screen", "cosmic-power", "double-slap", "encore"]], ["jigglypuff", 42, 100, 22, ["sing", "body-slam", "rollout", "disable"]], ["persian", 42, 100, 14, ["pay-day", "feint-attack", "bite", "screech"]], ["dewgong", 42, 100, 14, ["sheer-cold", "take-down", "rest", "aurora-beam"]], ["chansey", 42, 100, 14, ["sing", "egg-bomb", "soft-boiled", "minimize"]]]}, +"TRAINER_COOLTRAINER_SHANNON": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["beedrill", 42, 100, 22, ["pin-missile", "twineedle", "agility", "pursuit"]], ["butterfree", 42, 100, 24, ["safeguard", "psybeam", "gust", "supersonic"]], ["parasect", 42, 100, 22, ["spore", "leech-life", "slash", "growth"]], ["venonat", 42, 100, 2, ["psybeam", "stun-spore", "leech-life", "disable"]], ["venomoth", 42, 100, 24, ["psybeam", "gust", "supersonic", "leech-life"]]]}, +"TRAINER_COOLTRAINER_NAOMI": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["persian", 42, 100, 16, ["fury-swipes", "screech", "feint-attack", "pay-day"]], ["ponyta", 42, 100, 0, ["agility", "take-down", "fire-spin", "stomp"]], ["rapidash", 42, 100, 1, ["fury-attack", "fire-spin", "stomp", "growl"]], ["vulpix", 42, 100, 13, ["flamethrower", "confuse-ray", "quick-attack", "imprison"]], ["ninetales", 42, 100, 18, ["safeguard", "will-o-wisp", "confuse-ray", "fire-spin"]]]}, +"TRAINER_COOLTRAINER_BROOKE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["tangela", 42, 100, 9, ["slam", "bind", "mega-drain", "ingrain"]], ["gloom", 42, 100, 3, ["acid", "moonlight", "sleep-powder", "stun-spore"]], ["vileplume", 42, 100, 4, ["mega-drain", "acid", "stun-spore", "aromatherapy"]], ["ivysaur", 42, 100, 23, ["razor-leaf", "sweet-scent", "growl", "leech-seed"]], ["venusaur", 42, 100, 19, ["razor-leaf", "growth", "sleep-powder", "poison-powder"]]]}, +"TRAINER_COOLTRAINER_AUSTINA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["rhyhorn", 42, 100, 15, ["horn-drill", "rock-blast", "scary-face", "stomp"]], ["nidorina", 42, 100, 19, ["double-kick", "fury-swipes", "bite", "flatter"]], ["nidoqueen", 42, 100, 9, ["body-slam", "double-kick", "bite", "growl"]], ["nidorino", 42, 100, 22, ["horn-attack", "poison-sting", "focus-energy", "leer"]], ["nidoking", 42, 100, 20, ["thrash", "double-kick", "poison-sting", "peck"]]]}, +"TRAINER_COOLTRAINER_JULIE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["persian", 42, 100, 21, ["fury-swipes", "bite", "screech", "feint-attack"]], ["ninetales", 42, 100, 6, ["flamethrower", "will-o-wisp", "confuse-ray", "grudge"]], ["rapidash", 42, 100, 12, ["fury-attack", "fire-spin", "take-down", "agility"]], ["pikachu", 42, 100, 10, ["thunderbolt", "thunder-wave", "double-team", "quick-attack"]], ["raichu", 42, 100, 13, ["thunder", "thunder-wave", "slam", "double-team"]]]}, +"TRAINER_ELITE_FOUR_LORELEI": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["dewgong", 52, 250, 0, ["ice-beam", "surf", "hail", "safeguard"]], ["cloyster", 51, 250, 23, ["spikes", "protect", "hail", "dive"]], ["slowbro", 52, 250, 2, ["ice-beam", "surf", "amnesia", "yawn"]], ["jynx", 54, 250, 22, ["ice-punch", "double-slap", "lovely-kiss", "attract"]], ["lapras", 54, 250, 13, ["confuse-ray", "ice-beam", "surf", "body-slam"]]]}, +"TRAINER_ELITE_FOUR_BRUNO": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["onix", 51, 250, 22, ["earthquake", "rock-tomb", "iron-tail", "roar"]], ["hitmonchan", 53, 250, 12, ["sky-uppercut", "mach-punch", "rock-tomb", "counter"]], ["hitmonlee", 53, 250, 12, ["mega-kick", "foresight", "brick-break", "facade"]], ["onix", 54, 250, 23, ["double-edge", "earthquake", "iron-tail", "sand-tomb"]], ["machamp", 56, 250, 15, ["cross-chop", "bulk-up", "scary-face", "rock-tomb"]]]}, +"TRAINER_ELITE_FOUR_AGATHA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["gengar", 54, 250, 2, ["shadow-punch", "confuse-ray", "toxic", "double-team"]], ["golbat", 54, 250, 14, ["confuse-ray", "poison-fang", "air-cutter", "bite"]], ["haunter", 53, 250, 22, ["hypnosis", "dream-eater", "curse", "mean-look"]], ["arbok", 56, 250, 8, ["sludge-bomb", "screech", "iron-tail", "bite"]], ["gengar", 58, 250, 15, ["shadow-ball", "sludge-bomb", "hypnosis", "nightmare"]]]}, +"TRAINER_ELITE_FOUR_LANCE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["gyarados", 56, 250, 19, ["hyper-beam", "dragon-rage", "twister", "bite"]], ["dragonair", 54, 250, 0, ["hyper-beam", "safeguard", "dragon-rage", "outrage"]], ["dragonair", 54, 250, 6, ["hyper-beam", "safeguard", "thunder-wave", "outrage"]], ["aerodactyl", 58, 250, 5, ["hyper-beam", "ancient-power", "wing-attack", "scary-face"]], ["dragonite", 60, 250, 22, ["hyper-beam", "safeguard", "outrage", "wing-attack"]]]}, +"TRAINER_LEADER_BROCK": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["geodude", 12, 0, 13, ["tackle", "defense-curl"]], ["onix", 14, 0, 23, ["tackle", "bind", "rock-tomb"]]]}, +"TRAINER_LEADER_MISTY": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["super-potion"], "party": [["staryu", 18, 0, 11, ["tackle", "harden", "recover", "water-pulse"]], ["starmie", 21, 0, 4, ["swift", "recover", "rapid-spin", "water-pulse"]]]}, +"TRAINER_LEADER_LT_SURGE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["super-potion", "full-heal"], "party": [["voltorb", 21, 0, 9, ["sonic-boom", "tackle", "screech", "shock-wave"]], ["pikachu", 18, 0, 22, ["quick-attack", "thunder-wave", "double-team", "shock-wave"]], ["raichu", 24, 0, 15, ["quick-attack", "thunder-wave", "double-team", "shock-wave"]]]}, +"TRAINER_LEADER_ERIKA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "full-heal"], "party": [["victreebel", 29, 0, 5, ["stun-spore", "acid", "poison-powder", "giga-drain"]], ["tangela", 24, 0, 21, ["poison-powder", "constrict", "ingrain", "giga-drain"]], ["vileplume", 29, 0, 24, ["sleep-powder", "acid", "stun-spore", "giga-drain"]]]}, +"TRAINER_LEADER_KOGA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "hyper-potion", "full-heal"], "party": [["koffing", 37, 0, 24, ["self-destruct", "sludge", "smokescreen", "toxic"]], ["muk", 39, 0, 10, ["minimize", "sludge", "acid-armor", "toxic"]], ["koffing", 37, 0, 23, ["self-destruct", "sludge", "smokescreen", "toxic"]], ["weezing", 43, 0, 12, ["tackle", "sludge", "smokescreen", "toxic"]]]}, +"TRAINER_LEADER_BLAINE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "hyper-potion", "full-heal"], "party": [["growlithe", 42, 0, 11, ["bite", "roar", "take-down", "fire-blast"]], ["ponyta", 40, 0, 7, ["stomp", "bounce", "fire-spin", "fire-blast"]], ["rapidash", 42, 0, 20, ["stomp", "bounce", "fire-spin", "fire-blast"]], ["arcanine", 47, 0, 17, ["bite", "roar", "take-down", "fire-blast"]]]}, +"TRAINER_LEADER_SABRINA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion", "hyper-potion", "full-heal"], "party": [["kadabra", 38, 0, 6, ["psybeam", "reflect", "future-sight", "calm-mind"]], ["mr-mime", 37, 0, 12, ["barrier", "psybeam", "baton-pass", "calm-mind"]], ["venomoth", 38, 0, 8, ["psybeam", "gust", "leech-life", "supersonic"]], ["alakazam", 43, 0, 3, ["psychic", "recover", "future-sight", "calm-mind"]]]}, +"TRAINER_GENTLEMAN_THOMAS": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 18, 0, 9, ["bite", "roar", "ember", "leer"]], ["growlithe", 18, 0, 7, ["bite", "roar", "ember", "leer"]]]}, +"TRAINER_GENTLEMAN_ARTHUR": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 19, 0, 21, ["peck", "focus-energy", "double-kick", "poison-sting"]], ["nidoran-f", 19, 0, 12, ["scratch", "tail-whip", "double-kick", "poison-sting"]]]}, +"TRAINER_GENTLEMAN_TUCKER": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 23, 0, 1, ["thunder-wave", "quick-attack", "double-team", "slam"]]]}, +"TRAINER_GENTLEMAN_NORTON": {"ai": ["check-bad-move"], "items": [], "party": [["persian", 48, 0, 12, ["pay-day", "feint-attack", "screech", "fury-swipes"]]]}, +"TRAINER_GENTLEMAN_WALTER": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 17, 0, 2, ["bite", "roar", "ember", "leer"]], ["ponyta", 17, 0, 14, ["quick-attack", "growl", "tail-whip", "ember"]]]}, +"TRAINER_RIVAL_SS_ANNE_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 19, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["raticate", 16, 50, 3, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["kadabra", 18, 50, 14, ["teleport", "kinesis", "confusion", "disable"]], ["wartortle", 20, 100, 21, ["bubble", "withdraw", "water-gun", "bite"]]]}, +"TRAINER_RIVAL_SS_ANNE_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 19, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["raticate", 16, 50, 3, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["kadabra", 18, 50, 14, ["teleport", "kinesis", "confusion", "disable"]], ["ivysaur", 20, 100, 12, ["leech-seed", "vine-whip", "poison-powder", "sleep-powder"]]]}, +"TRAINER_RIVAL_SS_ANNE_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 19, 50, 17, ["tackle", "sand-attack", "gust", "quick-attack"]], ["raticate", 16, 50, 3, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["kadabra", 18, 50, 14, ["teleport", "kinesis", "confusion", "disable"]], ["charmeleon", 20, 100, 9, ["growl", "ember", "metal-claw", "smokescreen"]]]}, +"TRAINER_RIVAL_POKEMON_TOWER_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 25, 100, 17, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["growlithe", 23, 100, 9, ["roar", "ember", "leer", "odor-sleuth"]], ["exeggcute", 22, 100, 6, ["hypnosis", "reflect", "leech-seed", "confusion"]], ["kadabra", 20, 100, 17, ["teleport", "kinesis", "confusion", "disable"]], ["wartortle", 25, 100, 24, ["withdraw", "water-gun", "bite", "rapid-spin"]]]}, +"TRAINER_RIVAL_POKEMON_TOWER_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 25, 100, 17, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["gyarados", 23, 100, 6, ["thrash", "bite"]], ["growlithe", 22, 100, 23, ["roar", "ember", "leer", "odor-sleuth"]], ["kadabra", 20, 100, 9, ["teleport", "kinesis", "confusion", "disable"]], ["ivysaur", 25, 100, 7, ["vine-whip", "poison-powder", "sleep-powder", "razor-leaf"]]]}, +"TRAINER_RIVAL_POKEMON_TOWER_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeotto", 25, 100, 17, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["exeggcute", 23, 100, 14, ["hypnosis", "reflect", "leech-seed", "confusion"]], ["gyarados", 22, 100, 3, ["thrash", "bite"]], ["kadabra", 20, 100, 14, ["teleport", "kinesis", "confusion", "disable"]], ["charmeleon", 25, 100, 9, ["growl", "ember", "metal-claw", "smokescreen"]]]}, +"TRAINER_RIVAL_SILPH_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 37, 100, 0, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["growlithe", 38, 100, 17, ["odor-sleuth", "take-down", "flame-wheel", "helping-hand"]], ["exeggcute", 35, 100, 14, ["leech-seed", "confusion", "stun-spore", "poison-powder"]], ["alakazam", 35, 100, 9, ["reflect", "recover", "future-sight", "calm-mind"]], ["blastoise", 40, 150, 11, ["water-gun", "bite", "rapid-spin", "protect"]]]}, +"TRAINER_RIVAL_SILPH_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 37, 100, 0, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["gyarados", 38, 100, 14, ["bite", "dragon-rage", "leer", "twister"]], ["growlithe", 35, 100, 6, ["leer", "odor-sleuth", "take-down", "flame-wheel"]], ["alakazam", 35, 100, 1, ["reflect", "recover", "future-sight", "calm-mind"]], ["venusaur", 40, 150, 1, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]]]}, +"TRAINER_RIVAL_SILPH_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 37, 100, 0, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["exeggcute", 38, 100, 22, ["confusion", "stun-spore", "poison-powder", "sleep-powder"]], ["gyarados", 35, 100, 11, ["bite", "dragon-rage", "leer", "twister"]], ["alakazam", 35, 100, 6, ["reflect", "recover", "future-sight", "calm-mind"]], ["charizard", 40, 150, 24, ["smokescreen", "scary-face", "flamethrower", "wing-attack"]]]}, +"TRAINER_RIVAL_ROUTE22_LATE_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 47, 150, 0, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, 150, 19, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["growlithe", 45, 150, 11, ["flame-wheel", "take-down", "leer", "agility"]], ["exeggcute", 45, 150, 8, ["solar-beam", "sleep-powder", "poison-powder", "stun-spore"]], ["alakazam", 47, 150, 3, ["psychic", "calm-mind", "future-sight", "disable"]], ["blastoise", 53, 250, 5, ["water-gun", "rain-dance", "bite", "rapid-spin"]]]}, +"TRAINER_RIVAL_ROUTE22_LATE_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 47, 150, 0, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, 150, 19, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["gyarados", 45, 150, 8, ["hydro-pump", "twister", "leer", "rain-dance"]], ["growlithe", 45, 150, 0, ["flame-wheel", "take-down", "leer", "agility"]], ["alakazam", 47, 150, 20, ["psychic", "calm-mind", "future-sight", "disable"]], ["venusaur", 53, 250, 20, ["razor-leaf", "sweet-scent", "growth", "synthesis"]]]}, +"TRAINER_RIVAL_ROUTE22_LATE_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["pidgeot", 47, 150, 0, ["feather-dance", "wing-attack", "gust", "quick-attack"]], ["rhyhorn", 45, 150, 19, ["take-down", "horn-drill", "rock-blast", "fury-attack"]], ["exeggcute", 45, 150, 16, ["solar-beam", "sleep-powder", "poison-powder", "stun-spore"]], ["gyarados", 45, 150, 5, ["hydro-pump", "twister", "leer", "rain-dance"]], ["alakazam", 47, 150, 0, ["psychic", "calm-mind", "future-sight", "disable"]], ["charizard", 53, 250, 18, ["flamethrower", "wing-attack", "slash", "scary-face"]]]}, +"TRAINER_CHAMPION_FIRST_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["pidgeot", 59, 255, 0, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, 255, 20, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, 255, 16, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["arcanine", 59, 255, 5, ["extreme-speed", "flamethrower", "roar", "bite"]], ["exeggutor", 61, 255, 2, ["giga-drain", "egg-bomb", "sleep-powder", "light-screen"]], ["blastoise", 63, 255, 4, ["hydro-pump", "rain-dance", "skull-bash", "bite"]]]}, +"TRAINER_CHAMPION_FIRST_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["pidgeot", 59, 255, 0, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, 255, 20, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, 255, 16, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["gyarados", 59, 255, 5, ["hydro-pump", "dragon-rage", "bite", "thrash"]], ["arcanine", 61, 255, 19, ["extreme-speed", "flamethrower", "roar", "bite"]], ["venusaur", 63, 255, 19, ["solar-beam", "synthesis", "sunny-day", "growth"]]]}, +"TRAINER_CHAMPION_FIRST_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["pidgeot", 59, 255, 0, ["aerial-ace", "feather-dance", "sand-attack", "whirlwind"]], ["alakazam", 57, 255, 20, ["psychic", "future-sight", "recover", "reflect"]], ["rhydon", 59, 255, 16, ["take-down", "earthquake", "rock-tomb", "scary-face"]], ["exeggutor", 59, 255, 13, ["giga-drain", "egg-bomb", "sleep-powder", "light-screen"]], ["gyarados", 61, 255, 2, ["hydro-pump", "dragon-rage", "bite", "thrash"]], ["charizard", 63, 255, 20, ["fire-blast", "aerial-ace", "slash", "fire-spin"]]]}, +"TRAINER_CHANNELER_PATRICIA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 10, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_CARLY": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 4, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_HOPE": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 23, 0, 23, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_PAULA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 6, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_LAUREL": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 23, 0, 5, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 23, 0, 15, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_JODY": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 8, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_TAMMY": {"ai": ["check-bad-move"], "items": [], "party": [["haunter", 23, 0, 16, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_RUTH": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 11, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_KARINA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 15, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_JANAE": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 11, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_ANGELICA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 10, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 22, 0, 0, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 22, 0, 15, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_EMILIA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 10, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_JENNIFER": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 9, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_1": {"ai": ["check-bad-move"], "items": [], "party": [["haunter", 23, 0, 4, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_2": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_3": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_4": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_5": {"ai": ["check-bad-move"], "items": [], "party": [["haunter", 22, 0, 4, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_6": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 22, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 22, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]], ["gastly", 22, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_7": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_8": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 24, 0, 20, ["spite", "curse", "night-shade", "confuse-ray"]]]}, +"TRAINER_CHANNELER_AMANDA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 34, 0, 20, ["night-shade", "confuse-ray", "dream-eater", "destiny-bond"]], ["haunter", 34, 0, 4, ["night-shade", "confuse-ray", "shadow-punch", "dream-eater"]]]}, +"TRAINER_CHANNELER_STACY": {"ai": ["check-bad-move"], "items": [], "party": [["haunter", 38, 0, 17, ["night-shade", "confuse-ray", "shadow-punch", "dream-eater"]]]}, +"TRAINER_CHANNELER_TASHA": {"ai": ["check-bad-move"], "items": [], "party": [["gastly", 33, 0, 19, ["night-shade", "confuse-ray", "dream-eater", "destiny-bond"]], ["gastly", 33, 0, 18, ["night-shade", "confuse-ray", "dream-eater", "destiny-bond"]], ["haunter", 33, 0, 1, ["night-shade", "confuse-ray", "shadow-punch", "dream-eater"]]]}, +"TRAINER_HIKER_JEREMY": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 20, 0, 20, ["leer", "focus-energy", "karate-chop", "seismic-toss"]], ["onix", 20, 0, 8, ["screech", "bind", "rock-throw", "harden"]]]}, +"TRAINER_PICNICKER_ALMA": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 28, 0, 5, ["water-sport", "supersonic", "horn-attack", "flail"]], ["poliwag", 28, 0, 16, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["horsea", 28, 0, 9, ["bubble", "smokescreen", "leer", "water-gun"]]]}, +"TRAINER_PICNICKER_SUSIE": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 24, 0, 5, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["meowth", 24, 0, 23, ["scratch", "growl", "bite", "pay-day"]], ["rattata", 24, 0, 14, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["pikachu", 24, 0, 8, ["thunder-wave", "quick-attack", "double-team", "slam"]], ["meowth", 24, 0, 1, ["scratch", "growl", "bite", "pay-day"]]]}, +"TRAINER_PICNICKER_VALERIE": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 30, 0, 24, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["poliwag", 30, 0, 3, ["hypnosis", "water-gun", "double-slap", "rain-dance"]]]}, +"TRAINER_PICNICKER_GWEN": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 27, 0, 20, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["meowth", 27, 0, 3, ["growl", "bite", "pay-day", "feint-attack"]], ["pidgey", 27, 0, 3, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 27, 0, 21, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, +"TRAINER_BIKER_VIRGIL": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 28, 0, 15, ["smokescreen", "sludge", "smog", "tackle"]], ["koffing", 28, 0, 18, ["smokescreen", "sludge", "smog", "tackle"]], ["weezing", 28, 0, 22, ["smokescreen", "sludge", "smog", "tackle"]]]}, +"TRAINER_CAMPER_FLINT": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 14, 0, 5, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["ekans", 14, 0, 6, ["wrap", "leer", "poison-sting", "bite"]]]}, +"TRAINER_PICNICKER_MISSY": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 31, 0, 19, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 31, 0, 17, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_PICNICKER_IRENE": {"ai": ["check-bad-move"], "items": [], "party": [["tentacool", 30, 0, 5, ["constrict", "acid", "bubble-beam", "wrap"]], ["horsea", 30, 0, 8, ["smokescreen", "leer", "water-gun", "twister"]], ["seel", 30, 0, 4, ["growl", "icy-wind", "aurora-beam", "rest"]]]}, +"TRAINER_PICNICKER_DANA": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 20, 0, 4, ["scratch", "growl", "bite", "pay-day"]], ["oddish", 20, 0, 13, ["sweet-scent", "poison-powder", "stun-spore", "sleep-powder"]], ["pidgey", 20, 0, 14, ["sand-attack", "gust", "quick-attack", "whirlwind"]]]}, +"TRAINER_PICNICKER_ARIANA": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 19, 0, 22, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["rattata", 19, 0, 5, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["rattata", 19, 0, 13, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["bellsprout", 19, 0, 23, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]]]}, +"TRAINER_PICNICKER_LEAH": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 22, 0, 15, ["wrap", "sleep-powder", "poison-powder", "stun-spore"]], ["clefairy", 22, 0, 12, ["sing", "double-slap", "follow-me", "minimize"]]]}, +"TRAINER_CAMPER_JUSTIN": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 29, 0, 13, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]], ["nidorino", 29, 0, 8, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]]]}, +"TRAINER_PICNICKER_YAZMIN": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 29, 0, 19, ["sleep-powder", "poison-powder", "stun-spore", "acid"]], ["oddish", 29, 0, 18, ["poison-powder", "stun-spore", "sleep-powder", "acid"]], ["tangela", 29, 0, 14, ["growth", "poison-powder", "vine-whip", "bind"]]]}, +"TRAINER_PICNICKER_KINDRA": {"ai": ["check-bad-move"], "items": [], "party": [["gloom", 28, 0, 10, ["poison-powder", "stun-spore", "sleep-powder", "acid"]], ["oddish", 28, 0, 23, ["poison-powder", "stun-spore", "sleep-powder", "acid"]], ["oddish", 28, 0, 11, ["poison-powder", "stun-spore", "sleep-powder", "acid"]]]}, +"TRAINER_PICNICKER_BECKY": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 29, 0, 2, ["quick-attack", "double-team", "slam", "thunderbolt"]], ["raichu", 29, 0, 14, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, +"TRAINER_PICNICKER_CELIA": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 33, 0, 7, ["minimize", "defense-curl", "metronome", "cosmic-power"]]]}, +"TRAINER_GENTLEMAN_BROOKS": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 23, 0, 13, ["thunder-wave", "quick-attack", "double-team", "slam"]]]}, +"TRAINER_GENTLEMAN_LAMAR": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 17, 0, 7, ["bite", "roar", "ember", "leer"]], ["ponyta", 17, 0, 24, ["quick-attack", "growl", "tail-whip", "ember"]]]}, +"TRAINER_TWINS_ELI_ANNE": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 22, 0, 22, ["sing", "double-slap", "follow-me", "minimize"]], ["jigglypuff", 22, 0, 13, ["defense-curl", "pound", "disable", "rollout"]]]}, +"TRAINER_COOL_COUPLE_RAY_TYRA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": [], "party": [["nidoqueen", 45, 100, 1, ["superpower", "body-slam", "double-kick", "poison-sting"]], ["nidoking", 45, 100, 7, ["megahorn", "thrash", "double-kick", "poison-sting"]]]}, +"TRAINER_YOUNG_COUPLE_GIA_JES": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 24, 0, 23, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]], ["nidoran-f", 24, 0, 24, ["double-kick", "poison-sting", "bite", "helping-hand"]]]}, +"TRAINER_TWINS_KIRI_JAN": {"ai": ["check-bad-move"], "items": [], "party": [["charmander", 29, 0, 12, ["ember", "metal-claw", "smokescreen", "scary-face"]], ["squirtle", 29, 0, 5, ["water-gun", "bite", "rapid-spin", "protect"]]]}, +"TRAINER_CRUSH_KIN_RON_MYA": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 29, 50, 0, ["mach-punch", "thunder-punch", "ice-punch", "fire-punch"]], ["hitmonlee", 29, 50, 7, ["jump-kick", "brick-break", "focus-energy", "high-jump-kick"]]]}, +"TRAINER_YOUNG_COUPLE_LEA_JED": {"ai": ["check-bad-move"], "items": [], "party": [["rapidash", 29, 0, 0, ["tail-whip", "ember", "stomp", "fire-spin"]], ["ninetales", 29, 0, 1, ["ember", "quick-attack", "confuse-ray", "safeguard"]]]}, +"TRAINER_SIS_AND_BRO_LIA_LUC": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 30, 0, 1, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 30, 0, 23, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_SIS_AND_BRO_LIL_IAN": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 33, 0, 20, ["smokescreen", "leer", "water-gun", "twister"]], ["starmie", 33, 0, 0, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_YOUNGSTER_BEN_3": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 28, 60, 0, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["ekans", 28, 60, 4, ["poison-sting", "bite", "glare", "screech"]]]}, +"TRAINER_YOUNGSTER_BEN_4": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 48, 120, 0, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["arbok", 48, 120, 11, ["acid", "stockpile", "swallow", "spit-up"]]]}, +"TRAINER_YOUNGSTER_CHAD_2": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 20, 20, 1, ["leer", "poison-sting", "bite", "glare"]], ["sandshrew", 20, 20, 21, ["scratch", "defense-curl", "sand-attack", "poison-sting"]]]}, +"TRAINER_LASS_RELI_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 20, 20, 15, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["nidoran-f", 20, 20, 22, ["tail-whip", "double-kick", "poison-sting", "bite"]]]}, +"TRAINER_LASS_RELI_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 28, 60, 8, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["nidorina", 28, 60, 18, ["double-kick", "poison-sting", "bite", "helping-hand"]]]}, +"TRAINER_YOUNGSTER_TIMMY_2": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 19, 20, 11, ["tackle", "tail-whip", "quick-attack", "hyper-fang"]], ["ekans", 19, 20, 1, ["wrap", "leer", "poison-sting", "bite"]], ["zubat", 19, 20, 11, ["leech-life", "astonish", "supersonic", "bite"]]]}, +"TRAINER_YOUNGSTER_TIMMY_3": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 27, 60, 11, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["ekans", 27, 60, 1, ["poison-sting", "bite", "glare", "screech"]], ["golbat", 27, 60, 24, ["astonish", "supersonic", "bite", "wing-attack"]]]}, +"TRAINER_YOUNGSTER_TIMMY_4": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 52, 120, 11, ["scary-face", "pursuit", "super-fang", "endeavor"]], ["arbok", 52, 120, 8, ["acid", "stockpile", "swallow", "spit-up"]], ["golbat", 52, 120, 6, ["confuse-ray", "air-cutter", "mean-look", "poison-fang"]]]}, +"TRAINER_YOUNGSTER_CHAD_3": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 28, 60, 8, ["poison-sting", "bite", "glare", "screech"]], ["sandshrew", 28, 60, 3, ["defense-curl", "sand-attack", "poison-sting", "slash"]]]}, +"TRAINER_LASS_JANICE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 20, 20, 3, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["pidgeotto", 20, 20, 11, ["sand-attack", "gust", "quick-attack", "whirlwind"]]]}, +"TRAINER_LASS_JANICE_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 28, 60, 3, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 28, 60, 11, ["gust", "quick-attack", "whirlwind", "wing-attack"]]]}, +"TRAINER_YOUNGSTER_CHAD_4": {"ai": ["check-bad-move"], "items": [], "party": [["arbok", 48, 80, 8, ["acid", "stockpile", "swallow", "spit-up"]], ["sandslash", 48, 80, 19, ["poison-sting", "slash", "swift", "fury-swipes"]]]}, +"TRAINER_HIKER_FRANKLIN_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 25, 40, 22, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["graveler", 25, 40, 16, ["mud-sport", "rock-throw", "magnitude", "self-destruct"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_42": {"ai": ["check-bad-move"], "items": [], "party": [["houndour", 49, 0, 20, ["odor-sleuth", "feint-attack", "flamethrower", "crunch"]], ["houndour", 49, 0, 4, ["odor-sleuth", "feint-attack", "flamethrower", "crunch"]]]}, +"TRAINER_PSYCHIC_JACLYN": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 48, 100, 6, ["night-shade", "confuse-ray", "future-sight", "wish"]], ["slowbro", 48, 100, 3, ["psychic", "headbutt", "amnesia", "yawn"]], ["kadabra", 49, 100, 4, ["psychic", "future-sight", "recover", "reflect"]]]}, +"TRAINER_CRUSH_GIRL_SHARON": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 37, 50, 17, ["focus-energy", "seismic-toss", "cross-chop", "swagger"]], ["primeape", 37, 50, 14, ["focus-energy", "seismic-toss", "rage", "cross-chop"]]]}, +"TRAINER_TUBER_AMIRA": {"ai": ["check-bad-move"], "items": [], "party": [["poliwag", 34, 0, 3, ["water-gun", "double-slap", "rain-dance", "body-slam"]], ["poliwhirl", 35, 0, 11, ["water-gun", "double-slap", "rain-dance", "body-slam"]], ["poliwag", 34, 0, 3, ["water-gun", "double-slap", "rain-dance", "body-slam"]]]}, +"TRAINER_PKMN_BREEDER_ALIZE": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 48, 30, 10, ["slam", "thunderbolt", "agility", "thunder"]], ["clefairy", 48, 30, 10, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["marill", 48, 30, 19, ["bubble-beam", "double-edge", "rain-dance", "hydro-pump"]]]}, +"TRAINER_PKMN_RANGER_NICOLAS": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["weepinbell", 51, 100, 14, ["razor-leaf", "acid", "sweet-scent", "wrap"]], ["victreebel", 51, 100, 5, ["razor-leaf", "acid", "sleep-powder", "stun-spore"]]]}, +"TRAINER_PKMN_RANGER_MADELINE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["gloom", 51, 100, 3, ["petal-dance", "acid", "sweet-scent", "poison-powder"]], ["vileplume", 51, 100, 18, ["petal-dance", "moonlight", "acid", "stun-spore"]]]}, +"TRAINER_AROMA_LADY_NIKKI": {"ai": ["check-bad-move"], "items": [], "party": [["bellsprout", 37, 0, 24, ["stun-spore", "acid", "sweet-scent", "razor-leaf"]], ["weepinbell", 37, 0, 6, ["poison-powder", "stun-spore", "acid", "sweet-scent"]]]}, +"TRAINER_RUIN_MANIAC_STANLY": {"ai": ["check-bad-move"], "items": [], "party": [["graveler", 48, 0, 9, ["self-destruct", "rollout", "rock-blast", "earthquake"]], ["onix", 48, 0, 12, ["dragon-breath", "sandstorm", "slam", "iron-tail"]], ["graveler", 48, 0, 10, ["self-destruct", "rollout", "rock-blast", "earthquake"]]]}, +"TRAINER_LADY_JACKI": {"ai": ["check-bad-move"], "items": ["full-restore"], "party": [["hoppip", 48, 0, 21, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]], ["skiploom", 50, 0, 18, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]]]}, +"TRAINER_PAINTER_DAISY": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 50, 50, 22, ["dynamic-punch", "dizzy-punch", "focus-punch", "mega-punch"]]]}, +"TRAINER_BIKER_GOON": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 37, 0, 1, ["haze", "smokescreen", "sludge", "tackle"]], ["grimer", 37, 0, 12, ["acid-armor", "screech", "minimize", "sludge"]]]}, +"TRAINER_BIKER_GOON_2": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 38, 0, 1, ["haze", "smokescreen", "sludge", "tackle"]]]}, +"TRAINER_BIKER_GOON_3": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 38, 0, 22, ["sludge", "minimize", "screech", "acid-armor"]]]}, +"TRAINER_BUG_CATCHER_ANTHONY": {"ai": ["check-bad-move"], "items": [], "party": [["caterpie", 7, 0, 20, ["tackle", "string-shot"]], ["caterpie", 8, 0, 4, ["tackle", "string-shot"]]]}, +"TRAINER_BUG_CATCHER_CHARLIE": {"ai": ["check-bad-move"], "items": [], "party": [["metapod", 7, 0, 15, ["harden"]], ["caterpie", 7, 0, 3, ["tackle", "string-shot"]], ["metapod", 7, 0, 7, ["harden"]]]}, +"TRAINER_TWINS_ELI_ANNE_2": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 28, 60, 22, ["double-slap", "follow-me", "minimize", "defense-curl"]], ["jigglypuff", 28, 60, 13, ["pound", "disable", "rollout", "double-slap"]]]}, +"TRAINER_YOUNGSTER_JOHNSON": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 33, 0, 23, ["bite", "glare", "screech", "acid"]], ["ekans", 33, 0, 10, ["bite", "glare", "screech", "acid"]], ["raticate", 34, 0, 7, ["quick-attack", "hyper-fang", "scary-face", "pursuit"]]]}, +"TRAINER_BIKER_RICARDO": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 22, 0, 1, ["sludge", "smog", "tackle", "poison-gas"]], ["koffing", 22, 0, 16, ["sludge", "smog", "tackle", "poison-gas"]], ["grimer", 23, 0, 2, ["minimize", "sludge", "disable", "pound"]]]}, +"TRAINER_BIKER_JAREN": {"ai": ["check-bad-move"], "items": [], "party": [["grimer", 24, 0, 20, ["harden", "disable", "sludge", "minimize"]], ["grimer", 24, 0, 4, ["harden", "disable", "sludge", "minimize"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_43": {"ai": ["check-bad-move"], "items": [], "party": [["cubone", 37, 0, 2, ["bonemerang", "rage", "false-swipe", "thrash"]], ["marowak", 37, 0, 16, ["leer", "focus-energy", "bonemerang", "rage"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_44": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 35, 0, 19, ["hyper-fang", "focus-energy", "pursuit", "super-fang"]], ["raticate", 35, 0, 19, ["quick-attack", "hyper-fang", "scary-face", "pursuit"]], ["sandshrew", 35, 0, 14, ["sand-attack", "poison-sting", "slash", "swift"]], ["sandslash", 35, 0, 0, ["sand-attack", "poison-sting", "slash", "swift"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_45": {"ai": ["check-bad-move"], "items": [], "party": [["zubat", 38, 0, 21, ["wing-attack", "confuse-ray", "air-cutter", "mean-look"]], ["zubat", 38, 0, 6, ["wing-attack", "confuse-ray", "air-cutter", "mean-look"]], ["golbat", 38, 0, 4, ["bite", "wing-attack", "confuse-ray", "air-cutter"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_46": {"ai": ["check-bad-move"], "items": [], "party": [["muk", 48, 0, 14, ["minimize", "screech", "acid-armor", "sludge-bomb"]], ["golbat", 48, 0, 12, ["wing-attack", "confuse-ray", "air-cutter", "mean-look"]], ["raticate", 48, 0, 12, ["hyper-fang", "scary-face", "pursuit", "super-fang"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_47": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 48, 0, 3, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machop", 48, 0, 20, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machoke", 48, 0, 3, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_48": {"ai": ["check-bad-move"], "items": [], "party": [["hypno", 49, 0, 19, ["meditate", "psychic", "psych-up", "swagger"]], ["hypno", 49, 0, 2, ["meditate", "psychic", "psych-up", "swagger"]]]}, +"TRAINER_TEAM_ROCKET_ADMIN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["muk", 52, 150, 5, ["sludge-bomb", "screech", "minimize", "rock-tomb"]], ["arbok", 53, 150, 18, ["sludge-bomb", "bite", "earthquake", "iron-tail"]], ["vileplume", 54, 150, 3, ["sludge-bomb", "giga-drain", "sleep-powder", "stun-spore"]]]}, +"TRAINER_TEAM_ROCKET_ADMIN_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["golbat", 53, 200, 0, ["confuse-ray", "sludge-bomb", "air-cutter", "shadow-ball"]], ["weezing", 54, 200, 22, ["sludge-bomb", "thunderbolt", "explosion", "shadow-ball"]], ["houndoom", 55, 200, 6, ["flamethrower", "crunch", "iron-tail", "shadow-ball"]]]}, +"TRAINER_SCIENTIST_GIDEON": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 46, 0, 17, ["swift", "screech", "spark", "sonic-boom"]], ["electrode", 46, 0, 3, ["spark", "sonic-boom", "screech", "charge"]], ["magnemite", 46, 0, 14, ["screech", "swift", "spark", "thunder-wave"]], ["magneton", 46, 0, 21, ["tri-attack", "spark", "thunder-wave", "sonic-boom"]], ["porygon", 46, 0, 13, ["tri-attack", "conversion", "recover", "psybeam"]]]}, +"TRAINER_SWIMMER_FEMALE_AMARA": {"ai": ["check-bad-move"], "items": [], "party": [["seel", 36, 0, 14, ["growl", "icy-wind", "aurora-beam", "rest"]], ["seel", 36, 0, 8, ["growl", "icy-wind", "aurora-beam", "rest"]], ["dewgong", 36, 0, 4, ["icy-wind", "aurora-beam", "rest", "sheer-cold"]]]}, +"TRAINER_SWIMMER_FEMALE_MARIA": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 37, 0, 11, ["smokescreen", "leer", "water-gun", "twister"]], ["seadra", 37, 0, 2, ["smokescreen", "leer", "water-gun", "twister"]]]}, +"TRAINER_SWIMMER_FEMALE_ABIGAIL": {"ai": ["check-bad-move"], "items": [], "party": [["psyduck", 35, 0, 9, ["disable", "confusion", "screech", "psych-up"]], ["psyduck", 36, 0, 23, ["disable", "confusion", "screech", "psych-up"]], ["golduck", 37, 0, 6, ["disable", "confusion", "screech", "psych-up"]]]}, +"TRAINER_SWIMMER_MALE_FINN": {"ai": ["check-bad-move"], "items": [], "party": [["starmie", 38, 0, 5, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_SWIMMER_MALE_GARRETT": {"ai": ["check-bad-move"], "items": [], "party": [["shellder", 35, 0, 8, ["icicle-spear", "supersonic", "aurora-beam", "protect"]], ["cloyster", 35, 0, 9, ["withdraw", "supersonic", "aurora-beam", "protect"]], ["wartortle", 38, 0, 16, ["bite", "rapid-spin", "protect", "rain-dance"]]]}, +"TRAINER_FISHERMAN_TOMMY": {"ai": ["check-bad-move"], "items": [], "party": [["goldeen", 33, 0, 16, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["goldeen", 33, 0, 21, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 35, 0, 0, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 35, 0, 4, ["supersonic", "horn-attack", "flail", "fury-attack"]], ["seaking", 35, 0, 8, ["supersonic", "horn-attack", "flail", "fury-attack"]]]}, +"TRAINER_CRUSH_GIRL_TANYA": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonlee", 38, 50, 7, ["focus-energy", "high-jump-kick", "mind-reader", "foresight"]], ["hitmonchan", 38, 50, 18, ["ice-punch", "fire-punch", "sky-uppercut", "mega-punch"]]]}, +"TRAINER_BLACK_BELT_SHEA": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 38, 100, 5, ["foresight", "revenge", "vital-throw", "submission"]], ["machoke", 38, 100, 15, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, +"TRAINER_BLACK_BELT_HUGH": {"ai": ["check-bad-move"], "items": [], "party": [["machop", 37, 100, 21, ["foresight", "revenge", "vital-throw", "submission"]], ["machoke", 37, 100, 22, ["seismic-toss", "foresight", "revenge", "vital-throw"]]]}, +"TRAINER_CAMPER_BRYCE": {"ai": ["check-bad-move"], "items": [], "party": [["nidorino", 36, 0, 0, ["poison-sting", "horn-attack", "helping-hand", "fury-attack"]], ["raticate", 36, 0, 13, ["quick-attack", "hyper-fang", "scary-face", "pursuit"]], ["sandslash", 36, 0, 12, ["sand-attack", "poison-sting", "slash", "swift"]]]}, +"TRAINER_PICNICKER_CLAIRE": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 35, 0, 4, ["bite", "pay-day", "feint-attack", "screech"]], ["meowth", 35, 0, 13, ["bite", "pay-day", "feint-attack", "screech"]], ["pikachu", 35, 0, 23, ["double-team", "slam", "thunderbolt", "agility"]], ["clefairy", 35, 0, 9, ["minimize", "defense-curl", "metronome", "cosmic-power"]]]}, +"TRAINER_CRUSH_KIN_MIK_KIA": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 39, 50, 16, ["seismic-toss", "foresight", "revenge", "vital-throw"]], ["primeape", 39, 50, 7, ["focus-energy", "seismic-toss", "rage", "cross-chop"]]]}, +"TRAINER_AROMA_LADY_VIOLET": {"ai": ["check-bad-move"], "items": [], "party": [["bulbasaur", 36, 0, 15, ["sleep-powder", "razor-leaf", "sweet-scent", "growth"]], ["ivysaur", 36, 0, 11, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]], ["ivysaur", 36, 0, 7, ["poison-powder", "sleep-powder", "razor-leaf", "sweet-scent"]]]}, +"TRAINER_TUBER_ALEXIS": {"ai": ["check-bad-move"], "items": [], "party": [["staryu", 34, 0, 22, ["camouflage", "swift", "bubble-beam", "minimize"]], ["staryu", 34, 0, 8, ["camouflage", "swift", "bubble-beam", "minimize"]], ["krabby", 34, 0, 24, ["harden", "mud-shot", "stomp", "guillotine"]], ["krabby", 34, 0, 15, ["harden", "mud-shot", "stomp", "guillotine"]]]}, +"TRAINER_TWINS_JOY_MEG": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 37, 0, 21, ["defense-curl", "metronome", "cosmic-power", "moonlight"]], ["clefairy", 37, 0, 14, ["defense-curl", "metronome", "cosmic-power", "moonlight"]]]}, +"TRAINER_SWIMMER_FEMALE_TISHA": {"ai": ["check-bad-move"], "items": [], "party": [["kingler", 38, 0, 10, ["harden", "mud-shot", "stomp", "guillotine"]]]}, +"TRAINER_PAINTER_CELINA": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 50, 50, 4, ["fly", "dig", "dive", "bounce"]]]}, +"TRAINER_PAINTER_RAYNA": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 50, 50, 3, ["cross-chop", "megahorn", "double-edge", "self-destruct"]]]}, +"TRAINER_LADY_GILLIAN": {"ai": ["check-bad-move"], "items": ["full-restore"], "party": [["mareep", 47, 0, 1, ["thunder-wave", "cotton-spore", "light-screen", "thunder"]], ["mareep", 48, 0, 16, ["thunder-wave", "cotton-spore", "light-screen", "thunder"]], ["flaaffy", 49, 0, 16, ["thunder-wave", "cotton-spore", "light-screen", "thunder"]]]}, +"TRAINER_YOUNGSTER_DESTIN": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 48, 0, 23, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["pidgeotto", 48, 0, 5, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, +"TRAINER_SWIMMER_MALE_TOBY": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 48, 0, 23, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["tentacool", 48, 0, 8, ["bubble-beam", "wrap", "barrier", "screech"]], ["tentacruel", 48, 0, 18, ["bubble-beam", "wrap", "barrier", "screech"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_49": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 48, 0, 19, ["focus-energy", "pursuit", "super-fang", "endeavor"]], ["grimer", 48, 0, 20, ["minimize", "screech", "acid-armor", "sludge-bomb"]], ["muk", 48, 0, 23, ["minimize", "screech", "acid-armor", "sludge-bomb"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_50": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 49, 0, 16, ["memento", "haze", "smokescreen", "sludge"]], ["weezing", 49, 0, 22, ["haze", "smokescreen", "sludge", "self-destruct"]]]}, +"TRAINER_TEAM_ROCKET_GRUNT_51": {"ai": ["check-bad-move"], "items": [], "party": [["ekans", 48, 50, 1, ["stockpile", "swallow", "spit-up", "haze"]], ["gloom", 48, 50, 13, ["sleep-powder", "acid", "moonlight", "petal-dance"]], ["gloom", 48, 50, 0, ["sleep-powder", "acid", "moonlight", "petal-dance"]]]}, +"TRAINER_BIRD_KEEPER_MILO": {"ai": ["check-bad-move"], "items": [], "party": [["pidgey", 47, 0, 11, ["wing-attack", "feather-dance", "agility", "mirror-move"]], ["pidgeotto", 49, 0, 4, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, +"TRAINER_BIRD_KEEPER_CHAZ": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 47, 0, 22, ["aerial-ace", "mirror-move", "drill-peck", "agility"]], ["fearow", 49, 0, 18, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, +"TRAINER_BIRD_KEEPER_HAROLD": {"ai": ["check-bad-move"], "items": [], "party": [["hoothoot", 47, 0, 4, ["hypnosis", "reflect", "take-down", "confusion"]], ["noctowl", 49, 0, 22, ["hypnosis", "reflect", "take-down", "confusion"]]]}, +"TRAINER_FISHERMAN_TYLOR": {"ai": ["check-bad-move"], "items": [], "party": [["qwilfish", 49, 0, 2, ["revenge", "take-down", "hydro-pump", "destiny-bond"]], ["qwilfish", 49, 0, 18, ["revenge", "take-down", "hydro-pump", "destiny-bond"]]]}, +"TRAINER_SWIMMER_MALE_MYMO": {"ai": ["check-bad-move"], "items": [], "party": [["kingler", 49, 0, 14, ["mud-shot", "stomp", "guillotine", "protect"]], ["wartortle", 49, 0, 10, ["rapid-spin", "protect", "rain-dance", "skull-bash"]]]}, +"TRAINER_SWIMMER_FEMALE_NICOLE": {"ai": ["check-bad-move"], "items": [], "party": [["marill", 50, 0, 0, ["bubble-beam", "double-edge", "rain-dance", "hydro-pump"]]]}, +"TRAINER_SIS_AND_BRO_AVA_GEB": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 50, 0, 23, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["starmie", 50, 0, 14, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_AROMA_LADY_ROSE": {"ai": ["check-bad-move"], "items": [], "party": [["sunkern", 49, 0, 0, ["endeavor", "sunny-day", "synthesis", "giga-drain"]], ["sunflora", 49, 0, 20, ["bullet-seed", "sunny-day", "petal-dance", "solar-beam"]]]}, +"TRAINER_SWIMMER_MALE_SAMIR": {"ai": ["check-bad-move"], "items": [], "party": [["gyarados", 50, 0, 19, ["twister", "hydro-pump", "rain-dance", "dragon-dance"]]]}, +"TRAINER_SWIMMER_FEMALE_DENISE": {"ai": ["check-bad-move"], "items": [], "party": [["chinchou", 49, 0, 16, ["confuse-ray", "take-down", "hydro-pump", "charge"]], ["lanturn", 49, 0, 10, ["water-gun", "spark", "confuse-ray", "take-down"]]]}, +"TRAINER_TWINS_MIU_MIA": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 50, 0, 16, ["thunderbolt", "agility", "thunder", "light-screen"]], ["pikachu", 50, 0, 4, ["thunderbolt", "agility", "thunder", "light-screen"]]]}, +"TRAINER_HIKER_EARL": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 49, 0, 2, ["dragon-breath", "sandstorm", "slam", "iron-tail"]], ["machoke", 49, 0, 5, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_RUIN_MANIAC_FOSTER": {"ai": ["check-bad-move"], "items": [], "party": [["golem", 50, 0, 22, ["self-destruct", "rollout", "rock-blast", "earthquake"]]]}, +"TRAINER_RUIN_MANIAC_LARRY": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 49, 0, 8, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machoke", 49, 0, 5, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_HIKER_DARYL": {"ai": ["check-bad-move"], "items": [], "party": [["sudowoodo", 50, 0, 6, ["rock-slide", "block", "feint-attack", "slam"]]]}, +"TRAINER_POKEMANIAC_HECTOR": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 49, 30, 19, ["scary-face", "rock-blast", "horn-drill", "take-down"]], ["kangaskhan", 49, 30, 11, ["rage", "endure", "dizzy-punch", "reversal"]]]}, +"TRAINER_PSYCHIC_DARIO": {"ai": ["check-bad-move"], "items": [], "party": [["girafarig", 52, 100, 23, ["crunch", "psybeam", "odor-sleuth", "agility"]]]}, +"TRAINER_PSYCHIC_RODETTE": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 48, 100, 4, ["night-shade", "confuse-ray", "wish", "future-sight"]], ["drowzee", 48, 100, 1, ["psychic", "disable", "psych-up", "future-sight"]], ["hypno", 50, 100, 8, ["psychic", "hypnosis", "psych-up", "future-sight"]]]}, +"TRAINER_AROMA_LADY_MIAH": {"ai": ["check-bad-move"], "items": [], "party": [["bellossom", 50, 0, 11, ["sweet-scent", "stun-spore", "magical-leaf", "petal-dance"]], ["bellossom", 50, 0, 2, ["sweet-scent", "stun-spore", "magical-leaf", "petal-dance"]]]}, +"TRAINER_YOUNG_COUPLE_EVE_JON": {"ai": ["check-bad-move"], "items": [], "party": [["golduck", 50, 0, 20, ["confusion", "screech", "psych-up", "fury-swipes"]], ["psyduck", 50, 0, 18, ["screech", "psych-up", "fury-swipes", "hydro-pump"]]]}, +"TRAINER_JUGGLER_MASON": {"ai": ["check-bad-move"], "items": [], "party": [["voltorb", 47, 0, 24, ["swift", "light-screen", "spark", "sonic-boom"]], ["pineco", 47, 0, 19, ["spikes", "bide", "rapid-spin", "take-down"]], ["voltorb", 47, 0, 7, ["swift", "light-screen", "spark", "sonic-boom"]], ["pineco", 47, 0, 2, ["spikes", "bide", "rapid-spin", "explosion"]]]}, +"TRAINER_CRUSH_GIRL_CYNDY": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 48, 50, 18, ["seismic-toss", "rage", "cross-chop", "swagger"]], ["hitmontop", 48, 50, 23, ["rapid-spin", "counter", "agility", "detect"]], ["machoke", 48, 50, 2, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_CRUSH_GIRL_JOCELYN": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 38, 50, 17, ["ice-punch", "fire-punch", "sky-uppercut", "mega-punch"]], ["hitmonchan", 38, 50, 23, ["ice-punch", "fire-punch", "sky-uppercut", "mega-punch"]]]}, +"TRAINER_TAMER_EVAN": {"ai": ["check-bad-move"], "items": [], "party": [["sandslash", 48, 40, 3, ["poison-sting", "slash", "swift", "fury-swipes"]], ["lickitung", 48, 40, 24, ["wrap", "disable", "slam", "screech"]], ["ursaring", 49, 40, 10, ["rest", "slash", "snore", "thrash"]]]}, +"TRAINER_POKEMANIAC_MARK_2": {"ai": ["check-bad-move"], "items": [], "party": [["rhyhorn", 33, 90, 6, ["stomp", "fury-attack", "scary-face", "rock-blast"]], ["lickitung", 33, 90, 8, ["defense-curl", "knock-off", "stomp", "wrap"]]]}, +"TRAINER_PKMN_RANGER_LOGAN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["exeggcute", 37, 100, 11, ["sleep-powder", "poison-powder", "stun-spore", "confusion"]], ["exeggutor", 40, 100, 11, ["egg-bomb", "stomp", "confusion", "hypnosis"]]]}, +"TRAINER_PKMN_RANGER_JACKSON": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["tangela", 49, 100, 8, ["slam", "mega-drain", "bind", "ingrain"]], ["exeggcute", 49, 100, 9, ["confusion", "poison-powder", "barrage", "reflect"]], ["exeggutor", 49, 100, 10, ["confusion", "egg-bomb", "sleep-powder", "stomp"]]]}, +"TRAINER_PKMN_RANGER_BETH": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["bellsprout", 38, 100, 19, ["stun-spore", "acid", "sweet-scent", "razor-leaf"]], ["gloom", 38, 100, 20, ["stun-spore", "sleep-powder", "acid", "moonlight"]], ["gloom", 38, 100, 21, ["stun-spore", "sleep-powder", "acid", "moonlight"]]]}, +"TRAINER_PKMN_RANGER_KATELYN": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["chansey", 52, 100, 22, ["egg-bomb", "defense-curl", "minimize", "soft-boiled"]]]}, +"TRAINER_COOLTRAINER_LEROY": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["rhydon", 47, 100, 16, ["take-down", "horn-drill", "rock-blast", "scary-face"]], ["slowbro", 48, 100, 7, ["psychic", "headbutt", "amnesia", "disable"]], ["kangaskhan", 47, 100, 19, ["dizzy-punch", "bite", "endure", "reversal"]], ["machoke", 48, 100, 22, ["cross-chop", "vital-throw", "revenge", "seismic-toss"]], ["ursaring", 50, 100, 22, ["slash", "feint-attack", "snore", "rest"]]]}, +"TRAINER_COOLTRAINER_MICHELLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["persian", 47, 100, 4, ["slash", "screech", "feint-attack", "bite"]], ["dewgong", 47, 100, 21, ["ice-beam", "take-down", "icy-wind", "growl"]], ["ninetales", 48, 100, 14, ["flamethrower", "confuse-ray", "will-o-wisp", "grudge"]], ["rapidash", 48, 100, 3, ["bounce", "agility", "fire-spin", "take-down"]], ["girafarig", 50, 100, 8, ["crunch", "psybeam", "stomp", "odor-sleuth"]]]}, +"TRAINER_COOL_COUPLE_LEX_NYA": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["miltank", 52, 100, 22, ["body-slam", "milk-drink", "growl", "defense-curl"]], ["tauros", 52, 100, 9, ["thrash", "horn-attack", "pursuit", "swagger"]]]}, +"TRAINER_RUIN_MANIAC_BRANDON": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 50, 0, 17, ["dragon-breath", "sandstorm", "slam", "iron-tail"]]]}, +"TRAINER_RUIN_MANIAC_BENJAMIN": {"ai": ["check-bad-move"], "items": [], "party": [["geodude", 48, 0, 0, ["earthquake", "rock-blast", "rollout", "self-destruct"]], ["graveler", 48, 0, 17, ["earthquake", "rock-blast", "rock-throw", "self-destruct"]], ["graveler", 48, 0, 9, ["earthquake", "rock-blast", "rock-throw", "self-destruct"]]]}, +"TRAINER_PAINTER_EDNA": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 50, 50, 2, ["fake-out", "extreme-speed", "protect", "quick-attack"]]]}, +"TRAINER_GENTLEMAN_CLIFFORD": {"ai": ["check-bad-move"], "items": [], "party": [["marowak", 49, 0, 6, ["bonemerang", "rage", "false-swipe", "thrash"]], ["golduck", 49, 0, 22, ["confusion", "screech", "psych-up", "fury-swipes"]]]}, +"TRAINER_LADY_SELPHY": {"ai": ["check-bad-move"], "items": ["full-restore"], "party": [["persian", 49, 0, 21, ["pay-day", "bite", "taunt", "torment"]], ["persian", 49, 0, 6, ["pay-day", "scratch", "torment", "taunt"]]]}, +"TRAINER_RUIN_MANIAC_LAWSON": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 47, 0, 22, ["dragon-breath", "sandstorm", "slam", "iron-tail"]], ["graveler", 48, 0, 3, ["self-destruct", "rollout", "rock-blast", "earthquake"]], ["marowak", 49, 0, 7, ["bonemerang", "rage", "false-swipe", "thrash"]]]}, +"TRAINER_PSYCHIC_LAURA": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 48, 100, 18, ["teleport", "wish", "future-sight", "confuse-ray"]], ["natu", 48, 100, 16, ["teleport", "wish", "future-sight", "confuse-ray"]], ["xatu", 49, 100, 24, ["night-shade", "teleport", "wish", "future-sight"]]]}, +"TRAINER_PKMN_BREEDER_BETHANY": {"ai": ["check-bad-move"], "items": [], "party": [["chansey", 50, 30, 10, ["sing", "egg-bomb", "defense-curl", "light-screen"]]]}, +"TRAINER_PKMN_BREEDER_ALLISON": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 48, 30, 17, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["clefairy", 48, 30, 23, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["clefable", 48, 30, 6, ["sing", "double-slap", "minimize", "metronome"]]]}, +"TRAINER_BUG_CATCHER_GARRET": {"ai": ["check-bad-move"], "items": [], "party": [["heracross", 49, 0, 1, ["brick-break", "counter", "take-down", "reversal"]]]}, +"TRAINER_BUG_CATCHER_JONAH": {"ai": ["check-bad-move"], "items": [], "party": [["yanma", 45, 0, 8, ["detect", "uproar", "wing-attack", "supersonic"]], ["beedrill", 45, 0, 6, ["pursuit", "pin-missile", "agility", "endeavor"]], ["yanma", 46, 0, 3, ["detect", "uproar", "wing-attack", "supersonic"]], ["beedrill", 47, 0, 1, ["pursuit", "pin-missile", "agility", "endeavor"]]]}, +"TRAINER_BUG_CATCHER_VANCE": {"ai": ["check-bad-move"], "items": [], "party": [["venonat", 48, 0, 19, ["stun-spore", "psybeam", "sleep-powder", "psychic"]], ["venomoth", 48, 0, 19, ["stun-spore", "gust", "psybeam", "sleep-powder"]]]}, +"TRAINER_YOUNGSTER_NASH": {"ai": ["check-bad-move"], "items": [], "party": [["weepinbell", 47, 0, 5, ["stun-spore", "acid", "sweet-scent", "razor-leaf"]], ["weepinbell", 47, 0, 24, ["stun-spore", "acid", "sweet-scent", "razor-leaf"]], ["victreebel", 49, 0, 6, ["vine-whip", "sleep-powder", "sweet-scent", "razor-leaf"]]]}, +"TRAINER_YOUNGSTER_CORDELL": {"ai": ["check-bad-move"], "items": [], "party": [["farfetch-d", 48, 0, 12, ["swords-dance", "agility", "slash", "false-swipe"]], ["farfetch-d", 48, 0, 13, ["swords-dance", "agility", "slash", "false-swipe"]]]}, +"TRAINER_LASS_DALIA": {"ai": ["check-bad-move"], "items": [], "party": [["hoppip", 46, 0, 13, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]], ["hoppip", 47, 0, 6, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]], ["skiploom", 47, 0, 11, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]], ["skiploom", 48, 0, 16, ["sleep-powder", "leech-seed", "cotton-spore", "mega-drain"]]]}, +"TRAINER_LASS_JOANA": {"ai": ["check-bad-move"], "items": [], "party": [["snubbull", 49, 0, 17, ["lick", "roar", "rage", "take-down"]]]}, +"TRAINER_CAMPER_RILEY": {"ai": ["check-bad-move"], "items": [], "party": [["pinsir", 49, 0, 11, ["brick-break", "guillotine", "submission", "swords-dance"]], ["heracross", 50, 0, 10, ["brick-break", "counter", "take-down", "reversal"]]]}, +"TRAINER_PICNICKER_MARCY": {"ai": ["check-bad-move"], "items": [], "party": [["paras", 48, 0, 20, ["spore", "slash", "growth", "giga-drain"]], ["paras", 48, 0, 20, ["spore", "slash", "growth", "giga-drain"]], ["parasect", 49, 0, 11, ["leech-life", "spore", "slash", "growth"]]]}, +"TRAINER_RUIN_MANIAC_LAYTON": {"ai": ["check-bad-move"], "items": [], "party": [["sandslash", 48, 0, 5, ["poison-sting", "slash", "swift", "fury-swipes"]], ["onix", 48, 0, 9, ["dragon-breath", "sandstorm", "slam", "iron-tail"]], ["sandslash", 48, 0, 3, ["poison-sting", "slash", "swift", "fury-swipes"]]]}, +"TRAINER_PICNICKER_KELSEY_2": {"ai": ["check-bad-move"], "items": [], "party": [["nidoran-m", 21, 20, 1, ["focus-energy", "double-kick", "poison-sting", "horn-attack"]], ["nidoran-f", 21, 20, 13, ["tail-whip", "double-kick", "poison-sting", "bite"]]]}, +"TRAINER_PICNICKER_KELSEY_3": {"ai": ["check-bad-move"], "items": [], "party": [["nidorino", 29, 60, 19, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]], ["nidorina", 29, 60, 9, ["double-kick", "poison-sting", "bite", "helping-hand"]]]}, +"TRAINER_PICNICKER_KELSEY_4": {"ai": ["check-bad-move"], "items": [], "party": [["nidorino", 49, 80, 19, ["horn-attack", "helping-hand", "fury-attack", "flatter"]], ["nidorina", 49, 80, 9, ["bite", "helping-hand", "fury-swipes", "flatter"]]]}, +"TRAINER_CAMPER_RICKY_2": {"ai": ["check-bad-move"], "items": [], "party": [["squirtle", 22, 20, 16, ["bubble", "withdraw", "water-gun", "bite"]]]}, +"TRAINER_CAMPER_RICKY_3": {"ai": ["check-bad-move"], "items": [], "party": [["wartortle", 30, 60, 23, ["withdraw", "water-gun", "bite", "rapid-spin"]]]}, +"TRAINER_CAMPER_RICKY_4": {"ai": ["check-bad-move"], "items": [], "party": [["wartortle", 55, 120, 23, ["protect", "rain-dance", "skull-bash", "hydro-pump"]]]}, +"TRAINER_CAMPER_JEFF_2": {"ai": ["check-bad-move"], "items": [], "party": [["spearow", 21, 20, 6, ["growl", "leer", "fury-attack", "pursuit"]], ["raticate", 21, 20, 22, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, +"TRAINER_CAMPER_JEFF_3": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 29, 60, 16, ["growl", "leer", "fury-attack", "pursuit"]], ["raticate", 29, 60, 7, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, +"TRAINER_CAMPER_JEFF_4": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 54, 120, 16, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["raticate", 54, 120, 7, ["scary-face", "pursuit", "super-fang", "endeavor"]]]}, +"TRAINER_PICNICKER_ISABELLE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 21, 20, 23, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["pidgeotto", 21, 20, 1, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["pidgey", 18, 20, 11, ["tackle", "sand-attack", "gust", "quick-attack"]]]}, +"TRAINER_PICNICKER_ISABELLE_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 29, 60, 23, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 29, 60, 1, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 26, 60, 4, ["sand-attack", "gust", "quick-attack", "whirlwind"]]]}, +"TRAINER_PICNICKER_ISABELLE_4": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 47, 80, 23, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["pidgeotto", 47, 80, 1, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["pidgeot", 50, 80, 12, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, +"TRAINER_YOUNGSTER_YASU_2": {"ai": ["check-bad-move"], "items": [], "party": [["rattata", 22, 40, 19, ["tail-whip", "quick-attack", "hyper-fang", "focus-energy"]], ["raticate", 22, 40, 19, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["raticate", 22, 40, 19, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]]]}, +"TRAINER_YOUNGSTER_YASU_3": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 47, 80, 11, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["raticate", 47, 80, 11, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["raticate", 47, 80, 11, ["hyper-fang", "scary-face", "pursuit", "super-fang"]]]}, +"TRAINER_ENGINEER_BERNIE_2": {"ai": ["check-bad-move"], "items": [], "party": [["magneton", 28, 60, 12, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["magneton", 28, 60, 13, ["supersonic", "sonic-boom", "thunder-wave", "spark"]], ["magneton", 28, 60, 14, ["supersonic", "sonic-boom", "thunder-wave", "spark"]]]}, +"TRAINER_GAMER_DARIAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 29, 60, 10, ["ember", "leer", "odor-sleuth", "take-down"]], ["vulpix", 29, 60, 8, ["will-o-wisp", "confuse-ray", "imprison", "flamethrower"]]]}, +"TRAINER_CAMPER_CHRIS_2": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 24, 40, 4, ["roar", "ember", "leer", "odor-sleuth"]], ["charmander", 24, 40, 21, ["growl", "ember", "metal-claw", "smokescreen"]]]}, +"TRAINER_CAMPER_CHRIS_3": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 29, 60, 4, ["ember", "leer", "odor-sleuth", "take-down"]], ["charmeleon", 29, 60, 0, ["ember", "metal-claw", "smokescreen", "scary-face"]]]}, +"TRAINER_CAMPER_CHRIS_4": {"ai": ["check-bad-move"], "items": [], "party": [["arcanine", 54, 120, 1, ["roar", "ember", "odor-sleuth", "extreme-speed"]], ["charmeleon", 54, 120, 22, ["scary-face", "flamethrower", "slash", "dragon-rage"]]]}, +"TRAINER_PICNICKER_ALICIA_2": {"ai": ["check-bad-move"], "items": [], "party": [["meowth", 25, 40, 1, ["growl", "bite", "pay-day", "feint-attack"]]]}, +"TRAINER_PICNICKER_ALICIA_3": {"ai": ["check-bad-move"], "items": [], "party": [["persian", 30, 60, 5, ["growl", "bite", "pay-day", "feint-attack"]]]}, +"TRAINER_PICNICKER_ALICIA_4": {"ai": ["check-bad-move"], "items": [], "party": [["persian", 55, 120, 5, ["screech", "fury-swipes", "slash", "fake-out"]]]}, +"TRAINER_HIKER_JEREMY_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 30, 60, 11, ["karate-chop", "seismic-toss", "foresight", "revenge"]], ["onix", 28, 60, 24, ["bind", "rock-throw", "harden", "rage"]]]}, +"TRAINER_POKEMANIAC_MARK_3": {"ai": ["check-bad-move"], "items": [], "party": [["rhydon", 54, 150, 8, ["scary-face", "rock-blast", "horn-drill", "take-down"]], ["lickitung", 54, 150, 10, ["disable", "slam", "screech", "refresh"]]]}, +"TRAINER_POKEMANIAC_HERMAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["marowak", 29, 90, 15, ["headbutt", "leer", "focus-energy", "bonemerang"]], ["slowbro", 29, 90, 1, ["water-gun", "confusion", "disable", "headbutt"]]]}, +"TRAINER_POKEMANIAC_HERMAN_3": {"ai": ["check-bad-move"], "items": [], "party": [["marowak", 54, 150, 15, ["rage", "false-swipe", "thrash", "bone-rush"]], ["slowbro", 54, 150, 1, ["headbutt", "amnesia", "withdraw", "psychic"]]]}, +"TRAINER_HIKER_TRENT_2": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 31, 60, 14, ["rock-throw", "harden", "rage", "dragon-breath"]], ["graveler", 31, 60, 12, ["rock-throw", "magnitude", "self-destruct", "rollout"]]]}, +"TRAINER_LASS_MEGAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 22, 40, 0, ["sand-attack", "gust", "quick-attack", "whirlwind"]], ["raticate", 22, 40, 10, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["nidoran-m", 23, 40, 3, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]], ["meowth", 21, 40, 23, ["scratch", "growl", "bite", "pay-day"]], ["pikachu", 22, 40, 19, ["thunder-wave", "quick-attack", "double-team", "slam"]]]}, +"TRAINER_LASS_MEGAN_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeot", 46, 80, 8, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["raticate", 47, 80, 18, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["nidorino", 47, 80, 4, ["horn-attack", "helping-hand", "fury-attack", "flatter"]], ["persian", 47, 80, 3, ["pay-day", "feint-attack", "screech", "fury-swipes"]], ["raichu", 48, 80, 4, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, +"TRAINER_SUPER_NERD_GLENN_2": {"ai": ["check-bad-move"], "items": [], "party": [["muk", 28, 60, 21, ["disable", "sludge", "minimize", "screech"]], ["muk", 28, 60, 6, ["disable", "sludge", "minimize", "screech"]], ["muk", 28, 60, 16, ["disable", "sludge", "minimize", "screech"]]]}, +"TRAINER_GAMER_RICH_2": {"ai": ["check-bad-move"], "items": [], "party": [["growlithe", 30, 60, 24, ["ember", "leer", "odor-sleuth", "take-down"]], ["vulpix", 30, 60, 11, ["will-o-wisp", "confuse-ray", "imprison", "flamethrower"]]]}, +"TRAINER_BIKER_JAREN_2": {"ai": ["check-bad-move"], "items": [], "party": [["muk", 28, 60, 22, ["disable", "sludge", "minimize", "screech"]], ["muk", 30, 60, 8, ["disable", "sludge", "minimize", "screech"]]]}, +"TRAINER_FISHERMAN_ELLIOT_2": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 28, 60, 21, ["hypnosis", "water-gun", "double-slap", "rain-dance"]], ["cloyster", 28, 60, 10, ["withdraw", "supersonic", "aurora-beam", "protect"]], ["seaking", 28, 60, 2, ["water-sport", "supersonic", "horn-attack", "flail"]], ["seadra", 28, 60, 20, ["bubble", "smokescreen", "leer", "water-gun"]]]}, +"TRAINER_ROCKER_LUCA_2": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 33, 60, 13, ["screech", "sonic-boom", "spark", "self-destruct"]], ["electrode", 33, 60, 15, ["screech", "sonic-boom", "spark", "self-destruct"]]]}, +"TRAINER_BEAUTY_SHEILA_2": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 49, 80, 17, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["persian", 49, 80, 16, ["feint-attack", "screech", "fury-swipes", "slash"]]]}, +"TRAINER_BIRD_KEEPER_ROBERT_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 28, 60, 10, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["pidgeotto", 28, 60, 9, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["fearow", 28, 60, 2, ["growl", "leer", "fury-attack", "pursuit"]], ["fearow", 28, 60, 20, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_ROBERT_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeot", 47, 80, 18, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["pidgeot", 47, 80, 0, ["quick-attack", "whirlwind", "wing-attack", "feather-dance"]], ["fearow", 47, 80, 18, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 47, 80, 11, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, +"TRAINER_PICNICKER_SUSIE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 27, 60, 23, ["gust", "quick-attack", "whirlwind", "wing-attack"]], ["meowth", 27, 60, 16, ["growl", "bite", "pay-day", "feint-attack"]], ["raticate", 27, 60, 24, ["tail-whip", "quick-attack", "hyper-fang", "scary-face"]], ["pikachu", 27, 60, 18, ["quick-attack", "double-team", "slam", "thunderbolt"]], ["meowth", 27, 60, 11, ["growl", "bite", "pay-day", "feint-attack"]]]}, +"TRAINER_PICNICKER_SUSIE_3": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 47, 80, 23, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["persian", 47, 80, 20, ["pay-day", "feint-attack", "screech", "fury-swipes"]], ["raticate", 47, 80, 3, ["hyper-fang", "scary-face", "pursuit", "super-fang"]], ["pikachu", 47, 80, 22, ["slam", "thunderbolt", "agility", "thunder"]], ["persian", 47, 80, 19, ["pay-day", "feint-attack", "screech", "fury-swipes"]]]}, +"TRAINER_PICNICKER_SUSIE_4": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeot", 52, 120, 6, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["persian", 52, 120, 3, ["feint-attack", "screech", "fury-swipes", "slash"]], ["raticate", 52, 120, 11, ["scary-face", "pursuit", "super-fang", "endeavor"]], ["raichu", 52, 120, 10, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]], ["persian", 52, 120, 7, ["feint-attack", "screech", "fury-swipes", "slash"]]]}, +"TRAINER_BIKER_LUKAS_2": {"ai": ["check-bad-move"], "items": [], "party": [["koffing", 47, 80, 20, ["smokescreen", "haze", "explosion", "destiny-bond"]], ["koffing", 47, 80, 4, ["smokescreen", "haze", "explosion", "destiny-bond"]], ["muk", 47, 80, 11, ["minimize", "screech", "acid-armor", "sludge-bomb"]], ["weezing", 47, 80, 21, ["sludge", "smokescreen", "haze", "explosion"]]]}, +"TRAINER_BIRD_KEEPER_BENNY_2": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 32, 60, 5, ["leer", "fury-attack", "pursuit", "mirror-move"]], ["fearow", 32, 60, 24, ["leer", "fury-attack", "pursuit", "mirror-move"]]]}, +"TRAINER_BIRD_KEEPER_BENNY_3": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 49, 80, 5, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 49, 80, 24, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, +"TRAINER_BIRD_KEEPER_MARLON_2": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 30, 60, 24, ["growl", "leer", "fury-attack", "pursuit"]], ["doduo", 30, 60, 17, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["fearow", 30, 60, 5, ["growl", "leer", "fury-attack", "pursuit"]]]}, +"TRAINER_BIRD_KEEPER_MARLON_3": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 48, 80, 24, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["dodrio", 48, 80, 19, ["tri-attack", "rage", "uproar", "drill-peck"]], ["fearow", 48, 80, 7, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, +"TRAINER_BEAUTY_GRACE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeot", 49, 80, 22, ["whirlwind", "wing-attack", "feather-dance", "agility"]], ["wigglytuff", 49, 80, 7, ["sing", "disable", "defense-curl", "double-slap"]]]}, +"TRAINER_BIRD_KEEPER_CHESTER_2": {"ai": ["check-bad-move"], "items": [], "party": [["dodrio", 30, 60, 2, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["dodrio", 30, 60, 18, ["pursuit", "fury-attack", "tri-attack", "rage"]], ["doduo", 30, 60, 7, ["pursuit", "fury-attack", "tri-attack", "rage"]]]}, +"TRAINER_BIRD_KEEPER_CHESTER_3": {"ai": ["check-bad-move"], "items": [], "party": [["dodrio", 48, 80, 2, ["tri-attack", "rage", "uproar", "drill-peck"]], ["dodrio", 48, 80, 18, ["tri-attack", "rage", "uproar", "drill-peck"]], ["dodrio", 48, 80, 9, ["tri-attack", "rage", "uproar", "drill-peck"]]]}, +"TRAINER_PICNICKER_BECKY_2": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 32, 60, 2, ["quick-attack", "double-team", "slam", "thunderbolt"]], ["raichu", 32, 60, 14, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, +"TRAINER_PICNICKER_BECKY_3": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 49, 80, 2, ["slam", "thunderbolt", "agility", "thunder"]], ["raichu", 49, 80, 14, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, +"TRAINER_PICNICKER_BECKY_4": {"ai": ["check-bad-move"], "items": [], "party": [["raichu", 54, 120, 7, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]], ["raichu", 54, 120, 19, ["thunder-shock", "tail-whip", "quick-attack", "thunderbolt"]]]}, +"TRAINER_CRUSH_KIN_RON_MYA_2": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 33, 110, 0, ["thunder-punch", "ice-punch", "fire-punch", "sky-uppercut"]], ["hitmonlee", 33, 110, 7, ["brick-break", "focus-energy", "high-jump-kick", "mind-reader"]]]}, +"TRAINER_CRUSH_KIN_RON_MYA_3": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 51, 130, 0, ["sky-uppercut", "mega-punch", "detect", "counter"]], ["hitmonlee", 51, 130, 7, ["foresight", "endure", "mega-kick", "reversal"]]]}, +"TRAINER_CRUSH_KIN_RON_MYA_4": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonchan", 56, 170, 0, ["sky-uppercut", "mega-punch", "detect", "counter"]], ["hitmonlee", 56, 170, 7, ["foresight", "endure", "mega-kick", "reversal"]]]}, +"TRAINER_BIKER_RUBEN_2": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 48, 80, 22, ["sludge", "smokescreen", "haze", "explosion"]], ["weezing", 48, 80, 8, ["sludge", "smokescreen", "haze", "explosion"]], ["weezing", 48, 80, 19, ["sludge", "smokescreen", "haze", "explosion"]]]}, +"TRAINER_CUE_BALL_CAMRON_2": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 49, 80, 17, ["seismic-toss", "rage", "cross-chop", "swagger"]], ["machoke", 49, 80, 20, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_BIKER_JAXON_2": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 49, 80, 21, ["sludge", "smokescreen", "haze", "explosion"]], ["muk", 49, 80, 3, ["minimize", "screech", "acid-armor", "sludge-bomb"]]]}, +"TRAINER_CUE_BALL_ISAIAH_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 49, 80, 12, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machamp", 49, 80, 7, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_CUE_BALL_COREY_2": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 49, 80, 13, ["seismic-toss", "rage", "cross-chop", "swagger"]], ["machamp", 49, 80, 6, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_BIRD_KEEPER_JACOB_2": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 28, 60, 6, ["growl", "leer", "fury-attack", "pursuit"]], ["spearow", 28, 60, 16, ["leer", "fury-attack", "pursuit", "aerial-ace"]], ["fearow", 28, 60, 11, ["growl", "leer", "fury-attack", "pursuit"]], ["spearow", 28, 60, 21, ["leer", "fury-attack", "pursuit", "aerial-ace"]]]}, +"TRAINER_BIRD_KEEPER_JACOB_3": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 47, 80, 6, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 47, 80, 1, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 47, 80, 21, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 47, 80, 16, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, +"TRAINER_SWIMMER_FEMALE_ALICE_2": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 49, 80, 13, ["flail", "fury-attack", "waterfall", "horn-drill"]], ["seaking", 49, 80, 6, ["flail", "fury-attack", "waterfall", "horn-drill"]]]}, +"TRAINER_SWIMMER_MALE_DARRIN_2": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 52, 120, 0, ["water-gun", "twister", "agility", "hydro-pump"]], ["seadra", 52, 120, 14, ["water-gun", "twister", "agility", "hydro-pump"]], ["seadra", 52, 120, 3, ["water-gun", "twister", "agility", "hydro-pump"]], ["seadra", 52, 120, 17, ["water-gun", "twister", "agility", "hydro-pump"]]]}, +"TRAINER_PICNICKER_MISSY_2": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 49, 80, 18, ["flail", "fury-attack", "waterfall", "horn-drill"]], ["seaking", 49, 80, 16, ["flail", "fury-attack", "waterfall", "horn-drill"]]]}, +"TRAINER_PICNICKER_MISSY_3": {"ai": ["check-bad-move"], "items": [], "party": [["seaking", 54, 120, 18, ["flail", "fury-attack", "waterfall", "horn-drill"]], ["seaking", 54, 120, 16, ["flail", "fury-attack", "waterfall", "horn-drill"]]]}, +"TRAINER_FISHERMAN_WADE_2": {"ai": ["check-bad-move"], "items": [], "party": [["magikarp", 47, 80, 7, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 3, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 24, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 20, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 16, ["splash", "tackle", "flail"]], ["magikarp", 47, 80, 12, ["splash", "tackle", "flail"]]]}, +"TRAINER_SWIMMER_MALE_JACK_2": {"ai": ["check-bad-move"], "items": [], "party": [["starmie", 50, 80, 22, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_SIS_AND_BRO_LIL_IAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 50, 80, 20, ["leer", "water-gun", "twister", "agility"]], ["starmie", 50, 80, 0, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_SIS_AND_BRO_LIL_IAN_3": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 55, 120, 20, ["water-gun", "twister", "agility", "hydro-pump"]], ["starmie", 55, 120, 0, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_SWIMMER_MALE_FINN_2": {"ai": ["check-bad-move"], "items": [], "party": [["starmie", 50, 80, 5, ["rapid-spin", "recover", "swift", "confuse-ray"]]]}, +"TRAINER_CRUSH_GIRL_SHARON_2": {"ai": ["check-bad-move"], "items": [], "party": [["mankey", 50, 130, 17, ["cross-chop", "swagger", "screech", "thrash"]], ["primeape", 50, 130, 14, ["seismic-toss", "rage", "cross-chop", "swagger"]]]}, +"TRAINER_CRUSH_GIRL_SHARON_3": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 55, 170, 8, ["rage", "cross-chop", "swagger", "screech"]], ["primeape", 55, 170, 5, ["rage", "cross-chop", "swagger", "screech"]]]}, +"TRAINER_CRUSH_GIRL_TANYA_2": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonlee", 50, 130, 7, ["mind-reader", "foresight", "endure", "mega-kick"]], ["hitmonchan", 50, 130, 18, ["sky-uppercut", "mega-punch", "detect", "counter"]]]}, +"TRAINER_CRUSH_GIRL_TANYA_3": {"ai": ["check-bad-move"], "items": [], "party": [["hitmonlee", 55, 170, 7, ["foresight", "endure", "mega-kick", "reversal"]], ["hitmonchan", 55, 170, 18, ["sky-uppercut", "mega-punch", "detect", "counter"]]]}, +"TRAINER_BLACK_BELT_SHEA_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 50, 180, 21, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machoke", 50, 180, 6, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_BLACK_BELT_SHEA_3": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 55, 220, 21, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machamp", 55, 220, 0, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, +"TRAINER_BLACK_BELT_HUGH_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 50, 180, 12, ["revenge", "vital-throw", "submission", "cross-chop"]], ["machoke", 50, 180, 13, ["revenge", "vital-throw", "submission", "cross-chop"]]]}, +"TRAINER_BLACK_BELT_HUGH_3": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 55, 220, 12, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machamp", 55, 220, 7, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, +"TRAINER_CRUSH_KIN_MIK_KIA_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 51, 130, 16, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["primeape", 51, 130, 7, ["seismic-toss", "rage", "cross-chop", "swagger"]]]}, +"TRAINER_CRUSH_KIN_MIK_KIA_3": {"ai": ["check-bad-move"], "items": [], "party": [["machamp", 56, 170, 10, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["primeape", 56, 170, 1, ["rage", "cross-chop", "swagger", "screech"]]]}, +"TRAINER_TUBER_AMIRA_2": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 47, 80, 19, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["poliwhirl", 47, 80, 2, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["poliwhirl", 47, 80, 10, ["double-slap", "rain-dance", "body-slam", "belly-drum"]]]}, +"TRAINER_TWINS_JOY_MEG_2": {"ai": ["check-bad-move"], "items": [], "party": [["clefairy", 49, 80, 21, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["clefairy", 49, 80, 14, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]]]}, +"TRAINER_PAINTER_RAYNA_2": {"ai": ["check-bad-move"], "items": [], "party": [["smeargle", 54, 120, 3, ["cross-chop", "megahorn", "double-edge", "self-destruct"]]]}, +"TRAINER_YOUNGSTER_DESTIN_2": {"ai": ["check-bad-move"], "items": [], "party": [["raticate", 53, 120, 23, ["scary-face", "pursuit", "super-fang", "endeavor"]], ["pidgeot", 53, 120, 13, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, +"TRAINER_PKMN_BREEDER_ALIZE_2": {"ai": ["check-bad-move"], "items": [], "party": [["pikachu", 53, 150, 10, ["thunderbolt", "agility", "thunder", "light-screen"]], ["clefairy", 53, 150, 10, ["cosmic-power", "moonlight", "light-screen", "meteor-mash"]], ["marill", 53, 150, 19, ["bubble-beam", "double-edge", "rain-dance", "hydro-pump"]]]}, +"TRAINER_YOUNG_COUPLE_GIA_JES_2": {"ai": ["check-bad-move"], "items": [], "party": [["nidorina", 30, 60, 7, ["double-kick", "poison-sting", "bite", "helping-hand"]], ["nidorino", 30, 60, 20, ["double-kick", "poison-sting", "horn-attack", "helping-hand"]]]}, +"TRAINER_YOUNG_COUPLE_GIA_JES_3": {"ai": ["check-bad-move"], "items": [], "party": [["nidoking", 55, 120, 1, ["double-kick", "poison-sting", "thrash", "megahorn"]], ["nidoqueen", 55, 120, 16, ["double-kick", "poison-sting", "body-slam", "superpower"]]]}, +"TRAINER_BIRD_KEEPER_MILO_2": {"ai": ["check-bad-move"], "items": [], "party": [["pidgeotto", 53, 120, 4, ["wing-attack", "feather-dance", "agility", "mirror-move"]], ["pidgeot", 55, 120, 5, ["whirlwind", "wing-attack", "feather-dance", "agility"]]]}, +"TRAINER_BIRD_KEEPER_CHAZ_2": {"ai": ["check-bad-move"], "items": [], "party": [["fearow", 53, 120, 7, ["pursuit", "mirror-move", "drill-peck", "agility"]], ["fearow", 55, 120, 3, ["pursuit", "mirror-move", "drill-peck", "agility"]]]}, +"TRAINER_BIRD_KEEPER_HAROLD_2": {"ai": ["check-bad-move"], "items": [], "party": [["noctowl", 53, 120, 4, ["hypnosis", "reflect", "take-down", "confusion"]], ["noctowl", 55, 120, 22, ["hypnosis", "reflect", "take-down", "confusion"]]]}, +"TRAINER_SWIMMER_FEMALE_NICOLE_2": {"ai": ["check-bad-move"], "items": [], "party": [["marill", 54, 120, 0, ["bubble-beam", "double-edge", "rain-dance", "hydro-pump"]]]}, +"TRAINER_PSYCHIC_JACLYN_2": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 52, 220, 6, ["psychic", "confuse-ray", "future-sight", "wish"]], ["slowbro", 52, 220, 3, ["psychic", "headbutt", "amnesia", "yawn"]], ["kadabra", 54, 220, 4, ["psychic", "future-sight", "recover", "reflect"]]]}, +"TRAINER_SWIMMER_MALE_SAMIR_2": {"ai": ["check-bad-move"], "items": [], "party": [["gyarados", 55, 120, 19, ["hydro-pump", "rain-dance", "dragon-dance", "hyper-beam"]]]}, +"TRAINER_HIKER_EARL_2": {"ai": ["check-bad-move"], "items": [], "party": [["onix", 54, 120, 2, ["sandstorm", "slam", "iron-tail", "sand-tomb"]], ["machamp", 54, 120, 24, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, +"TRAINER_RUIN_MANIAC_LARRY_2": {"ai": ["check-bad-move"], "items": [], "party": [["machoke", 54, 120, 8, ["vital-throw", "submission", "cross-chop", "scary-face"]], ["machoke", 54, 120, 5, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, +"TRAINER_POKEMANIAC_HECTOR_2": {"ai": ["check-bad-move"], "items": [], "party": [["rhydon", 55, 150, 21, ["scary-face", "rock-blast", "horn-drill", "take-down"]], ["kangaskhan", 55, 150, 13, ["rage", "endure", "dizzy-punch", "reversal"]]]}, +"TRAINER_PSYCHIC_DARIO_2": {"ai": ["check-bad-move"], "items": [], "party": [["girafarig", 56, 220, 23, ["crunch", "psybeam", "odor-sleuth", "agility"]]]}, +"TRAINER_PSYCHIC_RODETTE_2": {"ai": ["check-bad-move"], "items": [], "party": [["natu", 53, 220, 4, ["psychic", "confuse-ray", "wish", "future-sight"]], ["hypno", 53, 220, 11, ["psychic", "disable", "psych-up", "future-sight"]], ["hypno", 53, 220, 18, ["psychic", "hypnosis", "psych-up", "future-sight"]]]}, +"TRAINER_JUGGLER_MASON_2": {"ai": ["check-bad-move"], "items": [], "party": [["electrode", 52, 120, 4, ["self-destruct", "rollout", "light-screen", "swift"]], ["pineco", 52, 120, 24, ["bide", "explosion", "spikes", "double-edge"]], ["electrode", 52, 120, 17, ["self-destruct", "rollout", "light-screen", "swift"]], ["pineco", 52, 120, 12, ["bide", "explosion", "spikes", "double-edge"]]]}, +"TRAINER_PKMN_RANGER_NICOLAS_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["victreebel", 55, 220, 2, ["razor-leaf", "acid", "stun-spore", "wrap"]], ["victreebel", 55, 220, 18, ["razor-leaf", "acid", "sleep-powder", "slam"]]]}, +"TRAINER_PKMN_RANGER_MADELINE_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["vileplume", 55, 220, 10, ["petal-dance", "moonlight", "acid", "sleep-powder"]], ["vileplume", 55, 220, 0, ["petal-dance", "moonlight", "acid", "stun-spore"]]]}, +"TRAINER_CRUSH_GIRL_CYNDY_2": {"ai": ["check-bad-move"], "items": [], "party": [["primeape", 54, 170, 18, ["rage", "cross-chop", "swagger", "screech"]], ["hitmontop", 54, 170, 23, ["counter", "agility", "detect", "endeavor"]], ["machamp", 54, 170, 21, ["vital-throw", "submission", "cross-chop", "scary-face"]]]}, +"TRAINER_TAMER_EVAN_2": {"ai": ["check-bad-move"], "items": [], "party": [["sandslash", 52, 160, 3, ["slash", "swift", "fury-swipes", "sand-tomb"]], ["lickitung", 52, 160, 24, ["disable", "slam", "screech", "refresh"]], ["ursaring", 55, 160, 10, ["rest", "slash", "snore", "thrash"]]]}, +"TRAINER_PKMN_RANGER_JACKSON_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["tangela", 53, 220, 8, ["slam", "mega-drain", "bind", "ingrain"]], ["exeggutor", 54, 220, 9, ["confusion", "egg-bomb", "stun-spore", "reflect"]], ["exeggutor", 55, 220, 10, ["confusion", "egg-bomb", "sleep-powder", "stomp"]]]}, +"TRAINER_PKMN_RANGER_KATELYN_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["chansey", 56, 220, 22, ["egg-bomb", "defense-curl", "minimize", "soft-boiled"]]]}, +"TRAINER_COOLTRAINER_LEROY_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore"], "party": [["rhydon", 52, 220, 16, ["earthquake", "horn-drill", "rock-blast", "scary-face"]], ["slowbro", 54, 220, 7, ["psychic", "headbutt", "amnesia", "disable"]], ["kangaskhan", 52, 220, 19, ["dizzy-punch", "bite", "endure", "reversal"]], ["machamp", 52, 220, 16, ["cross-chop", "vital-throw", "revenge", "seismic-toss"]], ["ursaring", 55, 220, 16, ["slash", "feint-attack", "snore", "rest"]]]}, +"TRAINER_COOLTRAINER_MICHELLE_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["hyper-potion"], "party": [["persian", 53, 220, 4, ["slash", "screech", "feint-attack", "bite"]], ["dewgong", 53, 220, 21, ["ice-beam", "take-down", "icy-wind", "sheer-cold"]], ["ninetales", 54, 220, 14, ["flamethrower", "confuse-ray", "will-o-wisp", "grudge"]], ["rapidash", 54, 220, 3, ["bounce", "agility", "fire-spin", "take-down"]], ["girafarig", 56, 220, 8, ["crunch", "psybeam", "stomp", "odor-sleuth"]]]}, +"TRAINER_COOL_COUPLE_LEX_NYA_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["miltank", 57, 220, 22, ["body-slam", "milk-drink", "growl", "defense-curl"]], ["tauros", 57, 220, 9, ["take-down", "scary-face", "pursuit", "swagger"]]]}, +"TRAINER_BUG_CATCHER_COLTON_2": {"ai": ["check-bad-move"], "items": [], "party": [["metapod", 19, 20, 12, ["harden"]], ["weedle", 19, 20, 2, ["poison-sting", "string-shot"]], ["metapod", 19, 20, 3, ["harden"]]]}, +"TRAINER_BUG_CATCHER_COLTON_3": {"ai": ["check-bad-move"], "items": [], "party": [["butterfree", 27, 60, 11, ["stun-spore", "sleep-powder", "supersonic", "whirlwind"]], ["kakuna", 27, 60, 6, ["harden"]], ["butterfree", 27, 60, 6, ["stun-spore", "sleep-powder", "supersonic", "whirlwind"]]]}, +"TRAINER_BUG_CATCHER_COLTON_4": {"ai": ["check-bad-move"], "items": [], "party": [["butterfree", 51, 120, 11, ["gust", "psybeam", "safeguard", "silver-wind"]], ["beedrill", 54, 120, 11, ["pursuit", "pin-missile", "agility", "endeavor"]], ["butterfree", 51, 120, 11, ["gust", "psybeam", "safeguard", "silver-wind"]]]}, +"TRAINER_SWIMMER_MALE_MATTHEW_2": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 49, 80, 14, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["poliwrath", 49, 80, 17, ["water-gun", "hypnosis", "double-slap", "submission"]]]}, +"TRAINER_SWIMMER_MALE_TONY_2": {"ai": ["check-bad-move"], "items": [], "party": [["seadra", 49, 80, 3, ["leer", "water-gun", "twister", "agility"]], ["seadra", 49, 80, 20, ["leer", "water-gun", "twister", "agility"]]]}, +"TRAINER_SWIMMER_FEMALE_MELISSA_2": {"ai": ["check-bad-move"], "items": [], "party": [["poliwhirl", 49, 80, 1, ["double-slap", "rain-dance", "body-slam", "belly-drum"]], ["seaking", 49, 80, 14, ["flail", "fury-attack", "waterfall", "horn-drill"]]]}, +"TRAINER_ELITE_FOUR_LORELEI_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["dewgong", 64, 255, 16, ["ice-beam", "surf", "signal-beam", "double-team"]], ["cloyster", 63, 255, 14, ["ice-beam", "surf", "supersonic", "rain-dance"]], ["piloswine", 63, 255, 8, ["blizzard", "earthquake", "double-edge", "rock-slide"]], ["jynx", 66, 255, 3, ["ice-beam", "psychic", "lovely-kiss", "attract"]], ["lapras", 66, 255, 19, ["ice-beam", "surf", "psychic", "thunder"]]]}, +"TRAINER_ELITE_FOUR_BRUNO_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["steelix", 65, 255, 12, ["earthquake", "iron-tail", "crunch", "rock-tomb"]], ["hitmonchan", 65, 255, 2, ["sky-uppercut", "mach-punch", "rock-slide", "counter"]], ["hitmonlee", 65, 255, 2, ["mega-kick", "foresight", "earthquake", "rock-slide"]], ["steelix", 66, 255, 3, ["earthquake", "iron-tail", "crunch", "dragon-breath"]], ["machamp", 68, 255, 20, ["cross-chop", "earthquake", "brick-break", "rock-slide"]]]}, +"TRAINER_ELITE_FOUR_AGATHA_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["gengar", 66, 255, 18, ["shadow-ball", "psychic", "confuse-ray", "hypnosis"]], ["crobat", 66, 255, 17, ["sludge-bomb", "air-cutter", "shadow-ball", "confuse-ray"]], ["misdreavus", 65, 255, 12, ["shadow-ball", "psychic", "thunderbolt", "attract"]], ["arbok", 68, 255, 23, ["sludge-bomb", "earthquake", "giga-drain", "double-team"]], ["gengar", 70, 255, 5, ["shadow-ball", "psychic", "thunderbolt", "sludge-bomb"]]]}, +"TRAINER_ELITE_FOUR_LANCE_2": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore"], "party": [["gyarados", 68, 255, 19, ["hyper-beam", "dragon-dance", "earthquake", "thunder-wave"]], ["dragonite", 66, 255, 11, ["hyper-beam", "earthquake", "dragon-claw", "flamethrower"]], ["kingdra", 66, 255, 22, ["hyper-beam", "dragon-dance", "surf", "ice-beam"]], ["aerodactyl", 70, 255, 21, ["hyper-beam", "ancient-power", "aerial-ace", "earthquake"]], ["dragonite", 72, 255, 13, ["hyper-beam", "outrage", "thunderbolt", "ice-beam"]]]}, +"TRAINER_CHAMPION_REMATCH_SQUIRTLE": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["heracross", 72, 255, 12, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, 255, 7, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, 255, 3, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["arcanine", 73, 255, 17, ["extreme-speed", "overheat", "aerial-ace", "iron-tail"]], ["exeggutor", 73, 255, 14, ["giga-drain", "psychic", "sleep-powder", "light-screen"]], ["blastoise", 75, 255, 16, ["hydro-pump", "ice-beam", "earthquake", "rain-dance"]]]}, +"TRAINER_CHAMPION_REMATCH_BULBASAUR": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["heracross", 72, 255, 12, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, 255, 7, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, 255, 3, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["gyarados", 73, 255, 17, ["hydro-pump", "dragon-dance", "earthquake", "hyper-beam"]], ["arcanine", 73, 255, 6, ["extreme-speed", "overheat", "aerial-ace", "iron-tail"]], ["venusaur", 75, 255, 6, ["solar-beam", "sludge-bomb", "earthquake", "sunny-day"]]]}, +"TRAINER_CHAMPION_REMATCH_CHARMANDER": {"ai": ["check-bad-move", "try-to-faint", "check-viability"], "items": ["full-restore", "full-restore", "full-restore", "full-restore"], "party": [["heracross", 72, 255, 12, ["megahorn", "earthquake", "counter", "rock-tomb"]], ["alakazam", 73, 255, 7, ["psychic", "shadow-ball", "calm-mind", "reflect"]], ["tyranitar", 72, 255, 3, ["crunch", "earthquake", "thunderbolt", "aerial-ace"]], ["exeggutor", 73, 255, 0, ["giga-drain", "psychic", "sleep-powder", "light-screen"]], ["gyarados", 73, 255, 14, ["hydro-pump", "dragon-dance", "earthquake", "hyper-beam"]], ["charizard", 75, 255, 7, ["fire-blast", "dragon-claw", "aerial-ace", "earthquake"]]]}, +"TRAINER_CUE_BALL_PAXTON": {"ai": ["check-bad-move"], "items": [], "party": [["weezing", 39, 50, 18, ["self-destruct", "sludge", "smokescreen", "haze"]], ["muk", 39, 50, 22, ["sludge", "minimize", "screech", "acid-armor"]]]} } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 9aa194324b..e2b794e28d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -28,6 +28,7 @@ #include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryBattleDecisions.h" #include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryFoeTracker.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -327,6 +328,7 @@ class BattleLoop{ , m_supplies(supplies) , m_decisions(supplies, kind) , m_evolution(supplies.lead) + , m_foes(kind == BattleKind::TRAINER ? supplies.trainer : "", supplies.lead) , m_kind(kind) , m_checks(checks) , m_language(language) @@ -397,6 +399,7 @@ class BattleLoop{ m_last_battle = now; read_hp(screen); watch_for_faint(screen); + m_foes.boxes_seen(BattleBoxes{.lead = BattlePokemonDetector(COLOR_RED).detect(screen), .foe = BattleOpponentDetector(COLOR_RED).detect(screen)}); act(seen, screen, now); return false; } @@ -598,6 +601,10 @@ class BattleLoop{ if (m_kind != BattleKind::TRAINER && m_decisions.turns() == 0){ m_supplies.wild_foes = read_wild_foes(m_console.logger(), m_language, screen); } + if (!m_foes.species().empty()){ + m_foes.at_menu(read_trainer_foe(m_console.logger(), m_language, screen, m_foes.species())); + m_supplies.foe_out = m_foes.out(); + } if (m_refusal.refused(current_time())){ m_console.log("Battle: the move list came back without a turn (Disable?); choosing another move.", COLOR_ORANGE); m_decisions.turn_done(TurnChoice::MOVE, TurnResult::REFUSED); @@ -647,6 +654,7 @@ class BattleLoop{ Supplies& m_supplies; BattleDecisions m_decisions; EvolutionHold m_evolution; + TrainerFoeTracker m_foes; BattleEndWatch m_end; MoveRefusalWatch m_refusal; const BattleKind m_kind; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index 1c074a07ad..f3a7ad74f7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -21,6 +21,8 @@ #ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattle_H #define PokemonAutomation_PokemonFRLG_AutoStoryBattle_H +#include +#include #include #include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" @@ -30,6 +32,7 @@ #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryParty.h" namespace PokemonAutomation{ @@ -73,8 +76,16 @@ struct Supplies{ std::vector protected_slots = {}; // The party of the trainer the table's battle step fights, when the // story knows it (trainer_party()): the lead's attacks are chosen - // against it. Empty otherwise; wild battles never use it. + // against it while the one out isn't known. Empty otherwise; wild + // battles never use it. std::vector foes = {}; + // That trainer (story_trainer()), "" otherwise. + std::string trainer = {}; + // How carefully that battle is fought (story_battle_risk()). + BattleRisk risk = BattleRisk::LOW; + // The slot of the trainer's party out, as the battle loop tracks it + // (TrainerFoeTracker): the lead's attacks are chosen against it. + std::optional foe_out = {}; // The wild Pokemon of the battle going on, as read at its first battle // menu (read_wild_foes()): the lead's attacks are chosen against it. // Empty when it wasn't read; trainer battles never use it. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp index 141de1a96e..4b7e4f2e3c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp @@ -6,7 +6,9 @@ #include #include +#include #include +#include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" @@ -25,11 +27,13 @@ namespace{ // step leaves the player on and the step's name. The rival's teams are // those against a player who took Squirtle. On a map with more than one // trainer of a kind, the object's tile and script (pret -// data/maps//map.json, scripts.inc) say which. +// data/maps//map.json, scripts.inc) say which. A row's `risk`, when +// set, overrides its trainer's default_battle_risk(): tune it here. struct StoryTrainer{ std::string_view map; std::string_view battle; std::string_view trainer; + std::optional risk = std::nullopt; }; constexpr StoryTrainer STORY_TRAINERS[] = { {.map = "PalletTown_ProfessorOaksLab", .battle = "rival_battle", .trainer = "TRAINER_RIVAL_OAKS_LAB_BULBASAUR"}, @@ -80,18 +84,24 @@ uint8_t byte_of(const JsonValue& value){ template using Table = std::map>; +// [power, type, pp, accuracy, priority, effect, chance] const Table& moves(){ static const Table MOVES = []{ Table moves; for (const auto& [name, value] : file_json("moves").to_object_throw()){ const JsonArray& entry = value.to_array_throw(); - moves.emplace(name, MoveData{.power = byte_of(entry[0]), .type = type_of(entry[1]), .pp = byte_of(entry[2])}); + moves.emplace(name, MoveData{ + .power = byte_of(entry[0]), .type = type_of(entry[1]), .pp = byte_of(entry[2]), + .accuracy = byte_of(entry[3]), .priority = static_cast(entry[4].to_integer_throw()), + .effect = entry[5].to_string_throw(), .effect_chance = byte_of(entry[6]), + }); } return moves; }(); return MOVES; } +// [type, type, HP, Attack, Defense, Sp. Atk, Sp. Def, Speed] const Table& species(){ static const Table SPECIES = []{ Table species; @@ -99,7 +109,10 @@ const Table& species(){ const JsonArray& entry = value.to_array_throw(); species.emplace(name, SpeciesData{ .first = type_of(entry[0]), .second = type_of(entry[1]), - .attack = byte_of(entry[2]), .sp_attack = byte_of(entry[3]), + .base = BaseStats{ + .hp = byte_of(entry[2]), .attack = byte_of(entry[3]), .defense = byte_of(entry[4]), + .sp_attack = byte_of(entry[5]), .sp_defense = byte_of(entry[6]), .speed = byte_of(entry[7]), + }, }); } return species; @@ -107,6 +120,19 @@ const Table& species(){ return SPECIES; } +// The type chart's rows in its order: (attack, defend, tenths). +const std::vector>& chart_rows(){ + static const std::vector> ROWS = []{ + std::vector> rows; + for (const JsonValue& value : file_json("type_chart").to_array_throw()){ + const JsonArray& entry = value.to_array_throw(); + rows.emplace_back(type_of(entry[0]), type_of(entry[1]), static_cast(entry[2].to_integer_throw())); + } + return rows; + }(); + return ROWS; +} + std::vector strings_of(const JsonValue& value){ std::vector strings; for (const JsonValue& item : value.to_array_throw()){ @@ -115,12 +141,27 @@ std::vector strings_of(const JsonValue& value){ return strings; } +// [species, level, iv, nature, [moves]] TrainerMon trainer_mon(const JsonArray& entry){ - TrainerMon mon{.species = entry[0].to_string_throw(), .level = byte_of(entry[1]), .moves = {}}; - if (entry.size() > 2){ - mon.moves = strings_of(entry[2]); + return TrainerMon{ + .species = entry[0].to_string_throw(), .level = byte_of(entry[1]), + .iv = byte_of(entry[2]), .nature = byte_of(entry[3]), .moves = strings_of(entry[4]), + }; +} + +// {"ai": [...], "items": [...], "party": [...]} +TrainerData trainer_entry(const JsonObject& entry){ + TrainerData data{.ai = strings_of(entry.get_value_throw("ai")), .items = strings_of(entry.get_value_throw("items")), .party = {}}; + for (const JsonValue& value : entry.get_value_throw("party").to_array_throw()){ + data.party.push_back(trainer_mon(value.to_array_throw())); } - return mon; + return data; +} + +bool starts_with_any(std::string_view text, std::initializer_list prefixes){ + return std::ranges::any_of(prefixes, [text](std::string_view prefix){ + return text.starts_with(prefix); + }); } } @@ -180,6 +221,22 @@ size_t type_effectiveness(PokemonType attack, PokemonType defend){ return it == CHART.end() ? 10 : it->second; } +std::vector type_multipliers(PokemonType attack, PokemonType first, PokemonType second){ + std::vector multipliers; + for (const auto& [row_attack, defend, tenths] : chart_rows()){ + if (row_attack != attack){ + continue; + } + if (defend == first){ + multipliers.push_back(tenths); + } + if (defend == second && first != second){ + multipliers.push_back(tenths); + } + } + return multipliers; +} + bool special_type(PokemonType type){ switch (type){ case PokemonType::FIRE: @@ -197,16 +254,30 @@ bool special_type(PokemonType type){ } std::vector trainer_mons(std::string_view trainer){ + std::optional data = trainer_data(trainer); + return data ? std::move(data->party) : std::vector{}; +} + +std::optional trainer_data(std::string_view trainer){ const JsonObject& trainers = file_json("trainers").to_object_throw(); const auto it = trainers.find(std::string(trainer)); - std::vector party; if (it == trainers.end()){ - return party; + return std::nullopt; + } + return trainer_entry(it->second.to_object_throw()); +} + +std::string read_trainer_foe(Logger& logger, Language language, const ImageViewRGB32& screen, const std::vector& party){ + if (language == Language::None || party.empty()){ + return ""; } - for (const JsonValue& value : it->second.to_array_throw()){ - party.push_back(trainer_mon(value.to_array_throw())); + const std::set species(party.begin(), party.end()); + std::string read = WildEncounterReader().read_encounter(logger, language, screen, species).name; + if (!species.contains(read)){ + read.clear(); } - return party; + logger.log(read.empty() ? "Battle: the trainer's Pokemon wasn't read." : "Battle: the trainer's " + read + " is out."); + return read; } std::vector map_trainers(std::string_view map){ @@ -224,6 +295,26 @@ std::optional story_trainer(std::string_view map, std::string_ return std::nullopt; } +const char* battle_risk_name(BattleRisk risk){ + return risk == BattleRisk::HIGH ? "high" : "low"; +} + +BattleRisk default_battle_risk(std::string_view trainer){ + const bool big = starts_with_any(trainer, { + "TRAINER_RIVAL_", "TRAINER_CHAMPION_", "TRAINER_LEADER_", "TRAINER_ELITE_FOUR_", "TRAINER_BOSS_", "TRAINER_TEAM_ROCKET_ADMIN", + }); + return big ? BattleRisk::HIGH : BattleRisk::LOW; +} + +BattleRisk story_battle_risk(std::string_view map, std::string_view battle){ + for (const StoryTrainer& entry : STORY_TRAINERS){ + if (entry.map == map && entry.battle == battle){ + return entry.risk ? *entry.risk : default_battle_risk(entry.trainer); + } + } + return BattleRisk::LOW; +} + } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h index 3172f7cbc9..cc15a6b446 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h @@ -5,9 +5,10 @@ * The game's data the story's attacks are chosen from, generated from * pret/pokefirered by devtools/maps/frlg_battle_data.py into BattleData/ * and built into the program: the type chart, every species' types and - * base Attack and Sp. Atk, every move's power, type and PP, - * every trainer's party, and the trainers each map battles. Also which - * trainer each of the story's battle steps fights. + * base stats, every move's power, type, PP, accuracy, priority and + * effect, every trainer's AI flags, items and party, and the trainers + * each map battles. Also which trainer each of the story's battle steps + * fights, and how carefully (BattleRisk). * * Names are the program's slugs ("water-gun", "mr-mime"); trainers are * pret's constants ("TRAINER_SUPER_NERD_MIGUEL"). @@ -45,23 +46,53 @@ struct MoveData{ // NONE for Curse's "???". PokemonType type = PokemonType::NONE; uint8_t pp = 0; + // In percent; 0 never misses. + uint8_t accuracy = 0; + int8_t priority = 0; + // pret's EFFECT_X as a slug: "hit", "flinch-hit", "sleep", + // "attack-down", "dragon-rage". + std::string effect = {}; + // The secondary effect's chance in percent (Bite's flinch: 30). + uint8_t effect_chance = 0; +}; + +// The base stats, in the game's order. +struct BaseStats{ + uint8_t hp = 0; + uint8_t attack = 0; + uint8_t defense = 0; + uint8_t sp_attack = 0; + uint8_t sp_defense = 0; + uint8_t speed = 0; }; struct SpeciesData{ // The same type twice for a species with one. PokemonType first = PokemonType::NONE; PokemonType second = PokemonType::NONE; - uint8_t attack = 0; - uint8_t sp_attack = 0; + BaseStats base = {}; }; struct TrainerMon{ std::string species; uint8_t level = 0; - // The moves the party gives it; empty for its level-up moves. + // pret's iv, 0 to 255: every IV is iv * 31 / 255 (CreateNPCTrainerParty). + uint8_t iv = 0; + // The nature's index (0 Hardy, 1 Lonely, ... 24 Quirky): the one the + // game's personality gives it (see frlg_battle_data.py). + uint8_t nature = 0; + // The moves the party gives it, else the level-up moves the game gives. std::vector moves; }; +struct TrainerData{ + // pret's AI flags as slugs: "check-bad-move", "try-to-faint", ... + std::vector ai = {}; + // The items the trainer can use, in order, each once ("super-potion"). + std::vector items = {}; + std::vector party = {}; +}; + // None for a move or species the data doesn't have. const MoveData* move_data(std::string_view move); const SpeciesData* species_data(std::string_view species); @@ -81,6 +112,11 @@ std::vector read_wild_foes(Logger& logger, Language language, const // How well `attack` hits `defend`, in tenths: 20 is 2x, 5 is 0.5x. size_t type_effectiveness(PokemonType attack, PokemonType defend); +// The multipliers (in tenths) a move of type `attack` meets on a Pokemon +// of types `first` and `second`, in the type chart's order, as the game +// applies them one after another (pret Cmd_typecalc); none for 1x. +std::vector type_multipliers(PokemonType attack, PokemonType first, PokemonType second); + // Gen 3 splits physical and special by type: Fire, Water, Grass, // Electric, Psychic, Ice, Dragon and Dark are special. bool special_type(PokemonType type); @@ -88,6 +124,14 @@ bool special_type(PokemonType type); // A trainer's party in order; empty for a trainer the data doesn't have. std::vector trainer_mons(std::string_view trainer); +// A trainer's AI flags, items and party; none for one the data doesn't have. +std::optional trainer_data(std::string_view trainer); + +// The Pokemon a trainer's battle shows on `screen`, a battle menu: the +// name its HP box shows (WildEncounterReader), among `party`'s species. +// Empty if not read. Logs what it read. +std::string read_trainer_foe(Logger& logger, Language language, const ImageViewRGB32& screen, const std::vector& party); + // The trainers `map`'s scripts and objects battle. std::vector map_trainers(std::string_view map); @@ -95,6 +139,28 @@ std::vector map_trainers(std::string_view map); // it leaves the player on). None for a battle the table doesn't name. std::optional story_trainer(std::string_view map, std::string_view battle); +// How carefully a battle step is fought. +enum class BattleRisk{ + // The move with the best expected damage against the foe out. + LOW, + // A battle sim (PokemonFRLG_AutoStoryBattleSim.h) picks the moves and + // Potions, and the step fails before the fight when it wins too rarely. + HIGH, +}; +const char* battle_risk_name(BattleRisk risk); + +// A trainer's risk by its kind: HIGH for the rival, gym leaders, bosses +// (Giovanni, the Rocket admins), the Elite Four and the Champion; LOW +// for the rest. +BattleRisk default_battle_risk(std::string_view trainer); + +// The risk of the story's battle step `battle` on `map`: its table row's, +// else its trainer's default. LOW for a battle the table doesn't name. +BattleRisk story_battle_risk(std::string_view map, std::string_view battle); + +// A HIGH battle is fought only if the sim wins at least this often. +inline constexpr double MIN_WIN_CHANCE = 0.70; + // (name, JSON text) of each file in BattleData/, sorted by name. // Generated at build time (SerialPrograms/cmake/EmbedTextFiles.cmake). diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp index 8e61b63dc8..42ff159fbf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp @@ -18,6 +18,7 @@ #include "PokemonFRLG_AutoStoryBattle.h" #include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryBattleDecisions.h" +#include "PokemonFRLG_AutoStoryBattleSim.h" #include "PokemonFRLG_AutoStoryParty.h" #include "PokemonFRLG_AutoStoryTable.h" @@ -83,7 +84,7 @@ UnitTestResult test_data(){ return "Expected Bite: 60 power, Dark (special in Gen 3), 25 PP."; } const SpeciesData* starmie = species_data("starmie"); - if (starmie == nullptr || starmie->first != PokemonType::WATER || starmie->second != PokemonType::PSYCHIC || starmie->sp_attack != 100){ + if (starmie == nullptr || starmie->first != PokemonType::WATER || starmie->second != PokemonType::PSYCHIC || starmie->base.sp_attack != 100){ return "Expected Starmie: Water, Psychic, base Sp. Atk 100."; } if (battle_species().size() != 386 || species_data("farfetch-d") == nullptr || species_data("missingno") != nullptr){ @@ -193,6 +194,7 @@ void add_tests_AutoStoryBattleData(UnitTestDatabase& database){ database.add("Miguel's Grimer: Water Gun", test_miguel_grimer); database.add("Bite on Psychic, Ghost and Water-resistant foes", test_bite_wins); database.add("a wild Pokemon not read: the plan's order", test_wild_fallback); + add_tests_AutoStoryBattleSim(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp index 9c979d7590..1873eac719 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -7,6 +7,7 @@ #include #include #include "PokemonFRLG_AutoStoryBattleDecisions.h" +#include "PokemonFRLG_AutoStoryBattleSim.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -48,6 +49,46 @@ constexpr size_t LOW_ATTACK_PP = 10; // The move prompts a turn can bring: two moves offered, NO then YES each. constexpr int MOVE_PROMPTS = 4; +// The trainer's Pokemon out, at full HP (its damage taken isn't read), +// when the battle loop knows which. +std::optional foe_out(const Supplies& supplies){ + if (supplies.trainer.empty() || !supplies.foe_out){ + return std::nullopt; + } + const std::vector party = trainer_mons(supplies.trainer); + return *supplies.foe_out < party.size() ? trainer_battler(party[*supplies.foe_out]) : std::nullopt; +} + +// A trainer's battle: against the foe out, the best expected damage at +// BattleRisk::LOW, the sim's planned move at HIGH (its items taken as not +// used yet); else, or while the story doesn't know all the lead's +// moves, attack_slot_against() the whole party. +std::optional trainer_attack_slot(const PartyMember& usable, const Supplies& supplies){ + const std::optional foe = foe_out(supplies); + const std::optional own = own_battler(usable); + std::optional slot; + if (foe && own && attack_slot(usable)){ + const std::optional trainer = trainer_data(supplies.trainer); + slot = supplies.risk == BattleRisk::HIGH && trainer + ? planned_attack_slot(*own, *foe, trainer->items, trainer->party.size()) + : best_damage_slot(*own, *foe); + } + return slot ? slot : attack_slot_against(usable, supplies.foes); +} + +// A Potion this turn: at BattleRisk::HIGH against a known foe, when its +// next hit could faint the lead (potion_now(), the HP from the bar's +// share) or the bar is red; else whenever the bar isn't green. +bool wants_potion(const Supplies& supplies, const PartyStatus& status){ + const bool hurt = status.hp_red || status.hp_yellow; + const std::optional foe = supplies.risk == BattleRisk::HIGH ? foe_out(supplies) : std::nullopt; + const std::optional own = own_battler(supplies.lead, status.hp_seen ? status.hp_fill : 1.0); + if (!foe || !own){ + return hurt; + } + return status.hp_red || potion_now(*own, *foe, supplies.potions); +} + } @@ -103,7 +144,7 @@ TurnAction BattleDecisions::lead_turn(const PartyStatus& status){ m_run_tries++; return TurnAction{.choice = TurnChoice::RUN}; } - if (!m_items_off && hurt && m_supplies.potions > 0){ + if (!m_items_off && m_supplies.potions > 0 && wants_potion(m_supplies, status)){ return TurnAction{.choice = TurnChoice::POTION}; } if (!m_items_off && m_psn_reads >= PSN_READS && !m_antidote_used && m_supplies.antidotes > 0){ @@ -125,7 +166,9 @@ TurnAction BattleDecisions::move_turn(){ usable.moves[refused.first].pp = 0; } } - const std::optional slot = attack_slot_against(usable, m_kind == BattleKind::TRAINER ? m_supplies.foes : m_supplies.wild_foes); + const std::optional slot = m_kind == BattleKind::TRAINER + ? trainer_attack_slot(usable, m_supplies) + : attack_slot_against(usable, m_supplies.wild_foes); if (!slot){ return TurnAction{.choice = TurnChoice::MOVE, .slot = BOTTOM_LEFT_MOVE}; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp new file mode 100644 index 0000000000..5e449a679d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp @@ -0,0 +1,523 @@ +/* AutoStory Battle Sim + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "PokemonFRLG_AutoStoryBattleSim.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +constexpr int START_SCORE = 100; +constexpr int BAD_MOVE = 10; +constexpr int CAN_FAINT = 4; +constexpr int QUICK_FAINT = 2; +constexpr int NOT_STRONGEST = 1; +constexpr int MAX_STAGE = 6; +// More turns than this to faint a foe counts as never. +constexpr size_t TURNS_CAP = 30; +// The hits a multi-hit move is taken to land when sizing a foe's hit. +constexpr uint32_t MULTI_HITS = 3; + +const MoveData& data_of(std::string_view move){ + static const MoveData NONE; + const MoveData* data = move_data(move); + return data == nullptr ? NONE : *data; +} + +size_t effectiveness(PokemonType type, const Combatant& target){ + size_t tenths = 10; + for (size_t multiplier : type_multipliers(type, target.first, target.second)){ + tenths = tenths * multiplier / 10; + } + return tenths; +} + +bool has_type(const Combatant& combatant, PokemonType type){ + return combatant.first == type || combatant.second == type; +} + +uint32_t hits_of(const MoveData& move){ + if (move.effect == "multi-hit"){ + return MULTI_HITS; + } + return move.effect == "double-hit" || move.effect == "twineedle" ? 2 : 1; +} + +uint32_t speed_of(const SimBattler& battler){ + const uint32_t speed = staged_stat(battler.body.stats.speed, battler.body.stages[static_cast(Stage::SPEED)]); + return battler.status == SimStatus::PARALYSIS ? speed / 4 : speed; +} + +bool status_effect(std::string_view effect){ + return effect == "sleep" || effect == "poison" || effect == "toxic" || effect == "paralyze"; +} + +// A stat-stage effect ("attack-down", "defense-up-2") at its limit. +bool stage_at_limit(std::string_view effect, const SimBattler& user, const SimBattler& target){ + static const std::pair STATS[] = { + {"attack-", Stage::ATTACK}, {"defense-", Stage::DEFENSE}, {"speed-", Stage::SPEED}, + {"special-attack-", Stage::SP_ATTACK}, {"special-defense-", Stage::SP_DEFENSE}, + {"accuracy-", Stage::ACCURACY}, {"evasion-", Stage::EVASION}, + }; + for (const auto& [prefix, stage] : STATS){ + if (!effect.starts_with(prefix) || effect.ends_with("-hit")){ + continue; + } + const bool up = effect.substr(prefix.size()).starts_with("up"); + const int now = (up ? user : target).body.stages[static_cast(stage)]; + return up ? now >= MAX_STAGE : now <= -MAX_STAGE; + } + return false; +} + +// AI_CheckBadMove, as the top of the header says. +bool bad_move(const MoveData& move, const SimBattler& user, const SimBattler& target){ + if (move.power > 0 && effectiveness(move.type, target.body) == 0){ + return true; + } + if (status_effect(move.effect) && target.status != SimStatus::NONE){ + return true; + } + if ((move.effect == "poison" || move.effect == "toxic") + && (has_type(target.body, PokemonType::POISON) || has_type(target.body, PokemonType::STEEL)) + ){ + return true; + } + if (move.effect == "leech-seed" && (target.seeded || has_type(target.body, PokemonType::GRASS))){ + return true; + } + if ((move.effect == "restore-hp" || move.effect == "softboiled") && user.hp >= user.body.stats.hp){ + return true; + } + return stage_at_limit(move.effect, user, target); +} + +void add_try_to_faint(std::vector& scores, const SimBattler& foe, const SimBattler& target){ + std::vector damage(foe.moves.size(), 0); + double strongest = 0; + for (size_t slot = 0; slot < foe.moves.size(); slot++){ + const MoveData& move = data_of(foe.moves[slot].move); + if (move.power > 0 && foe.moves[slot].pp > 0){ + damage[slot] = average_damage(foe.body, target.body, move) * hits_of(move); + strongest = move.power > 1 ? std::max(strongest, damage[slot]) : strongest; + } + } + for (size_t slot = 0; slot < foe.moves.size(); slot++){ + const MoveData& move = data_of(foe.moves[slot].move); + if (scores[slot] <= 0 || move.power == 0){ + continue; + } + if (damage[slot] >= target.hp){ + scores[slot] += CAN_FAINT + (move.effect == "quick-attack" ? QUICK_FAINT : 0); + }else if (move.power > 1 && damage[slot] < strongest){ + scores[slot] -= NOT_STRONGEST; + } + } +} + +// CHECK_VIABILITY's terms: HP in percent, a stage as the game's level (6 +// for none), the speed comparison, and if_random_less_than (n / 256). +int hp_percent(const SimBattler& battler){ + return battler.hp * 100 / std::max(battler.body.stats.hp, 1); +} +int level(const SimBattler& battler, Stage stage){ + return battler.body.stages[static_cast(stage)] + MAX_STAGE; +} +bool faster(const SimBattler& a, const SimBattler& b){ + return speed_of(a) > speed_of(b); +} +bool random_below(std::mt19937& rng, uint32_t n){ + return rng() % 256 < n; +} + +bool physical_type(PokemonType type){ + switch (type){ + case PokemonType::NORMAL: + case PokemonType::FIGHTING: + case PokemonType::GROUND: + case PokemonType::ROCK: + case PokemonType::BUG: + case PokemonType::STEEL: + return true; + default: + return false; + } +} + +int cv_attack_down(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ + int score = 0; + if (level(target, Stage::ATTACK) != MAX_STAGE){ + score -= user.hp * 100 > 90 * user.body.stats.hp ? 1 : 2; + score -= level(target, Stage::ATTACK) > 3 || random_below(rng, 50) ? 0 : 2; + } + score -= hp_percent(target) > 70 ? 0 : 2; + const bool physical = physical_type(target.body.first) || physical_type(target.body.second); + return score - (physical || random_below(rng, 50) ? 0 : 2); +} + +int cv_defense_down(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ + int score = 0; + if (hp_percent(user) < 70 || level(target, Stage::DEFENSE) <= 3){ + score -= random_below(rng, 50) ? 0 : 2; + } + return score - (hp_percent(target) > 70 ? 0 : 2); +} + +int cv_accuracy_down(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ + int score = 0; + if (hp_percent(user) < 70 || hp_percent(target) <= 70){ + score -= random_below(rng, 100) ? 0 : 1; + } + score -= level(user, Stage::ACCURACY) > 4 || random_below(rng, 80) ? 0 : 2; + score += target.seeded && !random_below(rng, 70) ? 2 : 0; + if (hp_percent(user) > 70 || level(target, Stage::ACCURACY) == MAX_STAGE){ + return score; + } + const bool low = hp_percent(user) < 40 || hp_percent(target) < 40; + return score - (low || !random_below(rng, 70) ? 2 : 0); +} + +int cv_toxic(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ + int score = 0; + score -= hp_percent(user) > 50 || random_below(rng, 50) ? 0 : 3; + return score - (hp_percent(target) > 50 || random_below(rng, 50) ? 0 : 3); +} + +int cv_heal(const SimBattler& user, const SimBattler& target, std::mt19937& rng){ + if (hp_percent(user) == 100){ + return -3; + } + if (!faster(target, user)){ + return -8; + } + if (hp_percent(user) >= 70 && !random_below(rng, 30)){ + return -3; + } + return random_below(rng, 20) ? 0 : 2; +} + +// CHECK_VIABILITY for the status moves (see the header). +int viability(const MoveData& move, const SimBattler& user, const SimBattler& target, std::mt19937& rng){ + const std::string_view effect = move.effect; + if (effect == "attack-down"){ + return cv_attack_down(user, target, rng); + } + if (effect == "defense-down"){ + return cv_defense_down(user, target, rng); + } + if (effect == "accuracy-down"){ + return cv_accuracy_down(user, target, rng); + } + if (effect == "speed-down"){ + return faster(target, user) ? (random_below(rng, 70) ? 0 : 2) : -3; + } + if (effect == "poison"){ + return hp_percent(user) < 50 || hp_percent(target) <= 50 ? -1 : 0; + } + if (effect == "toxic" || effect == "leech-seed"){ + return cv_toxic(user, target, rng); + } + if (effect == "paralyze"){ + return faster(target, user) ? (random_below(rng, 20) ? 0 : 3) : (hp_percent(user) > 70 ? 0 : -1); + } + if (effect == "restore-hp" || effect == "softboiled"){ + return cv_heal(user, target, rng); + } + return 0; +} + +bool has_super_effective(const SimBattler& foe, const SimBattler& lead){ + return std::ranges::any_of(foe.moves, [&lead](const SimMove& known){ + const MoveData& move = data_of(known.move); + return move.power > 0 && effectiveness(move.type, lead.body) > 10; + }); +} + +// GetMostSuitableMonToSwitchInto's first pass: the lead's two types +// (the same one twice for a single type) against each, the best +// that has a super effective move. +std::optional suitable_by_type(const std::vector& left, const std::vector& party, const SimBattler& lead){ + std::set invalid; + while (invalid.size() < left.size()){ + std::optional best; + size_t best_tenths = 0; + for (size_t slot : left){ + const size_t tenths = invalid.contains(slot) ? 0 + : effectiveness(lead.body.first, party[slot].body) * effectiveness(lead.body.second, party[slot].body) / 10; + if (!invalid.contains(slot) && tenths > best_tenths){ + best = slot; + best_tenths = tenths; + } + } + if (!best){ + return std::nullopt; + } + if (has_super_effective(party[*best], lead)){ + return best; + } + invalid.insert(*best); + } + return std::nullopt; +} + +// Its second pass: the strongest move, compared as the game's u8 does. +std::optional suitable_by_damage(const std::vector& left, const std::vector& party, const SimBattler& fainted, const SimBattler& lead){ + std::optional best; + uint8_t best_damage = 0; + for (size_t slot : left){ + for (const SimMove& known : party[slot].moves){ + const MoveData& move = data_of(known.move); + const uint32_t damage = move.power > 1 ? damage_before_roll(fainted.body, lead.body, move, false) : 0; + if (best_damage < damage){ + best_damage = static_cast(damage); + best = slot; + } + } + } + return best; +} + +uint32_t lowest_roll(const SimBattler& own, const SimBattler& foe, const MoveData& move){ + return damage_range(own.body, foe.body, move, false).min * hits_of(move); +} + +double mean_per_turn(const SimBattler& own, const SimBattler& foe, const MoveData& move){ + const double accuracy = move.accuracy == 0 ? 1.0 : move.accuracy / 100.0; + return average_damage(own.body, foe.body, move) * hits_of(move) * accuracy; +} + +// Turns to faint `foe` with `per_turn` a turn, the AI healing it as +// ai_item_choice() says. +size_t turns_to_faint(SimBattler foe, std::vector items, size_t foes_left, double per_turn){ + double hp = foe.hp; + for (size_t turn = 1; turn <= TURNS_CAP; turn++){ + foe.hp = static_cast(std::max(0.0, std::ceil(hp))); + if (const std::optional item = ai_item_choice(foe, items, foes_left)){ + hp = std::min(foe.body.stats.hp, hp + ai_item_hp(items[*item])); + items[*item].clear(); + } + hp -= per_turn; + if (hp <= 0){ + return turn; + } + } + return TURNS_CAP + 1; +} + +// The slots with PP left that do damage to `foe`. +std::vector damaging_slots(const SimBattler& own, const SimBattler& foe){ + std::vector slots; + for (size_t slot = 0; slot < own.moves.size(); slot++){ + const MoveData& move = data_of(own.moves[slot].move); + if (own.moves[slot].pp > 0 && damage_before_roll(own.body, foe.body, move, false) > 0){ + slots.push_back(slot); + } + } + return slots; +} + +} + + +std::optional own_battler(const PartyMember& lead, double hp_share, const Genes& genes){ + std::optional body = combatant(lead.species, lead.moves_through_level, genes); + if (!body){ + return std::nullopt; + } + SimBattler battler{.species = lead.species, .body = *body, .hp = 0, .moves = {}}; + battler.hp = static_cast(std::clamp(std::round(body->stats.hp * hp_share), 1, body->stats.hp)); + for (const KnownMove& known : lead.moves){ + battler.moves.push_back(SimMove{.move = known.move, .pp = known.pp}); + } + return battler; +} + +std::optional trainer_battler(const TrainerMon& mon){ + std::optional body = combatant(mon.species, mon.level, Genes{.iv = trainer_iv(mon.iv), .ev = 0, .nature = mon.nature}); + if (!body){ + return std::nullopt; + } + SimBattler battler{.species = mon.species, .body = *body, .hp = body->stats.hp, .moves = {}}; + for (const std::string& move : mon.moves){ + battler.moves.push_back(SimMove{.move = move, .pp = data_of(move).pp}); + } + return battler; +} + +std::optional sim_trainer(std::string_view trainer){ + const std::optional data = trainer_data(trainer); + if (!data || data->party.empty()){ + return std::nullopt; + } + SimTrainer sim{ + .party = {}, .items = data->items, + .check_bad_move = std::ranges::find(data->ai, "check-bad-move") != data->ai.end(), + .try_to_faint = std::ranges::find(data->ai, "try-to-faint") != data->ai.end(), + .check_viability = std::ranges::find(data->ai, "check-viability") != data->ai.end(), + }; + for (const TrainerMon& mon : data->party){ + std::optional battler = trainer_battler(mon); + if (!battler){ + return std::nullopt; + } + sim.party.push_back(std::move(*battler)); + } + return sim; +} + +uint16_t ai_item_hp(std::string_view item){ + static const std::pair HEALS[] = { + {"potion", 20}, {"super-potion", 50}, {"hyper-potion", 200}, {"max-potion", 255}, {"full-restore", 255}, + }; + for (const auto& [name, hp] : HEALS){ + if (name == item){ + return hp; + } + } + return 0; +} + +std::optional ai_item_choice(const SimBattler& foe, const std::vector& items, size_t foes_left){ + const uint16_t max_hp = foe.body.stats.hp; + for (size_t i = 0; i < items.size(); i++){ + if (i > 0 && foes_left > items.size() - i + 1){ + continue; + } + const uint16_t heal = ai_item_hp(items[i]); + if (heal == 0 || foe.hp == 0){ + continue; + } + const bool low = foe.hp < max_hp / 4; + if (low || (items[i] != "full-restore" && max_hp - foe.hp > heal)){ + return i; + } + } + return std::nullopt; +} + +std::vector ai_move_scores(const SimTrainer& trainer, const SimBattler& foe, const SimBattler& target, std::mt19937& rng){ + std::vector scores; + for (const SimMove& known : foe.moves){ + const MoveData& move = data_of(known.move); + const bool bad = trainer.check_bad_move && bad_move(move, foe, target); + const int viable = trainer.check_viability ? viability(move, foe, target, rng) : 0; + scores.push_back(known.pp == 0 ? 0 : START_SCORE - (bad ? BAD_MOVE : 0) + viable); + } + if (trainer.try_to_faint){ + add_try_to_faint(scores, foe, target); + } + return scores; +} + +size_t ai_next_foe(const std::vector& party, size_t fainted, const SimBattler& lead){ + std::vector left; + for (size_t slot = 0; slot < party.size(); slot++){ + if (slot != fainted && party[slot].hp > 0){ + left.push_back(slot); + } + } + if (left.empty()){ + return fainted; + } + if (const std::optional slot = suitable_by_type(left, party, lead)){ + return *slot; + } + if (const std::optional slot = suitable_by_damage(left, party, party[fainted], lead)){ + return *slot; + } + return left.front(); +} + +std::optional best_damage_slot(const SimBattler& own, const SimBattler& foe){ + std::optional best; + double best_damage = 0; + for (size_t slot : damaging_slots(own, foe)){ + const double damage = mean_per_turn(own, foe, data_of(own.moves[slot].move)); + if (damage > best_damage){ + best = slot; + best_damage = damage; + } + } + return best; +} + +std::optional planned_attack_slot( + const SimBattler& own, const SimBattler& foe, + const std::vector& items, size_t foes_left +){ + using Rank = std::tuple; + std::optional best; + Rank best_rank{}; + for (size_t slot : damaging_slots(own, foe)){ + const MoveData& move = data_of(own.moves[slot].move); + const bool faints = lowest_roll(own, foe, move) >= foe.hp; + const int sure = move.accuracy == 0 ? 100 : move.accuracy; + // Fewest turns, then surest, then weakest, then most PP left. + const size_t turns = faints ? 1 : turns_to_faint(foe, items, foes_left, mean_per_turn(own, foe, move)); + const Rank rank{turns, -(faints ? sure : 0), move.power, -own.moves[slot].pp}; + if (!best || rank < best_rank){ + best = slot; + best_rank = rank; + } + } + return best; +} + +uint32_t foe_max_hit(const SimBattler& foe, const SimBattler& own){ + uint32_t most = 0; + for (const SimMove& known : foe.moves){ + const MoveData& move = data_of(known.move); + if (known.pp > 0){ + most = std::max(most, damage_range(foe.body, own.body, move, false).max * hits_of(move)); + } + } + return most; +} + +bool potion_now(const SimBattler& own, const SimBattler& foe, int potions){ + const uint16_t max_hp = own.body.stats.hp; + if (potions <= 0 || own.hp >= max_hp){ + return false; + } + const uint32_t hit = foe_max_hit(foe, own); + const uint32_t healed = std::min(max_hp, own.hp + POTION_HP); + return hit >= own.hp && healed > hit; +} + +OwnTurn own_turn( + const SimBattler& own, int potions, const SimBattler& foe, + const std::vector& items, size_t foes_left +){ + const std::optional slot = planned_attack_slot(own, foe, items, foes_left); + if (slot){ + const MoveData& move = data_of(own.moves[*slot].move); + const bool foe_priority = std::ranges::any_of(foe.moves, [](const SimMove& known){ + return known.pp > 0 && data_of(known.move).priority > 0; + }); + const bool first = speed_of(own) > speed_of(foe) && !foe_priority && move.priority >= 0; + const bool sure = move.accuracy == 0 || move.accuracy >= 100; + if (first && sure && lowest_roll(own, foe, move) >= foe.hp && !ai_item_choice(foe, items, foes_left)){ + return OwnTurn{.potion = false, .slot = slot}; + } + } + if (potion_now(own, foe, potions)){ + return OwnTurn{.potion = true, .slot = std::nullopt}; + } + return OwnTurn{.potion = false, .slot = slot}; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h new file mode 100644 index 0000000000..4748c8e426 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h @@ -0,0 +1,172 @@ +/* AutoStory Battle Sim + * + * From: https://github.com/PokemonAutomation/ + * + * The story's lead against a trainer's party as Gen 3 FireRed plays it, + * for the battles fought at BattleRisk::HIGH: the Pokemon on each side, + * the trainer AI's choices (its items, its moves, its next Pokemon) and + * the lead's (its move, a Potion). PokemonFRLG_AutoStoryWinChance.h plays + * whole battles from these. + * + * The trainer's side is pret's: party, levels, IVs, natures, moves, items + * and AI flags (trainers.json). The lead's stats come from its species + * and level (PartyMember::moves_through_level, the level the story knows) + * with OWN_GENES, since the summary isn't read for stats. + * + * Approximations, from pret/pokefirered: + * - The AI's move (battle_ai_script_commands.c, data/battle_ai_scripts.s): + * every move starts at 100; CHECK_BAD_MOVE takes 10 off a move the + * target is immune to, a status the target already has, Leech Seed on + * a seeded or Grass target, and a stat change past +-6; TRY_TO_FAINT + * adds 4 to a move that faints the target at the mean roll (6 for Quick + * Attack) and takes 1 off the damaging moves that aren't its strongest; + * CHECK_VIABILITY scores the status moves the early trainers carry + * (AI_CV_AttackDown, DefenseDown, AccuracyDown, SpeedDown, Poison, + * Toxic for Leech Seed too, Paralyze, Heal) by HP, speed and stages, + * with their random parts. The best score wins, ties at random. The + * other scripts, and CHECK_VIABILITY on damaging moves, are left out. + * - The AI's items (battle_ai_switch_items.c ShouldUseItem) as the game + * has them for the HP items: Full Restore below 1/4 HP, the others + * below 1/4 or when more HP is missing than the item heals; each item + * once, and item i > 0 only once at most itemsNo - i + 1 Pokemon are + * left. Other items are not used. + * - The AI's next Pokemon (GetMostSuitableMonToSwitchInto): the one the + * lead's types hit hardest that has a super effective move against the + * lead, else the one whose strongest move does the lead most damage, + * else the first left. + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattleSim_H +#define PokemonAutomation_PokemonFRLG_AutoStoryBattleSim_H + +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonFRLG_AutoStoryBattleData.h" +#include "PokemonFRLG_AutoStoryDamage.h" +#include "PokemonFRLG_AutoStoryParty.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The lead's IVs and EVs, which the story doesn't read: middling IVs, no +// EVs, a neutral nature (Hardy). +inline constexpr Genes OWN_GENES{.iv = 15, .ev = 0, .nature = 0}; + +// HP a Potion heals. +inline constexpr uint16_t POTION_HP = 20; + +enum class SimStatus{ + NONE, + SLEEP, + POISON, // and Toxic, as plain poison + PARALYSIS, +}; + +struct SimMove{ + std::string move = {}; + uint8_t pp = 0; +}; + +// A Pokemon in the sim. +struct SimBattler{ + std::string species = {}; + Combatant body = {}; + uint16_t hp = 0; + // In the move list's slot order. + std::vector moves = {}; + SimStatus status = SimStatus::NONE; + // SLEEP: the game's counter (2 to 5): each turn takes one off, and it + // moves on the turn it reaches 0. + uint8_t sleep = 0; + bool seeded = false; +}; + +// The lead with `hp_share` of its HP (1 for full), its moves and PP as +// the story counts them. None for a species the data doesn't have. +std::optional own_battler(const PartyMember& lead, double hp_share = 1.0, const Genes& genes = OWN_GENES); + +// A trainer's Pokemon at full HP and PP. +std::optional trainer_battler(const TrainerMon& mon); + +struct SimTrainer{ + std::vector party = {}; + // Each used once; a used one becomes "". + std::vector items = {}; + bool check_bad_move = false; + bool try_to_faint = false; + bool check_viability = false; +}; +// None for a trainer the data doesn't have (or a species in its party). +std::optional sim_trainer(std::string_view trainer); + + +// The HP the AI's `item` heals (255 for all of it), 0 for one that +// doesn't heal. +uint16_t ai_item_hp(std::string_view item); + +// The item the AI uses on `foe` this turn (its index in `items`), with +// `foes_left` Pokemon on its side not fainted, none for its move. +std::optional ai_item_choice(const SimBattler& foe, const std::vector& items, size_t foes_left); + +// The scores the AI gives `foe`'s moves against `target` (see the top); +// 0 for a move with no PP. In slot order. `rng` for CHECK_VIABILITY's +// random parts. +std::vector ai_move_scores(const SimTrainer& trainer, const SimBattler& foe, const SimBattler& target, std::mt19937& rng); + +// The party slot the AI sends out after `fainted`, of the ones still up. +size_t ai_next_foe(const std::vector& party, size_t fainted, const SimBattler& lead); + + +// BattleRisk::LOW: the slot with PP left whose mean damage against `foe` +// is highest. None if no move does damage. +std::optional best_damage_slot(const SimBattler& own, const SimBattler& foe); + +// BattleRisk::HIGH: a move that faints `foe` at the lowest roll, the +// weakest of them to keep the strong moves' PP; else the one that faints +// it in the fewest turns at the mean roll and accuracy, counting the +// heals the AI would use on it from `items` (ai_item_choice()), ties to +// the weaker move. None if no move does damage. +std::optional planned_attack_slot( + const SimBattler& own, const SimBattler& foe, + const std::vector& items, size_t foes_left +); + +// The most `foe` can do to `own` with one move, no crit, highest roll. +uint32_t foe_max_hit(const SimBattler& foe, const SimBattler& own); + +// BattleRisk::HIGH: a Potion now: `foe`'s next hit could faint `own`, and +// after the Potion it couldn't. +bool potion_now(const SimBattler& own, const SimBattler& foe, int potions); + +// The lead's turn at BattleRisk::HIGH. +struct OwnTurn{ + bool potion = false; + // Not a Potion: the move's slot, none if no move does damage. + std::optional slot = std::nullopt; +}; +// planned_attack_slot()'s move when it surely faints `foe` first (the +// lead is faster, the lowest roll faints it, it never misses and the AI +// won't heal first), else a Potion if potion_now(), else that move. +OwnTurn own_turn( + const SimBattler& own, int potions, const SimBattler& foe, + const std::vector& items, size_t foes_left +); + + +// The damage calculator, the sim's choices and its win chance. +void add_tests_AutoStoryBattleSim(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp new file mode 100644 index 0000000000..dce0b63f5a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp @@ -0,0 +1,310 @@ +/* AutoStory Battle Sim Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The Gen 3 damage calculator against numbers worked by hand and the + * Elite Four Farmer's Starmie table, the move chosen against the foe out, + * the trainer AI's items and next Pokemon, and the win chance before the + * Cerulean rival. + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryBattleDecisions.h" +#include "PokemonFRLG_AutoStoryBattleSim.h" +#include "PokemonFRLG_AutoStoryFoeTracker.h" +#include "PokemonFRLG_AutoStoryWinChance.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +class Test_AutoStoryBattleSim : public UnitTest{ +public: + Test_AutoStoryBattleSim(std::string name, std::function body) + : UnitTest("PokemonFRLG::AutoStoryBattleSim - " + std::move(name)) + , m_body(std::move(body)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + std::function m_body; +}; + +constexpr std::string_view RIVAL = "TRAINER_RIVAL_CERULEAN_BULBASAUR"; +constexpr std::string_view MISTY = "TRAINER_LEADER_MISTY"; + +std::string stats_text(const Stats& s){ + return std::format("{}/{}/{}/{}/{}/{}", s.hp, s.attack, s.defense, s.sp_attack, s.sp_defense, s.speed); +} + +std::string range_text(const DamageRange& r){ + return std::format("{}-{}", r.min, r.max); +} + +// The story's Wartortle at Lv22, OWN_GENES. +Combatant wartortle22(){ + return *combatant("wartortle", 22, OWN_GENES); +} + +// The rival's Bulbasaur: Lv18, pret iv 100 (IVs 12), Hardy. +Combatant rival_bulbasaur(){ + return *combatant("bulbasaur", 18, Genes{.iv = trainer_iv(100), .ev = 0, .nature = 0}); +} + + +// Worked by hand from CalculateMonStats and CalculateBaseDamage: +// Wartortle Lv22 IV15: HP (2*59+15)*22/100+32 = 61, Attack 141*22/100+5 = 36, +// ... Bite on the Bulbasaur (Sp. Def 142*18/100+5 = 30): 36*60*10/30/50+2 +// = 16, no STAB, neutral: 13 to 16; a crit doubles the 16 before the +// roll: 27 to 32. Water Gun: 36*40*10/30/50+2 = 11, STAB 16, Grass 0.5x +// 8: 6 to 8. Its Vine Whip back: 30*35*9/43/50+2 = 6, STAB 9, Water 2x +// 18: 15 to 18. +UnitTestResult test_hand_numbers(){ + const Combatant own = wartortle22(); + const Combatant foe = rival_bulbasaur(); + if (stats_text(own.stats) != "61/36/43/36/43/33" || stats_text(foe.stats) != "46/24/24/30/30/23"){ + return "Stats: expected 61/36/43/36/43/33 and 46/24/24/30/30/23, got " + stats_text(own.stats) + " and " + stats_text(foe.stats) + "."; + } + const std::vector> cases = { + {"Bite", damage_range(own, foe, *move_data("bite"), false), "13-16"}, + {"Bite, crit", damage_range(own, foe, *move_data("bite"), true), "27-32"}, + {"Water Gun", damage_range(own, foe, *move_data("water-gun"), false), "6-8"}, + {"Vine Whip", damage_range(foe, own, *move_data("vine-whip"), false), "15-18"}, + {"Dragon Rage", damage_range(own, foe, *move_data("dragon-rage"), false), "40-40"}, + }; + for (const auto& [name, range, expected] : cases){ + if (range_text(range) != expected){ + return std::format("{}: expected {}, got {}.", name, expected, range_text(range)); + } + } + // Tail Whip's -1: Defense 24 * 10 / 15 = 16; Tackle 36*35*10/16/50+2 = 17. + Combatant whipped = foe; + whipped.stages[static_cast(Stage::DEFENSE)] = -1; + const DamageRange tackle = damage_range(own, whipped, *move_data("tackle"), false); + if (range_text(tackle) != "14-17"){ + return "Tackle after Tail Whip: expected 14-17, got " + range_text(tackle) + "."; + } + return true; +} + + +// The Elite Four Farmer's STARMIE_PLAN (PokemonFRLG_EliteFourFarmer.cpp): +// each pick "one-hit KOs each rematch opponent (min damage roll, no crit)" +// at Sp. Atk 302, Lv100. Every rematch party's Pokemon of that species. +const std::map& starmie_plan(){ + static const std::map PLAN = { + {"dewgong", "thunderbolt"}, {"cloyster", "thunderbolt"}, {"piloswine", "surf"}, + {"jynx", "surf"}, {"lapras", "thunderbolt"}, {"steelix", "surf"}, + {"hitmonchan", "psychic"}, {"hitmonlee", "psychic"}, {"machamp", "psychic"}, + {"gengar", "psychic"}, {"crobat", "thunderbolt"}, {"misdreavus", "surf"}, + {"arbok", "psychic"}, {"gyarados", "thunderbolt"}, {"dragonite", "ice-beam"}, + {"kingdra", "psychic"}, {"aerodactyl", "surf"}, {"heracross", "psychic"}, + {"alakazam", "surf"}, {"tyranitar", "surf"}, {"arcanine", "surf"}, + {"exeggutor", "ice-beam"}, {"blastoise", "thunderbolt"}, {"venusaur", "psychic"}, + {"charizard", "thunderbolt"}, + }; + return PLAN; +} + +Combatant starmie(uint16_t sp_attack){ + Combatant body = *combatant("starmie", 100, OWN_GENES); + body.stats.sp_attack = sp_attack; + body.volcano_badge = true; + return body; +} + +// The species whose pick misses the OHKO at `sp_attack`; "" for none. +std::string first_miss(uint16_t sp_attack, std::string_view only = ""){ + for (std::string_view trainer : { + "TRAINER_ELITE_FOUR_LORELEI_2", "TRAINER_ELITE_FOUR_BRUNO_2", "TRAINER_ELITE_FOUR_AGATHA_2", "TRAINER_ELITE_FOUR_LANCE_2", + "TRAINER_CHAMPION_REMATCH_SQUIRTLE", "TRAINER_CHAMPION_REMATCH_BULBASAUR", "TRAINER_CHAMPION_REMATCH_CHARMANDER", + }){ + for (const TrainerMon& mon : trainer_mons(trainer)){ + const auto pick = starmie_plan().find(mon.species); + if (pick == starmie_plan().end() || (!only.empty() && mon.species != only)){ + continue; + } + const Combatant foe = *combatant(mon.species, mon.level, Genes{.iv = trainer_iv(mon.iv), .ev = 0, .nature = mon.nature}); + const DamageRange range = damage_range(starmie(sp_attack), foe, *move_data(pick->second), false); + if (range.min < foe.stats.hp){ + return std::format("{} {} Lv{} ({} HP, {} {})", trainer, mon.species, mon.level, foe.stats.hp, pick->second, range_text(range)); + } + } + } + return ""; +} + +UnitTestResult test_elite_four_table(){ + const std::string miss = first_miss(302); + if (!miss.empty()){ + return "At Sp. Atk 302, no OHKO at the lowest roll: " + miss + "."; + } + if (first_miss(301, "kingdra").empty()){ + return "Expected Kingdra to set the 302 Sp. Atk requirement: Psychic OHKOs it at 301 too."; + } + return true; +} + + +// Misty's Staryu (Water) and Starmie (Water/Psychic): a lead with +// Thundershock and Bite thunders the Staryu (2x against 1x) and bites the +// Starmie (both 2x, Bite stronger). As the battle loop asks, with the +// foe out known; summing over the party picked one move for both. +UnitTestResult test_misty_per_foe(){ + const PartyMember lead = member_from_summary("wartortle", 22, { + {.move = "tackle", .pp = 35, .max_pp = 35}, {.move = "bite", .pp = 25, .max_pp = 25}, + {.move = "thunder-shock", .pp = 30, .max_pp = 30}, {.move = "withdraw", .pp = 40, .max_pp = 40}, + }); + for (const BattleRisk risk : {BattleRisk::LOW, BattleRisk::HIGH}){ + for (const auto& [out, expected] : {std::pair{0, 2}, {1, 1}}){ + Supplies supplies; + supplies.lead = lead; + supplies.potions = 0; + supplies.trainer = std::string(MISTY); + supplies.foes = trainer_party(MISTY); + supplies.risk = risk; + supplies.foe_out = out; + BattleDecisions decisions(supplies, BattleKind::TRAINER); + const PartyStatus green{.hp_seen = true, .hp_yellow = false, .hp_red = false, .hp_fill = 1, .status = StatusCondition::NONE}; + const size_t slot = decisions.turn(green).slot; + if (slot != expected){ + return std::format("Risk {}, foe {}: expected slot {}, got {}.", battle_risk_name(risk), out, expected, slot); + } + } + } + return true; +} + + +// ShouldUseItem for Misty's Super Potion on her Starmie (56 HP): below +// 1/4 (14) or more than 50 missing; a Full Restore only below 1/4. A +// second item waits until at most itemsNo - 1 + 1 Pokemon are left. +UnitTestResult test_ai_heal_rule(){ + SimBattler starmie = *trainer_battler(trainer_mons(MISTY)[1]); + if (starmie.body.stats.hp != 56){ + return std::format("Expected Misty's Starmie at 56 HP, got {}.", starmie.body.stats.hp); + } + const std::vector super = {"super-potion"}; + const std::vector, size_t, bool>> cases = { + {56, super, 1, false}, {20, super, 1, false}, {13, super, 1, true}, {5, super, 1, true}, + {20, {"full-restore"}, 1, false}, {13, {"full-restore"}, 1, true}, + {13, {"", "hyper-potion"}, 3, false}, {13, {"", "hyper-potion"}, 2, true}, + }; + for (const auto& [hp, items, left, uses] : cases){ + starmie.hp = hp; + if (ai_item_choice(starmie, items, left).has_value() != uses){ + return std::format("At {} HP with {} items, {} left: expected {}.", hp, items.size(), left, uses ? "an item" : "none"); + } + } + // Each item once: the heal it would use is gone after. + starmie.hp = 6; + std::vector once = super; + once[*ai_item_choice(starmie, once, 1)].clear(); + if (ai_item_choice(starmie, once, 1)){ + return "Expected the Super Potion used only once."; + } + return true; +} + + +// GetMostSuitableMonToSwitchInto against a Wartortle after the rival's +// Pidgeotto: Water hits Abra and Rattata 1x and Bulbasaur 0.25x, but +// only Bulbasaur has a move super effective on Water (Vine Whip): it +// comes next, not Abra. The tracker, with no name read, follows that. +UnitTestResult test_next_foe(){ + const PartyMember lead = grown_to(new_member("squirtle", 5), 22); + TrainerFoeTracker tracker(RIVAL, lead); + if (tracker.out() != 0){ + return "Expected the rival's Pidgeotto out first."; + } + for (int i = 0; i < 3; i++){ + tracker.boxes_seen(BattleBoxes{.lead = true, .foe = false}); + } + tracker.at_menu(""); + if (tracker.out() != 3){ + return std::format("Expected Bulbasaur (slot 3) after Pidgeotto, got {}.", tracker.out() ? std::to_string(*tracker.out()) : "none"); + } + tracker.at_menu("abra"); + if (tracker.out() != 1){ + return "Expected the name read (Abra) over the AI's choice."; + } + return true; +} + + +// The default risks: the rival and gym leaders HIGH, route trainers and +// grunts LOW. +UnitTestResult test_risks(){ + const std::vector> cases = { + {"CeruleanCity", "rival_cerulean", BattleRisk::HIGH}, + {"CeruleanCity_Gym", "misty", BattleRisk::HIGH}, + {"PewterCity_Gym", "brock", BattleRisk::HIGH}, + {"Route24", "lass_ali", BattleRisk::LOW}, + {"MtMoon_B2F", "rocket_grunt", BattleRisk::LOW}, + {"Route1", "nobody", BattleRisk::LOW}, + }; + for (const auto& [map, battle, risk] : cases){ + if (story_battle_risk(map, battle) != risk){ + return std::format("{} on {}: expected {}.", battle, map, battle_risk_name(risk)); + } + } + return true; +} + + +// The Cerulean rival (Pidgeotto, Abra, Rattata, then a Bulbasaur with +// Sleep Powder, Poison Powder and Leech Seed): the Lv22 Wartortle with 5 +// Potions that 00.15's GRIND plans for wins about a quarter of the sim's +// battles, and is refused with the reason; at Lv30 it wins over 90%. +UnitTestResult test_rival_win_chance(){ + const std::optional planned = story_win_chance(grown_to(new_member("squirtle", 5), 22), 5, 1.0, RIVAL); + const std::optional refusal = planned ? win_chance_refusal(*planned) : std::nullopt; + if (!planned || planned->chance < 0.15 || planned->chance > 0.40){ + return std::format("Lv22, 5 Potions: expected 15% to 40%, got {:.1f}%.", planned ? 100 * planned->chance : 0.0); + } + if (refusal != std::format("win chance {:.0f}% < 70%: grind first", std::floor(100 * planned->chance))){ + return "Lv22, 5 Potions: expected a refusal with the chance, got \"" + refusal.value_or("") + "\"."; + } + const std::optional ground = story_win_chance(grown_to(new_member("squirtle", 5), 30), 5, 1.0, RIVAL); + if (!ground || ground->chance < 0.90 || win_chance_refusal(*ground)){ + return std::format("Lv30, 5 Potions: expected over 90% and no refusal, got {:.1f}%.", ground ? 100 * ground->chance : 0.0); + } + return true; +} + +} + + +void add_tests_AutoStoryBattleSim(UnitTestDatabase& database){ + database.add("Gen 3 stats and damage worked by hand", test_hand_numbers); + database.add("the Elite Four Farmer's Starmie picks OHKO at Sp. Atk 302", test_elite_four_table); + database.add("Misty: Thundershock on Staryu, Bite on Starmie", test_misty_per_foe); + database.add("the trainer AI's healing items", test_ai_heal_rule); + database.add("the rival's next Pokemon when no name is read", test_next_foe); + database.add("battle risks by trainer", test_risks); + database.add("Cerulean rival: refused at Lv22, fought at Lv30", test_rival_win_chance); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp new file mode 100644 index 0000000000..a2eb5b8bf4 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp @@ -0,0 +1,175 @@ +/* AutoStory Damage + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "PokemonFRLG_AutoStoryDamage.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +constexpr uint32_t MAX_IV = 31; +constexpr uint32_t MIN_ROLL = 85; +constexpr uint32_t MAX_ROLL = 100; +constexpr uint32_t ROLLS = MAX_ROLL - MIN_ROLL + 1; +constexpr int MAX_STAGE = 6; + +// CALC_STAT with ModifyStatByNature. `index` is the nature table's: +// Attack 0, Defense 1, Speed 2, Sp. Atk 3, Sp. Def 4. +uint16_t other_stat(uint8_t base, const Genes& genes, uint8_t level, size_t index){ + uint32_t stat = (2 * base + genes.iv + genes.ev / 4) * level / 100 + 5; + const size_t raised = genes.nature / 5; + const size_t lowered = genes.nature % 5; + if (raised != lowered && index == raised){ + stat = stat * 110 / 100; + }else if (raised != lowered && index == lowered){ + stat = stat * 90 / 100; + } + return static_cast(stat); +} + +uint32_t boosted(uint32_t stat, bool badge){ + return badge ? 110 * stat / 100 : stat; +} + +// APPLY_STAT_MOD, and a crit's: the attacker's drops and the defender's +// rises are left out. +uint32_t attack_side(uint32_t stat, int stage, bool crit){ + return crit && stage <= 0 ? stat : staged_stat(stat, stage); +} +uint32_t defense_side(uint32_t stat, int stage, bool crit){ + return crit && stage >= 0 ? stat : staged_stat(stat, stage); +} + +int stage_of(const Combatant& combatant, Stage stage){ + return combatant.stages[static_cast(stage)]; +} + +// CalculateBaseDamage, for a physical or special move. +uint32_t base_damage(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit){ + const bool special = special_type(move.type); + const uint32_t attack = special + ? attack_side(boosted(attacker.stats.sp_attack, attacker.volcano_badge), stage_of(attacker, Stage::SP_ATTACK), crit) + : attack_side(boosted(attacker.stats.attack, attacker.boulder_badge), stage_of(attacker, Stage::ATTACK), crit); + const uint32_t defense = special + ? defense_side(boosted(defender.stats.sp_defense, defender.volcano_badge), stage_of(defender, Stage::SP_DEFENSE), crit) + : defense_side(boosted(defender.stats.defense, defender.soul_badge), stage_of(defender, Stage::DEFENSE), crit); + uint32_t damage = attack * move.power; + damage *= 2 * attacker.level / 5 + 2; + damage /= std::max(defense, 1); + damage /= 50; + // Only the physical branch has this. + if (!special && damage == 0){ + damage = 1; + } + return damage + 2; +} + +} + + +uint8_t trainer_iv(uint8_t pret_iv){ + return static_cast(pret_iv * MAX_IV / 255); +} + +Stats gen3_stats(const BaseStats& base, uint8_t level, const Genes& genes){ + return Stats{ + .hp = static_cast((2 * base.hp + genes.iv + genes.ev / 4) * level / 100 + level + 10), + .attack = other_stat(base.attack, genes, level, 0), + .defense = other_stat(base.defense, genes, level, 1), + .sp_attack = other_stat(base.sp_attack, genes, level, 3), + .sp_defense = other_stat(base.sp_defense, genes, level, 4), + .speed = other_stat(base.speed, genes, level, 2), + }; +} + +uint32_t staged_stat(uint32_t stat, int stage){ + stage = std::clamp(stage, -MAX_STAGE, MAX_STAGE); + // gStatStageRatios: (10 + 5n) / 10 up, 10 / (10 + 5n) down. + return stage >= 0 ? stat * (10 + 5 * stage) / 10 : stat * 10 / (10 - 5 * stage); +} + +std::optional combatant(std::string_view species, uint8_t level, const Genes& genes){ + const SpeciesData* data = species_data(species); + if (data == nullptr){ + return std::nullopt; + } + return Combatant{.first = data->first, .second = data->second, .level = level, .stats = gen3_stats(data->base, level, genes)}; +} + +std::optional fixed_damage(const MoveData& move, const Combatant& attacker){ + if (move.effect == "dragon-rage"){ + return 40; + } + if (move.effect == "sonicboom"){ + return 20; + } + if (move.effect == "level-damage"){ + return attacker.level; + } + return std::nullopt; +} + +uint32_t damage_before_roll(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit){ + if (move.power == 0 || move.type == PokemonType::NONE){ + return 0; + } + const std::vector multipliers = type_multipliers(move.type, defender.first, defender.second); + const bool immune = std::ranges::find(multipliers, 0) != multipliers.end(); + if (const std::optional fixed = fixed_damage(move, attacker)){ + return immune ? 0 : *fixed; + } + uint32_t damage = base_damage(attacker, defender, move, crit); + if (crit){ + damage *= 2; + } + if (attacker.first == move.type || attacker.second == move.type){ + damage = damage * 15 / 10; + } + for (size_t tenths : multipliers){ + damage = static_cast(damage * tenths / 10); + if (damage == 0 && tenths != 0){ + damage = 1; + } + } + return damage; +} + +uint32_t rolled_damage(uint32_t before, uint32_t percent){ + if (before == 0){ + return 0; + } + return std::max(before * percent / 100, 1); +} + +DamageRange damage_range(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit){ + const uint32_t before = damage_before_roll(attacker, defender, move, crit); + if (fixed_damage(move, attacker)){ + return DamageRange{.min = before, .max = before}; + } + return DamageRange{.min = rolled_damage(before, MIN_ROLL), .max = rolled_damage(before, MAX_ROLL)}; +} + +double average_damage(const Combatant& attacker, const Combatant& defender, const MoveData& move){ + const uint32_t before = damage_before_roll(attacker, defender, move, false); + if (fixed_damage(move, attacker)){ + return before; + } + uint32_t total = 0; + for (uint32_t percent = MIN_ROLL; percent <= MAX_ROLL; percent++){ + total += rolled_damage(before, percent); + } + return static_cast(total) / ROLLS; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h new file mode 100644 index 0000000000..745d40ebe5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h @@ -0,0 +1,123 @@ +/* AutoStory Damage + * + * From: https://github.com/PokemonAutomation/ + * + * Gen 3 stats and damage as FireRed computes them, for the story's move + * choices and battle sim (PokemonFRLG_AutoStoryBattleSim.h). From + * pret/pokefirered: + * - stats: CalculateMonStats (src/pokemon.c), the nature's 10% as + * ModifyStatByNature; + * - damage: CalculateBaseDamage (src/pokemon.c), whose result already + * holds the +2, then in battle_script_commands.c Cmd_damagecalc's crit + * x2, Cmd_typecalc's STAB x1.5 and type multipliers one by one in the + * type chart's order (ModulateDmgByType: at least 1 unless 0x), then + * ApplyRandomDmgMultiplier's roll of 85 to 100 percent (at least 1). + * Physical or special goes by the move's type. Stat stages (and a + * crit's ignoring of the unhelpful ones) and the player's badge boosts + * are in; burn, Reflect, Light Screen, weather, abilities and held items + * are not. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryDamage_H +#define PokemonAutomation_PokemonFRLG_AutoStoryDamage_H + +#include +#include +#include +#include +#include "PokemonFRLG_AutoStoryBattleData.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// A Pokemon's stats, in the game's order. +struct Stats{ + uint16_t hp = 0; + uint16_t attack = 0; + uint16_t defense = 0; + uint16_t sp_attack = 0; + uint16_t sp_defense = 0; + uint16_t speed = 0; +}; + +// The same IV and EV in every stat, and the nature's index (0 Hardy to +// 24 Quirky; a nature raises stat n / 5 and lowers n % 5, of Attack, +// Defense, Speed, Sp. Atk, Sp. Def). +struct Genes{ + uint8_t iv = 0; + uint8_t ev = 0; + uint8_t nature = 0; +}; + +// A trainer's Pokemon's IVs from pret's iv (0 to 255). +uint8_t trainer_iv(uint8_t pret_iv); + +Stats gen3_stats(const BaseStats& base, uint8_t level, const Genes& genes); + +// The stat stages the damage formula and the sim use, from -6 to +6. +enum class Stage : size_t{ + ATTACK, + DEFENSE, + SPEED, + SP_ATTACK, + SP_DEFENSE, + ACCURACY, + EVASION, +}; +inline constexpr size_t STAGES = 7; +using StatStages = std::array; + +// `stat` at `stage` (gStatStageRatios). +uint32_t staged_stat(uint32_t stat, int stage); + +// A Pokemon in battle as the damage formula sees it. +struct Combatant{ + PokemonType first = PokemonType::NONE; + PokemonType second = PokemonType::NONE; + uint8_t level = 0; + Stats stats = {}; + StatStages stages = {}; + // The player's badges that boost this Pokemon's stats by 10% + // (ShouldGetStatBadgeBoost): the Boulder Badge its Attack, the Soul + // Badge its Defense, the Volcano Badge its Sp. Atk and Sp. Def. Only + // for the player's Pokemon. + bool boulder_badge = false; + bool soul_badge = false; + bool volcano_badge = false; +}; + +// `species` at `level` with `genes`: its types and stats. +std::optional combatant(std::string_view species, uint8_t level, const Genes& genes); + +// The damage of a move whose damage doesn't come from the formula: +// Dragon Rage 40, Sonic Boom 20, Seismic Toss and Night Shade the +// attacker's level. None for the rest. +std::optional fixed_damage(const MoveData& move, const Combatant& attacker); + +// The damage before the random roll: CalculateBaseDamage (with its +2), +// the crit, STAB and the type chart. 0 for a move with no power, or one +// the defender is immune to. Fixed damage as fixed_damage() says. +uint32_t damage_before_roll(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit); + +// `before` at the random roll `percent` (85 to 100). +uint32_t rolled_damage(uint32_t before, uint32_t percent); + +struct DamageRange{ + uint32_t min = 0; + uint32_t max = 0; +}; +// The damage at the lowest roll (85) and the highest (100). +DamageRange damage_range(const Combatant& attacker, const Combatant& defender, const MoveData& move, bool crit); + +// The mean over the 16 rolls, without crits. +double average_damage(const Combatant& attacker, const Combatant& defender, const MoveData& move); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 6afda3f039..cc77668f1f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -18,6 +18,7 @@ #include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStorySummary.h" +#include "PokemonFRLG_AutoStoryWinChance.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -150,17 +151,49 @@ Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ return Pokemon::outcome_ok(to_pose(StoryPose{state.pose.map, tiles[0].next(step.direction), step.direction})); } +// Before a BattleRisk::HIGH battle the story may lose: the sim's win +// chance, the HP as the last bar read left it. Why not to fight, if so. +std::optional refuse_battle(StoryEnv& env, const StoryStep& step, std::string_view trainer){ + const Supplies& supplies = env.supplies; + if (step.may_lose || supplies.risk != BattleRisk::HIGH){ + return std::nullopt; + } + // The bar's colors, as HP: green full, yellow half, red a fifth. + const double hp_share = supplies.hp_red ? 0.2 : supplies.hurt ? 0.5 : 1.0; + const std::optional estimate = story_win_chance(supplies.lead, supplies.potions, hp_share, trainer); + if (!estimate){ + return std::nullopt; + } + env.console.log(std::format( + "Story: {} against {}: the sim wins {} of {} ({:.0f}%), {} Potions.", + step.name, trainer, estimate->wins, estimate->battles, 100 * estimate->chance, supplies.potions + )); + return win_chance_refusal(*estimate); +} + Outcome battle(StoryEnv& env, const StoryStep& step){ + const std::optional trainer = step.pose_after ? story_trainer(step.pose_after->map, step.name) : std::nullopt; + env.supplies.trainer = trainer ? std::string(*trainer) : ""; + env.supplies.risk = trainer ? story_battle_risk(step.pose_after->map, step.name) : BattleRisk::LOW; + env.supplies.foe_out.reset(); + if (const std::optional refusal = trainer ? refuse_battle(env, step, *trainer) : std::nullopt){ + env.console.log("Story: " + step.name + ": " + *refusal + ".", COLOR_RED); + return Pokemon::outcome_failed("win_chance", *refusal); + } if (advance_text(env.console, env.context, BATTLE_TEXT_TIMEOUT, true) != TextEnd::BATTLE){ return Pokemon::outcome_failed("no_battle"); } - const std::optional trainer = step.pose_after ? story_trainer(step.pose_after->map, step.name) : std::nullopt; env.supplies.foes = trainer ? trainer_party(*trainer) : std::vector{}; if (!env.supplies.foes.empty()){ - env.console.log("Story: " + step.name + " is " + std::string(*trainer) + "; attacks are chosen against the party."); + env.console.log(std::format( + "Story: {} is {}, risk {}; attacks are chosen against the foe out.", + step.name, *trainer, battle_risk_name(env.supplies.risk) + )); } const BattleEnd end = fight_battle(env.console, env.context, env.supplies, BattleKind::TRAINER, env.checks, env.language); env.supplies.foes.clear(); + env.supplies.trainer.clear(); + env.supplies.foe_out.reset(); if (end == BattleEnd::LOST && !step.may_lose){ return Pokemon::outcome_failed("blackout"); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp new file mode 100644 index 0000000000..ce5fb1c586 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp @@ -0,0 +1,77 @@ +/* AutoStory Foe Tracker + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonFRLG_AutoStoryFoeTracker.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// Looks in a row with the foe's box gone and the lead's there: a faint, +// not a frame between two animations (as for the lead's, FAINT_POLLS in +// PokemonFRLG_AutoStoryBattle.cpp). +constexpr int FOE_GONE_POLLS = 3; + +} + + +TrainerFoeTracker::TrainerFoeTracker(std::string_view trainer, const PartyMember& lead) + : m_lead(own_battler(lead)) +{ + const std::optional sim = trainer.empty() ? std::nullopt : sim_trainer(trainer); + if (!sim){ + return; + } + m_party = sim->party; + for (const SimBattler& battler : m_party){ + m_species.push_back(battler.species); + } +} + +void TrainerFoeTracker::boxes_seen(BattleBoxes boxes){ + if (m_party.empty() || boxes.foe || !boxes.lead){ + m_gone_polls = boxes.foe ? 0 : m_gone_polls; + return; + } + if (++m_gone_polls == FOE_GONE_POLLS && !m_next_due){ + m_fainted.insert(m_out); + m_party[m_out].hp = 0; + m_next_due = true; + } +} + +void TrainerFoeTracker::at_menu(std::string_view read){ + if (m_party.empty()){ + return; + } + if (m_next_due && m_lead){ + m_out = ai_next_foe(m_party, m_out, *m_lead); + } + m_next_due = false; + if (read.empty() || m_species[m_out] == read){ + return; + } + // The name says otherwise: the first of that species not fainted. + for (size_t slot = 0; slot < m_party.size(); slot++){ + if (m_species[slot] == read && !m_fainted.contains(slot)){ + m_out = slot; + return; + } + } +} + +std::optional TrainerFoeTracker::out() const{ + return m_party.empty() ? std::nullopt : std::optional(m_out); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h new file mode 100644 index 0000000000..2dc37a8b90 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h @@ -0,0 +1,72 @@ +/* AutoStory Foe Tracker + * + * From: https://github.com/PokemonAutomation/ + * + * Which of a trainer's Pokemon is out, in a story battle whose trainer + * the story knows, so the lead's move is chosen against that one. The + * name in the foe's HP box is read at each battle menu + * (read_trainer_foe()). When it isn't read, the tracker goes by the game: + * the party's first Pokemon opens, a foe faints when its box is gone + * while the lead's stays, and the next one is the AI's choice + * (ai_next_foe()) against the lead. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryFoeTracker_H +#define PokemonAutomation_PokemonFRLG_AutoStoryFoeTracker_H + +#include +#include +#include +#include +#include +#include +#include "PokemonFRLG_AutoStoryBattleSim.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Which HP boxes a battle screen shows. +struct BattleBoxes{ + bool lead = false; + bool foe = false; +}; + +class TrainerFoeTracker{ +public: + // `trainer`: pret's constant, or "" when the battle's trainer isn't + // known (then nothing is tracked). `lead`: the story's lead, for the + // AI's next Pokemon. + TrainerFoeTracker(std::string_view trainer, const PartyMember& lead); + + // The species in the party, for reading the name. + const std::vector& species() const{ return m_species; } + + // At each look at a battle screen. + void boxes_seen(BattleBoxes boxes); + + // At a battle menu, with the foe's species as read ("" if not read). + void at_menu(std::string_view read); + + // The party slot out; none when the trainer isn't known. + std::optional out() const; + +private: + std::vector m_party; + std::vector m_species; + std::optional m_lead; + std::set m_fainted; + size_t m_out = 0; + int m_gone_polls = 0; + // A foe fainted, and no menu since: the next one isn't known yet. + bool m_next_due = false; +}; + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp index 8e474b2dd1..383e12d0d1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp @@ -196,7 +196,7 @@ void take_level(PartyMember& member, uint8_t level){ // The base stat `attacker` uses `move` with: Attack or Sp. Atk, by the // move's type. uint8_t attacking_stat(const SpeciesData& attacker, const MoveData& move){ - return special_type(move.type) ? attacker.sp_attack : attacker.attack; + return special_type(move.type) ? attacker.base.sp_attack : attacker.base.attack; } // In tenths. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp new file mode 100644 index 0000000000..dd22731552 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp @@ -0,0 +1,388 @@ +/* AutoStory Win Chance + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "PokemonFRLG_AutoStoryWinChance.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// A battle still going after this many turns counts as lost. +constexpr size_t MAX_TURNS = 100; +constexpr uint32_t CRIT_CHANCE = 16; +constexpr uint32_t HIGH_CRIT_CHANCE = 8; +constexpr int MAX_STAGE = 6; + +// sAccuracyStageRatios, -6 to +6, in hundredths. +constexpr uint32_t ACCURACY_RATIOS[] = {33, 36, 43, 50, 60, 75, 100, 133, 166, 200, 233, 266, 300}; + +const MoveData& data_of(std::string_view move){ + static const MoveData NONE; + const MoveData* data = move_data(move); + return data == nullptr ? NONE : *data; +} + +int8_t& stage(SimBattler& battler, Stage which){ + return battler.body.stages[static_cast(which)]; +} + +uint16_t eighth(const SimBattler& battler){ + return std::max(battler.body.stats.hp / 8, 1); +} + +void lose_hp(SimBattler& battler, uint32_t damage){ + battler.hp = static_cast(battler.hp > damage ? battler.hp - damage : 0); +} + +void gain_hp(SimBattler& battler, uint32_t heal){ + battler.hp = static_cast(std::min(battler.body.stats.hp, battler.hp + heal)); +} + +// "attack-down", "speed-up-2", "defense-down-hit": the stage, by how much +// and on whom. None for another effect. +struct StageChange{ + Stage stat = Stage::ATTACK; + int amount = 0; + bool on_user = false; +}; +std::optional stage_change(std::string_view effect){ + static const std::pair STATS[] = { + {"attack-", Stage::ATTACK}, {"defense-", Stage::DEFENSE}, {"speed-", Stage::SPEED}, + {"special-attack-", Stage::SP_ATTACK}, {"special-defense-", Stage::SP_DEFENSE}, + {"accuracy-", Stage::ACCURACY}, {"evasion-", Stage::EVASION}, + }; + for (const auto& [prefix, stat] : STATS){ + if (!effect.starts_with(prefix)){ + continue; + } + std::string_view rest = effect.substr(prefix.size()); + if (rest.ends_with("-hit")){ + rest.remove_suffix(4); + } + const bool up = rest.starts_with("up"); + if (!up && !rest.starts_with("down")){ + return std::nullopt; + } + const int amount = rest.ends_with("-2") ? 2 : 1; + return StageChange{.stat = stat, .amount = up ? amount : -amount, .on_user = up}; + } + return std::nullopt; +} + +void change_stage(SimBattler& user, SimBattler& target, std::string_view effect){ + if (const std::optional change = stage_change(effect)){ + int8_t& now = stage(change->on_user ? user : target, change->stat); + now = static_cast(std::clamp(now + change->amount, -MAX_STAGE, MAX_STAGE)); + } +} + + +// One battle, played once. +class SimBattle{ +public: + SimBattle(const SimBattler& own, int potions, const SimTrainer& trainer, std::mt19937& rng) + : m_own(own) + , m_potions(potions) + , m_trainer(trainer) + , m_rng(rng) + {} + + bool won(){ + for (size_t turn = 0; turn < MAX_TURNS; turn++){ + play_turn(); + if (m_own.hp == 0){ + return false; + } + if (foe().hp == 0 && !send_next()){ + return true; + } + } + return false; + } + +private: + SimBattler& foe(){ + return m_trainer.party[m_out]; + } + + size_t foes_left() const{ + return static_cast(std::ranges::count_if(m_trainer.party, [](const SimBattler& battler){ + return battler.hp > 0; + })); + } + + bool send_next(){ + if (foes_left() == 0){ + return false; + } + m_out = ai_next_foe(m_trainer.party, m_out, m_own); + return true; + } + + uint32_t random(uint32_t n){ + return static_cast(m_rng() % n); + } + + // The AI's move: the best score, ties at random. None with no PP left. + std::optional foe_move(){ + const std::vector scores = ai_move_scores(m_trainer, foe(), m_own, m_rng); + const int best = scores.empty() ? 0 : *std::ranges::max_element(scores); + std::vector ties; + for (size_t slot = 0; slot < scores.size(); slot++){ + if (best > 0 && scores[slot] == best){ + ties.push_back(slot); + } + } + if (ties.empty()){ + return std::nullopt; + } + return ties[random(static_cast(ties.size()))]; + } + + void play_turn(){ + const size_t left = foes_left(); + const OwnTurn own = own_turn(m_own, m_potions, foe(), m_trainer.items, left); + const std::optional item = ai_item_choice(foe(), m_trainer.items, left); + const std::optional foe_slot = item ? std::nullopt : foe_move(); + if (own.potion){ + gain_hp(m_own, POTION_HP); + m_potions--; + } + if (item){ + gain_hp(foe(), ai_item_hp(m_trainer.items[*item])); + m_trainer.items[*item].clear(); + } + const std::string own_move = own.potion ? "" : own.slot ? m_own.moves[*own.slot].move : "struggle"; + const std::string foe_used = item ? "" : foe_slot ? foe().moves[*foe_slot].move : "struggle"; + play_moves(own_move, own.slot, foe_used, foe_slot); + end_of_turn(); + } + + bool own_first(const std::string& own_move, const std::string& foe_used){ + const int own_priority = data_of(own_move).priority; + const int foe_priority = data_of(foe_used).priority; + if (own_priority != foe_priority){ + return own_priority > foe_priority; + } + const uint32_t own_speed = speed(m_own); + const uint32_t foe_speed = speed(foe()); + return own_speed != foe_speed ? own_speed > foe_speed : random(2) == 0; + } + + void play_moves(const std::string& own_move, std::optional own_slot, const std::string& foe_used, std::optional foe_slot){ + m_flinched = false; + const bool first = own_move.empty() || foe_used.empty() || own_first(own_move, foe_used); + if (first){ + use(m_own, foe(), own_move, own_slot, true); + use(foe(), m_own, foe_used, foe_slot, false); + }else{ + use(foe(), m_own, foe_used, foe_slot, true); + use(m_own, foe(), own_move, own_slot, false); + } + } + + static uint32_t speed(const SimBattler& battler){ + const uint32_t speed = staged_stat(battler.body.stats.speed, battler.body.stages[static_cast(Stage::SPEED)]); + return battler.status == SimStatus::PARALYSIS ? speed / 4 : speed; + } + + // Whether `user` gets to move: sleep, flinch, paralysis. + bool can_move(SimBattler& user, bool moves_first){ + if (user.status == SimStatus::SLEEP){ + if (--user.sleep > 0){ + return false; + } + user.status = SimStatus::NONE; + } + if (!moves_first && m_flinched){ + return false; + } + return user.status != SimStatus::PARALYSIS || random(4) != 0; + } + + bool hits(const SimBattler& user, const SimBattler& target, const MoveData& move){ + if (move.accuracy == 0){ + return true; + } + const int buff = std::clamp( + user.body.stages[static_cast(Stage::ACCURACY)] - target.body.stages[static_cast(Stage::EVASION)], + -MAX_STAGE, MAX_STAGE + ); + const uint32_t chance = move.accuracy * ACCURACY_RATIOS[buff + MAX_STAGE] / 100; + return random(100) + 1 <= chance; + } + + void use(SimBattler& user, SimBattler& target, const std::string& move_name, std::optional slot, bool moves_first){ + if (move_name.empty() || user.hp == 0 || target.hp == 0 || !can_move(user, moves_first)){ + return; + } + if (slot && user.moves[*slot].pp > 0){ + user.moves[*slot].pp--; + } + const MoveData& move = data_of(move_name); + if (!hits(user, target, move)){ + return; + } + if (move.power > 0){ + strike(user, target, move, moves_first); + }else{ + apply_status_move(user, target, move); + } + } + + uint32_t hit_count(const MoveData& move){ + if (move.effect == "double-hit" || move.effect == "twineedle"){ + return 2; + } + if (move.effect != "multi-hit"){ + return 1; + } + // Cmd_setmultihitcounter: 2 or 3 at 3/8 each, 4 or 5 at 1/8 each. + const uint32_t first = random(4); + return first > 1 ? random(4) + 2 : first + 2; + } + + uint32_t one_hit(const SimBattler& user, const SimBattler& target, const MoveData& move){ + if (move.effect == "super-fang"){ + return std::max(target.hp / 2, 1); + } + const bool crit = random(move.effect == "high-critical" ? HIGH_CRIT_CHANCE : CRIT_CHANCE) == 0; + const uint32_t before = damage_before_roll(user.body, target.body, move, crit); + return fixed_damage(move, user.body) ? before : rolled_damage(before, 100 - random(16)); + } + + void strike(SimBattler& user, SimBattler& target, const MoveData& move, bool moves_first){ + const uint32_t count = hit_count(move); + uint32_t dealt = 0; + for (uint32_t i = 0; i < count && target.hp > 0; i++){ + const uint32_t damage = std::min(one_hit(user, target, move), target.hp); + lose_hp(target, damage); + dealt += damage; + } + if (move.effect == "absorb"){ + gain_hp(user, std::max(dealt / 2, 1)); + } + if (dealt > 0 && target.hp > 0 && random(100) < move.effect_chance){ + secondary(user, target, move, moves_first); + } + } + + void secondary(SimBattler& user, SimBattler& target, const MoveData& move, bool moves_first){ + if (move.effect == "flinch-hit" || move.effect == "flinch-minimize-hit"){ + m_flinched = moves_first; + }else if (move.effect == "poison-hit"){ + set_status(target, SimStatus::POISON); + }else if (move.effect == "paralyze-hit"){ + set_status(target, SimStatus::PARALYSIS); + }else{ + change_stage(user, target, move.effect); + } + } + + void set_status(SimBattler& target, SimStatus status){ + if (target.status != SimStatus::NONE){ + return; + } + const bool poison_proof = target.body.first == PokemonType::POISON || target.body.second == PokemonType::POISON + || target.body.first == PokemonType::STEEL || target.body.second == PokemonType::STEEL; + if (status == SimStatus::POISON && poison_proof){ + return; + } + target.status = status; + if (status == SimStatus::SLEEP){ + target.sleep = static_cast(2 + random(4)); + } + } + + void apply_status_move(SimBattler& user, SimBattler& target, const MoveData& move){ + if (move.effect == "sleep"){ + set_status(target, SimStatus::SLEEP); + }else if (move.effect == "poison" || move.effect == "toxic"){ + set_status(target, SimStatus::POISON); + }else if (move.effect == "paralyze"){ + set_status(target, SimStatus::PARALYSIS); + }else if (move.effect == "leech-seed"){ + const bool grass = target.body.first == PokemonType::GRASS || target.body.second == PokemonType::GRASS; + target.seeded = target.seeded || !grass; + }else if (move.effect == "restore-hp" || move.effect == "softboiled"){ + gain_hp(user, user.body.stats.hp / 2); + }else{ + change_stage(user, target, move.effect); + } + } + + void end_of_turn(){ + for (SimBattler* battler : {&m_own, &foe()}){ + if (battler->hp > 0 && battler->status == SimStatus::POISON){ + lose_hp(*battler, eighth(*battler)); + } + } + seed(m_own, foe()); + seed(foe(), m_own); + } + + static void seed(SimBattler& seeded, SimBattler& other){ + if (!seeded.seeded || seeded.hp == 0 || other.hp == 0){ + return; + } + const uint16_t drained = std::min(eighth(seeded), seeded.hp); + lose_hp(seeded, drained); + gain_hp(other, drained); + } + + SimBattler m_own; + int m_potions; + SimTrainer m_trainer; + std::mt19937& m_rng; + size_t m_out = 0; + bool m_flinched = false; +}; + +} + + +WinEstimate estimate_win_chance(const SimBattler& own, int potions, const SimTrainer& trainer, size_t battles, uint32_t seed){ + std::mt19937 rng(seed); + WinEstimate estimate{.battles = battles, .wins = 0, .chance = 0}; + for (size_t i = 0; i < battles; i++){ + SimBattle battle(own, potions, trainer, rng); + estimate.wins += battle.won() ? 1 : 0; + } + estimate.chance = battles == 0 ? 0 : static_cast(estimate.wins) / battles; + return estimate; +} + +std::optional story_win_chance(const PartyMember& lead, int potions, double hp_share, std::string_view trainer){ + const std::optional own = own_battler(lead, hp_share); + const std::optional sim = sim_trainer(trainer); + if (!own || !sim){ + return std::nullopt; + } + return estimate_win_chance(*own, potions, *sim); +} + +std::optional win_chance_refusal(const WinEstimate& estimate, double minimum){ + if (estimate.chance >= minimum){ + return std::nullopt; + } + return std::format( + "win chance {:.0f}% < {:.0f}%: grind first", + std::floor(100 * estimate.chance), std::round(100 * minimum) + ); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h new file mode 100644 index 0000000000..31c2315b5f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h @@ -0,0 +1,63 @@ +/* AutoStory Win Chance + * + * From: https://github.com/PokemonAutomation/ + * + * Before a BattleRisk::HIGH battle: how often the lead beats the trainer, + * by playing the battle many times over (Monte Carlo) with the choices + * of PokemonFRLG_AutoStoryBattleSim.h and the game's random parts: the + * damage roll, crits (1/16, 1/8 for a high-crit move), accuracy with + * accuracy and evasion stages, speed ties, secondary effects, and the + * AI's ties. Too low a chance stops the story before the fight, for a + * GRIND or the nurse first. + * + * Each turn: the Potion and the AI's item first, then the moves by + * priority and speed (a quarter with PARALYSIS). Sleep (2 to 5 on the + * game's counter), poison (1/8 HP a turn), paralysis (1/4 no move), Leech + * Seed (1/8 a turn to the other side), flinch, one- and two-stage stat + * changes, multi-hit moves (2 to 5 as the game draws them), drain (half) + * and Recover (half) are played; burn, freeze, confusion, recoil, + * recharge, two-turn moves, trapping, abilities and held items are not. + * The lead is never switched out: a fainted lead is a lost battle. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryWinChance_H +#define PokemonAutomation_PokemonFRLG_AutoStoryWinChance_H + +#include +#include +#include +#include +#include +#include "PokemonFRLG_AutoStoryBattleSim.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +struct WinEstimate{ + size_t battles = 0; + size_t wins = 0; + // wins / battles + double chance = 0; +}; + +// `own` with `potions` Potions against `trainer`, `battles` times, from a +// fixed `seed` so the same inputs give the same estimate. +WinEstimate estimate_win_chance(const SimBattler& own, int potions, const SimTrainer& trainer, size_t battles = 1000, uint32_t seed = 1); + +// The story's lead (`hp_share` of its HP) with `potions` against +// `trainer`. None if the data lacks the lead's species or the trainer. +std::optional story_win_chance(const PartyMember& lead, int potions, double hp_share, std::string_view trainer); + +// Why not to fight: "win chance 41% < 70%: grind first", or none at +// `minimum` or above. +std::optional win_chance_refusal(const WinEstimate& estimate, double minimum = MIN_WIN_CHANCE); + + + +} +} +} +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 3ef0ca6a55..c99a56150f 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1846,8 +1846,15 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryDamage.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h @@ -1856,6 +1863,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EliteFourFarmer.cpp diff --git a/devtools/maps/frlg_battle_data.py b/devtools/maps/frlg_battle_data.py index b56cabb61c..d89c74e5ec 100644 --- a/devtools/maps/frlg_battle_data.py +++ b/devtools/maps/frlg_battle_data.py @@ -8,11 +8,20 @@ - src/battle_main.c gTypeEffectiveness: type_chart.json, each pairing that isn't 1x, in tenths; - src/data/pokemon/species_info.h: species.json, every species' two types - and base Attack and Sp. Atk; -- src/data/battle_moves.h: moves.json, every move's power, type and PP; + and base stats: HP, Attack, Defense, Sp. Atk, Sp. Def, Speed; +- src/data/battle_moves.h: moves.json, every move's power, type, PP, + accuracy, priority, effect (EFFECT_FLINCH_HIT is "flinch-hit") and its + secondary effect's chance; - src/data/trainers.h and src/data/trainer_parties.h: trainers.json, every - trainer's party: species, level, and the moves where the party gives them - (not the Ruby/Sapphire placeholders, DUMMY_TRAINER_MON); + trainer's AI flags (AI_SCRIPT_TRY_TO_FAINT is "try-to-faint"), items and + party (not the Ruby/Sapphire placeholders, DUMMY_TRAINER_MON): each + member's species, level, iv (0 to 255, as pret has it), nature and moves. + A party that gives no moves gets the game's (GiveBoxMonInitialMoveset: + the last four of its level-up moves up to its level, from + src/data/pokemon/level_up_learnsets.h). The nature is the one + CreateNPCTrainerParty's personality gives: a hash of the trainer's and + the species' names (charmap.txt) on top of 0x78 for a female trainer, + 0x80 for a double battle, else 0x88, mod 25; - data/maps/*/scripts.inc, map.json and data/scripts/trainers.inc: map_trainers.json, the trainers each map battles (trainerbattle_* TRAINER_X in its scripts or its objects'). @@ -42,6 +51,8 @@ } # Not species a battle can show. SKIPPED_SPECIES = re.compile(r'NONE$|EGG$|OLD_UNOWN_') +# The AI flags, as include/constants/battle_ai.h names them. +AI_FLAG = re.compile(r'AI_SCRIPT_(\w+)') # gTypeEffectiveness's multipliers, in tenths. MULTIPLIERS = {'TYPE_MUL_NO_EFFECT': 0, 'TYPE_MUL_NOT_EFFECTIVE': 5, 'TYPE_MUL_SUPER_EFFECTIVE': 20} @@ -81,7 +92,7 @@ def species(text): if SKIPPED_SPECIES.search(name): continue types = re.search(r'\.types\s*=\s*\{(TYPE_\w+),\s*(TYPE_\w+)\}', body) - stats = [int(field(body, f)) for f in ('baseAttack', 'baseSpAttack')] + stats = [int(field(body, f)) for f in ('baseHP', 'baseAttack', 'baseDefense', 'baseSpAttack', 'baseSpDefense', 'baseSpeed')] data[slug(name, SPECIES_SLUGS)] = [type_slug(types.group(1)), type_slug(types.group(2))] + stats return data @@ -91,36 +102,104 @@ def moves(text): for name, body in entries(text, 'MOVE'): if name == 'NONE': continue - data[slug(name, MOVE_SLUGS)] = [int(field(body, 'power')), type_slug(field(body, 'type')), int(field(body, 'pp'))] + data[slug(name, MOVE_SLUGS)] = [ + int(field(body, 'power')), type_slug(field(body, 'type')), int(field(body, 'pp')), + int(field(body, 'accuracy')), int(field(body, 'priority')), + slug(field(body, 'effect')[len('EFFECT_'):]), int(field(body, 'secondaryEffectChance')), + ] return data -def parties(text): - """sParty_X: [[species, level, [moves]?], ...].""" +def learnsets(text, pointers): + """{species slug: [(level, move slug), ...]} from level_up_learnsets.h.""" + by_name = {} + for name, body in re.findall(r'static const u16 (s\w+LevelUpLearnset)\[\]\s*=\s*\{(.*?)\};', text, re.S): + by_name[name] = [(int(lvl), slug(move, MOVE_SLUGS)) for lvl, move in re.findall(r'LEVEL_UP_MOVE\(\s*(\d+),\s*MOVE_(\w+)\)', body)] + return {slug(s, SPECIES_SLUGS): by_name[n] for s, n in re.findall(r'\[SPECIES_(\w+)\]\s*=\s*(s\w+LevelUpLearnset)', pointers)} + + +def initial_moves(learnset, level): + """GiveBoxMonInitialMoveset: each level-up move up to `level` in turn; + one already known is skipped, a fifth pushes out the first.""" + known = [] + for move_level, move in learnset: + if move_level > level: + break + if move in known: + continue + if len(known) == 4: + known.pop(0) + known.append(move) + return known + + +def charmap(text): + """{character: byte} for the single characters charmap.txt maps.""" + chars = {} + for char, code in re.findall(r"^'(\\?.)'\s*=\s*([0-9A-F]{2})\s*$", text, re.M): + chars[char[-1]] = int(code, 16) + return chars + + +def name_sum(name, chars): + return sum(chars[c] for c in name) + + +def species_names(text): + return {slug(name, SPECIES_SLUGS): value for name, value in re.findall(r'\[SPECIES_(\w+)\]\s*=\s*_\("(.*?)"\)', text)} + + +def parties(text, moves_at): + """sParty_X: [(species, level, iv, [moves]), ...]; `moves_at(species, + level)` gives a member's moves where the party doesn't.""" data = {} # A placeholder's {DUMMY_TRAINER_MON} on one line doesn't match. for name, body in re.findall(r'struct TrainerMon\w+ (sParty_\w+)\[\]\s*=\s*\{\n((?:(?!\nstatic ).)*?)\n\};', text, re.S): party = [] for mon in re.findall(r'\{(.*?)\n \}', body, re.S): - member = [slug(field(mon, 'species')[len('SPECIES_'):], SPECIES_SLUGS), int(field(mon, 'lvl'))] + species, level = slug(field(mon, 'species')[len('SPECIES_'):], SPECIES_SLUGS), int(field(mon, 'lvl')) given = re.search(r'\.moves\s*=\s*\{(.*?)\}', mon) if given: - member.append([slug(m.strip()[len('MOVE_'):], MOVE_SLUGS) for m in given.group(1).split(',') if m.strip() != 'MOVE_NONE']) - party.append(member) + moves = [slug(m.strip()[len('MOVE_'):], MOVE_SLUGS) for m in given.group(1).split(',') if m.strip() != 'MOVE_NONE'] + else: + moves = moves_at(species, level) + party.append((species, level, int(field(mon, 'iv')), moves)) data[name] = party return data -def trainers(text, party_text): - by_party = parties(party_text) +def personality_base(body): + """CreateNPCTrainerParty's personality before the name hash.""" + if field(body, 'doubleBattle') == 'TRUE': + return 0x80 + if 'F_TRAINER_FEMALE' in field(body, 'encounterMusic_gender'): + return 0x78 + return 0x88 + + +def trainers(text, party_text, learned, names, chars): + by_party = parties(party_text, lambda species, level: initial_moves(learned.get(species, []), level)) data = {} for name, body in entries(text, 'TRAINER'): if name == 'NONE': continue party = re.search(r'\.party\s*=\s*\w+\((sParty_\w+)\)', body) # Left out: the Ruby/Sapphire placeholders (DUMMY_TRAINER_MON). - if party and party.group(1) in by_party: - data['TRAINER_' + name] = by_party[party.group(1)] + if not party or party.group(1) not in by_party: + continue + trainer_sum = name_sum(re.search(r'\.trainerName\s*=\s*_\("(.*?)"\)', body).group(1), chars) + name_hash = 0 + members = [] + for species, level, iv, moves in by_party[party.group(1)]: + name_hash += trainer_sum + name_sum(names[species], chars) + nature = ((personality_base(body) + (name_hash << 8)) & 0xFFFFFFFF) % 25 + members.append([species, level, iv, nature, moves]) + items = re.search(r'\.items\s*=\s*\{(.*?)\}', body).group(1) + data['TRAINER_' + name] = { + 'ai': [slug(flag) for flag in AI_FLAG.findall(field(body, 'aiFlags') or '')], + 'items': [slug(item.strip()[len('ITEM_'):]) for item in items.split(',') if item.strip() not in ('', 'ITEM_NONE')], + 'party': members, + } return data @@ -162,7 +241,11 @@ def files(decomp): 'type_chart': json_lines(type_chart(read('src/battle_main.c'))), 'species': json_lines(species(read('src/data/pokemon/species_info.h'))), 'moves': json_lines(moves(read('src/data/battle_moves.h'))), - 'trainers': json_lines(trainers(read('src/data/trainers.h'), read('src/data/trainer_parties.h'))), + 'trainers': json_lines(trainers( + read('src/data/trainers.h'), read('src/data/trainer_parties.h'), + learnsets(read('src/data/pokemon/level_up_learnsets.h'), read('src/data/pokemon/level_up_learnset_pointers.h')), + species_names(read('src/data/text/species_names.h')), charmap(read('charmap.txt')), + )), 'map_trainers': json_lines(map_trainers(decomp)), } From e19ee3e4e9353e210db49593e495d20607bed194 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 06:27:45 -0800 Subject: [PATCH 73/75] FRLG AutoStory battle: no Potion the next hit undoes, and the sim plays the lead the summary showed Console B, 2026-11-03 (m51): at 8/60 HP against Misty's Starmie, the HIGH tier used a Potion five turns running, each undone by the next hit, then fainted with none left. At either tier a Potion is now used only if it outheals the foe's expected hit (the sim's mean, or the HP the last hit was seen to take, if more), or if it lets the lead last until it faints the foe when attacking now wouldn't; otherwise it attacks. The sim's lead was the story's: its level from moves_through_level and its stats at OWN_GENES. It now takes the summary's species, level, moves and PP, and POKEMON SKILLS' stats, with the levels since added, and the HP from the last bar read. A refusal names the chance and the lead and Potions it was played with. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 2 + .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 3 + .../PokemonFRLG_AutoStoryBattleDecisions.cpp | 54 ++++++- .../PokemonFRLG_AutoStoryBattleDecisions.h | 10 ++ .../PokemonFRLG_AutoStoryBattleSim.cpp | 61 +++++++- .../PokemonFRLG_AutoStoryBattleSim.h | 41 ++++- .../PokemonFRLG_AutoStoryBattleSim_Tests.cpp | 148 +++++++++++++++++- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 12 +- .../AutoStory/PokemonFRLG_AutoStoryParty.cpp | 20 ++- .../AutoStory/PokemonFRLG_AutoStoryParty.h | 23 ++- .../PokemonFRLG_AutoStorySummary.cpp | 27 +++- .../AutoStory/PokemonFRLG_AutoStorySummary.h | 6 +- .../PokemonFRLG_AutoStoryWinChance.cpp | 15 +- .../PokemonFRLG_AutoStoryWinChance.h | 7 +- 14 files changed, 388 insertions(+), 41 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index e2b794e28d..1e1c5b3848 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -577,6 +577,7 @@ class BattleLoop{ if (status.hp_seen){ m_supplies.hurt = status.hp_red || status.hp_yellow; m_supplies.hp_red = status.hp_red; + m_supplies.hp_fill = status.hp_fill; } m_supplies.status = status.status; } @@ -945,6 +946,7 @@ void recover_after_battle( supplies.potions--; supplies.hurt = false; supplies.hp_red = false; + supplies.hp_fill = 1.0; } } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index f3a7ad74f7..4a0d1650af 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -67,6 +67,9 @@ struct Supplies{ // screen that showed it, and no Potion or nurse healed it since. bool hurt = false; bool hp_red = false; + // The starter's HP bar's filled share at the last battle screen that + // showed it, 1 after the nurse or a Potion on the overworld. + double hp_fill = 1.0; // The starter's moves and their PP, as far as the story knows them: // a new game's Squirtle unless a checkpoint's row says otherwise. PartyMember lead = new_member("squirtle", 5); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp index 1873eac719..145b9e8c5f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -76,17 +76,33 @@ std::optional trainer_attack_slot(const PartyMember& usable, const Suppl return slot ? slot : attack_slot_against(usable, supplies.foes); } -// A Potion this turn: at BattleRisk::HIGH against a known foe, when its -// next hit could faint the lead (potion_now(), the HP from the bar's -// share) or the bar is red; else whenever the bar isn't green. -bool wants_potion(const Supplies& supplies, const PartyStatus& status){ +// A Potion this turn, against a known foe (`seen_hit` the HP its last hit +// took, 0 if not seen): at BattleRisk::HIGH when its next hit could faint +// the lead (potion_now(), the HP from the bar's share) or the bar is red, +// at LOW whenever the bar isn't green; either only if potion_pays(). +// Against a foe not known, whenever the bar isn't green, unless the last +// hit took a Potion's worth or more. +bool wants_potion(const Supplies& supplies, const PartyStatus& status, double seen_hit){ const bool hurt = status.hp_red || status.hp_yellow; - const std::optional foe = supplies.risk == BattleRisk::HIGH ? foe_out(supplies) : std::nullopt; + const std::optional foe = foe_out(supplies); const std::optional own = own_battler(supplies.lead, status.hp_seen ? status.hp_fill : 1.0); if (!foe || !own){ - return hurt; + return hurt && seen_hit < POTION_HP; + } + if (supplies.risk == BattleRisk::HIGH && potion_now(*own, *foe, supplies.potions, seen_hit)){ + return true; + } + const bool asked = supplies.risk == BattleRisk::HIGH ? status.hp_red : hurt; + return asked && potion_pays(potion_case(*own, *foe, seen_hit)); +} + +// The lead's HP from the bar's share, if it showed. +std::optional lead_hp(const Supplies& supplies, const PartyStatus& status){ + const std::optional own = own_battler(supplies.lead); + if (!status.hp_seen || !own){ + return std::nullopt; } - return status.hp_red || potion_now(*own, *foe, supplies.potions); + return status.hp_fill * own->body.stats.hp; } } @@ -95,6 +111,7 @@ bool wants_potion(const Supplies& supplies, const PartyStatus& status){ void healed_by_nurse(Supplies& supplies){ supplies.hurt = false; supplies.hp_red = false; + supplies.hp_fill = 1.0; supplies.status = StatusCondition::NONE; restore_pp(supplies.lead); } @@ -133,6 +150,9 @@ TurnAction BattleDecisions::turn(const PartyStatus& status){ TurnAction BattleDecisions::lead_turn(const PartyStatus& status){ const bool hurt = status.hp_red || status.hp_yellow; m_supplies.hurt = hurt; + if (status.hp_seen){ + m_supplies.hp_fill = status.hp_fill; + } m_supplies.status = status.status; m_psn_reads = status.status == StatusCondition::POISON ? m_psn_reads + 1 : 0; // A wild Pokemon is fought for EXP only at full strength: fighting @@ -144,7 +164,8 @@ TurnAction BattleDecisions::lead_turn(const PartyStatus& status){ m_run_tries++; return TurnAction{.choice = TurnChoice::RUN}; } - if (!m_items_off && m_supplies.potions > 0 && wants_potion(m_supplies, status)){ + see_hit(status); + if (!m_items_off && m_supplies.potions > 0 && wants_potion(m_supplies, status, m_seen_hit)){ return TurnAction{.choice = TurnChoice::POTION}; } if (!m_items_off && m_psn_reads >= PSN_READS && !m_antidote_used && m_supplies.antidotes > 0){ @@ -154,6 +175,22 @@ TurnAction BattleDecisions::lead_turn(const PartyStatus& status){ return move_turn(); } +void BattleDecisions::see_hit(const PartyStatus& status){ + if (m_supplies.foe_out != m_hit_by){ + m_seen_hit = 0; + m_hit_by = m_supplies.foe_out; + } + const std::optional hp = lead_hp(m_supplies, status); + if (hp && m_last_hp){ + const double taken = *m_last_hp + (m_healed ? POTION_HP : 0) - *hp; + if (taken > 0){ + m_seen_hit = taken; + } + } + m_last_hp = hp; + m_healed = false; +} + // The plan's attack with PP left, or against known foes (a trainer's // party, the wild Pokemon read), the one that does them most damage. While the story doesn't know // all four moves, the bottom left one (Bubble from Lv7), which the cursor @@ -214,6 +251,7 @@ void BattleDecisions::turn_done(TurnChoice choice, TurnResult result){ } switch (choice){ case TurnChoice::POTION: + m_healed = true; m_supplies.potions--; m_supplies.hurt = false; m_supplies.hp_red = false; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h index 7505efae52..7d5e8e1736 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h @@ -121,6 +121,8 @@ class BattleDecisions{ private: TurnAction lead_turn(const PartyStatus& status); TurnAction move_turn(); + // The HP the lead lost since the last turn, from the bar. + void see_hit(const PartyStatus& status); void count_down_refused(); void move_refused(); @@ -141,6 +143,14 @@ class BattleDecisions{ // A YES/NO before the next turn means nothing was forgotten. std::optional m_before_forget; std::optional m_last_move_slot; + // The lead's HP at the last turn, from the bar, and whether a Potion + // was used on it since. + std::optional m_last_hp; + bool m_healed = false; + // The HP the last hit seen took, from the foe out `m_hit_by`; 0 if none + // was seen. + double m_seen_hit = 0; + std::optional m_hit_by; // The slots the game turned down, and the turns until they are tried again. std::map m_refused; // The members sent in after the lead fainted. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp index 5e449a679d..23e7f10f78 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp @@ -330,10 +330,26 @@ std::vector damaging_slots(const SimBattler& own, const SimBattler& foe) std::optional own_battler(const PartyMember& lead, double hp_share, const Genes& genes){ - std::optional body = combatant(lead.species, lead.moves_through_level, genes); + std::optional body = combatant(lead.species, battle_level(lead), genes); if (!body){ return std::nullopt; } + if (lead.stats && lead.level > 0){ + // The stats read, and what the levels since add with `genes`. + const Stats then = combatant(lead.species, lead.level, genes)->stats; + const Stats now = body->stats; + const auto grown = [](uint16_t read, uint16_t before, uint16_t after){ + return static_cast(read + after - before); + }; + body->stats = Stats{ + .hp = grown(lead.stats->hp, then.hp, now.hp), + .attack = grown(lead.stats->attack, then.attack, now.attack), + .defense = grown(lead.stats->defense, then.defense, now.defense), + .sp_attack = grown(lead.stats->sp_attack, then.sp_attack, now.sp_attack), + .sp_defense = grown(lead.stats->sp_defense, then.sp_defense, now.sp_defense), + .speed = grown(lead.stats->speed, then.speed, now.speed), + }; + } SimBattler battler{.species = lead.species, .body = *body, .hp = 0, .moves = {}}; battler.hp = static_cast(std::clamp(std::round(body->stats.hp * hp_share), 1, body->stats.hp)); for (const KnownMove& known : lead.moves){ @@ -484,14 +500,51 @@ uint32_t foe_max_hit(const SimBattler& foe, const SimBattler& own){ return most; } -bool potion_now(const SimBattler& own, const SimBattler& foe, int potions){ +PotionCase potion_case(const SimBattler& own, const SimBattler& foe, double seen_hit){ + double expected = 0; + for (const SimMove& known : foe.moves){ + if (known.pp > 0){ + expected = std::max(expected, mean_per_turn(foe, own, data_of(known.move))); + } + } + const std::optional slot = planned_attack_slot(own, foe, {}, 1); + const size_t turns = slot + ? turns_to_faint(foe, {}, 1, mean_per_turn(own, foe, data_of(own.moves[*slot].move))) + : TURNS_CAP + 1; + // A faster foe hits before each of the lead's attacks, a slower one + // only between them. + const size_t hits = speed_of(foe) >= speed_of(own) ? turns : turns - 1; + return PotionCase{ + .hp = own.hp, + .max_hp = own.body.stats.hp, + .expected_hit = std::max(expected, seen_hit), + .max_hit = std::max(foe_max_hit(foe, own), static_cast(std::ceil(seen_hit))), + .hits_to_ko = hits, + }; +} + +bool potion_pays(const PotionCase& c){ + const uint16_t heal = static_cast(std::min(POTION_HP, c.max_hp - c.hp)); + if (heal == 0){ + return false; + } + const double healed = c.hp + heal; + if (heal > c.expected_hit && healed > c.expected_hit){ + return true; + } + const bool lasts_if_healed = healed > c.expected_hit * static_cast(c.hits_to_ko + 1); + const bool lasts_now = c.hp > c.expected_hit * static_cast(c.hits_to_ko); + return lasts_if_healed && !lasts_now; +} + +bool potion_now(const SimBattler& own, const SimBattler& foe, int potions, double seen_hit){ const uint16_t max_hp = own.body.stats.hp; if (potions <= 0 || own.hp >= max_hp){ return false; } - const uint32_t hit = foe_max_hit(foe, own); + const PotionCase c = potion_case(own, foe, seen_hit); const uint32_t healed = std::min(max_hp, own.hp + POTION_HP); - return hit >= own.hp && healed > hit; + return c.max_hit >= own.hp && healed > c.max_hit && potion_pays(c); } OwnTurn own_turn( diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h index 4748c8e426..d5e142d2b7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h @@ -9,9 +9,10 @@ * whole battles from these. * * The trainer's side is pret's: party, levels, IVs, natures, moves, items - * and AI flags (trainers.json). The lead's stats come from its species - * and level (PartyMember::moves_through_level, the level the story knows) - * with OWN_GENES, since the summary isn't read for stats. + * and AI flags (trainers.json). The lead is what its summary showed + * when the run started (species, level, moves and PP, stats from POKEMON + * SKILLS), with the levels since (battle_level()) added at OWN_GENES; + * without a summary, its species and battle_level() at OWN_GENES. * * Approximations, from pret/pokefirered: * - The AI's move (battle_ai_script_commands.c, data/battle_ai_scripts.s): @@ -90,7 +91,9 @@ struct SimBattler{ }; // The lead with `hp_share` of its HP (1 for full), its moves and PP as -// the story counts them. None for a species the data doesn't have. +// the story counts them, at battle_level(): its stats as read +// (PartyMember::stats) plus what the levels since add with `genes`, else +// from `genes`. None for a species the data doesn't have. std::optional own_battler(const PartyMember& lead, double hp_share = 1.0, const Genes& genes = OWN_GENES); // A trainer's Pokemon at full HP and PP. @@ -142,9 +145,33 @@ std::optional planned_attack_slot( // The most `foe` can do to `own` with one move, no crit, highest roll. uint32_t foe_max_hit(const SimBattler& foe, const SimBattler& own); -// BattleRisk::HIGH: a Potion now: `foe`'s next hit could faint `own`, and -// after the Potion it couldn't. -bool potion_now(const SimBattler& own, const SimBattler& foe, int potions); +// What a Potion now is weighed on. +struct PotionCase{ + uint16_t hp = 0; + uint16_t max_hp = 0; + // The foe's next hit, on average and at most. + double expected_hit = 0; + uint32_t max_hit = 0; + // The foe's hits the lead takes before its attacks faint the foe, if + // it attacks from now on. + size_t hits_to_ko = 0; +}; +// `own` against `foe`: the foe's strongest move at the mean roll and +// accuracy, or `seen_hit` (HP the last hit took, as the battle loop read +// it) if more; the lead's planned move against the foe at its HP now. +PotionCase potion_case(const SimBattler& own, const SimBattler& foe, double seen_hit = 0); + +// At either BattleRisk: a Potion is worth the turn only if, after it and +// the foe's expected hit, the lead has gained HP, or if it lets the lead +// last until its attacks faint the foe when attacking now wouldn't. +// Otherwise it attacks: a Potion the next hit undoes only gives the foe +// another turn (console B, 2026-11-03, m51: five Potions at 8/60 HP each +// undone by Misty's Starmie, then no Potions and a faint). +bool potion_pays(const PotionCase& c); + +// BattleRisk::HIGH: a Potion now: `foe`'s next hit could faint `own`, +// after the Potion it couldn't, and potion_pays(). +bool potion_now(const SimBattler& own, const SimBattler& foe, int potions, double seen_hit = 0); // The lead's turn at BattleRisk::HIGH. struct OwnTurn{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp index dce0b63f5a..375d088738 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp @@ -280,7 +280,7 @@ UnitTestResult test_rival_win_chance(){ if (!planned || planned->chance < 0.15 || planned->chance > 0.40){ return std::format("Lv22, 5 Potions: expected 15% to 40%, got {:.1f}%.", planned ? 100 * planned->chance : 0.0); } - if (refusal != std::format("win chance {:.0f}% < 70%: grind first", std::floor(100 * planned->chance))){ + if (refusal != std::format("win chance {:.0f}% < 70% with {}: grind first", std::floor(100 * planned->chance), planned->inputs)){ return "Lv22, 5 Potions: expected a refusal with the chance, got \"" + refusal.value_or("") + "\"."; } const std::optional ground = story_win_chance(grown_to(new_member("squirtle", 5), 30), 5, 1.0, RIVAL); @@ -290,6 +290,148 @@ UnitTestResult test_rival_win_chance(){ return true; } + +// Console B, 2026-11-03 (run m51), Misty: the Wartortle's moves, Bite, +// Tail Whip, Bubble, Withdraw (Water Gun was lost earlier). +std::vector m51_moves(){ + return { + {.move = "bite", .pp = 25, .max_pp = 25}, {.move = "tail-whip", .pp = 30, .max_pp = 30}, + {.move = "bubble", .pp = 30, .max_pp = 30}, {.move = "withdraw", .pp = 40, .max_pp = 40}, + }; +} + +// m51's Wartortle as its summary would read: `level`, 60 HP at Lv20, +// the other stats at OWN_GENES. +PartyMember m51_lead(uint8_t level){ + Stats stats = combatant("wartortle", 20, OWN_GENES)->stats; + stats.hp = 60; + PartyMember lead = member_from_summary("wartortle", 20, m51_moves(), stats); + lead.moves_through_level = level; + return lead; +} + +// m51's Wartortle Lv20 at `hp` of 60. +SimBattler m51_wartortle(uint16_t hp){ + SimBattler own = *own_battler(m51_lead(20)); + own.hp = hp; + return own; +} + +// m51, turns 8 to 13: at 8/60 HP against Misty's Starmie, which hit +// about 20 a turn, the HIGH tier's Potion (+20) was undone by each hit, +// five times over; then Bite once with no Potions left, and it fainted. +// The loop replayed at either tier: once a Potion is seen undone by the +// next hit, no more, but Bite, which also flinches. +UnitTestResult test_m51_potion_loop(){ + for (const BattleRisk risk : {BattleRisk::LOW, BattleRisk::HIGH}){ + Supplies supplies; + supplies.lead = m51_lead(20); + supplies.potions = 5; + supplies.trainer = std::string(MISTY); + supplies.foes = trainer_party(MISTY); + supplies.risk = risk; + supplies.foe_out = 1; + BattleDecisions decisions(supplies, BattleKind::TRAINER); + const PartyStatus red{.hp_seen = true, .hp_yellow = false, .hp_red = true, .hp_fill = 8.0 / 60, .status = StatusCondition::NONE}; + int potions = 0; + for (int turn = 8; turn <= 13; turn++){ + const TurnAction action = decisions.turn(red); + if (action.choice == TurnChoice::POTION){ + potions++; + }else if (action.choice != TurnChoice::MOVE || action.slot != 0){ + return std::format("Risk {}, turn {}: expected a Potion or Bite (slot 0), got slot {}.", battle_risk_name(risk), turn, action.slot); + } + decisions.turn_done(action.choice, TurnResult::DONE); + } + if (potions > 1){ + return std::format("Risk {}: {} Potions at 8/60 HP over turns 8 to 13, each undone by the next hit; expected at most 1.", battle_risk_name(risk), potions); + } + } + return true; +} + +// The sim's own choice by the same rule: at 8/60 a Potion against a foe +// whose hit undoes it, no Potion; against one whose hit could faint the +// lead but heals less than 20, a Potion. +UnitTestResult test_sim_potion_rule(){ + const SimTrainer misty = *sim_trainer(MISTY); + SimBattler starmie = misty.party[1]; + const SimBattler own = m51_wartortle(8); + // Starmie as m51 saw it: at least the Potion's 20 a hit. + starmie.body.stats.attack = static_cast(starmie.body.stats.attack * 2); + starmie.body.stats.sp_attack = static_cast(starmie.body.stats.sp_attack * 2); + if (potion_case(own, starmie).expected_hit < POTION_HP){ + return std::format("Expected Starmie's mean hit at 20 or more, got {:.1f}.", potion_case(own, starmie).expected_hit); + } + const OwnTurn sim = own_turn(own, 5, starmie, misty.items, 1); + if (sim.potion || sim.slot != size_t(0)){ + return std::format( + "Sim at 8/60 against Starmie (max hit {}): expected Bite (slot 0), got {}.", + foe_max_hit(starmie, own), sim.potion ? "a Potion" : "slot " + std::to_string(sim.slot.value_or(9)) + ); + } + const SimBattler& staryu = misty.party[0]; + const SimBattler low = m51_wartortle(6); + const uint32_t hit = foe_max_hit(staryu, low); + if (hit < 6 || hit >= POTION_HP){ + return std::format("Expected Staryu's best hit on the Wartortle from 6 to 19, got {}.", hit); + } + if (!own_turn(low, 5, staryu, misty.items, 2).potion){ + return std::format("At 6/60 against Staryu (max hit {}): expected a Potion.", hit); + } + return true; +} + +// The sim plays the lead the summary showed, not the one the story +// counts: m51's Wartortle (Lv20, 60 HP, Bite, Tail Whip, Bubble, +// Withdraw) with 5 Potions wins about 96% against Misty; the story's own +// Wartortle Lv20 (Tackle, Bite, Water Gun, Withdraw; 56 HP at OWN_GENES) +// about 94%, from other inputs. m51 lost: the sim leaves out Water +// Pulse's confusion, among others (PokemonFRLG_AutoStoryWinChance.h). +UnitTestResult test_misty_real_lead(){ + const std::optional real = story_win_chance(m51_lead(20), 5, 1.0, MISTY); + const std::optional story = story_win_chance(grown_to(new_member("squirtle", 5), 20), 5, 1.0, MISTY); + if (!real || !story){ + return "Expected win chances for both leads."; + } + const std::string expected = "wartortle Lv20 60/60 HP: bite 25/25, tail-whip 30/30, bubble 30/30, withdraw 40/40; 5 Potions"; + if (real->inputs != expected){ + return "m51's lead: expected the inputs \"" + expected + "\", got \"" + real->inputs + "\"."; + } + if (real->chance < 0.90 || story->chance < 0.85 || real->chance == story->chance || story->inputs == real->inputs){ + return std::format( + "Expected m51's lead ({:.1f}%) and the story's ({:.1f}%, {}) to differ, both over 85%.", + 100 * real->chance, 100 * story->chance, story->inputs + ); + } + return true; +} + +// The Cerulean rival against m51's moves (no Water Gun), the levels +// since the summary added to its stats: refused at Lv20, 22 and 25 (about +// 32%, 37%, 66%), fought at Lv30 (about 95%). The refusal names the +// chance and the lead it was played with. +UnitTestResult test_rival_real_moves(){ + const std::vector> cases = { + {20, 0.20, 0.45}, {22, 0.25, 0.50}, {25, 0.50, 0.70}, {30, 0.90, 1.00}, + }; + for (const auto& [level, low, high] : cases){ + const std::optional estimate = story_win_chance(m51_lead(level), 5, 1.0, RIVAL); + if (!estimate || estimate->chance < low || estimate->chance >= high){ + return std::format("Lv{}: expected {:.0f}% to {:.0f}%, got {:.1f}%.", level, 100 * low, 100 * high, estimate ? 100 * estimate->chance : 0.0); + } + const bool refused = win_chance_refusal(*estimate).has_value(); + if (refused != (level < 30)){ + return std::format("Lv{} at {:.1f}%: expected {}.", level, 100 * estimate->chance, level < 30 ? "a refusal" : "no refusal"); + } + } + const std::optional lv22 = story_win_chance(m51_lead(22), 5, 1.0, RIVAL); + const std::string refusal = win_chance_refusal(*lv22).value_or(""); + if (refusal.find("wartortle Lv22 65/65 HP: bite") == std::string::npos || refusal.find("; 5 Potions") == std::string::npos){ + return "Lv22: expected the refusal to name the lead's level, HP, moves and Potions, got \"" + refusal + "\"."; + } + return true; +} } @@ -301,6 +443,10 @@ void add_tests_AutoStoryBattleSim(UnitTestDatabase& database){ database.add("the rival's next Pokemon when no name is read", test_next_foe); database.add("battle risks by trainer", test_risks); database.add("Cerulean rival: refused at Lv22, fought at Lv30", test_rival_win_chance); + database.add("m51: no Potion the foe's hit undoes", test_m51_potion_loop); + database.add("the sim's Potion: only when it outheals the hit", test_sim_potion_rule); + database.add("Misty: m51's lead as the summary showed it", test_misty_real_lead); + database.add("Cerulean rival with m51's moves at Lv20 to 30", test_rival_real_moves); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index cc77668f1f..c747f0edb6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -158,15 +158,13 @@ std::optional refuse_battle(StoryEnv& env, const StoryStep& step, s if (step.may_lose || supplies.risk != BattleRisk::HIGH){ return std::nullopt; } - // The bar's colors, as HP: green full, yellow half, red a fifth. - const double hp_share = supplies.hp_red ? 0.2 : supplies.hurt ? 0.5 : 1.0; - const std::optional estimate = story_win_chance(supplies.lead, supplies.potions, hp_share, trainer); + const std::optional estimate = story_win_chance(supplies.lead, supplies.potions, supplies.hp_fill, trainer); if (!estimate){ return std::nullopt; } env.console.log(std::format( - "Story: {} against {}: the sim wins {} of {} ({:.0f}%), {} Potions.", - step.name, trainer, estimate->wins, estimate->battles, 100 * estimate->chance, supplies.potions + "Story: {} against {}: the sim wins {} of {} ({:.0f}%) with {}.", + step.name, trainer, estimate->wins, estimate->battles, 100 * estimate->chance, estimate->inputs )); return win_chance_refusal(*estimate); } @@ -471,7 +469,9 @@ void read_lead_moves(StoryEnv& env, StartMenu menu){ const PartyMember& before = env.supplies.lead; const std::string species = read->species.empty() ? before.species : read->species; const uint8_t level = read->level && *read->level <= 100 ? static_cast(*read->level) : before.moves_through_level; - env.supplies.lead = member_from_summary(species, level, read->moves); + // The stats belong to the species and level read. + const bool stats_fit = species == read->species && read->level.has_value(); + env.supplies.lead = member_from_summary(species, level, read->moves, stats_fit ? read->stats : std::nullopt); env.saved_supplies.lead = env.supplies.lead; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp index 383e12d0d1..117355debf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp @@ -268,7 +268,10 @@ uint8_t move_power(std::string_view move){ } PartyMember new_member(std::string_view species, uint8_t level){ - PartyMember member{.species = std::string(species), .moves = {}, .moves_through_level = level, .moves_read = false}; + PartyMember member{ + .species = std::string(species), .moves = {}, .moves_through_level = level, .moves_read = false, + .level = 0, .stats = std::nullopt, + }; for (const LevelUpMove& entry : LEVEL_UP_MOVES){ if (entry.species != species || entry.level > level || knows(member, entry.move)){ continue; @@ -298,8 +301,18 @@ PartyMember story_lead_after_brock(){ return grown_to(new_member("squirtle", 5), 13); } -PartyMember member_from_summary(std::string_view species, uint8_t level, const std::vector& moves){ - PartyMember member{.species = std::string(species), .moves = {}, .moves_through_level = level, .moves_read = true}; +uint8_t battle_level(const PartyMember& member){ + return std::max(member.level, member.moves_through_level); +} + +PartyMember member_from_summary( + std::string_view species, uint8_t level, const std::vector& moves, + const std::optional& stats +){ + PartyMember member{ + .species = std::string(species), .moves = {}, .moves_through_level = level, .moves_read = true, + .level = level, .stats = stats, + }; for (const SummaryMove& read : moves){ const uint8_t full = max_pp(read.move); const uint8_t pp = read.pp >= 0 ? static_cast(std::min(read.pp, 255)) : static_cast(full / 2); @@ -332,6 +345,7 @@ LearnDecision learn_move(PartyMember& member){ void evolve(PartyMember& member){ if (const std::optional evolution = level_evolution(member.species)){ member.species = std::string(evolution->into); + member.stats.reset(); } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h index 400d008dd1..ad6f636b3d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h @@ -32,6 +32,7 @@ #include #include #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" +#include "PokemonFRLG_AutoStoryDamage.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -60,8 +61,18 @@ struct PartyMember{ // The moves were read off its summary: they are all it knows, even // fewer than four. bool moves_read = false; + // Its level as its summary showed it, 0 if not read. Level-ups since + // aren't seen: battle_level() takes the higher of this and + // moves_through_level. + uint8_t level = {}; + // Its stats as POKEMON SKILLS showed them at `level`, as this + // species; none if not read, or once it evolves. + std::optional stats = {}; }; +// The level the battle sim takes for `member`. +uint8_t battle_level(const PartyMember& member); + // The species `species` evolves into by level, and at which level. struct LevelEvolution{ std::string_view into; @@ -89,10 +100,14 @@ PartyMember grown_to(PartyMember member, uint8_t level); PartyMember story_lead_after_brock(); // `species` at `level` with `moves` as its summary shows them, in slot -// order. A PP that wasn't read is taken as half the move's full PP: the -// game draws the PP in color from half down (pokefirered -// pokemon_summary_screen.c), which the reader may not read. -PartyMember member_from_summary(std::string_view species, uint8_t level, const std::vector& moves); +// order, and its `stats` if POKEMON SKILLS was read. A PP that wasn't +// read is taken as half the move's full PP: the game draws the PP in +// color from half down (pokefirered pokemon_summary_screen.c), which the +// reader may not read. +PartyMember member_from_summary( + std::string_view species, uint8_t level, const std::vector& moves, + const std::optional& stats = std::nullopt +); // The answer to "Delete a move to make room for ?". diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp index 815baad92d..bfc466a410 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp @@ -44,6 +44,20 @@ bool wait_drawn(ConsoleHandle& console, ProControllerContext& context, VisualInf return true; } +// POKEMON SKILLS' stats, none unless all six read. +std::optional skills_stats(ConsoleHandle& console, Language language, const ImageViewRGB32& screen){ + PokemonFRLG_Stats read; + StatsReader().read_page2(console, language, screen, read); + if (!read.hp || !read.attack || !read.defense || !read.sp_attack || !read.sp_defense || !read.speed){ + return std::nullopt; + } + return Stats{ + .hp = static_cast(*read.hp), .attack = static_cast(*read.attack), + .defense = static_cast(*read.defense), .sp_attack = static_cast(*read.sp_attack), + .sp_defense = static_cast(*read.sp_defense), .speed = static_cast(*read.speed), + }; +} + // From the party menu with the cursor on the member: its summary, read. std::optional read_open_summary(ConsoleHandle& console, ProControllerContext& context, Language language){ PartySelectionWatcher submenu(COLOR_RED); @@ -76,6 +90,9 @@ std::optional read_open_summary(ConsoleHandle& console, ProControll console.log("Summary: POKEMON SKILLS didn't show.", COLOR_ORANGE); return std::nullopt; } + if (VideoSnapshot page = console.video().snapshot()){ + read.stats = skills_stats(console, language, page); + } SummaryPage3Watcher moves(COLOR_RED); tap(context, DPAD_RIGHT, 0ms); if (!wait_drawn(console, context, moves, 3000ms)){ @@ -114,10 +131,16 @@ std::optional read_party_summary( for (const SummaryMove& move : read->moves){ moves += std::format("{}{} {}/{}", moves.empty() ? "" : ", ", move.move, move.pp, move.max_pp); } + const std::string stats = read->stats + ? std::format( + "{} HP, {}/{}/{}/{}/{}", read->stats->hp, read->stats->attack, read->stats->defense, + read->stats->sp_attack, read->stats->sp_defense, read->stats->speed + ) + : "stats not read"; console.log(std::format( - "Summary of party slot {}: {} Lv{}, {}.", + "Summary of party slot {}: {} Lv{}, {}, {}.", slot + 1, read->species.empty() ? "?" : read->species, - read->level ? std::to_string(*read->level) : "?", moves.empty() ? "no moves read" : moves + read->level ? std::to_string(*read->level) : "?", stats, moves.empty() ? "no moves read" : moves )); } return read; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h index f5b61cd819..9839147e90 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h @@ -20,6 +20,7 @@ #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" #include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryDamage.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -33,10 +34,13 @@ struct SummaryRead{ std::optional level = std::nullopt; // KNOWN MOVES, from the top, up to the first name not read. std::vector moves = {}; + // POKEMON SKILLS (HP as its maximum), none unless all six were read. + std::optional stats = std::nullopt; }; // From the overworld: the party menu, party slot `slot`'s SUMMARY, its -// first page (species, level) and KNOWN MOVES, then back to the overworld. +// first page (species, level), POKEMON SKILLS (stats) and KNOWN MOVES, +// then back to the overworld. // Each screen is waited for before the next press: a press sent before a // menu is drawn goes to what was there before (console B, 2026-11-02, the // PC's menus). Nothing if a screen didn't show, or before the starter diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp index dd22731552..5a636778dd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp @@ -368,7 +368,15 @@ std::optional story_win_chance(const PartyMember& lead, int potions if (!own || !sim){ return std::nullopt; } - return estimate_win_chance(*own, potions, *sim); + WinEstimate estimate = estimate_win_chance(*own, potions, *sim); + estimate.inputs = std::format("{} Lv{} {}/{} HP:", own->species, own->body.level, own->hp, own->body.stats.hp); + for (size_t slot = 0; slot < own->moves.size(); slot++){ + estimate.inputs += std::format( + "{} {} {}/{}", slot == 0 ? "" : ",", own->moves[slot].move, own->moves[slot].pp, max_pp(own->moves[slot].move) + ); + } + estimate.inputs += std::format("; {} Potions", potions); + return estimate; } std::optional win_chance_refusal(const WinEstimate& estimate, double minimum){ @@ -376,8 +384,9 @@ std::optional win_chance_refusal(const WinEstimate& estimate, doubl return std::nullopt; } return std::format( - "win chance {:.0f}% < {:.0f}%: grind first", - std::floor(100 * estimate.chance), std::round(100 * minimum) + "win chance {:.0f}% < {:.0f}%{}: grind first", + std::floor(100 * estimate.chance), std::round(100 * minimum), + estimate.inputs.empty() ? "" : " with " + estimate.inputs ); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h index 31c2315b5f..9056a41f83 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h @@ -41,6 +41,9 @@ struct WinEstimate{ size_t wins = 0; // wins / battles double chance = 0; + // The lead and Potions the battles were played with, for the log: + // "wartortle Lv20 60/60 HP: bite 25/25, ...; 5 Potions". + std::string inputs = {}; }; // `own` with `potions` Potions against `trainer`, `battles` times, from a @@ -51,8 +54,8 @@ WinEstimate estimate_win_chance(const SimBattler& own, int potions, const SimTra // `trainer`. None if the data lacks the lead's species or the trainer. std::optional story_win_chance(const PartyMember& lead, int potions, double hp_share, std::string_view trainer); -// Why not to fight: "win chance 41% < 70%: grind first", or none at -// `minimum` or above. +// Why not to fight: "win chance 41% < 70% with : grind first", or +// none at `minimum` or above. std::optional win_chance_refusal(const WinEstimate& estimate, double minimum = MIN_WIN_CHANCE); From 8935c6057b3ab0dc51c80bbbc9da67feac5ac7c2 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 07:21:11 -0800 Subject: [PATCH 74/75] FRLG SummaryMovesReader: read the TMs' and HMs' moves, and a move name in any box A taught TM's move (Water Pulse on console B, 2026-11-03) wasn't in the dictionary, so the moves read stopped before it and the TEACH step's check after teaching failed. read_move_name() reads the TM CASE's rows too. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Menus/PokemonFRLG_SummaryMovesReader.cpp | 111 ++++++++++++++---- .../Menus/PokemonFRLG_SummaryMovesReader.h | 8 +- 2 files changed, 93 insertions(+), 26 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp index 55c66ed1a5..0fd8d48b8e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp @@ -5,6 +5,7 @@ */ #include +#include #include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" @@ -40,6 +41,86 @@ constexpr double CURSOR_EDGE_LEFT = 120; constexpr double CURSOR_EDGE_TOP = 24; constexpr double CURSOR_EDGE_HEIGHT = 16; +// The level-up moves of Squirtle's and Magikarp's lines (pret +// pokefirered src/data/pokemon/level_up_learnsets.h), then the TMs' +// and HMs' moves not among them (src/data/items.h; Hyper Beam, Protect +// and Rain Dance are above), as the game writes them. +constexpr std::pair MOVE_NAMES[] = { + {"tackle", "Tackle"}, + {"tail-whip", "Tail Whip"}, + {"bubble", "Bubble"}, + {"withdraw", "Withdraw"}, + {"water-gun", "Water Gun"}, + {"bite", "Bite"}, + {"rapid-spin", "Rapid Spin"}, + {"protect", "Protect"}, + {"rain-dance", "Rain Dance"}, + {"skull-bash", "Skull Bash"}, + {"hydro-pump", "Hydro Pump"}, + {"splash", "Splash"}, + {"flail", "Flail"}, + {"thrash", "Thrash"}, + {"dragon-rage", "Dragon Rage"}, + {"leer", "Leer"}, + {"twister", "Twister"}, + {"dragon-dance", "Dragon Dance"}, + {"hyper-beam", "Hyper Beam"}, + {"focus-punch", "Focus Punch"}, + {"dragon-claw", "Dragon Claw"}, + {"water-pulse", "Water Pulse"}, + {"calm-mind", "Calm Mind"}, + {"roar", "Roar"}, + {"toxic", "Toxic"}, + {"hail", "Hail"}, + {"bulk-up", "Bulk Up"}, + {"bullet-seed", "Bullet Seed"}, + {"hidden-power", "Hidden Power"}, + {"sunny-day", "Sunny Day"}, + {"taunt", "Taunt"}, + {"ice-beam", "Ice Beam"}, + {"blizzard", "Blizzard"}, + {"light-screen", "Light Screen"}, + {"giga-drain", "Giga Drain"}, + {"safeguard", "Safeguard"}, + {"frustration", "Frustration"}, + {"solar-beam", "SolarBeam"}, + {"iron-tail", "Iron Tail"}, + {"thunderbolt", "Thunderbolt"}, + {"thunder", "Thunder"}, + {"earthquake", "Earthquake"}, + {"return", "Return"}, + {"dig", "Dig"}, + {"psychic", "Psychic"}, + {"shadow-ball", "Shadow Ball"}, + {"brick-break", "Brick Break"}, + {"double-team", "Double Team"}, + {"reflect", "Reflect"}, + {"shock-wave", "Shock Wave"}, + {"flamethrower", "Flamethrower"}, + {"sludge-bomb", "Sludge Bomb"}, + {"sandstorm", "Sandstorm"}, + {"fire-blast", "Fire Blast"}, + {"rock-tomb", "Rock Tomb"}, + {"aerial-ace", "Aerial Ace"}, + {"torment", "Torment"}, + {"facade", "Facade"}, + {"secret-power", "Secret Power"}, + {"rest", "Rest"}, + {"attract", "Attract"}, + {"thief", "Thief"}, + {"steel-wing", "Steel Wing"}, + {"skill-swap", "Skill Swap"}, + {"snatch", "Snatch"}, + {"overheat", "Overheat"}, + {"cut", "Cut"}, + {"fly", "Fly"}, + {"surf", "Surf"}, + {"strength", "Strength"}, + {"flash", "Flash"}, + {"rock-smash", "Rock Smash"}, + {"waterfall", "Waterfall"}, +}; + class MoveNameMatcher : public OCR::SmallDictionaryMatcher{ public: static constexpr double MAX_LOG10P = -1.40; @@ -67,31 +148,9 @@ class MoveNameMatcher : public OCR::SmallDictionaryMatcher{ : SmallDictionaryMatcher(dictionary()) {} - // The level-up moves of Squirtle's and Magikarp's lines (pret - // pokefirered src/data/pokemon/level_up_learnsets.h). static JsonObject dictionary(){ JsonObject english; - for (const auto& [slug, name] : { - std::pair{"tackle", "Tackle"}, - {"tail-whip", "Tail Whip"}, - {"bubble", "Bubble"}, - {"withdraw", "Withdraw"}, - {"water-gun", "Water Gun"}, - {"bite", "Bite"}, - {"rapid-spin", "Rapid Spin"}, - {"protect", "Protect"}, - {"rain-dance", "Rain Dance"}, - {"skull-bash", "Skull Bash"}, - {"hydro-pump", "Hydro Pump"}, - {"splash", "Splash"}, - {"flail", "Flail"}, - {"thrash", "Thrash"}, - {"dragon-rage", "Dragon Rage"}, - {"leer", "Leer"}, - {"twister", "Twister"}, - {"dragon-dance", "Dragon Dance"}, - {"hyper-beam", "Hyper Beam"}, - }){ + for (const auto& [slug, name] : MOVE_NAMES){ JsonArray names; names.push_back(name); english[slug] = std::move(names); @@ -133,7 +192,11 @@ ImageFloatBox summary_move_max_pp_box(size_t row){ } std::string read_summary_move_name(Logger& logger, Language language, const ImageViewRGB32& screen, size_t row){ - return MoveNameMatcher::instance().read(logger, language, extract_box_reference(game_box(screen), summary_move_name_box(row))); + return read_move_name(logger, language, extract_box_reference(game_box(screen), summary_move_name_box(row))); +} + +std::string read_move_name(Logger& logger, Language language, const ImageViewRGB32& name){ + return MoveNameMatcher::instance().read(logger, language, name); } std::vector read_summary_moves(Logger& logger, Language language, const ImageViewRGB32& screen){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h index 561713fd9f..dc4202857d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h @@ -11,8 +11,8 @@ * PP at 64. The fifth row is CANCEL, or the move offered. * * It knows the names of the moves of the lines the FRLG AutoStory party - * comes from, in English only so far: in another language a name is never - * read. + * comes from, and of the TMs' and HMs' moves, in English only so far: in + * another language a name is never read. * */ @@ -48,6 +48,10 @@ ImageFloatBox summary_move_max_pp_box(size_t row); // for, or a language it has no names for. std::string read_summary_move_name(Logger& logger, Language language, const ImageViewRGB32& screen, size_t row); +// The move named in `name`, a box around one move's name in dark text on +// a light background, such as a TM CASE row's; empty as above. +std::string read_move_name(Logger& logger, Language language, const ImageViewRGB32& name); + struct SummaryMove{ std::string move; // -1 if not read. The game draws a move's PP in color once it is down From b8a58dd80840d4b9b22fbd87a086df67a7f6949e Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 09:19:03 -0800 Subject: [PATCH 75/75] FRLG AutoStory: read the bag's rows below an item the reader can't name A MOON STONE at the top of the Items pocket stopped the reader, so every load read nothing and the rival at 00.15b was fought with 0 of the bag's 15 Potions (console B, 2026-11-03). An unread name now keeps its row, items the story doesn't count take their rows in item_row(), and every reload reads the bag again, so each verify run starts from the save's counts. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Menus/PokemonFRLG_ItemListReader.cpp | 22 ++++++++-- .../Menus/PokemonFRLG_ItemListReader.h | 16 +++++-- .../AutoStory/PokemonFRLG_AutoStory.cpp | 10 +++-- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 8 +++- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 6 ++- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 1 + .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 2 + .../PokemonFRLG_AutoStoryItems_Tests.cpp | 42 +++++++++++++++++++ 8 files changed, 95 insertions(+), 12 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp index 8b795c2552..b37226995b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/Json/JsonArray.h" @@ -102,7 +103,7 @@ std::vector read_bag_pocket(Logger& logger, Language language, const Ima std::vector rows; for (int row = 0; row < ITEM_LIST_ROWS; row++){ const std::string item = read_item_list_name(logger, language, screen, row); - if (item.empty() || item == "cancel"){ + if (item == "cancel"){ break; } const ImageViewRGB32 count = extract_box_reference(game_box(screen), bag_item_count_box(row)); @@ -112,7 +113,18 @@ std::vector read_bag_pocket(Logger& logger, Language language, const Ima // the same digits on the same cream. rows.push_back(BagRow{item, read_digits_waterfill_template(logger, count, DigitTemplateType::StatBox)}); } - return rows; + return pocket_rows(std::move(rows)); +} + +std::vector pocket_rows(std::vector reads){ + const auto cancel = std::find_if(reads.begin(), reads.end(), [](const BagRow& row){ + return row.item == "cancel"; + }); + reads.erase(cancel, reads.end()); + while (!reads.empty() && reads.back().item.empty()){ + reads.pop_back(); + } + return reads; } @@ -146,7 +158,7 @@ class Test_BagPocket : public ImageUnitTest{ for (size_t c = 0; c < rows.size(); c++){ labels.push_back(std::format("row {} item", c + 1)); labels.push_back(std::format("row {} count", c + 1)); - values.push_back(rows[c].item); + values.push_back(rows[c].item.empty() ? "(unread)" : rows[c].item); values.push_back(std::to_string(rows[c].count)); } return check_against_golden_file(UNIT_TEST_RESOURCE_PATH() + image_paths()[0], labels, values); @@ -189,6 +201,10 @@ void add_tests_ItemListReader(UnitTestDatabase& database){ // FireRed on console B, 2026-11-02, after the Viridian Mart: the 5 and // the 3 read as nothing before the digit templates. database.add("PokemonFRLG/ItemListReader/ItemsPocket_eng.png"); + // Console B, 2026-11-03, the save before Cerulean's rival: a MOON STONE, + // which the reader has no name for, above the PARLYZ HEAL and 15 POTIONs. + // Stopping at it read nothing, and the rival was fought with 0 Potions. + database.add("PokemonFRLG/ItemListReader/ItemsPocketMoonStone_eng.png"); // The Viridian Mart's BUY list, the same day, the cursor on POTION. database.add("PokemonFRLG/ItemListReader/MartBuyList_eng.png"); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h index 4100eeffb7..cddeb636c6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h @@ -41,16 +41,26 @@ ImageFloatBox bag_item_count_box(int row); std::string read_item_list_name(Logger& logger, Language language, const ImageViewRGB32& screen, int row); struct BagRow{ + // The item's slug, as read_item_list_name() gives it; empty if its name + // can't be read. std::string item; // -1 if the count couldn't be read: the row still holds at least one. int count = 0; }; -// The rows of the bag's open pocket from the top, up to its CANCEL (not -// included). Stops at a row it can't read, so it is empty in a language -// the reader has no names for. The pocket must be scrolled to its top. +// The rows of the bag's open pocket from the top, as pocket_rows() keeps +// them. The pocket must be scrolled to its top. std::vector read_bag_pocket(Logger& logger, Language language, const ImageViewRGB32& screen); +// The rows of a pocket from `reads`, each row as read from the top: up to +// the CANCEL (not included). A row whose name can't be read stays, with an +// empty item, so the rows below keep their places: stopping there read +// nothing below a MOON STONE, and the rival was fought with 0 of the bag's +// 15 Potions (console B, 2026-11-03). Unread rows after the last name read +// are dropped. Empty if no name is read, as in a language the reader has +// no names for. +std::vector pocket_rows(std::vector reads); + void add_tests_ItemListReader(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 856aba2734..fb400f1e09 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -89,8 +89,8 @@ static void check_start_save( namespace{ -// A failed attempt reloads the last save, with the supplies it had; the -// engine's lines go to the console's log. +// A failed attempt reloads the last save, with the supplies it had, read +// from its bag again; the engine's lines go to the console's log. Pokemon::SegmentHooks story_hooks(SingleSwitchProgramEnvironment& env, StoryEnv& story){ Pokemon::SegmentHooks hooks; hooks.reload = [&story](Pokemon::RunState&){ @@ -106,10 +106,14 @@ Pokemon::SegmentHooks story_hooks(SingleSwitchProgramEnvironment& env, StoryEnv& if (!error.empty()){ return Pokemon::outcome_failed("wrong_save", error); } + story.supplies = story.saved_supplies; + // Every reload, so each verify run starts from the bag as the + // save holds it, not from a count once read wrong or not at + // all (console B, 2026-11-03: 0 Potions in all 3 runs). + read_bag_supplies(story, story.start_menu); }catch (OperationFailedException& e){ return Pokemon::outcome_failed("reload_failed", e.message()); } - story.supplies = story.saved_supplies; return Pokemon::outcome_ok(); }; hooks.log = [&env](const std::string& line){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 1e1c5b3848..8428706822 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -858,10 +858,16 @@ int item_count(const Supplies& supplies, const std::string& item){ return 0; } +// Whether the story keeps a count for `item`. +static bool counted(const std::string& item){ + Supplies probe; + return count_slot(probe, item) != nullptr; +} + int item_row(const Supplies& supplies, const std::string& item){ int row = 0; for (const std::string& slot : supplies.pocket){ - if (item_count(supplies, slot) <= 0){ + if (counted(slot) && item_count(supplies, slot) <= 0){ continue; } if (slot == item){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index 4a0d1650af..7b16b43608 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -57,8 +57,9 @@ struct Supplies{ int antidotes = 0; int parlyz_heals = 0; // The Items pocket's order, by slug (see read_item_list_name()): the - // order bought, or as read from the bag. An item with none left takes - // no row. + // order bought, or as read from the bag, with "" for a row whose name + // couldn't be read. A counted item with none left takes no row; the + // others always take theirs. std::vector pocket = {"potion", "antidote", "parlyz-heal"}; // The starter's status at the last battle screen that showed it, and // not cured since. @@ -125,6 +126,7 @@ enum class BattleEnd{ int item_count(const Supplies& supplies, const std::string& item); // The row (from 0) of `item` in the Items pocket, or -1 if none is left. +// Items the story doesn't count, such as a MOON STONE, take rows too. int item_row(const Supplies& supplies, const std::string& item); // Sets the counts and the pocket's order from the Items pocket as read. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index c747f0edb6..4c205cbb49 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -496,6 +496,7 @@ Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); StoryEnv& env = executor.env(); env.start_map = data.start ? data.start->map : ""; + env.start_menu = data.menu; const StartMenu menu = data.menu; checkpoint.save = [&env, menu](RunState&){ return guarded([&]{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 38e97d706c..887ca363b6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -120,6 +120,8 @@ struct StoryEnv{ // The map the checkpoint under way starts on, where its save is: a // reload checks the save card against it. std::string start_map = {}; + // That checkpoint's START menu: a reload reads the bag again with it. + StartMenu start_menu = StartMenu::BEFORE_POKEMON; }; // After a save is loaded for a checkpoint that starts on `start_map`: the diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index e568269e39..107e9fc670 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -159,6 +159,46 @@ UnitTestResult test_unread_counts(Logger&){ return true; } +// Console B, 2026-11-03: a save from Mt. Moon has a MOON STONE above the +// PARLYZ HEAL and 15 POTIONs. An item the story doesn't count still takes +// its row, so the battle knows all 15 Potions and finds them in row 2. +UnitTestResult test_loaded_bag_other_items(Logger&){ + Supplies row; + row.potions = 0; + row.parlyz_heals = 0; + Supplies saved = row; + set_from_loaded_bag(row, saved, {{"", 1}, {"parlyz-heal", 1}, {"potion", 15}}); + if (row.potions != 15 || saved.potions != 15 || row.parlyz_heals != 1){ + return std::format( + "Expected 15 Potions and 1 Parlyz Heal from the bag, now and for a reload; got {}, {} and {}.", + row.potions, saved.potions, row.parlyz_heals + ); + } + if (item_row(row, "parlyz-heal") != 1 || item_row(row, "potion") != 2 || item_row(saved, "potion") != 2){ + return std::format( + "Expected the Parlyz Heal in row 1 and the Potions in row 2 below the Moon Stone, got {} and {}.", + item_row(row, "parlyz-heal"), item_row(row, "potion") + ); + } + return true; +} + +// The pocket's rows as read: an unread name keeps its row, so the rows +// below it are still read; the rows end at CANCEL, or at the last name read. +UnitTestResult test_pocket_rows_unread(Logger&){ + const std::vector rows = pocket_rows({{"", 1}, {"parlyz-heal", 1}, {"potion", 15}, {"cancel", -1}, {"", -1}}); + if (rows.size() != 3 || !rows[0].item.empty() || rows[2].item != "potion" || rows[2].count != 15){ + return std::format("Expected 3 rows, the Potions' last with 15, got {}.", rows.size()); + } + if (pocket_rows({{"potion", 3}, {"", -1}, {"", -1}}).size() != 1){ + return "Expected the unread rows after the last name dropped."; + } + if (!pocket_rows({{"", 1}, {"", 2}}).empty()){ + return "Expected nothing with no name read."; + } + return true; +} + // In a language the reader has no names for, nothing is read, so the // checks fall back to positions instead of failing. UnitTestResult test_unread_language(Logger& logger){ @@ -236,6 +276,8 @@ void add_tests_AutoStoryItems(UnitTestDatabase& database){ database.add("Mart cursor stays on the row bought", test_mart_cursor); database.add("Items pocket rows", test_pocket_rows); database.add("a loaded save's counts come from the bag", test_loaded_bag); + database.add("an item the story doesn't count keeps its row", test_loaded_bag_other_items); + database.add("an unread item name keeps its row", test_pocket_rows_unread); database.add("unread bag counts count as some", test_unread_counts); database.add("no item names read in a language without them", test_unread_language); // "Wild CHANSEY appeared!" with its HP box, and Mt. Moon B2F's corridor