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/Inference/Menus/PokemonFRLG_ItemListReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp new file mode 100644 index 0000000000..b37226995b --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp @@ -0,0 +1,216 @@ +/* Item List Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#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" +#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, 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: + 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, 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, 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, language, screen, row); + if (item == "cancel"){ + break; + } + const ImageViewRGB32 count = extract_box_reference(game_box(screen), bag_item_count_box(row)); + // 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 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; +} + + +namespace{ + +// 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) + : ImageUnitTest("PokemonFRLG::ItemListReader - " + image, {image}) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const Language language = language_of_test_image(image_paths()[0]); + if (language == Language::None || language == Language::EndOfList){ + return "Error: filename must be _."; + } + 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.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); + } +}; + +// 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_MartList(const std::string& image) + : ImageUnitTest("PokemonFRLG::ItemListReader - " + image, {image}) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const Language language = language_of_test_image(image_paths()[0]); + if (language == Language::None || language == Language::EndOfList){ + return "Error: filename must be _."; + } + 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 check_against_golden_file(UNIT_TEST_RESOURCE_PATH() + image_paths()[0], labels, values); + } +}; + +} + +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 new file mode 100644 index 0000000000..cddeb636c6 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h @@ -0,0 +1,72 @@ +/* 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). 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. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_ItemListReader_H +#define PokemonAutomation_PokemonFRLG_ItemListReader_H + +#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{ + + +// 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, 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{ + // 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, 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); + + + +} +} +} +#endif 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/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp new file mode 100644 index 0000000000..bd099bb1da --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.cpp @@ -0,0 +1,205 @@ +/* Option Menu Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#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" + +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_SPREAD = 0.50; + + 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{ + 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(), + m_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; + } + + double m_max_log10p; +}; + +std::vector slugs_of(const std::vector& values){ + std::vector ret; + for (const OptionValue& value : values){ + ret.emplace_back(value.slug); + } + return ret; +} + +// 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 option_item(item).name; +} + +size_t option_menu_row(OptionMenuItem item){ + return option_item(item).row; +} + +const std::vector& option_menu_values(OptionMenuItem item){ + return option_item(item).slugs; +} + +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 option_item(item).matcher.read(logger, language, value); +} + + +namespace{ + +// 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) + : ImageUnitTest("PokemonFRLG::OptionMenuReader - " + 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()); + 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; + } +}; + +} + +void add_tests_OptionMenuReader(UnitTestDatabase& database){ + // 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_OptionMenuReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h new file mode 100644 index 0000000000..77dd54e53e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h @@ -0,0 +1,63 @@ +/* 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 "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 options AutoStory sets. +enum class OptionMenuItem{ + TEXT_SPEED, + BATTLE_SCENE, + BATTLE_STYLE, +}; + +// "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"; "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. +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); + + +void add_tests_OptionMenuReader(UnitTestDatabase& database); + + + +} +} +} +#endif 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..702d314298 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp @@ -0,0 +1,143 @@ +/* Save Card Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#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" + +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())); +} + + +namespace{ + +// 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) + : ImageUnitTest("PokemonFRLG::SaveCardReader - " + 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()); + 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; + } +}; + +} + +void add_tests_SaveCardReader(UnitTestDatabase& database){ + // FireRed on console B, 2026-11-02. The card covers the same corner of + // the screen everywhere; the places behind it differ. + 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"); +} + + + +} +} +} 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..8a037e0242 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h @@ -0,0 +1,45 @@ +/* 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 "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 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); + + +void add_tests_SaveCardReader(UnitTestDatabase& database); + + + +} +} +} +#endif 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..0fd8d48b8e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.cpp @@ -0,0 +1,320 @@ +/* Summary Moves Reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#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; + +// 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; + 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()) + {} + + static JsonObject dictionary(){ + JsonObject english; + for (const auto& [slug, name] : MOVE_NAMES){ + 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 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){ + 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..dc4202857d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h @@ -0,0 +1,77 @@ +/* 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, and of the TMs' and HMs' moves, 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); + +// 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 + // 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/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/PokemonFRLG_Panels.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp index 829a795624..1fa21bd655 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" @@ -58,7 +60,6 @@ PanelListFactory::PanelListFactory() std::vector PanelListFactory::make_panels() const{ std::vector ret; - ret.emplace_back("---- Settings ----"); ret.emplace_back(make_OptionsPanel()); @@ -70,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 1ac43e21a6..1973dbe3e4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -17,9 +17,13 @@ #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_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/Menus/PokemonFRLG_SummaryMovesReader.h" #include "Inference/PokemonFRLG_BattleLevelUpReader.h" #include "Inference/PokemonFRLG_BattleSelectionArrowDetector.h" #include "Inference/PokemonFRLG_PartyLevelUpReader.h" @@ -34,6 +38,8 @@ #include "Overworld/PokemonFRLG_OverworldWalk.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" #include "PokemonFRLG_Tests.h" @@ -269,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); @@ -293,6 +308,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_HallOfFameSavingDetector(database); add_tests_BattleMoveSelectionArrow(database); add_tests_BagDetector(database); + add_tests_AutoStoryReaders(database); add_tests_ExitWildBattle(database); add_tests_OverworldMaps(database); add_tests_OverworldRoute(database); @@ -300,6 +316,9 @@ void add_tests(UnitTestDatabase& database){ add_tests_OverworldReanchor(database); add_tests_OverworldRecovery(database); add_tests_PlayerFacingReader(database); + add_tests_AutoStory(database); + add_tests_AutoStorySimulation(database); + add_tests_AutoStoryItems(database); } 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..64425be1f6 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/moves.json @@ -0,0 +1,356 @@ +{ +"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 new file mode 100644 index 0000000000..5393e90c95 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/species.json @@ -0,0 +1,388 @@ +{ +"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 new file mode 100644 index 0000000000..3877817c87 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData/trainers.json @@ -0,0 +1,641 @@ +{ +"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/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_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp new file mode 100644 index 0000000000..fb400f1e09 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -0,0 +1,233 @@ +/* AutoStory + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#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" +#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 + ) +{} + +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.10. 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() + : 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 00.01. Otherwise the program loads the save, which must be the one the start checkpoint begins from.", + LockMode::LOCK_WHILE_RUNNING, + true + ) + , NOTIFICATIONS({ + &NOTIFICATION_PROGRAM_FINISH, + &NOTIFICATION_ERROR_FATAL, + }) +{ + PA_ADD_OPTION(RUN); + PA_ADD_OPTION(NEW_GAME_FROM_TITLE); + PA_ADD_OPTION(NOTIFICATIONS); +} + + +// 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_start_save( + SingleSwitchProgramEnvironment& env, StoryEnv& story, const StoryCheckpoint& checkpoint +){ + if (!checkpoint.start){ + return; + } + 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."); + } +} + +namespace{ + +// 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&){ + 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); + } + 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()); + } + return Pokemon::outcome_ok(); + }; + 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; +} + +// 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(); + 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, RUN.checks()}; + 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; + check_start_save(env, story, checkpoints[first]); + read_lead_moves(story, checkpoints[first].menu); + read_bag_supplies(story, checkpoints[first].menu); + } + + 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::SegmentReport report = run_segment( + state, segment, Pokemon::SegmentRange{checkpoints[first].id, checkpoints[last].id}, RUN.policy(), hooks + ); + Pokemon::record_story_stats(env.current_stats(), report); + env.update_stats(); + 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..e92eb74549 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h @@ -0,0 +1,56 @@ +/* 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, as the shared retry options say. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStory_H +#define PokemonAutomation_PokemonFRLG_AutoStory_H + +#include "Common/Cpp/Options/BooleanCheckBoxOption.h" +#include "Common/Cpp/Options/EnumDropdownOption.h" +#include "CommonFramework/Notifications/EventNotificationsTable.h" +#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "Pokemon/Options/Pokemon_StoryRunOptions.h" +#include "PokemonFRLG_AutoStoryActions.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +class AutoStory_Descriptor : public SingleSwitchProgramDescriptor{ +public: + AutoStory_Descriptor(); + virtual std::unique_ptr make_stats() const override; +}; + +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: + // The start and end checkpoints, attempts, checks and language, as in + // every game's AutoStory. + Pokemon::StoryRunOptions RUN; + BooleanCheckBoxOption NEW_GAME_FROM_TITLE; + 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..a67e107e31 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -0,0 +1,846 @@ +/* AutoStory Actions + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#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" +#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_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" +#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; +// 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. +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); +} + + + +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 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 std::nullopt; + } + 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; + } + } + 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); + } + context.wait_for_all_requests(); + 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)){ + 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. Everything but the names +// is advanced with A, which never hurts there (BOY is the default, YES to +// "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) + : 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 a message 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 (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)){ + m_dialog_seen = true; + m_last_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; + } + 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){ + 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; + } + // 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 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; + ProControllerContext& m_context; + 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: + 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; +} + + +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; + } + if (SelectionArrowDetector(COLOR_RED, nullptr, SelectionArrowPositionConfirmationMenu::NO).detect(screen)){ + return false; + } + 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(); + 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; +} + +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). + std::optional last_no; + while (current_time() < deadline){ + 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); + BattleLearnDialogWatcher learn(COLOR_RED); + context.wait_for_all_requests(); + 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, 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 = 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 ? std::nullopt : std::optional(current_time()); + continue; + } + 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(); +} + +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)); + // 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 + ); + } + 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, 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(); + 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; +} + +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 scene OFF, battle style SET."); + open_start_menu_row(console, context, menu, start_menu_option_row(menu)); + options_shot(console, context, "before"); + 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); +} + +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); + pbf_wait(context, HEAL_TIME); + 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()); +} + +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, Language language){ + context.wait_for_all_requests(); + VideoSnapshot screen = console.video().snapshot(); + 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; + } + 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, 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); + // 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 {} (cursor on row {}).", order.quantity, order.row + 1, cursor + 1)); + 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, language); + } + // "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); + } + 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); + 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..78d88a0d14 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -0,0 +1,225 @@ +/* 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 +#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" +#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/Navigation/Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// How much the story checks the screen before and after it acts: the +// shared level (Pokemon_StorySteps.h, set by StoryRunOptions). For FRLG, +// 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. +using StoryChecks = Pokemon::StoryChecks; + +// 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); + + +// 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); + + +// 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); + +// 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, + 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); + +// 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. 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); + +// 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 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. +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; + // 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. +// 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. +// `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, 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); + + + +} +} +} +#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..8428706822 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -0,0 +1,981 @@ +/* AutoStory Battle + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#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" +#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" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" +#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" +#include "PokemonFRLG_AutoStoryFoeTracker.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: 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 = 3000ms; +// 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; +// An evolution's animation, with no presses: as long as exit_wild_battle() +// (PokemonFRLG_Navigation.cpp) waits for one. +constexpr Milliseconds EVOLUTION = 20000ms; +// 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 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); + +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(). + 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 +}; + +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 "?"; +} + +// 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; + } + if (BattleDialogDetector(COLOR_RED).detect(screen)){ + return BattleScreen::OTHER; + } + 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); +} + +void tap(ProControllerContext& context, DpadPosition position){ + pbf_press_dpad(context, position, 160ms, 240ms); +} + +// In the bag, with the cursor on `row`: whether that row is `item`. FAST +// 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, 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; +} + +// 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. +// 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, 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); + 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); + } + if (!bag_row_is(console, context, row, item, checks, language)){ + 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. +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 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); + if (slot % 2 == 1){ + tap(context, DPAD_RIGHT); + } + if (slot >= 2){ + tap(context, DPAD_DOWN); + } + 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?". 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. +// 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 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){ + 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); + 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); + } + pbf_press_button(context, BUTTON_A, 160ms, 800ms); + pbf_press_button(context, BUTTON_A, 160ms, 1500ms); +} + + +class BattleLoop{ +public: + BattleLoop( + ConsoleHandle& console, ProControllerContext& context, + Supplies& supplies, BattleKind kind, StoryChecks checks, Language language + ) + : m_console(console) + , m_context(context) + , 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) + , 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(){ + 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." + ); + bool over = false; + while (!over){ + over = step(); + } + 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: + // 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; + } + 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; + } + 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())); + 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. + return press_blind(now); + } + if (seen == BattleScreen::NONE){ + m_refusal.no_battle_screen(); + return no_battle_screen(screen, now); + } + m_seen_battle = true; + 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; + } + + // 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, 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; + 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))){ + 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)); + } + 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 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 + // 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; + } + 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){ + m_last_overworld_check = now; + if (overworld_shows(m_console, m_context)){ + 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( + 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: + if (m_decisions.turns() == 0){ + // The prompts come after a turn; before one it is a misread. + break; + } + answer_prompt(screen, now); + return; + case BattleScreen::ADVANCE: + pbf_press_button(m_context, BUTTON_B, 160ms, 200ms); + m_last_press = now; + return; + default: + break; + } + if (now - m_last_press > STUCK){ + pbf_press_button(m_context, BUTTON_B, 160ms, 200ms); + m_last_press = now; + } + pbf_wait(m_context, POLL); + } + + // The HP bar whenever the starter's box shows, so the last reading + // includes the battle's last hit. Not once another member is out. + void read_hp(const ImageViewRGB32& screen){ + if (m_decisions.lost() || !BattlePokemonDetector(COLOR_RED).detect(screen)){ + return; + } + const PartyStatus status = read_party_status(screen); + 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; + } + + 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)); + 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); + } + m_last_press = now; + } + + 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_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); + } + 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 {} ({:.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, 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, 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; + } + } + + void watch_for_faint(const ImageViewRGB32& screen){ + 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_decisions.lead_fainted(); + } + } + + ConsoleHandle& m_console; + ProControllerContext& m_context; + Supplies& m_supplies; + BattleDecisions m_decisions; + EvolutionHold m_evolution; + TrainerFoeTracker m_foes; + BattleEndWatch m_end; + MoveRefusalWatch m_refusal; + const BattleKind m_kind; + const StoryChecks m_checks; + const Language m_language; + 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_confirmed = false; + bool m_press_a = true; + // A move was chosen and no battle menu has shown since. + bool m_move_chosen = false; + int m_faint_polls = 0; +}; + + +// 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); + 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); + } +} + +// 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, 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, language)){ + 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){ + 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, StoryChecks checks, Language language) + : m_supplies(supplies) + , m_checks(checks) + , m_language(language) + , 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; + } + // 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{ + const BattleKind kind = m_fight ? BattleKind::WILD_FIGHT : BattleKind::WILD_RUN; + 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; +}; + +// A message: read to its end, then a trainer's battle if one starts. +class StoryMessage : public OverworldInterrupt{ +public: + 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"; + } + 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, BattleKind::TRAINER, m_checks, m_language)); + mash_until_overworld(console, context, AFTER_BATTLE_TEXT); + recover_after_battle(console, context, m_supplies, m_checks, m_language); + } + +private: + Supplies& m_supplies; + const StoryChecks m_checks; + const Language m_language; +}; + +} + + +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 HpBarReading bar = read_player_hp_bar(game); + PartyStatus status; + 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; +} + +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"){ + 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; +} + +// 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 (counted(slot) && item_count(supplies, slot) <= 0){ + continue; + } + if (slot == item){ + return row; + } + row++; + } + return -1; +} + +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){ + 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 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(); + VideoSnapshot screen = console.video().snapshot(); + dump_debug_image(console, "AutoStory/bag", "items-pocket", screen); + 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); + } + 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, Language language +){ + if (supplies.status == StatusCondition::POISON && supplies.antidotes > 0){ + 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, language)){ + 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){ + if (use_item_on_overworld(console, context, item_row(supplies, "potion"), "potion", checks, language)){ + supplies.potions--; + supplies.hurt = false; + supplies.hp_red = false; + supplies.hp_fill = 1.0; + } + } +} + +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, 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, 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 new file mode 100644 index 0000000000..7b16b43608 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -0,0 +1,205 @@ +/* AutoStory Battle + * + * From: https://github.com/PokemonAutomation/ + * + * 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 + * battle is fought instead of stopping the route. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryBattle_H +#define PokemonAutomation_PokemonFRLG_AutoStoryBattle_H + +#include +#include +#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" +#include "PokemonFRLG_AutoStoryBattleData.h" +#include "PokemonFRLG_AutoStoryParty.h" + +namespace PokemonAutomation{ +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, Antidotes, then Parlyz Heals. +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, 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. + 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; + 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); + // 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 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 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. + std::vector wild_foes = {}; +}; + +// 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); + +// 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 + TRAINER, +}; + +enum class BattleEnd{ + WON, + // 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, +}; + +// 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. +// 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. +// 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); + +// 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); + + +// 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 filled share of its width, 0 to 1, for the log. + double hp_fill = 0; + StatusCondition status = StatusCondition::NONE; +}; +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. 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( + 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, 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, Language language); + + +void add_tests_AutoStoryItems(UnitTestDatabase& database); + + + +} +} +} +#endif 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..4b7e4f2e3c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp @@ -0,0 +1,322 @@ +/* AutoStory Battle Data + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#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. 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"}, + {.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>; + +// [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]), + .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; + 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]), + .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; + }(); + 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()){ + strings.push_back(item.to_string_throw()); + } + return strings; +} + +// [species, level, iv, nature, [moves]] +TrainerMon trainer_mon(const JsonArray& entry){ + 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 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); + }); +} + +} + + +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; +} + +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: + 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){ + 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)); + if (it == trainers.end()){ + 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 ""; + } + 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(); + } + 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){ + 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; +} + +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 new file mode 100644 index 0000000000..cc15a6b446 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h @@ -0,0 +1,177 @@ +/* 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 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"). + * + */ + +#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; + // 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; + BaseStats base = {}; +}; + +struct TrainerMon{ + std::string species; + uint8_t level = 0; + // 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); + +// 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); + +// 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); + +// 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); + +// 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); + +// 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). +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..42ff159fbf --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData_Tests.cpp @@ -0,0 +1,204 @@ +/* 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_AutoStoryBattleSim.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->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){ + 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); + 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 new file mode 100644 index 0000000000..145b9e8c5f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -0,0 +1,390 @@ +/* AutoStory Battle Decisions + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "PokemonFRLG_AutoStoryBattleDecisions.h" +#include "PokemonFRLG_AutoStoryBattleSim.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); +// 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); +// 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; +// 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, 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 = foe_out(supplies); + const std::optional own = own_battler(supplies.lead, status.hp_seen ? status.hp_fill : 1.0); + if (!foe || !own){ + 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_fill * own->body.stats.hp; +} + +} + + +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); +} + +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) + , m_kind(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){ + 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; + 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 + // 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}; + } + 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){ + m_antidote_used = true; + return TurnAction{.choice = TurnChoice::ANTIDOTE}; + } + 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 +// 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 + ? 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}; + } + spend_pp(m_supplies.lead, *slot); + m_last_move_slot = slot; + return TurnAction{.choice = TurnChoice::MOVE, .slot = *slot}; +} + +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); + } + return; + } + if (!done){ + m_items_off = true; + return; + } + switch (choice){ + case TurnChoice::POTION: + m_healed = true; + 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}; + } + 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; + return PromptAnswer{.answer = YesNo::YES}; + } + 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); + 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) +{} + +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){ + 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); +} + +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; +} + +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; + } + 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 new file mode 100644 index 0000000000..7d5e8e1736 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h @@ -0,0 +1,247 @@ +/* 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 +#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; +}; + +// 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, +}; + +// 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 = {}; + // 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 = {}; +}; + + +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 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: + // "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, + // 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(); + // 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(); + + 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; + // 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 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. + 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); + + // 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; +}; + + +// 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); + + + +} +} +} +#endif 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..23e7f10f78 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.cpp @@ -0,0 +1,576 @@ +/* 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, 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){ + 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; +} + +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 PotionCase c = potion_case(own, foe, seen_hit); + const uint32_t healed = std::min(max_hp, own.hp + POTION_HP); + return c.max_hit >= own.hp && healed > c.max_hit && potion_pays(c); +} + +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..d5e142d2b7 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim.h @@ -0,0 +1,199 @@ +/* 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 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): + * 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, 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. +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); + +// 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{ + 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..375d088738 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleSim_Tests.cpp @@ -0,0 +1,456 @@ +/* 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% 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); + 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; +} + + +// 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; +} +} + + +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); + 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_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 new file mode 100644 index 0000000000..4c205cbb49 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -0,0 +1,528 @@ +/* AutoStory Events + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#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 "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" +#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" +#include "PokemonFRLG_AutoStoryWinChance.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +using namespace std::chrono_literals; +using Pokemon::facing_of; +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()); + } +} + +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; +} + +// 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}})); +} + +// 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){ + 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 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 + ); + 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, 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, .wall_check = wall_check(env)}; + 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})); +} + +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, 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, .wall_check = wall_check(env)}; + 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})); +} + +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})); +} + +// 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; + } + 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}%) with {}.", + step.name, trainer, estimate->wins, estimate->battles, 100 * estimate->chance, estimate->inputs + )); + 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"); + } + env.supplies.foes = trainer ? trainer_party(*trainer) : std::vector{}; + if (!env.supplies.foes.empty()){ + 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"); + } + mash_until_overworld(env.console, env.context, SCENE_TIMEOUT); + return Pokemon::outcome_ok(); +} + +// HP and status are the battle loop's last reading. Items first (an +// 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( + "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, env.language); + if (!nurse_before_battle(supplies)){ + return Pokemon::outcome_ok(); + } + Outcome walked = walk_route(env, state, step); + if (!walked.succeeded()){ + return walked; + } + heal_at_center(env.console, env.context); + healed_by_nurse(supplies); + return walked; +} + +// 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; + // The name the item list reader reads (read_item_list_name()). + const char* slug; +}; +constexpr MartItem VIRIDIAN_MART_ITEMS[] = { + {.item = "potion", .row = 1, .count = &Supplies::potions, .slug = "potion"}, + {.item = "antidote", .row = 2, .count = &Supplies::antidotes, .slug = "antidote"}, + {.item = "parlyz_heal", .row = 3, .count = &Supplies::parlyz_heals, .slug = "parlyz-heal"}, +}; + +const MartItem* viridian_mart_item(const std::string& name){ + for (const MartItem& item : VIRIDIAN_MART_ITEMS){ + if (name == item.item){ + return &item; + } + } + 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); + } + // 2000 of the 3000 a new game starts with, plus the rival's prize. + buy_items(env.console, env.context, *orders, env.checks, env.language); + for (const Pokemon::StoryItem& item : step.items){ + env.supplies.*viridian_mart_item(item.item)->count += (int)item.quantity; + } + 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, 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(); + } + 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(); +} + +} + + +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, found->slug}); + } + 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; +} + +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); +} + +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::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::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 +){ + 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); + if (in_bounds(map, next) && tile_at(map, next) == TileKind::WALL && object_at(map, next) == nullptr){ + return direction; + } + } + return std::nullopt; +} + +StoryExecutor::StoryExecutor(StoryEnv& env) + : m_env(env) +{} + +Outcome StoryExecutor::run(RunState& state, const StoryStep& step){ + return guarded([&]{ return Pokemon::StoryStepExecutor::run(state, step); }); +} + +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, m_env.language); + 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); + healed_by_nurse(m_env.supplies); + 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); +} + + +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; +} + +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; + // 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; +} + +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); + 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([&]{ + 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, 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, &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 new file mode 100644 index 0000000000..887ca363b6 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -0,0 +1,192 @@ +/* AutoStory Events + * + * From: https://github.com/PokemonAutomation/ + * + * The FRLG story as data for the shared story engine + * (Pokemon/AutoStory/Pokemon_StoryEvents.h, Pokemon_StorySegments.h). + * A checkpoint is a list of the shared StorySteps + * (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 + * 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/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 "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +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; +}; + +// 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. + Supplies supplies; + // The START menu at its end, when it saves. + StartMenu menu = StartMenu::FULL; +}; + + +// 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); +// `pose` as a StoryPose: nothing unless it is on one tile. +std::optional story_pose(const Pokemon::Pose& 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); + +// 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. +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. +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. +struct StoryEnv{ + ConsoleHandle& console; + ProControllerContext& context; + Supplies supplies; + Supplies saved_supplies; + // 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 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 +// 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); + +// 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); + +// 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{ +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; + +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; + 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, StoryExecutor& executor); + +// `checkpoints` (kept alive by the caller) as a segment for run_segment(). +Pokemon::Segment make_story_segment(const std::vector& checkpoints, StoryExecutor& executor); + + + +} +} +} +#endif 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_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp new file mode 100644 index 0000000000..107e9fc670 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -0,0 +1,300 @@ +/* AutoStory Items Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The Mart cursor's moves, and the bag's rows as the story counts them. + * + */ + +#include +#include +#include +#include +#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 "Tests/ImageUnitTest.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryBattle.h" +#include "PokemonFRLG_AutoStoryBattleDecisions.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; +} + +// #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. +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; +} + +// 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){ + 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."; + } + if (!read_save_card_location(logger, Language::Japanese, screen).empty()){ + return "Read a save card's place in Japanese."; + } + return true; +} + + +// 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; +}; + +// 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; +}; + + +} + + +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 + // 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); + 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.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp new file mode 100644 index 0000000000..117355debf --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.cpp @@ -0,0 +1,445 @@ +/* AutoStory Party + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "PokemonFRLG_AutoStoryBattleData.h" +#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}}, +}; + +// 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"}, + // 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"}, +}; + +// 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; +}; +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: 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){ + continue; + } + if (const std::optional slot = slot_of(member, rule.replaces)){ + return slot; + } + } + 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; +} + +// 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.base.sp_attack : attacker.base.attack; +} + +// 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 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); + const SpeciesData* own = species_data(member.species); + if (data == nullptr || own == nullptr){ + return 0; + } + 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, *species_data(foe)) * attacking_stat(*own, *data); + } + 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; +} + +} + + +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){ + 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, .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; + } + 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); +} + +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); + 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); + 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); + member.stats.reset(); + } +} + +std::optional attack_slot(const PartyMember& member){ + if (member.moves.size() < MAX_MOVES && !member.moves_read){ + 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; + } + } + 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; + } + } + return TOP_LEFT_MOVE; +} + +std::vector trainer_party(std::string_view trainer){ + std::vector party; + 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); + 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, known); + 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){ + if (move_power(known.move) > 0){ + pp += known.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..ad6f636b3d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h @@ -0,0 +1,171 @@ +/* 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), 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 + * 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). + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryParty_H +#define PokemonAutomation_PokemonFRLG_AutoStoryParty_H + +#include +#include +#include +#include +#include +#include +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" +#include "PokemonFRLG_AutoStoryDamage.h" + +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 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; + 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); + +// 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); + +// 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(); + +// `species` at `level` with `moves` as its summary shows them, in slot +// 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 ?". +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 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 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. +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..1b5388de98 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp @@ -0,0 +1,831 @@ +/* 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_AutoStoryBattleData.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, .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}); + } + 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, TurnResult::NOT_DONE); + 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; +} + +// 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; +} + + +// #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, 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"}; + 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("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); + if (slot != bite){ + return std::format("{} ({}): expected Bite (slot 1), got slot {}.", c.name, joined(c.foes), slot ? std::to_string(*slot) : "none"); + } + } + 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; + 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 with nothing read to keep the plan's order (Water Gun), whatever foes are set."; + } + return true; +} + +// 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("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("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) + "."; + } + } + 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{ + 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): 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]); + 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); + 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) || 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."; + } + + 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)){ + 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)){ + 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; +} + + +} + + +// 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; +} + +// 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); + 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); + 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); + 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/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..6410a0710c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -0,0 +1,395 @@ +/* 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/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/AutoStory/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; +} + +// 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; + 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; + // 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; + 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); + } +protected: + 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(); } + // 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){ + 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)); + } + 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})); + } + + 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; + + // 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()){ + 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); + } + // 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; +} + +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.08/forest_north"] = {.failure = "operation_failed", .times = 1}; + const Pokemon::SegmentReport report = sim.run({.from = "00.08", .to = "00.09"}); + if (!report.completed || report.reloads != 1 || sim.begun() != std::vector{"00.08", "00.08", "00.09"} + || sim.count("00.08/forest_east") != 2 + ){ + return "Expected 00.08 reloaded once and run again from its start:" + joined(sim.game.trace); + } + if (std::find(sim.lines.begin(), sim.lines.end(), "[Checkpoint] 00.08: 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.09/brock"] = {.failure = "blackout", .times = 10}; + const Pokemon::SegmentReport report = sim.run({.from = "00.09", .to = std::nullopt}); + if (report.completed || report.reloads != 2 || report.failed_checkpoint != "00.09" || report.failed_event != "brock" + || report.failure.failure != "blackout" || sim.count("00.09/brock") != 3 || !sim.saves.empty() + ){ + return "Expected 00.09 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_AutoStorySummary.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp new file mode 100644 index 0000000000..bfc466a410 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp @@ -0,0 +1,153 @@ +/* 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; +} + +// 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); + 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; + } + 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)){ + 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); + } + 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{}, {}, {}.", + slot + 1, read->species.empty() ? "?" : read->species, + 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 new file mode 100644 index 0000000000..9839147e90 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h @@ -0,0 +1,57 @@ +/* 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" +#include "PokemonFRLG_AutoStoryDamage.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 = {}; + // 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), 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 +// (`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/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp new file mode 100644 index 0000000000..7db4cec429 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -0,0 +1,297 @@ +/* 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 FOREST_GATE = "Route2_ViridianForest_NorthEntrance"; +const char* const PEWTER = "PewterCity"; +const char* const PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; +const char* const GYM = "PewterCity_Gym"; + +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; +} + +// At the rows after Brock: no items counted, the starter with the moves +// 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(); + return supplies; +} + +// 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; + step.name = std::move(name); + step.why = std::move(why); + return step; +} + +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 = wild == WildBattles::FIGHT; + 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, 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; + return step; +} + +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 = wild == WildBattles::FIGHT; + return 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; +} + +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; +} + +StoryStep talk(std::string name, std::string why){ + return make(StoryStepKind::TALK, std::move(name), std::move(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; +} + +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 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::OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon"), + }); +} + +StoryCheckpoint leave_house(){ + 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 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 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"), + 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(){ + 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 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 shopping(){ + return row("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"), + // 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)"), + 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"), + // 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 row("00.08", "Viridian Forest to Pewter Center", at(FOREST, 29, 62, NORTH), {5, 3, 1}, StartMenu::FULL, { + // 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)", 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 + // (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", 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"), + }); +} + +StoryCheckpoint brock(){ + // The by-hand save: 2 Potions and 1 Antidote left after the forest. + return row("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, + // 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"), + // 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"), + }); +} + +StoryCheckpoint running_shoes(){ + 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. + 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"), + }); +} + +} + + +const std::vector& story_checkpoints(){ + static const std::vector checkpoints{ + new_game(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), + 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 new file mode 100644 index 0000000000..d8a3f8b15d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -0,0 +1,37 @@ +/* AutoStory Table + * + * 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.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. + * + */ + +#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.10, in order. +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); + + + +} +} +} +#endif 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..5a636778dd --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp @@ -0,0 +1,397 @@ +/* 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; + } + 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){ + 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), + 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 new file mode 100644 index 0000000000..9056a41f83 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h @@ -0,0 +1,66 @@ +/* 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; + // 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 +// 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% with : 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/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..fa4b926b71 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -0,0 +1,591 @@ +/* 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 +#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" +#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 (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) : ""); +} + +// 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: + 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; +} + +// 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_east" || 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}; + 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."; + } + } + 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(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 (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}){ + return step.name + ": walks over the old man's trigger " + to_string(tile) + ":" + describe(*route); + } + } + } + pose = StoryPose{target.map, 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 || 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; + } + }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}; + } + if (step.pose_after){ + pose = one_tile(*step.pose_after); + } + } + return true; +} + +UnitTestResult test_routes_and_chain(){ + const std::vector& checkpoints = story_checkpoints(); + 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++){ + const StoryCheckpoint& checkpoint = checkpoints[c]; + if (c > 0){ + 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) + "."; + } + pose = start; + } + UnitTestResult result = check_checkpoint(checkpoint, pose); + if (result.result != UnitTestResult::PASSED){ + return result; + } + } + return true; +} + +struct ExpectedLeg{ + Direction direction; + int tiles; + TilePos end; +}; + +// 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( + story_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.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. + 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 = *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)."; + } + // 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}}} + ); +} + +// 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; +} + +// 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; +} + +// 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); + 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++){ + 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; +} +// 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; +} + +// 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& scene = option_menu_values(OptionMenuItem::BATTLE_SCENE); + 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 = 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. + {.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}, + {.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); + 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; +} + +} + + +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); + database.add("routes run after the Running Shoes", test_runs_after_shoes); + 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 8b2cf990a1..c99a56150f 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1744,8 +1744,14 @@ 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 + 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 @@ -1753,16 +1759,22 @@ 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 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 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 @@ -1823,6 +1835,38 @@ 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_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_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 + 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_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 Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EliteFourFarmer.h Source/VideoGames/PokemonFRLG/Programs/Farming/PokemonFRLG_EvTrainer.cpp diff --git a/devtools/maps/frlg_battle_data.py b/devtools/maps/frlg_battle_data.py new file mode 100644 index 0000000000..d89c74e5ec --- /dev/null +++ b/devtools/maps/frlg_battle_data.py @@ -0,0 +1,278 @@ +"""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 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 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'). +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_') +# 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} + + +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 ('baseHP', 'baseAttack', 'baseDefense', 'baseSpAttack', 'baseSpDefense', 'baseSpeed')] + 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')), + int(field(body, 'accuracy')), int(field(body, 'priority')), + slug(field(body, 'effect')[len('EFFECT_'):]), int(field(body, 'secondaryEffectChance')), + ] + return data + + +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): + species, level = slug(field(mon, 'species')[len('SPECIES_'):], SPECIES_SLUGS), int(field(mon, 'lvl')) + given = re.search(r'\.moves\s*=\s*\{(.*?)\}', mon) + if given: + 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 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 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 + + +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'), + 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)), + } + + +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()