Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d37290c
FRLG AutoStory: MART, TEACH, LEVEL, GRIND and fossil CHOICE steps
dayfine Nov 3, 2026
4bc0111
Merge remote-tracking branch 'origin/frlg/autostory-capture-pc' into …
dayfine Nov 3, 2026
feea081
FRLG AutoStory: console_member_reader reads the member's summary
dayfine Nov 3, 2026
2283ac9
Merge frlg/autostory-capture-pc into frlg/autostory-mart-teach-grind
dayfine Nov 3, 2026
a50f170
FRLG fossil CHOICE: answer YES when the prompt can't be read
dayfine Nov 3, 2026
fdc6d0a
Merge frlg/autostory-capture-pc into frlg/autostory-mart-teach-grind
dayfine Nov 3, 2026
b8ba43a
Merge frlg/autostory-capture-pc into frlg/autostory-mart-teach-grind
dayfine Nov 3, 2026
4636c38
FRLG AutoStory GRIND: heal when low on PP; the nurse restores PP
dayfine Nov 3, 2026
3f3709b
Merge frlg/autostory-capture-pc (battle loop: end on the overworld af…
dayfine Nov 3, 2026
d3247cb
Merge frlg/autostory-capture-pc (a disabled move, and a move list tha…
dayfine Nov 3, 2026
f12362b
Merge frlg/autostory-mvp (matchup attacks in every battle) into frlg/…
dayfine Nov 3, 2026
49d9739
Merge frlg/autostory-mvp (HP bar share, nurse for yellow HP, move pro…
dayfine Nov 3, 2026
34ca088
Merge frlg/autostory-capture-pc (ff64107c1: verify mode from #122) in…
dayfine Nov 3, 2026
44bb736
Merge frlg/autostory-capture-pc (5e6546498: battle sim from #120) int…
dayfine Nov 3, 2026
bb2b4f7
Merge frlg/autostory-capture-pc into frlg/autostory-mart-teach-grind
dayfine Nov 3, 2026
7f65001
Merge frlg/autostory-capture-pc (TM moves in the summary reader) into…
dayfine Nov 3, 2026
5773655
FRLG AutoStory TEACH: test the console's steps through the TM CASE's …
dayfine Nov 3, 2026
7a3192d
FRLG AutoStory TEACH: read the bag, the TM CASE and the party menu's …
dayfine Nov 3, 2026
eac0670
FRLG AutoStory TEACH: skip, with a log line, when the TM isn't in the…
dayfine Nov 3, 2026
b88e7cd
FRLG AutoStory GRIND: grind until the sim beats the next boss often e…
dayfine Nov 3, 2026
574483d
FRLG AutoStory GRIND/CAPTURE: find a battle whose flash was missed
dayfine Nov 3, 2026
0b79952
FRLG AutoStory TEACH: page through the texts after a forget
dayfine Nov 3, 2026
5a99a04
Merge frlg/autostory-capture-pc (bag rows below an item the reader ca…
dayfine Nov 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/* Teach Screen Reader
*
* From: https://github.com/PokemonAutomation/
*
* Reads the screens a TM is taught through, from the bag to the move it
* replaces, as the game shows them (console B, 2026-11-03): the bag's
* pockets, TM CASE in KEY ITEMS and its OPEN/REGISTER/CANCEL menu, the TM
* CASE's list and a TM's USE/GIVE/EXIT menu, the party menu's "Teach which
* POKEMON?", its messages and YES/NO, and the KNOWN MOVES page picking the
* move to forget (read with PokemonFRLG_SummaryMovesReader.h).
*
* Which screen shows is told from the colors of its background, its boxes
* and the dark arrow of its cursor, measured on those captures in the
* game's 240x160 pixels: the bag's frame is orange, the TM CASE's mint,
* the party menu's dark teal. Names and messages are read by OCR, in
* English only so far: in another language nothing is read.
*
*/

#ifndef PokemonAutomation_PokemonFRLG_TeachScreenReader_H
#define PokemonAutomation_PokemonFRLG_TeachScreenReader_H

#include <optional>
#include <string>
#include <vector>
#include "Common/Cpp/Logging/AbstractLogger.h"
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/Language.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


enum class TeachScreen{
OTHER,
// A pocket's list, its cursor live.
BAG,
// OPEN/REGISTER/CANCEL over the bag, or USE/GIVE/EXIT over the TM CASE.
ITEM_MENU,
// The TM CASE's list, its cursor live.
TM_CASE,
// "Teach which POKEMON?"
PARTY_PROMPT,
// A message over the party menu.
PARTY_TEXT,
// A message over the party menu with YES/NO.
PARTY_YES_NO,
// The KNOWN MOVES page with its red cursor: the move to forget.
KNOWN_MOVES,
};
const char* teach_screen_name(TeachScreen screen);

TeachScreen read_teach_screen(const ImageViewRGB32& screen);


// Rows a list or menu shows at once: the bag's, the TM CASE's (its info
// box is below), the item menu's.
constexpr size_t TEACH_LIST_ROWS = 6;
constexpr size_t TM_CASE_ROWS = 5;
constexpr size_t ITEM_MENU_ROWS = 3;

// The row the cursor is on: the dark arrow in the bag's list, the TM
// CASE's list, the item menu (0: OPEN or USE) or the party menu's YES/NO
// (0: YES); the red box on KNOWN MOVES. Nothing if no row or more than one
// has it.
std::optional<size_t> read_teach_cursor(TeachScreen screen, const ImageViewRGB32& image);

// The open pocket's name: "items", "key-items" or "poke-balls"; empty if
// not read.
std::string read_pocket_name(Logger& logger, Language language, const ImageViewRGB32& screen);

// The key item in the bag's row `row`: "tm-case", "teachy-tv", ... or
// "cancel"; empty if not read.
std::string read_key_item(Logger& logger, Language language, const ImageViewRGB32& screen, size_t row);

// The move of the TM or HM in the TM CASE's row `row`, as a slug such as
// "water-pulse"; empty for CLOSE or a move not read.
std::string read_tm_case_move(Logger& logger, Language language, const ImageViewRGB32& screen, size_t row);

// The rows of KEY ITEMS (`screen` BAG) or the TM CASE from the top, up to
// the first not read; KEY ITEMS' end with its "cancel".
std::vector<std::string> read_teach_rows(Logger& logger, Language language, const ImageViewRGB32& image, TeachScreen screen);

// The messages of the party menu while a TM is taught.
enum class TeachText{
UNKNOWN,
TEACH_WHICH, // "Teach which POKEMON?"
WANTS_TO_LEARN, // "<MON> wants to learn the move <MOVE>."
KNOWS_FOUR, // "However, <MON> already knows four moves."
DELETE_QUESTION, // "Should a move be deleted and replaced with <MOVE>?"
WHICH_MOVE, // "Which move should be forgotten?"
STOP_QUESTION, // "Stop trying to teach <MOVE>?"
DID_NOT_LEARN, // "<MON> did not learn the move <MOVE>."
NOT_COMPATIBLE, // "<MON> and <MOVE> are not compatible."
};
const char* teach_text_name(TeachText text);

// The message over the party menu, from the prompt's or the message box's
// first two lines.
TeachText read_teach_text(Logger& logger, Language language, const ImageViewRGB32& screen);


void add_tests_TeachScreenReader(UnitTestDatabase& database);



}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Pokemon FRLG Tests

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=802 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -26,6 +26,7 @@
#include "Inference/Menus/PokemonFRLG_PartyMenuDetector.h"
#include "Inference/Menus/PokemonFRLG_SaveCardReader.h"
#include "Inference/Menus/PokemonFRLG_SummaryMovesReader.h"
#include "Inference/Menus/PokemonFRLG_TeachScreenReader.h"
#include "Inference/PokemonFRLG_BattleLevelUpReader.h"
#include "Inference/PokemonFRLG_BattleSelectionArrowDetector.h"
#include "Inference/PokemonFRLG_PartyLevelUpReader.h"
Expand All @@ -41,6 +42,7 @@
#include "Overworld/PokemonFRLG_PlayerFacingReader.h"
#include "Programs/PokemonFRLG_NamingScreenKeyboard.h"
#include "PokemonFRLG_Navigation.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryCapture.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage.h"
Expand Down Expand Up @@ -696,9 +698,10 @@
add_tests_OptionMenuReader(database);
add_tests_SaveCardReader(database);
add_tests_SummaryMovesReader(database);
add_tests_TeachScreenReader(database);
}

void add_tests(UnitTestDatabase& database){

Check warning on line 704 in SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::add_tests( UnitTestDatabase & database): function_lines=46 (advisory above 25, limit 50)
add_tests_AdvanceWhiteDialogDetector(database);
add_tests_BoxCellOccupiedDetector(database);
add_tests_BoxCellReader(database);
Expand Down Expand Up @@ -737,6 +740,7 @@
add_tests_AutoStoryRngLoop(database);
add_tests_AutoStoryCapture(database);
add_tests_AutoStoryPcStorage(database);
add_tests_AutoStoryAbilities(database);
add_tests_NamingCursor(database);
add_tests_NamingPlan(database);
add_tests_NamingKeys(database);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/* AutoStory Abilities
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/Exceptions/ProgramFinishedException.h"
#include "PokemonFRLG_AutoStoryAbilities.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{

using Pokemon::Outcome;


namespace{

Outcome mart(Logger& logger, const MartPlan& plan, StoryAbilities& abilities){
const MartResult result = run_mart(logger, abilities.mart, plan);
const std::string message = mart_message(plan, result);
const bool ok = result.end == MartEnd::DONE || result.end == MartEnd::NOTHING_TO_BUY;
logger.log(message, result.end == MartEnd::DONE ? COLOR_BLACK : COLOR_RED);
return ok ? Pokemon::outcome_ok() : Pokemon::outcome_failed(std::string("mart_") + mart_end_name(result.end), message);
}

Outcome teach(Logger& logger, const TeachPlan& plan, StoryAbilities& abilities){
const TeachResult result = run_teach(logger, abilities.teach, abilities.members, plan);
// NO_ITEM: skipped, with run_teach()'s log line.
if (result.end == TeachEnd::LEARNED || result.end == TeachEnd::ALREADY_KNOWN || result.end == TeachEnd::NO_ITEM){
return Pokemon::outcome_ok();
}
return Pokemon::outcome_failed(std::string("teach_") + teach_end_name(result.end), teach_message(plan, result));
}

Outcome level(Logger& logger, const LevelCheck& check, StoryAbilities& abilities){
const LevelResult result = run_level_check(logger, abilities.members, check);
switch (result.end){
case LevelEnd::REACHED:
return Pokemon::outcome_ok();
case LevelEnd::BELOW:
return Pokemon::outcome_failed("level_below", std::to_string(*result.level) + " < " + std::to_string(check.level));
case LevelEnd::UNREAD:
break;
}
return Pokemon::outcome_failed("level_unread");
}

Outcome grind(Logger& logger, VideoStream* stream, const GrindPlan& plan, StoryAbilities& abilities){
const GrindResult result = run_grind(logger, abilities.grind, abilities.members, plan);
const std::string message = grind_message(plan, result);
if (result.end == GrindEnd::SHINY){
// Not a failed Outcome, which would reload the save.
if (stream != nullptr){
throw ProgramFinishedException(message, *stream);
}
throw ProgramFinishedException(message);
}
if (result.end == GrindEnd::REACHED){
return Pokemon::outcome_ok();
}
return Pokemon::outcome_failed(std::string("grind_") + grind_end_name(result.end), message);
}

Outcome fossil(Logger& logger, Fossil fossil, StoryAbilities& abilities){
const ChoiceResult result = run_fossil_choice(logger, abilities.choice, fossil);
if (result.end == ChoiceEnd::TAKEN){
return Pokemon::outcome_ok();
}
logger.log("Choice: " + result.detail, COLOR_RED);
return Pokemon::outcome_failed(std::string("fossil_") + choice_end_name(result.end), result.detail);
}

}


std::optional<Outcome> run_ability_game_step(

Check warning on line 77 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::run_ability_game_step( Logger & logger , VideoStream * stream , const Pokemon :: StoryStep & step , StoryAbilities & abilities): function_lines=29 (advisory above 25, limit 50)
Logger& logger, VideoStream* stream, const Pokemon::StoryStep& step, StoryAbilities& abilities
){
const std::string_view variant = step.variant;
if (variant.starts_with(MART_VARIANT_PREFIX)){
const std::optional<MartPlan> plan = parse_mart_variant(variant);
return plan ? mart(logger, *plan, abilities) : Pokemon::outcome_failed("bad_variant", step.variant);
}
if (variant.starts_with(TEACH_VARIANT_PREFIX)){
const std::optional<TeachPlan> plan = parse_teach_variant(variant);
return plan ? teach(logger, *plan, abilities) : Pokemon::outcome_failed("bad_variant", step.variant);
}
if (variant.starts_with(LEVEL_VARIANT_PREFIX)){
const std::optional<LevelCheck> check = parse_level_variant(variant);
return check ? level(logger, *check, abilities) : Pokemon::outcome_failed("bad_variant", step.variant);
}
if (variant.starts_with(GRIND_VARIANT_PREFIX)){
const std::optional<GrindPlan> plan = parse_grind_variant(variant);
if (!plan || !step.target){
return Pokemon::outcome_failed("bad_variant", step.variant + (step.target ? "" : " (no nurse)"));
}
return grind(logger, stream, *plan, abilities);
}
if (variant.starts_with(FOSSIL_VARIANT_PREFIX)){
const std::optional<Fossil> choice = parse_fossil_variant(variant);
return choice ? fossil(logger, *choice, abilities) : Pokemon::outcome_failed("bad_variant", step.variant);
}
return std::nullopt;
}



}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* AutoStory Abilities
*
* From: https://github.com/PokemonAutomation/
*
* The GAME steps beyond walking and talking that later checkpoints name
* in the table: MART (a budgeted buy list), TEACH (a TM or HM), LEVEL (a
* member's level checked), GRIND (wild battles to a level) and
* CHOICE(fossil). Each is a variant of a GAME step; this runs the one a
* step names with the game steps it is given.
*
*/

#ifndef PokemonAutomation_PokemonFRLG_AutoStoryAbilities_H
#define PokemonAutomation_PokemonFRLG_AutoStoryAbilities_H

#include <optional>
#include "Common/Cpp/Logging/AbstractLogger.h"
#include "CommonFramework/Tools/VideoStream.h"
#include "Pokemon/AutoStory/Pokemon_StoryEvents.h"
#include "Pokemon/AutoStory/Pokemon_StorySteps.h"
#include "PokemonFRLG_AutoStoryChoice.h"
#include "PokemonFRLG_AutoStoryGrind.h"
#include "PokemonFRLG_AutoStoryMart.h"
#include "PokemonFRLG_AutoStoryMember.h"
#include "PokemonFRLG_AutoStoryTeach.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


// The game steps the abilities take.
struct StoryAbilities{
MemberReader members;
MartActions& mart;
TeachActions& teach;
GrindActions& grind;
ChoiceActions& choice;
};

// A MART, TEACH, LEVEL, GRIND or fossil step with `abilities`: nothing for
// another variant. A GRIND that meets a shiny throws
// ProgramFinishedException, with a screenshot from `stream` if given, so
// the segment stops without reloading. Any other end but success is a
// failed Outcome; a MART that buys nothing because the money doesn't
// cover it, and a TEACH whose TM isn't in the TM CASE, succeed, with the
// reason logged.
std::optional<Pokemon::Outcome> run_ability_game_step(
Logger& logger, VideoStream* stream, const Pokemon::StoryStep& step, StoryAbilities& abilities
);


// These steps' tests, with the Mart's, TEACH's, GRIND's and the fossil's.
void add_tests_AutoStoryAbilities(UnitTestDatabase& database);



}
}
}
#endif
Loading
Loading