Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
826ad51
BDSP AutoStory 00.05c: a plan from (35, 24), (36, 24) past the woman …
dayfine Nov 12, 2026
58c1372
BDSP AutoStory walk: D-pad taps where no wall holds every possible tile
dayfine Nov 12, 2026
5f8a8d4
Merge remote-tracking branch 'origin/bdsp/start-certainty' into bdsp/…
dayfine Nov 12, 2026
81394f9
BDSP AutoStory walk: a wall leg stopped well short is anywhere along …
dayfine Nov 12, 2026
18d4682
BDSP AutoStory walk: no safe wall behind a stop well short keeps the …
dayfine Nov 12, 2026
c5efcaa
Merge commit 'b258693ab' into bdsp/0005c-plaza
dayfine Nov 12, 2026
4fce148
BDSP AutoStory walk: hear out the Wonder Station's greeter each time …
dayfine Nov 12, 2026
a1690a0
BDSP AutoStory walk: hear out a talk no battle followed, then go roun…
dayfine Nov 12, 2026
e894a26
BDSP AutoStory walk: a fight with no battle replans, even when nothin…
dayfine Nov 12, 2026
6e7f5a2
BDSP AutoStory walk: find us again when a talk leaves no plan
dayfine Nov 12, 2026
62e07c9
Merge branch 'bdsp/start-certainty' into bdsp/0005c-plaza
dayfine Nov 13, 2026
a2a698b
Merge branch 'bdsp/start-certainty' into bdsp/0005c-plaza
dayfine Nov 13, 2026
0450a24
Merge branch 'bdsp/start-certainty' into mu/0005c-plaza
dayfine Nov 13, 2026
d9f1341
Merge branch 'bdsp/start-certainty' into bdsp/0005c-plaza
dayfine Nov 13, 2026
7aff867
BDSP walk: safe_tap uses recovery_hazard (OccupancyUse went in the an…
dayfine Nov 13, 2026
3e00bfc
BDSP AutoStory sim: the 07:44 greeter test's second talk is on the ne…
dayfine Nov 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void mart_lady(VideoStream& stream, ProControllerContext& context){
walk_until_stopped(stream, context, Direction::EAST, 40, "East along the path");
walk_until_stopped(stream, context, Direction::NORTH, 2, "North to the front row");
const StoryWorld& maps = story_maps();
RouteTrainers trainers{story_trainer_sights(), [&](const std::string& name){ fight_route_trainer(stream, context, name); }};
RouteTrainers trainers{story_trainer_sights(), [&](const std::string& name){ return fight_route_trainer(stream, context, name); }};
walk_to_route_202_save_spot(stream, context, maps, {maps.to_world(MAP_SANDGEM_TOWN, map_point("SandgemTown", "front_row_east_end"))}, trainers);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ uint64_t mean_brightness(const ImageViewRGB32& screen){

// Fights a trainer whose dialogue has opened, with whatever starter we
// have. Someone who only talks leaves no battle to fight.
void fight_route_trainer(VideoStream& stream, ProControllerContext& context, const std::string& name){
bool fight_route_trainer(VideoStream& stream, ProControllerContext& context, const std::string& name){
pbf_mash_button(context, BUTTON_B, 5000ms);
context.wait_for_all_requests();
BattleMenuWatcher battle_menu(BattleType::TRAINER, COLOR_YELLOW);
Expand All @@ -158,13 +158,14 @@ void fight_route_trainer(VideoStream& stream, ProControllerContext& context, con
stream.log("[Route] " + name + ": no battle followed the talk.");
pbf_mash_button(context, BUTTON_B, 2000ms);
context.wait_for_all_requests();
return;
return false;
}
fight_trainer(stream, context, name);
context.wait_for_all_requests();
// The next trainer may be a few tiles on: check HP now. With no
// Potion in the Bag this only looks.
use_potion_first_pokemon(stream, context, 0.8);
return true;
}

bool sign_text_matches(const std::string& text, const std::string& key){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ bool talk_or_fight(

// Fights a trainer whose dialogue has opened, with whatever starter we
// have, then a Potion if HP is under half. Someone who only talks leaves
// no battle to fight. How the story's planned walks fight (RouteTrainerFight).
void fight_route_trainer(VideoStream& stream, ProControllerContext& context, const std::string& name);
// no battle to fight; returns whether a battle followed. How the story's
// planned walks fight (RouteTrainerFight).
bool fight_route_trainer(VideoStream& stream, ProControllerContext& context, const std::string& name);

// A rough check that we stand in a Pokemon Center: its floor fills the lower
// half of the screen with warm yellow, where the gym is grey and routes are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,42 @@

};

// One D-pad tap, a whole tile for every possible position: safe when each
// next tile is open ground on the same map with no one on it.
bool safe_tap(const StoryWorld& world, const TilePos& from, Direction direction){
const auto map = world.to_local(from);
const auto next = step(world, from, direction);
const auto local = next ? world.to_local(*next) : std::nullopt;
return map && next && *next == from.next(direction) && local && local->map == map->map && standable(world, *next)
&& !recovery_hazard(world, *next);
}

// WallPolicy, with a tap where a hold has no wall for every position: a
// tile with no safe wall any way (someone beside it, a door, the map's
// edge) moves on a tile to where one is.
class WallOrTapPolicy : public WallPolicy{
public:
static std::optional<Pokemon::WallRecoveryStep<Hypothesis, Hold>> hold(
const StoryWorld& world, const std::vector<Hypothesis>& from, Direction direction
){
std::optional<Pokemon::WallRecoveryStep<Hypothesis, Hold>> wall = WallPolicy::hold(world, from, direction);
if (wall){
return wall;
}
std::vector<Hypothesis> ends;
for (const auto& start : from){
if (!safe_tap(world, start, direction)){
return std::nullopt;
}
ends.push_back(start.next(direction));
}
return Pokemon::WallRecoveryStep<Hypothesis, Hold>{
.positions = std::move(ends),
.hold = {.direction = direction, .tiles = 1, .ends_at_wall = false, .held = false},
};
}
};

} // namespace

std::vector<Pokemon::WallAnchor<Pokemon::TilePos, TileLeg>> wall_recovery_candidates(
Expand Down Expand Up @@ -106,14 +142,29 @@
}

namespace{
// The most holds, taps among them, plan_recovered_route() tries when walls
// alone bring several tiles to no one wall.
constexpr size_t MAX_TAP_RECOVERY_HOLDS = 4;

std::vector<Pokemon::WallAnchor<TilePos, TileLeg>> tap_recovery_candidates(
const StoryWorld& world, const std::vector<TilePos>& from
){
for (const auto& tile : from){
if (!standable(world, tile)){
return {};
}
}
return Pokemon::find_wall_anchors<WallOrTapPolicy>(from, world, {.max_holds = MAX_TAP_RECOVERY_HOLDS});
}

std::vector<PlannedLeg> recovery_legs(
const StoryWorld& world, std::vector<TilePos> from, const std::vector<TileLeg>& holds
){
std::vector<PlannedLeg> legs;
for (const auto& hold : holds){
std::vector<TilePos> after;
for (const auto& at : from){
const TilePos end = slide_to_wall(world, at, hold.direction).stop;
const TilePos end = hold.ends_at_wall ? slide_to_wall(world, at, hold.direction).stop : at.next(hold.direction);
if (std::find(after.begin(), after.end(), end) == after.end()){
after.push_back(end);
}
Expand All @@ -125,7 +176,7 @@
}
} // namespace

std::optional<std::vector<PlannedLeg>> plan_recovered_route(

Check warning on line 179 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonBDSP::plan_recovered_route( const StoryWorld & world , const std :: vector<TilePos> & from , const std :: function<bool(const TilePos&)> & goal , const RobustPlanCosts & costs): function_lines=49 (advisory above 25, limit 50)
const StoryWorld& world, const std::vector<TilePos>& from,
const std::function<bool(const TilePos&)>& goal, const RobustPlanCosts& costs
){
Expand All @@ -142,19 +193,34 @@
// fewest held tiles alone chose "south 12 (to wall), north 12 (open)"
// over "north 13 (to wall), south 5 (open)" for 01.10's line 5 (lab-B
// 2026-11-08 18:15:47). Ties keep find_wall_anchors()' order.
// Walls alone first; only when they bring the tiles to no one wall,
// D-pad taps where a hold has no wall, and a fourth hold. On lab-B
// (2026-11-12 02:52, 00.05c) a talk on Jubilife's row 24 left (35, 24)
// and (36, 24): from (36, 24) every way ends at no wall (the TV
// station's clown north, a man south, the woman's tile west, the map's
// edge east), and the walk failed with "no plan". Two taps east bring
// both tiles under the TV station's wall.
std::optional<std::vector<PlannedLeg>> best;
long long best_cost = 0;
for (const auto& anchor : wall_recovery_candidates(world, from)){
const auto back = plan_robust_route(world, std::vector<TilePos>{anchor.at}, goal, costs);
if (!back){
continue;
for (const bool taps : {false, true}){
if (best){
break;
}
auto route = recovery_legs(world, from, anchor.holds);
route.insert(route.end(), back->begin(), back->end());
const long long cost = robust_route_cost(world, from, route, costs);
if (!best || cost < best_cost){
best = std::move(route);
best_cost = cost;
long long best_cost = 0;
const std::vector<Pokemon::WallAnchor<TilePos, TileLeg>> anchors = taps
? tap_recovery_candidates(world, from)
: wall_recovery_candidates(world, from);
for (const auto& anchor : anchors){
const auto back = plan_robust_route(world, std::vector<TilePos>{anchor.at}, goal, costs);
if (!back){
continue;
}
auto route = recovery_legs(world, from, anchor.holds);
route.insert(route.end(), back->begin(), back->end());
const long long cost = robust_route_cost(world, from, route, costs);
if (!best || cost < best_cost){
best = std::move(route);
best_cost = cost;
}
}
}
return best;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* BDSP AutoStory Planned Route Tests

Check warning on line 1 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=759 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -156,11 +156,19 @@
std::vector<std::string> fights;
};

ScriptedWalk walk_script(const StoryWorld& maps, const TilePos& from, const TilePos& goal, std::vector<TrainerSight> sights, Script& script){
// What follows each talk that is fought.
enum class AfterTalk{
BATTLE,
NO_BATTLE,
};

ScriptedWalk walk_script(const StoryWorld& maps, const TilePos& from, const TilePos& goal, std::vector<TrainerSight> sights, Script& script,

Check warning on line 165 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: walk_script: output parameter 'Script& script' comes before an input; put inputs (by value, const&) first and non-const references last (Google "Function Parameter Ordering")
AfterTalk after_talk = AfterTalk::BATTLE
){
ScriptedWalk out;
RouteTrainers trainers{
.sights = std::move(sights),
.fight = [&out](const std::string& trainer){ out.fights.push_back(trainer); },
.fight = [&out, after_talk](const std::string& trainer){ out.fights.push_back(trainer); return after_talk == AfterTalk::BATTLE; },
};
ScriptedRouteIO io(script);
try{
Expand Down Expand Up @@ -207,6 +215,7 @@
Script script{.steps = {
walk_step("wall: T: east 4 (to wall)", WalkStop::LIMIT, 2050ms, 0),
walk_step("wall: T: east 4 (to wall): at the wall?", WalkStop::DIALOG, 400ms, 0),
answer_step("dialog within 5000 ms", false),
walk_step("wall: T: east 4 (to wall): on to the wall", WalkStop::BLOCKED, 1200ms, 0),
answer_step("dialog within 500 ms", false),
}};
Expand All @@ -229,6 +238,34 @@
}


// lab-B 2026-11-12 06:12 (00.05c below_the_company_clown, the 6th failure
// there): the Wonder Station's woman stopped the check walk of "west 1 (to
// wall)", the fight saw no battle follow and pressed her talk to its end,
// so nothing showed when we looked again; the walk on to the wall then
// started her talk again and ran out of time. A talk the fight saw end
// with no battle plans again from where it stopped, never walks on.
UnitTestResult test_wall_leg_talk_no_battle(Logger&){
Script script{.steps = {
walk_step("wall: T: east 4 (to wall)", WalkStop::LIMIT, 2050ms, 0),
walk_step("wall: T: east 4 (to wall): at the wall?", WalkStop::DIALOG, 400ms, 0),
answer_step("dialog within 5000 ms", false),
}};
try{
const ScriptedWalk walk = walk_script(make_world({"#.....#"}), {1, 0}, {5, 0}, {}, script, AfterTalk::NO_BATTLE);
if (!walk.failure.empty()){
return "failed after a talk no battle followed: " + walk.failure;

Check warning on line 256 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")
}
if (walk.at != std::vector<TilePos>{{5, 0}}){
return "did not plan again from the wall it stopped at, (5, 0).";
}
}catch (const ScriptMismatch& e){
return e.message;
}
const std::string left = script_left(script);
return left.empty() ? UnitTestResult(true) : UnitTestResult(left);
}


// A leg to a wall that ran out of time: a check walk that also runs out
// of time counts as at the wall only if holding on there changes the
// screen less than walking (r127a ran along the wrong row).
Expand Down Expand Up @@ -671,6 +708,10 @@
.input = {"a trainer on a wall leg, then on to the wall", test_wall_leg_trainer_on_the_way},
.expectation = {},
},
{
.input = {"a talk no battle followed on a wall leg plans again (lab-B 2026-11-12 06:12)", test_wall_leg_talk_no_battle},
.expectation = {},
},
{
.input = {"a wall leg out of time needs the holding check", test_wall_leg_limit},
.expectation = {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* BDSP Recovery Walk Tests

Check warning on line 1 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RecoveryWalk_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=938 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -92,7 +92,7 @@
public:
explicit RecoveryStepIO(RouteIO& route) : m_route(route){}
virtual RouteIO& route() override{ return m_route; }
virtual void fight(const std::string&) override{ throw GridSimFailure{"unexpected trainer"}; }
virtual bool fight(const std::string&) override{ throw GridSimFailure{"unexpected trainer"}; }
virtual void walk_until_stopped(Direction, size_t, const std::string&) override{ throw GridSimFailure{"unexpected blind hold"}; }
virtual bool run_until_map(Direction, Milliseconds, const std::string&, const std::string&) override{ throw GridSimFailure{"unexpected banner walk"}; }
virtual WarpSeen run_into_door(Direction, bool, Milliseconds = Milliseconds(12000), Milliseconds = Milliseconds(0), const std::string& = "") override{ throw GridSimFailure{"unexpected door"}; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ UnitTestResult test_blocked_from_several_tiles(Logger&){
const TilePos goal{52, 41};
std::vector<std::string> notes;
SimulatedRouteIO io(world, {53, 41}, {{54, 41}}, notes);
RouteTrainers trainers{.sights = {}, .fight = [](const std::string&){}};
RouteTrainers trainers{.sights = {}, .fight = [](const std::string&){ return true; }};
try{
walk_route(io, world, from, trainers, {
.goal = [goal](const TilePos& pos){ return pos == goal; },
Expand Down Expand Up @@ -245,7 +245,7 @@ UnitTestResult test_jubilife_center_held_overshoot(Logger&){
std::vector<std::string> notes;
SimulatedRouteIO io(world, from, {}, notes);
io.overshoot_timed_holds(true);
RouteTrainers trainers{.sights = {}, .fight = [](const std::string&){}};
RouteTrainers trainers{.sights = {}, .fight = [](const std::string&){ return true; }};
try{
walk_route(io, world, {from}, trainers, {
.goal = [goal](const TilePos& pos){ return pos == goal; },
Expand Down Expand Up @@ -273,7 +273,7 @@ UnitTestResult test_jubilife_center_kids(Logger&){
const TilePos goal{52, 41};
std::vector<std::string> notes;
SimulatedRouteIO io(world, from, {{52, 46}, {54, 46}}, notes);
RouteTrainers trainers{.sights = {}, .fight = [](const std::string&){}};
RouteTrainers trainers{.sights = {}, .fight = [](const std::string&){ return true; }};
try{
walk_route(io, world, {from}, trainers, {
.goal = [goal](const TilePos& pos){ return pos == goal; },
Expand Down Expand Up @@ -358,7 +358,7 @@ std::string sweep_story_route(const StoryRoute& route, bool overshoot, std::vect
SimulatedRouteIO io(*world, from, {}, notes);
io.overshoot_timed_holds(overshoot);
io.set_can_run(route.speed == MoveSpeed::RUN);
RouteTrainers trainers{.sights = story_trainers(*world), .fight = [](const std::string&){}};
RouteTrainers trainers{.sights = story_trainers(*world), .fight = [](const std::string&){ return true; }};
try{
walk_route(io, *world, start, trainers, {
.goal = [&](const TilePos& pos){ return std::find(targets.begin(), targets.end(), pos) != targets.end(); },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ std::vector<Pokemon::StoryActionSpec> make_bdsp_actions(){
}
const Pokemon::StoryArgSpec opt_avoid{.key = "avoid", .type = Pokemon::StoryArgType::INTEGER_ROWS, .required = false,
.fallback = std::nullopt, .why = "ground on the target's map to keep off: [x, y] tiles, [x0, y0, x1, y1] boxes"};
const Pokemon::StoryArgSpec opt_greeter{.key = "greeter", .type = Pokemon::StoryArgType::INTEGER_ROWS, .required = false,
.fallback = std::nullopt, .why = "ground on the target's map where someone walks up and talks, then walks off: [x, y] tiles, [x0, y0, x1, y1] boxes"};
for (std::string_view cost : {"town", "overworld", "indoors", "caves", "robust", "line", "trigger"}){
actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = std::string(cost), .args = {route_target, fight_wild, opt_legs, opt_avoid}});
actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = std::string(cost), .args = {route_target, fight_wild, opt_legs, opt_avoid, opt_greeter}});
}
actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = "into_scene", .args = {route_target, fight_wild, legs_arg}});
add_legs_actions(actions, legs_arg, fight_wild);
Expand All @@ -125,9 +127,7 @@ std::vector<Pokemon::StoryActionSpec> make_bdsp_actions(){
actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "starter", .args = {may_lose}});
actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "doubles", .args = {may_lose}});
actions.push_back({.kind = Pokemon::StoryStepKind::SHOP, .name = "sandgem_potions", .args = {items}});

add_event_actions(actions);

return actions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ ConsoleStoryStepIO::ConsoleStoryStepIO(VideoStream& stream, ProControllerContext
, m_route(stream, context, m_escape)
{}

void ConsoleStoryStepIO::fight(const std::string& trainer){
bool ConsoleStoryStepIO::fight(const std::string& trainer){
if (trainer.find("Twins") != std::string::npos){
talk_or_fight(m_stream, m_context, trainer, TalkExpect::BATTLE, BattleFormat::DOUBLES);
return;
return true;
}
fight_route_trainer(m_stream, m_context, trainer);
return fight_route_trainer(m_stream, m_context, trainer);
}

void ConsoleStoryStepIO::walk_until_stopped(Direction direction, size_t tiles, const std::string& label){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class StoryStepIO{
virtual RouteIO& route() = 0;
// Fights a trainer whose dialogue has opened (fight_route_trainer()):
// Route 204's Twins as a pair (01.10), everyone else alone.
virtual void fight(const std::string& trainer) = 0;
// Returns whether a battle followed.
virtual bool fight(const std::string& trainer) = 0;
// walk_until_stopped(): `direction` until something stops us, for at
// most `tiles` tiles' time. Fails on a door or a dialogue.
virtual void walk_until_stopped(Pokemon::Direction direction, size_t tiles, const std::string& label) = 0;
Expand Down Expand Up @@ -100,7 +101,7 @@ class ConsoleStoryStepIO : public StoryStepIO{
virtual RouteIO& route() override{
return m_route;
}
virtual void fight(const std::string& trainer) override;
virtual bool fight(const std::string& trainer) override;
virtual void walk_until_stopped(Pokemon::Direction direction, size_t tiles, const std::string& label) override;
virtual bool run_until_map(Pokemon::Direction direction, Milliseconds limit, const std::string& map, const std::string& label) override;
virtual WarpSeen run_into_door(Pokemon::Direction direction, bool run, Milliseconds timeout = Milliseconds(12000),
Expand Down
Loading
Loading