Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

#include <algorithm>
#include <format>
#include <string>
#include <string_view>
#include "Common/Cpp/Filesystem/Filesystem.h"
#include "Common/Cpp/Json/JsonArray.h"
#include "Common/Cpp/Json/JsonObject.h"
#include "Common/Cpp/TestRunners/UnitTest.h"
#include "CommonFramework/GlobalAutoPaths.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "CommonFramework/Language.h"
Expand Down Expand Up @@ -46,6 +48,15 @@
return matcher;
}

std::string match(Language language, const std::string& text) const{
if (!languages()[language]){
return "";
}
OCR::StringMatchResult result = match_substring(language, text, MAX_LOG10P_SPREAD);
result.clear_beyond_log10p(MAX_LOG10P);
return result.results.empty() ? "" : result.results.begin()->second.token;
}

std::string read(Logger& logger, Language language, const ImageViewRGB32& image) const{
if (!languages()[language]){
return "";
Expand All @@ -63,7 +74,7 @@
: SmallDictionaryMatcher(dictionary())
{}

static JsonObject dictionary(){

Check warning on line 77 in SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::ItemNameMatcher::dictionary(): function_lines=33 (advisory above 25, limit 50)
JsonObject english;
for (const auto& [slug, name] : {
std::pair<std::string_view, std::string_view>{"potion", "Potion"},
Expand All @@ -80,6 +91,12 @@
{"x-accuracy", "X Accuracy"},
{"guard-spec", "Guard Spec."},
{"bicycle", "Bicycle"},
// Route 17's hidden items. Without them a RARE CANDY read
// "FARE CANCY" and matched CANCEL: the pocket's read ended
// above it, and 11.02 counted no RARE CANDY in a bag with 2
// (console B, 2026-11-12).
{"rare-candy", "Rare Candy"},
{"max-elixir", "Max Elixir"},
{"cancel", "Cancel"},
}){
JsonArray names;
Expand All @@ -96,6 +113,16 @@
return extract_box_reference(screen, GameSettings::instance().GAME_BOX);
}

// A row from its name's and its count's reads: a row with a count that
// matched CANCEL is an item whose name can't be read, as the list's
// CANCEL shows no count.
BagRow bag_row(std::string item, int count){
if (item == "cancel"){
return count > 0 ? BagRow{"", count} : BagRow{std::move(item), 0};
}
return BagRow{std::move(item), count};
}

// Where row `row` of the bag shows its item count.
ImageFloatBox bag_item_count_box(int row){
return ImageFloatBox(208.0 / 240, (ROW_TOP + ROW_STEP * row) / 160, 15.0 / 240, ROW_HEIGHT / 160);
Expand All @@ -113,16 +140,13 @@
}

BagRow read_bag_row(Logger& logger, Language language, const ImageViewRGB32& screen, int shown){
const std::string item = read_item_list_name(logger, language, screen, shown);
if (item == "cancel"){
return BagRow{item, 0};
}
std::string item = read_item_list_name(logger, language, screen, shown);
const ImageViewRGB32 count = extract_box_reference(game_box(screen), bag_item_count_box(shown));
// 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.
return BagRow{item, read_digits_waterfill_template(logger, count, DigitTemplateType::StatBox)};
return bag_row(std::move(item), read_digits_waterfill_template(logger, count, DigitTemplateType::StatBox));
}

std::vector<BagRow> read_bag_pocket(Logger& logger, Language language, const ImageViewRGB32& screen){
Expand Down Expand Up @@ -186,6 +210,38 @@
}
};

// 11.02's counts (console B, 2026-11-12): OCR read the RARE CANDY's row
// "FARE CANCY", which matched CANCEL with no Rare Candy in the dictionary,
// and the pocket's read ended above it. A row with a count is never the
// CANCEL, whatever its name matched.
class Test_Route17ItemNames : public UnitTest{
public:
Test_Route17ItemNames()
: UnitTest("PokemonFRLG::ItemListReader - 11.02 the RARE CANDY's row is not the CANCEL")
{}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{
const ItemNameMatcher& matcher = ItemNameMatcher::instance();
for (const std::string& text : {"FARE CANCY", "RARE CANOY", "RARE CANDY"}){
const std::string item = matcher.match(Language::English, text);
if (item != "rare-candy"){
return std::format("Expected \"{}\" read as rare-candy, got \"{}\".", text, item);
}
}
if (matcher.match(Language::English, "MAX ELIXIR") != "max-elixir" || matcher.match(Language::English, "CANCEL") != "cancel"){
return "Expected MAX ELIXIR and CANCEL read as themselves.";
}
const BagRow counted = bag_row("cancel", 2);
if (!counted.item.empty() || counted.count != 2){
return std::format("Expected a CANCEL with 2 read as an unread item x2, got \"{}\" x{}.", counted.item, counted.count);
}
if (bag_row("cancel", -1).item != "cancel"){
return "Expected a CANCEL with no count kept as the CANCEL.";
}
return true;
}
};

// 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{
Expand Down Expand Up @@ -228,6 +284,7 @@
database.add<Test_BagPocket>("PokemonFRLG/ItemListReader/ItemsPocketMoonStone_eng.png");
// The Viridian Mart's BUY list, the same day, the cursor on POTION.
database.add<Test_MartList>("PokemonFRLG/ItemListReader/MartBuyList_eng.png");
database.add<Test_Route17ItemNames>();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
: SmallDictionaryMatcher(dictionary())
{}

static JsonObject dictionary(){

Check warning on line 64 in SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::PlaceNameMatcher::dictionary(): function_lines=31 (advisory above 25, limit 50)
JsonObject english;
for (const auto& [slug, name] : {
std::pair<std::string_view, std::string_view>{"pallet-town", "Pallet Town"},
Expand All @@ -82,6 +82,7 @@
{"rocket-hideout", "Rocket Hideout"},
{"pokemon-tower", "Pokemon Tower"},
{"route-16", "Route 16"},
{"fuchsia-city", "Fuchsia City"},
}){
JsonArray names;
names.push_back(std::string(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ constexpr std::string_view MAP_NAMES[] = {
"Route16",
"Route16_NorthEntrance_1F",
"Route16_House",
// Route 18 from the Cycling Road's foot (Route 17 has no map: its
// slope is ridden by presses, PokemonFRLG_AutoStorySlope.h), its gate,
// and Fuchsia City to the Safari Zone's door.
"Route18",
"Route18_EastEntrance_1F",
"FuchsiaCity",
"CeruleanCave_1F",
"CeruleanCave_2F",
"CeruleanCave_B1F",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ static void add_tests_AutoStoryRows(UnitTestDatabase& database){
add_tests_AutoStoryVermilionGym(database);
add_tests_AutoStoryCeladon(database);
add_tests_AutoStorySnorlax(database);
add_tests_AutoStorySlope(database);
}

void add_tests(UnitTestDatabase& database){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutoStory Events

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=985 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -28,6 +28,7 @@
#include "PokemonFRLG_AutoStoryHideout.h"
#include "PokemonFRLG_AutoStoryLegs.h"
#include "PokemonFRLG_AutoStoryScreenEvents.h"
#include "PokemonFRLG_AutoStorySlopeRun.h"
#include "PokemonFRLG_AutoStorySummary.h"
#include "PokemonFRLG_AutoStoryTable.h"
#include "PokemonFRLG_AutoStoryTeachScreens.h"
Expand Down Expand Up @@ -347,7 +348,7 @@
return StoryPose{pose.map, tiles[0], facing_of(pose)};
}

std::string save_card_place(const std::string& map){

Check warning on line 351 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::save_card_place( const std :: string & map): function_lines=29 (advisory above 25, limit 50)
// A map of the place, or a building in it ("Route4_PokemonCenter_1F"
// is on Route 4, "Route24" isn't on Route 2).
static const std::pair<std::string, std::string_view> PLACES[] = {
Expand All @@ -367,6 +368,7 @@
{"RocketHideout", "rocket-hideout"},
{"PokemonTower", "pokemon-tower"},
{"Route16", "route-16"},
{"FuchsiaCity", "fuchsia-city"},
};
for (const auto& [prefix, place] : PLACES){
if (map == prefix || map.rfind(prefix + "_", 0) == 0){
Expand Down Expand Up @@ -654,7 +656,7 @@

// The GAME steps without a row of their own: a capture or a PC deposit or
// withdrawal, a MART, TEACH, LEVEL, GRIND or fossil CHOICE.
Outcome other_game_step(StoryEnv& env, RunState& state, const StoryStep& step){

Check warning on line 659 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::other_game_step( StoryEnv & env , RunState & state , const StoryStep & step): function_lines=26 (advisory above 25, limit 50)
const Pokemon::Pose patch = state.pose;
ConsoleCaptureActions capture(env.console, env.context, env.language, env.player_gender, [&]{
pace_trainer_battle(env, state, step, patch);
Expand All @@ -667,6 +669,10 @@
if (!done){
done = run_abilities(env, state, step);
}
if (!done){
SlopeEnv slope{env.console, env.context, env.supplies, env.checks, env.language, env.counted_items};
done = run_slope_step(slope, step);
}
if (done && done->succeeded() && !done->pose){
// Pacing leaves the player on either of its tiles.
done->pose = paced_pose(state.pose, step);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define PokemonAutomation_PokemonFRLG_AutoStoryEvents_H

#include <functional>
#include <map>
#include <optional>
#include <string>
#include <vector>
Expand Down Expand Up @@ -89,6 +90,9 @@ struct StoryEnv{
// The player: the one a new game picks, and whose sprites the facing
// reader matches. A save must be of this player.
PlayerGender player_gender = PlayerGender::BOY;
// The Items pocket's counts a count_items step kept
// (PokemonFRLG_AutoStorySlopeRun.h), for the next to compare.
std::map<std::string, int> counted_items = {};
};

// After a save is loaded for a checkpoint that starts on `start_map`: the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN_11[] = {
"11.01 walk west 1 -> Route16 (32, 13)",
"11.01 east_of_cycling_road_gate from Route16 (32, 13) facing west to Route16 (28, 13) facing west",
"11.01 walk west 4 -> Route16 (28, 13)",
"11.02 east_of_bikers from Route16 (28, 13) facing west to Route16 (17, 13) facing west",
"11.02 walk west 2 (warp) -> Route16_NorthEntrance_1F (11, 12)",
"11.02 walk west 11 (warp) -> Route16 (20, 13)",
"11.02 walk west 3 -> Route16 (17, 13)",
"11.02 safari_zone_door from Route18 (8, 10) facing south to FuchsiaCity (24, 6) facing north",
"11.02 walk north 1 -> Route18 (8, 9)",
"11.02 walk east 34 (warp) -> Route18_EastEntrance_1F (1, 6)",
"11.02 walk east 11 (warp) -> Route18 (48, 9)",
"11.02 walk east 18 (to wall) -> FuchsiaCity (6, 19) [connection 12]",
"11.02 walk south 6 (to wall) -> FuchsiaCity (6, 25)",
"11.02 walk east 23 -> FuchsiaCity (29, 25)",
"11.02 walk north 8 (to wall) -> FuchsiaCity (29, 17)",
"11.02 walk east 7 -> FuchsiaCity (36, 17)",
"11.02 walk south 1 (to wall) -> FuchsiaCity (36, 18)",
"11.02 walk east 9 (to wall) -> FuchsiaCity (45, 18)",
"11.02 walk north 13 (to wall) -> FuchsiaCity (45, 5)",
"11.02 walk west 17 (to wall) -> FuchsiaCity (28, 5)",
"11.02 walk south 1 (to wall) -> FuchsiaCity (28, 6)",
"11.02 walk west 4 -> FuchsiaCity (24, 6)",
"11.02 face north -> FuchsiaCity (24, 6)",
};

} // namespace PokemonFRLG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutoStory Row Tests

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows_Tests.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<header>: header_symbols=7 (advisory above 6, limit 8)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -30,6 +30,8 @@
void add_tests_AutoStoryTower(UnitTestDatabase& database);
// Row 11.01 on the overworld sim (PokemonFRLG_AutoStorySnorlax_Tests.cpp).
void add_tests_AutoStorySnorlax(UnitTestDatabase& database);
// Row 11.02 on the sims (PokemonFRLG_AutoStorySlope_Tests.cpp).
void add_tests_AutoStorySlope(UnitTestDatabase& database);


} // namespace PokemonFRLG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutoStory Run Plan Tests

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=660 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -139,7 +139,7 @@
const RunPlanScenario m_scenario;
};

const std::string TODAY = "01.01 01.03 01.04 01.05 02.01 02.02 02.03 03.01 03.02 03.03 04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01";
const std::string TODAY = "01.01 01.03 01.04 01.05 02.01 02.02 02.03 03.01 03.02 03.03 04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02";

const RunPlanScenario RUN_PLAN_CASES[] = {
{
Expand Down Expand Up @@ -230,11 +230,11 @@
},
{
.input = {.name = "Gift RNG off: 04.03 is passed over", .first = "04.01"},
.expectation = {.expected_ids = "04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01"},
.expectation = {.expected_ids = "04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02"},
},
{
.input = {.name = "Gift RNG off: 04.03 runs when started at", .first = "04.03"},
.expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01"},
.expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02"},
},
{
.input = { .name = "Gift RNG: started at 04.03, from the save beside the salesman",
Expand Down Expand Up @@ -273,7 +273,7 @@
},
{
.input = {.name = "Starter RNG alone: 04.03 runs when started at", .first = "04.03", .handoffs = {.starter_rng = true}},
.expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01"},
.expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02"},
},
{
.input = { .name = "Starter RNG first, with both on",
Expand Down
Loading
Loading