Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a38a9b2
FRLG AutoStory: a trainer who walked up stays beside the player for t…
dayfine Nov 16, 2026
ebf0d8d
FRLG walker: a hold that moved nothing in a trainer's sight isn't tak…
dayfine Nov 16, 2026
5e7cf69
FRLG AutoStory: note the trainer who walked up after any step into a …
dayfine Nov 16, 2026
6f11f2f
FRLG AutoStory: the line trainer's walk-up in its own module
dayfine Nov 16, 2026
0bfb41f
FRLG AutoStory: 17.03 fights Takashi from his right; walked-up traine…
dayfine Nov 16, 2026
778babf
FRLG AutoStory: 12.02b flies to Fuchsia's Center; story maps carry th…
dayfine Nov 16, 2026
81af988
FRLG AutoStory: 17.03 golden; Fork Draft CI: 60-minute job timeout
dayfine Nov 16, 2026
8d03081
FRLG AutoStory: sim budget header, step lints in their own file, SimS…
dayfine Nov 16, 2026
4ce9525
FRLG AutoStory: code health
dayfine Nov 16, 2026
e1e1daf
FRLG AutoStory: the story sim plans on the run's maps (Silph cleared,…
dayfine Nov 16, 2026
147cfb4
FRLG sim: a press during a spinner slide is lost; 17.03 right_of_taka…
dayfine Nov 16, 2026
1109343
FRLG walker: wait out a spinner slide before the next leg, fail if it…
dayfine Nov 16, 2026
4866e0a
FRLG walker: code health (file lengths, param comment)
dayfine Nov 16, 2026
e32992a
FRLG sim: 17.03 right_of_takashi and below_giovanni walked clean (red)
dayfine Nov 16, 2026
8429e73
FRLG walk: a standing person ends a hold; plan open legs the walk can…
dayfine Nov 16, 2026
bd5fe15
FRLG walk: a trainer not yet beaten is no wall; plan goldens; 17.03 t…
dayfine Nov 16, 2026
f44f529
FRLG walk: code health (trainer crossing to its own .cpp, param comme…
dayfine Nov 16, 2026
7333615
Merge origin/frlg/fly-to-center into frlg/moved-trainers
dayfine Nov 16, 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
7 changes: 7 additions & 0 deletions .github/workflows/cpp-ci-serial-programs-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ on:
type: boolean
default: false

# The build job's limit; GitHub's default is 360. The fork's draft CI
# passes 60, so a test that hangs fails the run instead of holding a runner.
timeout-minutes:
type: number
default: 360

jobs:
build:
runs-on: ${{inputs.os}}
timeout-minutes: ${{inputs.timeout-minutes}}

steps:
- name: Set variables
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/fork-draft-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ jobs:
compiler: default
run-clang-query: true
run-tests: true
# The build takes ~5 minutes with ccache; a run past an hour has a test hanging.
timeout-minutes: 60
13 changes: 11 additions & 2 deletions SerialPrograms/Source/Pokemon/Navigation/Pokemon_GatedPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
* MapPlace place_of(const State&) const;
*
* and may have open_stop_risk(const State&, Direction, const GateState&)
* const and tap_stop_risk() with the same parameters, as plan_legs()'s
* model may have them without the gates.
* const and tap_stop_risk() with the same parameters, and
* open_check_risk(const State&, Direction, int, std::optional<Direction>,
* const GateState&) const, as plan_legs()'s model may have them without
* the gates.
*
* press() reads each tile with resolved_tile(), which makes a closed gate a
* wall. One-way warps (MapWarp::one_way) are the game's to take as any warp:
Expand Down Expand Up @@ -66,7 +68,7 @@

// The game's step model, wrapped: see the top of this file.
template <typename Inner>
class GatedModel{

Check failure on line 71 in SerialPrograms/Source/Pokemon/Navigation/Pokemon_GatedPlanner.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::Pokemon::GatedModel: public_methods=8, limit=7, allowed 7; split the class or move helpers into free functions
public:
using InnerState = typename Inner::State;
using State = GatedState<InnerState>;
Expand Down Expand Up @@ -113,6 +115,13 @@
std::optional<int> tap_stop_risk(const State& state, Direction direction) const requires HasTapStopRisk<Inner>{
return m_inner.tap_stop_risk(state.inner, direction, state.gates);
}
int open_check_risk(const State& state, Direction direction, int run, std::optional<Direction> next) const
requires requires (const Inner& inner, const InnerState& at, Direction way, int tiles, std::optional<Direction> then, const GateState& gates){
inner.open_check_risk(at, way, tiles, then, gates);
}
{
return m_inner.open_check_risk(state.inner, direction, run, next, state.gates);
}

private:
static Step<State> carry(const Step<InnerState>& walked, const GateState& gates){
Expand Down
36 changes: 27 additions & 9 deletions SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@
* interruption stopping it would leave the player is no guess: e.g. on
* open water, a hold to a wall and a tile on starts a leg down a column
* with no wall of its own. Once a route: a run of them, wall to wall,
* would weave round the open stops it can't avoid.
* would weave round the open stops it can't avoid. And
*
* int open_check_risk(const State& state, Direction direction, int run, std::optional<Direction> next) const;
*
* the extra cost of such a leg, `run` tiles long (counted up to
* MAX_COUNTED_RUN), followed by a leg `next` (none: the walk ends there),
* when the walk can't tell from that leg where the open one ended and has
* to find the player at walls.
*
*/

Expand Down Expand Up @@ -150,6 +157,10 @@ namespace LegPlannerInternal{
// wild step, whether it is one step from where a hold to a wall ended, and
// whether such a step was stopped after earlier (see tap_stop_risk() at
// the top of this file).
// How far a node counts the tiles of the leg it is in (Node::run): what
// open_check_risk() tells apart.
constexpr int MAX_COUNTED_RUN = 3;

template <typename State>
struct Node{
State state;
Expand All @@ -158,6 +169,8 @@ struct Node{
bool wild = false;
bool tap_from_wall = false;
bool tapped = false;
// The tiles of the leg so far, up to MAX_COUNTED_RUN.
int run = 0;

bool operator==(const Node& other) const = default;
};
Expand All @@ -166,8 +179,8 @@ struct Node{
template <typename State, typename StateHash>
struct NodeHash{
size_t operator()(const Node<State>& node) const{
return StateHash()(node.state) * 80 + node.facing * 16 + (node.moving ? 8 : 0) + (node.wild ? 4 : 0)
+ (node.tap_from_wall ? 2 : 0) + (node.tapped ? 1 : 0);
return (StateHash()(node.state) * 80 + node.facing * 16 + (node.moving ? 8 : 0) + (node.wild ? 4 : 0)
+ (node.tap_from_wall ? 2 : 0) + (node.tapped ? 1 : 0)) * (MAX_COUNTED_RUN + 1) + node.run;
}
};

Expand All @@ -179,9 +192,10 @@ struct Move{
Step<State> step;
};

// Cost incurred when stopping at a node.
// Cost incurred when stopping at a node, before a leg `next` (none: the
// walk ends there).
template <typename Model, typename State>
int stop_cost(const Model& model, const Node<State>& node, const LegCosts& costs){
int stop_cost(const Model& model, const Node<State>& node, const LegCosts& costs, std::optional<Direction> next){
if (!node.moving || model.held_at(node.state, (Direction)node.facing)){
return 0;
}
Expand All @@ -196,6 +210,9 @@ int stop_cost(const Model& model, const Node<State>& node, const LegCosts& costs
if constexpr (requires { model.open_stop_risk(node.state, Direction::NORTH); }){
cost += model.open_stop_risk(node.state, (Direction)node.facing);
}
if constexpr (requires { model.open_check_risk(node.state, Direction::NORTH, /*run=*/0, next); }){
cost += model.open_check_risk(node.state, (Direction)node.facing, node.run, next);
}
return cost;
}

Expand Down Expand Up @@ -283,11 +300,12 @@ void expand(
const bool from_wall = current.moving && model.held_at(current.state, (Direction)current.facing);
const Node<State> next{
step->next, (int)step->facing, continues, (extends && current.wild) || step->wild,
!extends && from_wall, current.tapped || (!extends && current.tap_from_wall)
!extends && from_wall, current.tapped || (!extends && current.tap_from_wall),
extends ? std::min(current.run + 1, MAX_COUNTED_RUN) : 1
};
int step_cost = costs.per_tile + step->extra_cost;
if (current.facing != (int)direction){
step_cost += costs.per_turn + stop_cost(model, current, costs);
step_cost += costs.per_turn + stop_cost(model, current, costs, std::optional<Direction>(direction));
}
relax(next, cost + step_cost, Move<State>{current, direction, *step}, search);
}
Expand All @@ -300,7 +318,7 @@ int arrival_cost(
const Model& model, const Node<State>& node,
std::optional<Direction> goal_facing, const LegCosts& costs
){
int cost = stop_cost(model, node, costs);
int cost = stop_cost(model, node, costs, std::nullopt);
if (goal_facing && node.facing != (int)*goal_facing){
cost += costs.per_turn;
}
Expand Down Expand Up @@ -382,7 +400,7 @@ std::optional<std::vector<Leg<typename Model::State>>> plan_legs(
using State = typename Model::State;
using Node = LegPlannerInternal::Node<State>;

const Node first{start, start_facing ? (int)*start_facing : 4, false, false, false, false};
const Node first{start, start_facing ? (int)*start_facing : 4, false, false, false, false, 0};
LegPlannerInternal::Search<Model> search;
const std::optional<Node> end = LegPlannerInternal::search_goal(model, first, at_goal, goal_facing, costs, search);
if (!end){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Bicycle and Spinner Presses

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_BikeSpinPresses.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<header>: header_symbols=8 (advisory above 6, limit 8)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -43,6 +43,20 @@
// last frames and the facing it leaves. Not measured.
inline constexpr Milliseconds SPIN_STOP_SETTLE(300);

// After a leg onto a spinner, the walker compares shots of the screen this
// far apart until two show the same: the slide is over. Longer than a
// tile of the slide (SPIN_TILE_TIME), so two shots taken while it goes on
// never match.
inline constexpr Milliseconds SLIDE_STILL_POLL(200);

// How long the walker waits for a slide of `tiles` to end before it fails:
// twice the slide's time and its settle, as SPIN_TILE_TIME is the
// decompilation's, not measured on the console.
constexpr Milliseconds slide_wait_limit(int tiles){
return 2 * SPIN_TILE_TIME * tiles + SPIN_STOP_SETTLE;
}
static_assert(SLIDE_STILL_POLL > SPIN_TILE_TIME);

static_assert(BIKE_TAP_PERIOD > BIKE_TAP_PERIOD_WORKED && BIKE_TAP_PERIOD_WORKED > BIKE_TAP_DROP_PERIOD);
static_assert(BIKE_TAP < BIKE_TILE_TIME && BIKE_TAP <= LONGEST_TAP);
static_assert(BIKE_SELECT_SETTLE > BIKE_SELECT_TIME);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Recovery

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

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

// The farthest sight of the trainers on `maps` but those `beaten` names
// who may see `tile`; 0 if none does.
int sight_onto(const std::vector<MapData>& maps, const MapPosition& tile, const std::set<std::string>& beaten){
int sight = 0;
for (const MapData& map : maps){
if (map.name != tile.map){
continue;
}
for (const MapObject& object : map.objects){
if (trainer_may_see(map, object, tile.point) && !beaten.contains(trainer_id(map, object))){
sight = std::max(sight, object.trainer->sight);
}
}
}
return sight;
}

// How far the holds that find the player after an open leg, and the way
// back, may walk, per tile of the leg. 2 left Rocket Hideout B3F's "west
// 7" off the stairs unchecked: the hold to its west wall and back walk up
Expand Down Expand Up @@ -113,16 +96,24 @@
return next.action == RouteAction::WALK && next.spin_tiles && !next.warps;
}

// Whether `next`, a hold to a wall, ends on its planned tile from each of
// `candidates`: then it finds the player itself.
bool hold_finds(const std::vector<MapData>& maps, const std::vector<StopCandidate>& candidates, const RouteStep& next){
// The tiles of `candidates` `next`, a hold to a wall, moves nothing from (seen if `told_apart`), if from
// each other one it ends on its tile; else nothing. Viridian Gym's "south 3 (to wall)" from (7, 3) moves
// from no tile short of it (console B, 2026-11-15 21:39: walls found, and walked back to (7, 3)).
std::optional<std::vector<StopCandidate>> hold_finds(
const std::vector<MapData>& maps, const std::vector<StopCandidate>& candidates, const RouteStep& next, bool told_apart
){
std::vector<StopCandidate> unmoved;
for (const StopCandidate& candidate : candidates){
const std::optional<WallHold> hold = hold_to_wall(maps, candidate.player, false, next.direction);
if (!hold || !(hold->end == next.end)){
return false;
if (hold && hold->end == next.end){
continue;
}
if (!told_apart || !hold || hold->tiles != 0){
return std::nullopt;
}
unmoved.push_back(candidate);
}
return true;
return unmoved;
}

// The route's lines in the route log the games share, as BDSP's walker
Expand Down Expand Up @@ -221,7 +212,7 @@
return outcome;
}
if (outcome.end == StepEnd::DONE && crossing && m_calls.watch_for_trainer){
outcome = StepOutcome{.end = m_calls.watch_for_trainer(step, *crossing), .walked = std::nullopt};
outcome = StepOutcome{.end = m_calls.watch_for_trainer(step, *crossing), .walked = std::nullopt, .movement = outcome.movement}; // kept: a bump into Takashi passed for walked (17.03, 2026-11-15)
}
m_last = leg;
m_last_late = outcome.end == StepEnd::LATE;
Expand Down Expand Up @@ -334,13 +325,13 @@
}

private:
// After `step` ended as planned: false, the route failed, if it lands
// the player and they are still on the water.
// After `step` ended as planned: false (failed) if its slide went on too long, or it left them surfing.
bool after_done(const RouteStep& step, HoldMovement movement){
if (step.lands_after > 0 && m_calls.landed_on && !m_calls.landed_on(step.end)){
const bool sliding = step.spin_tiles && m_calls.wait_out_slide && !m_calls.wait_out_slide(step);
if (sliding || (step.lands_after > 0 && m_calls.landed_on && !m_calls.landed_on(step.end))){
m_calls.fail(std::format(
"walk_overworld_route(): still surfing after {}: the player didn't land on {}.",
to_string(step), to_string(step.end)
"walk_overworld_route(): {} after {}: the player isn't on {}.",
sliding ? "the slide still went on" : "still surfing", to_string(step), to_string(step.end)
));
return false;
}
Expand Down Expand Up @@ -495,15 +486,21 @@
// that way (console B, 2026-11-13 19:20, 13.01 mansion_holes: a battle
// after "west 13 (to wall)" on Pokemon Mansion 2F, and the hold again
// moved nothing at the wall).
StepOutcome judge_movement(const RouteStep& step, StepOutcome outcome){

Check warning on line 489 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::RouteRun::judge_movement( const RouteStep & step , StepOutcome outcome): function_lines=26 (advisory above 25, limit 50)
const bool held_again = std::exchange(m_held_again, false);
const std::vector<StopCandidate> short_unmoved = std::exchange(m_short_unmoved, {});
if (outcome.end != StepEnd::DONE || step.action != RouteAction::WALK || step.warps){
return outcome;
}
if (outcome.movement != HoldMovement::NONE){
m_unmoved.clear();
return outcome;
}
if (!short_unmoved.empty()){
m_calls.log(std::format("Route: {} moved the screen not at all: the open leg before it ended short.", to_string(step)));
m_unmoved_starts = short_unmoved;
return StepOutcome{.end = StepEnd::STOPPED, .walked = WalkedTiles{.min = 0, .max = 0}, .movement = HoldMovement::NONE};
}
const int expected = held_again && step.to_wall ? 0 : expected_tiles(step);
if (expected < 1){
m_calls.log("Route: " + to_string(step) + " moved the screen not at all, as a bump into the wall it may stand at already; taken as walked.");
Expand All @@ -527,6 +524,9 @@
m_calls.fail("walk_overworld_route(): " + leg + " moved nothing twice in a row: the player is not walking.");
return false;
}
if (!m_unmoved_starts.empty() && maps() != nullptr){
return rejoin(step, std::exchange(m_unmoved_starts, {}), WalkedTiles{.min = 0, .max = 0});
}
if (!start || maps() == nullptr){
return after_unmoved_hold(step);
}
Expand Down Expand Up @@ -759,7 +759,7 @@
// 2026-11-11 15:34: a hold back north to (21, 2) after "south 2" and to the wall (17, 5) after
// "north 3"). A hold that scrolled (`movement`) left `start`. One that moved nothing and ended DONE is a
// bump into the wall judge_movement() found the player at already: not checked.
void check_open_leg(const RouteStep& step, const std::optional<MapPosition>& start, HoldMovement movement){

Check warning on line 762 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::RouteRun::check_open_leg( const RouteStep & step , const std :: optional<MapPosition> & start , HoldMovement movement): function_lines=48 (advisory above 25, limit 50)
if (maps() == nullptr || m_planning->open_leg_check != OpenLegCheck::REANCHOR || !start
|| movement == HoldMovement::NONE || counts_step_taps(step)
|| step.action != RouteAction::WALK || step.to_wall || step.warps || step.spin_tiles
Expand All @@ -774,7 +774,12 @@
return;
}
const std::vector<StopCandidate> candidates = short_candidates(*maps(), *start, step, movement);
if (candidates.size() < 2 || (!last && is_wall_hold(m_plan[m_next]) && hold_finds(*maps(), candidates, m_plan[m_next]))){
if (candidates.size() < 2){
return;
}
std::optional<std::vector<StopCandidate>> unmoved;
if (!last && is_wall_hold(m_plan[m_next]) && (unmoved = hold_finds(*maps(), candidates, m_plan[m_next], movement == HoldMovement::MOVED))){
m_short_unmoved = std::move(*unmoved); // a hold that moves nothing started on one of them
return;
}
const std::optional<Reanchor> anchor = plan_reanchor(*maps(), candidates, step, m_planning->costs, last && !(m_calls.riding && m_calls.riding(step)) ? std::optional(step.facing_after) : std::nullopt);
Expand Down Expand Up @@ -926,6 +931,8 @@
std::vector<std::vector<MapPosition>> m_walk_on_starts; // after walking on: where each of the plan's first steps may start
std::vector<MapPosition> m_hold_from; // the tiles the first hold of the plan may start from
std::string m_unmoved; // the leg that moved nothing last, until another walks
std::vector<StopCandidate> m_short_unmoved; // check_open_leg(): the tiles the next hold moves nothing from
std::vector<StopCandidate> m_unmoved_starts; // that hold moved nothing: it started on one of these
bool m_held_again = false; // the next walk holds a leg to a wall again after something seen after it
OpenLegDrift m_drift; // the ways the player may be a tile off since the last open legs
};
Expand All @@ -936,67 +943,6 @@
return WalkedTiles{.min = 1, .max = step.tiles - 1};
}

std::optional<TrainerCrossing> trainer_crossing(
const std::vector<MapData>& maps, const MapPosition& start, const RouteStep& step,
const std::set<std::string>& beaten
){
if (step.action != RouteAction::WALK){
return std::nullopt;
}
TrainerCrossing crossing;
const std::vector<MapPosition> tiles = leg_tiles(maps, start, step);
for (size_t c = 1; c < tiles.size(); c++){
const int sight = sight_onto(maps, tiles[c], beaten);
if (sight > 0){
crossing.seen.push_back(tiles[c]);
crossing.approach_tiles = std::max(crossing.approach_tiles, sight);
crossing.tiles_after_seen = (int)(tiles.size() - 1 - c);
}
}
if (crossing.seen.empty()){
return std::nullopt;
}
return crossing;
}

std::vector<std::string> beaten_trainers_crossed(
const std::vector<MapData>& maps, const MapPosition& start, const RouteStep& step,
const std::set<std::string>& beaten
){
std::vector<std::string> crossed;
if (step.action != RouteAction::WALK || beaten.empty()){
return crossed;
}
const std::vector<MapPosition> tiles = leg_tiles(maps, start, step);
for (size_t c = 1; c < tiles.size(); c++){
for (const MapData& map : maps){
if (map.name != tiles[c].map){
continue;
}
for (const MapObject& object : map.objects){
if (!object.trainer){
continue;
}
const std::string id = trainer_id(map, object);
const bool listed = std::find(crossed.begin(), crossed.end(), id) != crossed.end();
if (!listed && beaten.contains(id) && trainer_may_see(map, object, tiles[c].point)){
crossed.push_back(id);
}
}
}
}
return crossed;
}

Milliseconds trainer_full_watch(int approach_tiles){
return TRAINER_NOTICE + MovementMechanics::TILE_TIME * approach_tiles + TRAINER_SPEAKS;
}

Milliseconds trainer_first_look(const TrainerCrossing& crossing){
const Milliseconds held_on = MovementMechanics::RUN_TILE_TIME * crossing.tiles_after_seen;
return std::max(TRAINER_FIRST_LOOK, trainer_full_watch(crossing.approach_tiles) - held_on);
}

void run_route(
const std::vector<RouteStep>& route, std::optional<Direction> facing,
const RoutePlanning* planning, const RouteCalls& calls
Expand Down
Loading
Loading