Skip to content
Closed
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 @@ -59,7 +59,7 @@
: SmallDictionaryMatcher(dictionary())
{}

static JsonObject dictionary(){

Check warning on line 62 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=28 (advisory above 25, limit 50)
JsonObject english;
for (const auto& [slug, name] : {
std::pair<const char*, const char*>{"pallet-town", "Pallet Town"},
Expand All @@ -77,6 +77,7 @@
{"lavender-town", "Lavender Town"},
{"vermilion-city", "Vermilion City"},
{"celadon-city", "Celadon City"},
{"rocket-hideout", "Rocket Hideout"},
}){
JsonArray names;
names.push_back(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#include "PokemonFRLG_BikeSpinPresses.h"
#include "PokemonFRLG_BikeSpinMechanics.h"
#include "PokemonFRLG_OverworldMaps.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "PokemonFRLG_OverworldRecovery.h"
#include "PokemonFRLG_OverworldRecoveryWalk.h"
#include "PokemonFRLG_OverworldRoute.h"
#include "PokemonFRLG_OverworldSim.h"
#include "PokemonFRLG_OverworldSimField.h"
Expand Down Expand Up @@ -215,7 +217,47 @@ UnitTestResult test_speed_after_door(){
return true;
}

// A floor that repeats every 16-pixel tile, with a pillar on the bottom
// row, seen from `scroll` pixels east.
ImageRGB32 periodic_floor(size_t scroll){
ImageRGB32 image(160, 160);
for (size_t y = 0; y < 160; y++){
for (size_t x = 0; x < 160; x++){
const size_t floor_x = x + scroll;
uint32_t pixel = (floor_x % 16 < 8) ^ (y % 16 < 8) ? 0xff808040 : 0xffa0a060;
if (y >= 130 && floor_x >= 100 && floor_x < 120){
pixel = 0xff000000;
}
image.pixel(x, y) = pixel;
}
}
return image;
}

// Rocket Hideout B3F (00.32 run 1): a tap east over a floor that repeats
// every tile left the top band the same, so the tap read as a turn.
UnitTestResult test_scroll_over_periodic_floor(){
const ImageFloatBox game(0, 0, 1, 1);
const ImageRGB32 before = periodic_floor(0);
const double stepped = tap_scroll_change(before, periodic_floor(16), game);
if (stepped <= WALL_TAP_MOVED_RMSD){
return std::format("Expected a one-tile scroll to read as a step: change {}.", stepped);
}
ImageRGB32 turned = periodic_floor(0);
for (size_t y = 64; y < 96; y++){
for (size_t x = 64; x < 96; x++){
turned.pixel(x, y) = 0xffff0000;
}
}
const double bumped = tap_scroll_change(before, turned, game);
if (bumped > WALL_TAP_MOVED_RMSD){
return std::format("Expected the player turning in the middle not to read as a step: change {}.", bumped);
}
return true;
}

const BikeCase OVERWORLD_BIKE_CASES[] = {
{.input = {"a tap over a floor that repeats every tile", test_scroll_over_periodic_floor}, .expectation = {"scroll seen at the bottom edge; a turn is not"}},
{.input = {"taps a tile each, one in 12 dropped 60ms apart", test_tap_chains}, .expectation = {"23 of 25 tiles at 60ms; 25 at 100 and 120ms"}},
{.input = {"an open leg of 11 from a start 2 off, counted in taps", test_counted_leg_off_start}, .expectation = {"found against the rock and walked back"}},
{.input = {"SELECT onto the registered Bicycle", test_select_onto_bike}, .expectation = {"one press registered; two and off unregistered"}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
*/

#include <algorithm>
#include <format>
#include <memory>
#include <optional>
Expand Down Expand Up @@ -61,21 +62,26 @@ struct StepWalk{
bool blocked = false;
};

// TODO(forest drift, 2026-11-01): the threshold is a diagnostic's guess.
// How much the game screen's top quarter, clear of the player in the
// middle, may change when a tap toward a wall only bumps the player (the
// player's own animation, an animated tile). A step scrolls the whole map
// by a tile. Not yet measured on the console: a guess on the safe side.
constexpr double WALL_TAP_MOVED_RMSD = 20.0;

// How much the top quarter of the game screen changed from `before` to
// `after`: a step scrolls it by a tile.
double top_band_change(const ImageViewRGB32& before, const ImageViewRGB32& after){
const ImageFloatBox game = GameSettings::instance().GAME_BOX;
const ImageFloatBox band(game.x, game.y, game.width, game.height * 0.25);
return ImageMatch::pixel_RMSD(extract_box_reference(before, band), extract_box_reference(after, band));
} // namespace

double tap_scroll_change(const ImageViewRGB32& before, const ImageViewRGB32& after, const ImageFloatBox& game){
const double w = game.width * 0.25;
const double h = game.height * 0.25;
const ImageFloatBox bands[] = {
{game.x, game.y, game.width, h},
{game.x, game.y + game.height - h, game.width, h},
{game.x, game.y, w, game.height},
{game.x + game.width - w, game.y, w, game.height},
};
double most = 0;
for (const ImageFloatBox& band : bands){
most = std::max(most, ImageMatch::pixel_RMSD(extract_box_reference(before, band), extract_box_reference(after, band)));
}
return most;
}

namespace{

// A counted tap's press, its release and the wait after it for the
// screen to show the step.
struct TapTiming{
Expand Down Expand Up @@ -116,7 +122,7 @@ BikeTap console_bike_tap(
return BikeTap{.moved = false, .interrupt = (size_t)ret};
}
const VideoSnapshot after = console.video().snapshot();
if (before && after && top_band_change(before, after) > WALL_TAP_MOVED_RMSD){
if (before && after && tap_scroll_change(before, after, GameSettings::instance().GAME_BOX) > WALL_TAP_MOVED_RMSD){
return BikeTap{.moved = true};
}
const bool late = Pokemon::clear_late_interrupts(console, context, interrupts, AFTER_LEG_WATCH, MAX_INTERRUPTIONS_PER_LEG) > 0;
Expand Down Expand Up @@ -412,7 +418,7 @@ bool moved_past_wall(ConsoleHandle& console, ProControllerContext& context, cons
if (!before || !after){
return false;
}
const double change = top_band_change(before, after);
const double change = tap_scroll_change(before, after, GameSettings::instance().GAME_BOX);
console.log(std::format("Position check: a tap toward the wall of {} changed the screen by {:.1f}.", to_string(step), change));
return change > WALL_TAP_MOVED_RMSD;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include <optional>
#include <vector>
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
#include "PokemonFRLG_OverworldRecovery.h"
Expand All @@ -26,6 +28,21 @@ namespace NintendoSwitch{
namespace PokemonFRLG{


// TODO(forest drift, 2026-11-01): the threshold is a diagnostic's guess.
// How much each edge quarter of the game screen, clear of the player in the
// middle, may change when a tap toward a wall only bumps the player (the
// player's own animation, an animated tile). A step scrolls the whole map
// by a tile. Not yet measured on the console: a guess on the safe side.
constexpr double WALL_TAP_MOVED_RMSD = 20.0;

// How much a counted tap scrolled the map: the largest RMSD between `before`
// and `after` over the four edge quarters (top, bottom, left, right) of
// `game`, all clear of the player in the middle. One band alone misses a
// step over a floor that repeats every tile (Rocket Hideout B3F, 00.32): a
// one-tile scroll leaves the band nearly the same.
double tap_scroll_change(const ImageViewRGB32& before, const ImageViewRGB32& after, const ImageFloatBox& game);


// Walks `route`, planned with `planning`, at `speed`, as
// walk_overworld_route() does, from the same start: standing still on the
// overworld, not on the bike, facing `facing` (read from the screen if not
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Sim

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=994 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -326,7 +326,6 @@
return step;
}


// A trainer on the player's map who sees them now walks up and speaks.
bool OverworldSim::trainer_sees(Milliseconds pressed){
std::vector<MapObject>& objects = m_maps[m_map].objects;
Expand Down Expand Up @@ -528,7 +527,6 @@
}
}


std::optional<SimSeen> OverworldSim::hold(
Direction direction, Milliseconds duration, Milliseconds release, Milliseconds watch,
const std::vector<SimWatcher>& watchers
Expand Down Expand Up @@ -674,8 +672,6 @@
return true;
}



//
// OverworldSimWalker
//
Expand All @@ -698,7 +694,6 @@

} // namespace


OverworldSimWalker::OverworldSimWalker(OverworldSim& sim, SimWalkerRules rules, const OverworldInterruptSet& walker)
: m_sim(sim)
, m_rules(rules)
Expand Down Expand Up @@ -787,16 +782,22 @@
// was a wild battle's, run from. wait_out_warp()'s watcher takes a wild
// battle's wipe for the fade (run 7; console B, 2026-11-03, Mt. Moon 1F):
// the battle screen stands in for the wipe. The fade is watched for from
// `watched_from`: a fade over by then is missed.
// `watched_from`: a fade over by then is missed. No warp: a step more,
// twice: a hold ends up to two tiles short, and an arrow warp (stairs)
// fires on the press made standing on it.
bool OverworldSimWalker::after_warp(const RouteStep& step, int warps_before, Milliseconds watched_from){
if (black_without_warp(step, warps_before, watched_from)){
return true;
}
if (m_sim.state().warps == warps_before){
if (!m_sim.watch({SimWatcher::BATTLE_SCREEN}, WARP_TIMEOUT)){
fail("walk_overworld_route(): no fade in and out after walking onto the warp to " + step.end.map + ".");
bool battle = false;
if (m_sim.state().warps == warps_before && !(battle = m_sim.watch({SimWatcher::BATTLE_SCREEN}, WARP_TIMEOUT).has_value())){
for (int tap = 0; tap < 2 && m_sim.state().warps == warps_before; tap++){
m_log.push_back("Route: no fade; one more step into the warp.");
watched_from = m_sim.state().time;
m_sim.tap(step.direction, STEP_TAP, STEP_TAP_RELEASE);
}
}else if (!fade_over_since(watched_from) && !m_sim.watch({SimWatcher::FADE}, WARP_TIMEOUT)){
}
if (!battle && (m_sim.state().warps == warps_before || (!fade_over_since(watched_from) && !m_sim.watch({SimWatcher::FADE}, WARP_TIMEOUT)))){
fail("walk_overworld_route(): no fade in and out after walking onto the warp to " + step.end.map + ".");
}
m_sim.watch({}, AFTER_WARP);
Expand Down Expand Up @@ -988,8 +989,6 @@
return "";
}



} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Walk

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=782 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -354,19 +354,32 @@

// One watcher for the whole fade: a ladder's black is short enough to be
// over before a second watcher, started once the fade is seen, looks.
void wait_out_fade(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, Pokemon::WatchAlong& fade){

Check warning on line 357 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::OverworldWalkSteps::wait_out_fade( ConsoleHandle & console , ProControllerContext & context , const RouteStep & step , Pokemon :: WatchAlong & fade): function_lines=27 (advisory above 25, limit 50)
if (fade.fired()){
console.log("Route: the fade to " + step.end.map + " was over before the hold ended.");
return;
}
context.wait_for_all_requests();
if (wait_until(console, context, WARP_TIMEOUT, {fade.watcher()}) < 0){
OperationFailedExceptionWithScreenshot::fire(
ErrorReportMode::SEND_ERROR_REPORT,
"walk_overworld_route(): no fade in and out after walking onto the warp to " + step.end.map + ".",
console
);
if (wait_until(console, context, WARP_TIMEOUT, {fade.watcher()}) >= 0){
return;
}
// A hold that ended short of a stairs or door warp, or on an arrow
// warp: a step more at a time, twice, takes it. A hold ends up to two
// tiles short, and an arrow warp fires on the press made standing on it.
for (int tap = 0; tap < 2; tap++){
console.log("Route: no fade; one more step into the warp.", COLOR_ORANGE);
BlackScreenOverWatcher arrival(COLOR_RED);
Pokemon::WatchAlong retry_fade(arrival);
pbf_press_dpad(context, dpad(step.direction), STEP_TAP, STEP_TAP_RELEASE);
if (wait_until(console, context, WARP_TIMEOUT, {retry_fade.watcher()}) >= 0){
return;
}
}
OperationFailedExceptionWithScreenshot::fire(
ErrorReportMode::SEND_ERROR_REPORT,
"walk_overworld_route(): no fade in and out after walking onto the warp to " + step.end.map + ".",
console
);
}

} // namespace
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=994 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -368,6 +368,9 @@
const std::vector<MapData> all = overworld_maps();
std::set<std::string> flags = map_flag_set(all, "after_hall_of_fame");
flags.merge(map_flag_set(all, "new_game"));
// The one ball the story picks up in its way: B2F's MOON STONE
// blocks column 2 of the arrow floor (00.32's moon_stone).
flags.insert("FLAG_HIDE_ROCKET_HIDEOUT_B2F_MOON_STONE");
return overworld_maps(flags);
}();
return maps;
Expand All @@ -385,7 +388,7 @@
return StoryPose{pose.map, tiles[0], facing_of(pose)};
}

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

Check warning on line 391 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=26 (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, const char*> PLACES[] = {
Expand All @@ -402,6 +405,7 @@
{"Route10", "route-10"},
{"LavenderTown", "lavender-town"},
{"CeladonCity", "celadon-city"},
{"RocketHideout", "rocket-hideout"},
};
for (const auto& [prefix, place] : PLACES){
if (map == prefix || map.rfind(prefix + "_", 0) == 0){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,61 @@
return true;
}

// 00.32's taps (frlg-00.32.plan.json): B3F from below its Rare Candy up
// to the top corridor, and B2F's arrows to the MOON STONE's stop and on
// to the lift room's stop (13, 20), up to row 17 and on to below the
// lift, and B4F from the lift door to the guards, Giovanni and the
// SILPH SCOPE, with any one turn dropped; the stairs up from B3F, which
// end on their warp, with any hold short.
UnitTestResult test_b2f_maze_taps(){

Check warning on line 329 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::test_b2f_maze_taps(): function_lines=48 (advisory above 25, limit 50)
using Pokemon::StoryLeg;
const MapPosition b2f_stairs{"RocketHideout_B2F", {21, 2}};
const MapPosition lift_stop{"RocketHideout_B2F", {13, 20}};
const MapPosition left_guard{"RocketHideout_B4F", {16, 15}};
const MapPosition right_guard{"RocketHideout_B4F", {19, 15}};
const MapPosition below_giovanni{"RocketHideout_B4F", {19, 5}};
const std::vector<std::string> failures{
tap_legs_on_sim({"RocketHideout_B3F", {12, 13}}, Direction::NORTH, {
{Direction::WEST, 4}, {Direction::NORTH, 2}, {Direction::EAST, 4}, {Direction::NORTH, 7},
}, {"RocketHideout_B3F", {12, 2}}),
tap_legs_on_sim(b2f_stairs, Direction::EAST, {
{Direction::SOUTH, 1}, {Direction::WEST, 2}, {Direction::SOUTH, 2}, {Direction::WEST, 2}, {Direction::SOUTH, 1}, {Direction::WEST, 1},
}, {"RocketHideout_B2F", {1, 4}}),
tap_legs_on_sim({"RocketHideout_B2F", {2, 4}}, Direction::SOUTH, {
{Direction::SOUTH, 4}, {Direction::EAST, 1}, {Direction::SOUTH, 1}, {Direction::EAST, 1}, {Direction::EAST, 2}, {Direction::WEST, 2},
{Direction::EAST, 3}, {Direction::SOUTH, 2}, {Direction::WEST, 1}, {Direction::EAST, 1}, {Direction::SOUTH, 1},
}, lift_stop),
short_holds_on_sim({"RocketHideout_B3F", {12, 2}}, Direction::NORTH, b2f_stairs),
tap_legs_on_sim(lift_stop, Direction::EAST, {
{Direction::EAST, 2}, {Direction::NORTH, 3},
}, {"RocketHideout_B2F", {15, 17}}),
tap_legs_on_sim({"RocketHideout_B2F", {1, 4}}, Direction::WEST, {
{Direction::EAST, 1},
}, {"RocketHideout_B2F", {2, 4}}),
tap_legs_on_sim({"RocketHideout_B2F", {15, 17}}, Direction::NORTH, {
{Direction::EAST, 12}, {Direction::SOUTH, 1}, {Direction::EAST, 1}, {Direction::NORTH, 1},
}, {"RocketHideout_B2F", {28, 17}}),
tap_legs_on_sim({"RocketHideout_B4F", {20, 23}}, Direction::SOUTH, {
{Direction::SOUTH, 1}, {Direction::WEST, 4}, {Direction::NORTH, 9},
}, left_guard),
tap_legs_on_sim(left_guard, Direction::NORTH, {
{Direction::SOUTH, 1}, {Direction::EAST, 3}, {Direction::NORTH, 1},
}, right_guard),
tap_legs_on_sim(right_guard, Direction::NORTH, {
{Direction::WEST, 2}, {Direction::NORTH, 10}, {Direction::EAST, 2},
}, below_giovanni),
tap_legs_on_sim(below_giovanni, Direction::NORTH, {
{Direction::WEST, 2}, {Direction::SOUTH, 2}, {Direction::EAST, 4}, {Direction::NORTH, 2},
}, {"RocketHideout_B4F", {21, 5}}),
};
for (const std::string& failure : failures){
if (!failure.empty()){
return failure;
}
}
return true;
}

struct AutoStoryHideoutBodyInput{
std::string name;
UnitTestResult (*body)();
Expand Down Expand Up @@ -363,6 +418,10 @@
.input = {.name = "B3F's arrow floor a tap at a time", .body = test_b3f_maze_taps},
.expectation = {.description = "below the stairs to B4F, with any one turn dropped"},
},
{
.input = {.name = "B2F's arrow floor to the lift a tap at a time", .body = test_b2f_maze_taps},
.expectation = {.description = "00.32's taps and the routes between them, any turn dropped or hold short"},
},
};

const LiftCase LIFT_CASES[] = {
Expand Down
Loading
Loading