Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ enum class ScreenEvent : uint8_t{
PLAYER_CAN_MOVE, // The overworld with the player in control.
SCREEN_STILL, // The screen barely changed since the frame before.
SWITCH_HOME_MENU, // The Switch's HOME menu: the game is not on the screen.
PLAYER_STILL, // A box around the player barely changed since the
// frame before: people walking elsewhere do not count.
};
// How many ScreenEvent values there are.
constexpr size_t SCREEN_EVENT_COUNT = 11;
static_assert((size_t)ScreenEvent::SWITCH_HOME_MENU + 1 == SCREEN_EVENT_COUNT, "SWITCH_HOME_MENU is the last ScreenEvent");
constexpr size_t SCREEN_EVENT_COUNT = 12;
static_assert((size_t)ScreenEvent::PLAYER_STILL + 1 == SCREEN_EVENT_COUNT, "PLAYER_STILL is the last ScreenEvent");
// "dialog box", for the log.
std::string screen_event_name(ScreenEvent event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ std::string screen_event_name(ScreenEvent event){
case ScreenEvent::PLAYER_CAN_MOVE: return "player can move";
case ScreenEvent::SCREEN_STILL: return "screen still";
case ScreenEvent::SWITCH_HOME_MENU: return "Switch HOME menu";
case ScreenEvent::PLAYER_STILL: return "player still";
}
return "?";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@
{}

// One look and its answer; the launch's end when this look ended it.
std::optional<Outcome> step(){

Check warning on line 93 in SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryLaunch.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::Pokemon::LaunchDriver::step(): function_lines=28 (advisory above 25, limit 50)
const Observation<PoseType> observation = m_backend.observe();
if (m_looks_since_title_press){
++*m_looks_since_title_press;
if (*m_looks_since_title_press <= m_policy.load_black_looks && observation.events.has(ScreenEvent::FADE_BLACK)){
m_load_seen = true;
}
}
const LaunchLook look = read_launch_look(m_policy, observation, m_launched || m_loading);
if (look.screen != LaunchScreen::OVERWORLD){
m_settled = 0;
Expand Down Expand Up @@ -175,13 +181,24 @@
m_backend.press(each.button, each.hold, each.release);
}
}
// A black before this title was not the load.
m_load_seen = false;
m_looks_since_title_press = 0;
return press("title", m_policy.title_press, m_policy.presses_per_screen);
}

std::optional<Outcome> on_overworld(){
if (needs_load()){
return press("overworld", {.button = BUTTON_HOME}, m_policy.presses_per_screen, "HOME, to load the save");
}
if (m_policy.overworld_after_load && m_loading && !m_load_seen){
// Not the load's press: on the movie, it goes back to the
// title through a black.
return press(
"title", m_policy.title_press, m_policy.presses_per_screen,
std::format("no load yet, so the title's attract movie: {}", button_to_string(m_policy.title_press.button))
);
}
if (++m_settled >= m_policy.settled_looks){
log("overworld", std::format("settled for {} looks", m_settled));
return outcome_ok();
Expand Down Expand Up @@ -237,6 +254,13 @@
bool m_launch_pressed = false;
Milliseconds m_home_waited = Milliseconds(0);
bool m_backup_sent = false;
// Looks since the title press was sent on a look `policy.title` read
// as the title; nothing before one. A press on the attract movie
// (`overworld_after_load`) is not a title press.
std::optional<size_t> m_looks_since_title_press;
// A black screen showed within `policy.load_black_looks` looks of the
// title press, and the title has not shown since: the save loading.
bool m_load_seen = false;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ struct StoryLaunchPolicy{
std::vector<StoryLaunchPrompt> prompts = {};
// The player in control. Unset: the look shows PLAYER_CAN_MOVE.
std::function<bool(const ScreenObservation& look)> overworld = {};
// Once the launch closed the game or saw its title, the overworld
// counts only after a `title_press` on a look `title` matched and
// then the load's black (FADE_BLACK), with no title since; until then
// an overworld look takes `title_press` too, which does not start the
// load. BDSP's title plays an attract movie, a town with people
// walking, that reads as the overworld, and ZL on it goes back to
// the title through a black.
bool overworld_after_load = false;
// For `overworld_after_load`: the load's black comes within this many
// looks of the title press. A later black is the title, left idle
// after a dropped press, going to its attract movie.
size_t load_black_looks = 10;
// Looks in a row the overworld must show before the launch is done.
size_t settled_looks = 3;
// The wait between looks at a screen with nothing to press.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* The launch on a scripted console: each case is the screens the console
* shows, look by look (the last repeats), and the presses the launch must
* make, or where it must fail. The test game's screens are readings its
* policy reads; HOME is the shared SWITCH_HOME_MENU event and the
* overworld the shared PLAYER_CAN_MOVE.
* policy reads; HOME is the shared SWITCH_HOME_MENU event, a boot's or
* load's black the shared FADE_BLACK and the overworld the shared
* PLAYER_CAN_MOVE.
*
*/

Expand Down Expand Up @@ -38,6 +39,7 @@
LICENSE_CHECK, // the online license check
BLACK, // a boot or a load
TITLE,
TITLE_UNREAD, // the title, on a look its check misses
NEW_GAME, // the title's menu without a save
BACKUP_CONFIRM, // "Load the backup save?"
LOAD_MENU, // Continue / New Game
Expand All @@ -60,6 +62,9 @@
case Screen::OVERWORLD:
observation.events = ScreenEvents{ScreenEvent::PLAYER_CAN_MOVE};
return observation;
case Screen::BLACK:
observation.events = ScreenEvents{ScreenEvent::FADE_BLACK};
return observation;
default:
observation.readings[std::string(SCREEN)] = (int)screen;
return observation;
Expand Down Expand Up @@ -91,10 +96,16 @@
AFTER_LAUNCH, // read only once the launch launched the game
};

// When the test game's overworld counts after the launch closed it.
enum class OverworldCheck{
ANY_TIME,
AFTER_LOAD, // only after a title press and the load's black
};

// The test game: A on the title, `backup` for the backup save, A on each
// prompt (Up, Up, A on the update prompt; B on the game's dialog), and
// small bounds so a failure takes few looks.
StoryLaunchPolicy test_policy(Backup backup, GameScreens game_screens, TileCheck tile_check){
StoryLaunchPolicy test_policy(Backup backup, GameScreens game_screens, TileCheck tile_check, OverworldCheck overworld_check){

Check warning on line 108 in SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryLaunch_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::Pokemon::test_policy( Backup backup , GameScreens game_screens , TileCheck tile_check , OverworldCheck overworld_check): function_lines=33 (advisory above 25, limit 50)
StoryLaunchPolicy policy;
policy.game = "test";
policy.tile_selected = [](const ScreenObservation& observation){
Expand All @@ -120,7 +131,9 @@
.after_launch = game_screens == GameScreens::AFTER_LAUNCH},
};
policy.title_after_launch = game_screens == GameScreens::AFTER_LAUNCH;
policy.overworld_after_load = overworld_check == OverworldCheck::AFTER_LOAD;
policy.presses_per_screen = 3;
policy.load_black_looks = 3;
policy.launch_wait = Milliseconds(2000);
policy.max_looks = 12;
return policy;
Expand All @@ -143,6 +156,7 @@
Backup backup = Backup::PLZA;
GameScreens game_screens = GameScreens::STRICT;
TileCheck tile_check = TileCheck::READINGS;
OverworldCheck overworld_check = OverworldCheck::ANY_TIME;
};
struct Expectation{
// Empty: the launch succeeds; else a part of its failure's detail.
Expand Down Expand Up @@ -225,6 +239,45 @@
Screen::BLACK, Screen::GAME_DIALOG, Screen::TITLE}),
.game_screens = GameScreens::AFTER_LAUNCH},
.expectation = {.inputs = "HOME HOME X A wait B A wait wait"}},
// Console B, 2026-11-15 03:42 (BDSP): after the launch the title's
// attract movie, a town with people walking, read as the overworld
// and settled before the title took a press.
{.name = "attract movie never counts as the overworld",
.input = {.screens = {Screen::HOME_ON_GAME, Screen::HOME_ON_GAME, Screen::BLACK, Screen::OVERWORLD},
.game_screens = GameScreens::AFTER_LAUNCH, .overworld_check = OverworldCheck::AFTER_LOAD},
.expectation = {.failure = "stuck on title", .inputs = "X A wait A A A"}},
{.name = "attract movie takes the title press",
.input = {.screens = then_settled({Screen::HOME_ON_GAME, Screen::HOME_ON_GAME, Screen::BLACK, Screen::OVERWORLD,
Screen::TITLE, Screen::BLACK}),
.game_screens = GameScreens::AFTER_LAUNCH, .overworld_check = OverworldCheck::AFTER_LOAD},
.expectation = {.inputs = "X A wait A A wait wait wait"}},
// Console B, 2026-11-15 04:21 (BDSP, Japanese): the title press on the
// attract movie went back to the title through a black, and that
// black counted as the load; the title, read as the overworld,
// settled. Only a press on a recognised title starts the load.
{.name = "a black after the attract movie's press is not the load",
.input = {.screens = {Screen::HOME_ON_GAME, Screen::HOME_ON_GAME, Screen::BLACK, Screen::OVERWORLD, Screen::BLACK,
Screen::OVERWORLD},
.game_screens = GameScreens::AFTER_LAUNCH, .overworld_check = OverworldCheck::AFTER_LOAD},
.expectation = {.failure = "stuck on title", .inputs = "X A wait A wait A A"}},
// A title that shows again after a black: that black was not the load.
{.name = "the title again after a black is not loaded",
.input = {.screens = {Screen::HOME_ON_GAME, Screen::HOME_ON_GAME, Screen::BLACK, Screen::TITLE, Screen::BLACK,
Screen::TITLE, Screen::OVERWORLD},
.game_screens = GameScreens::AFTER_LAUNCH, .overworld_check = OverworldCheck::AFTER_LOAD},
.expectation = {.failure = "stuck on title", .inputs = "X A wait A wait A A"}},
// A title press dropped, and the title, its check missing it, left
// idle until the attract movie came up through a black: that black
// is too long after the press to be the load.
{.name = "a black long after a dropped title press is not the load",
.input = {.screens = {Screen::HOME_ON_GAME, Screen::HOME_ON_GAME, Screen::BLACK, Screen::TITLE, Screen::TITLE_UNREAD,
Screen::TITLE_UNREAD, Screen::TITLE_UNREAD, Screen::BLACK, Screen::OVERWORLD},
.game_screens = GameScreens::AFTER_LAUNCH, .overworld_check = OverworldCheck::AFTER_LOAD},
.expectation = {.failure = "stuck on title", .inputs = "X A wait A wait wait wait wait A A"}},
{.name = "kept overworld needs no load",
.input = {.screens = then_settled({}), .request = {.running = Running::KEEP},
.game_screens = GameScreens::AFTER_LAUNCH, .overworld_check = OverworldCheck::AFTER_LOAD},
.expectation = {.inputs = "wait wait"}},
};

// The fake backend's record of `input` ("A" -> "press A").
Expand Down Expand Up @@ -265,7 +318,7 @@
looks.push_back(look(screen));
}
FakeStoryBackend<GridPose> backend({.looks = std::move(looks)}, scope);
const Outcome outcome = launch_story_game(backend, test_policy(test.input.backup, test.input.game_screens, test.input.tile_check), test.input.request);
const Outcome outcome = launch_story_game(backend, test_policy(test.input.backup, test.input.game_screens, test.input.tile_check, test.input.overworld_check), test.input.request);
if (test.expectation.failure.empty() && !outcome.succeeded()){
return std::format("expected success, got {}", to_string(outcome));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
#include "Engine/Pokemon_StoryEngine_Tests.h"
#include "Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h"
#include "Pokemon_AutoStorySelect_Tests.h"
#include "Pokemon_CenterVisit_Tests.h"
#include "Pokemon_CheckpointRetry_Tests.h"
#include "Pokemon_Interrupts_Tests.h"
#include "Pokemon_SceneJudges_Tests.h"
#include "Pokemon_Settle_Tests.h"
#include "Pokemon_StoryActions_Tests.h"
#include "Pokemon_StoryEvents_Tests.h"
#include "Pokemon_StoryFailureClasses_Tests.h"
Expand All @@ -47,7 +49,7 @@


// Registers every shared AutoStory suite, for the unit test runner.
inline void add_tests_AutoStory(UnitTestDatabase& database){

Check warning on line 52 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::Pokemon::add_tests_AutoStory( UnitTestDatabase & database): function_lines=33 (advisory above 25, limit 50)
add_tests_AutoStorySelect(database);
add_tests_StoryRun(database);
add_tests_StoryRunCounts(database);
Expand All @@ -73,6 +75,8 @@
add_tests_FrameCoverage(database);
add_tests_CoveredWatch(database);
add_tests_SceneJudges(database);
add_tests_Settle(database);
add_tests_CenterVisit(database);
add_tests_Interrupts(database);
add_tests_Transitions(database);
add_tests_StoryActions(database);
Expand Down
102 changes: 102 additions & 0 deletions SerialPrograms/Source/Pokemon/AutoStory/Pokemon_CenterVisit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* Center Visit
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <format>
#include <optional>
#include <string>
#include <utility>
#include "Pokemon_CenterVisit.h"

namespace PokemonAutomation{
namespace Pokemon{


namespace{

std::string_view place_name(CenterPlace place){
switch (place){
case CenterPlace::INSIDE: return "inside";
case CenterPlace::OUTSIDE: return "outside";
case CenterPlace::UNKNOWN: return "unknown";
}
return "?";
}

// The settle after a door, as the visit's `failure` unless it ended
// quiet.
std::optional<Outcome> settle_door(SettleKind kind, std::string_view label, std::string_view failure, CenterVisitIO& io){
const SettleEnd end = io.settle(kind, label);
if (end.result == SettleEnd::Result::QUIET){
return std::nullopt;
}
return outcome_failed(std::string(failure), end.text);
}

} // namespace


Outcome enter_center(std::string_view label, CenterVisitIO& io){

Check warning on line 41 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_CenterVisit.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::Pokemon::enter_center( std :: string_view label , CenterVisitIO & io): function_lines=31 (advisory above 25, limit 50)
// Every way in settles before the walk to the nurse: the inside can
// still be fading in whether or not the walk saw the fade. With no
// fade, the walk can have gone on in as far as the counter (BDSP lab-B
// 2026-11-08, Oreburgh).
// A lineup that saw no fade either settles AFTER_WARP: it can return
// on the mat before the fade starts.
const WarpSeen seen = io.walk_in();
std::string how = describe(seen);
SettleKind kind = SettleKind::DOOR;
if (!seen.any()){
if (io.place() == CenterPlace::INSIDE){
how = "no fade, but inside";
}else{
const WarpSeen lined_up = io.line_up_and_walk_in();
how = std::format("no fade; lined up by sight: {}", describe(lined_up));
if (!lined_up.any()){
kind = SettleKind::AFTER_WARP;
}
}
}
if (std::optional<Outcome> failed = settle_door(kind, std::format("{}: into the Center", label), CENTER_NOT_ENTERED, io)){
return std::move(*failed);
}
const CenterPlace place = io.place();
io.log(std::format("[Center] {}: in: {}; reads {}.", label, how, place_name(place)));
if (place == CenterPlace::OUTSIDE){
return outcome_failed(std::string(CENTER_NOT_ENTERED), "not in a Pokemon Center after its door");
}
return outcome_ok();
}

Outcome leave_center(std::string_view label, CenterVisitIO& io){
// With no fade seen yet, the fade can still be to come: the settle
// waits for it, and fails when none shows.
const WarpSeen seen = io.walk_out();
const SettleKind kind = seen.any() ? SettleKind::DOOR : SettleKind::AFTER_WARP;
if (std::optional<Outcome> failed = settle_door(kind, std::format("{}: out of the Center", label), CENTER_NOT_LEFT, io)){
return std::move(*failed);
}
const CenterPlace place = io.place();
io.log(std::format("[Center] {}: out: {}; reads {}.", label, describe(seen), place_name(place)));
if (place == CenterPlace::INSIDE){
return outcome_failed(std::string(CENTER_NOT_LEFT), "still inside the Pokemon Center after its door");
}
return outcome_ok();
}

Outcome run_center_visit(std::string_view label, CenterVisitIO& io){
const Outcome in = enter_center(label, io);
if (!in.succeeded()){
return in;
}
io.heal();
io.log(std::format("[Center] {}: healed.", label));
return leave_center(label, io);
}



} // namespace Pokemon
} // namespace PokemonAutomation
Loading
Loading