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
3 changes: 3 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ add_library(SerialProgramsLib STATIC ${CORE_LIBRARY_SOURCES} ${LIBRARY_SOURCES})
include(cmake/EmbedTextFiles.cmake)
pa_embed_text_files(SerialProgramsLib Source/Pokemon/Navigation/TestMaps
Pokemon/Navigation/Pokemon_NavigationTestMaps.h PokemonAutomation::Pokemon navigation_test_map_json)
pa_embed_text_files(SerialProgramsLib Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures
PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureData.h
PokemonAutomation::NintendoSwitch::PokemonBDSP console_failure_json)
# Prepared data is validated by the shared publisher tooling. No source-map
# fallback or network download is performed during configuration.
set(POKESIM_TOOLS_SOURCE "$ENV{POKESIM_TOOLS_SOURCE}" CACHE PATH "Pinned PokemonSimulation tools checkout")
Expand Down
133 changes: 133 additions & 0 deletions SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegReplay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* Leg Replay
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <stdexcept>
#include "Common/Cpp/Json/JsonArray.h"
#include "Common/Cpp/Json/JsonObject.h"
#include "Common/Cpp/Json/JsonValue.h"
#include "Pokemon_LegReplay.h"

namespace PokemonAutomation{
namespace Pokemon{

namespace{

[[noreturn]] void bad(const std::string& name, const std::string& what){
throw std::runtime_error("console failure " + name + ": " + what);

Check warning on line 19 in SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegReplay.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")
}

Direction direction_of(const std::string& name, const std::string& text){
for (const Direction direction : ALL_DIRECTIONS){
if (direction_name(direction) == text){
return direction;
}
}
bad(name, "unknown direction \"" + text + "\"");

Check warning on line 28 in SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegReplay.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")
}

TilePos tile_of(const std::string& name, const JsonArray& array){
if (array.size() != 2){
bad(name, "a tile is [x, y]");
}
return {(int)array[0].to_integer_throw(), (int)array[1].to_integer_throw()};
}

ReplayFade fade_of(const std::string& name, const std::string& text){
if (text == "unseen"){
return ReplayFade::UNSEEN;
}
if (text == "black"){
return ReplayFade::BLACK;
}
if (text == "dim"){
return ReplayFade::DIM;
}
if (text == "white"){
return ReplayFade::WHITE;
}
bad(name, "unknown fade \"" + text + "\"");

Check warning on line 51 in SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegReplay.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")
}

ReplayFault fault_of(const std::string& name, const JsonObject& json){

Check warning on line 54 in SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegReplay.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::Pokemon::fault_of( const std :: string & name , const JsonObject & json): function_lines=28 (advisory above 25, limit 50)
const std::string kind = json.get_string_throw("kind");
ReplayFault fault;
if (kind == "fade_missed" || kind == "banner_missed"){
fault.kind = kind == "fade_missed" ? ReplayFaultKind::FADE_MISSED : ReplayFaultKind::BANNER_MISSED;
fault.index = (size_t)json.get_integer_throw("index");
}else if (kind == "moved_further" || kind == "hold_through_warp" || kind == "scene_ends_further"){
fault.kind = kind == "moved_further" ? ReplayFaultKind::MOVED_FURTHER
: kind == "hold_through_warp" ? ReplayFaultKind::HOLD_THROUGH_WARP : ReplayFaultKind::SCENE_ENDS_FURTHER;
fault.step = json.get_string_throw("step");
fault.direction = direction_of(name, json.get_string_throw("direction"));
fault.tiles = (size_t)json.get_integer_default("tiles", 1);
fault.fade = fade_of(name, json.get_string_default("fade", "unseen"));
fault.far_pose_of = json.get_string_default("far_pose_of", "");
}else if (kind == "moved_less"){
fault.kind = ReplayFaultKind::MOVED_LESS;
fault.step = json.get_string_throw("step");
fault.index = (size_t)json.get_integer_throw("index");
fault.tiles = (size_t)json.get_integer_throw("tiles");
}else if (kind == "person_stands"){
fault.kind = ReplayFaultKind::PERSON_STANDS;
fault.name = json.get_string_throw("name");
fault.tile = tile_of(name, json.get_array_throw("tile"));
}else{
bad(name, "unknown fault kind \"" + kind + "\"");

Check warning on line 78 in SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegReplay.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")
}
return fault;
}

} // namespace


std::string replay_fault_kind_name(ReplayFaultKind kind){
switch (kind){
case ReplayFaultKind::FADE_MISSED:
return "fade_missed";
case ReplayFaultKind::BANNER_MISSED:
return "banner_missed";
case ReplayFaultKind::MOVED_FURTHER:
return "moved_further";
case ReplayFaultKind::HOLD_THROUGH_WARP:
return "hold_through_warp";
case ReplayFaultKind::SCENE_ENDS_FURTHER:
return "scene_ends_further";
case ReplayFaultKind::PERSON_STANDS:
return "person_stands";
case ReplayFaultKind::MOVED_LESS:
return "moved_less";
}
return "";
}

ConsoleFailure parse_console_failure(const std::string& name, const std::string& text){
const JsonValue value = parse_json(text);
const JsonObject& json = value.to_object_throw();
ConsoleFailure out;
out.name = name;
out.checkpoint = json.get_string_throw("checkpoint");
if (const JsonObject* start = json.get_object("start")){
out.start = ReplayTile{start->get_string_throw("map"), tile_of(name, start->get_array_throw("tile"))};
out.start_facing = direction_of(name, start->get_string_throw("facing"));
}
for (const auto& item : json.get_array_throw("faults")){
out.faults.push_back(fault_of(name, item.to_object_throw()));
}
const JsonObject& failed = json.get_object_throw("failed");
out.failed_step = failed.get_string_throw("step");
out.failed_error = failed.get_string_throw("error");
out.frame = json.get_string_throw("frame");
if (const JsonArray* evidence = json.get_array("evidence")){
for (const auto& line : *evidence){
out.evidence.push_back(line.to_string_throw());
}
}
return out;
}


} // namespace Pokemon
} // namespace PokemonAutomation
107 changes: 107 additions & 0 deletions SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegReplay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* Leg Replay

Check warning on line 1 in SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegReplay.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/
*
* A console failure as a small fault file (the files of a game's ConsoleFailures folder beside
* a game's simulation tests), made from a console log's [Leg] records and
* raw walk facts by devtools/maps/leg_replay.py. The file keeps only what
* the simulation cannot work out from its map: where the run started if
* not on its checkpoint's start, the detections it missed, the walks that
* went further than counted, and the people the map lacks. Trainers, NPCs
* and walls come from the map. Where the failure happened and the frame it
* was checked against ride along for the reader.
*
* {"checkpoint": "01.02",
* "faults": [{"kind": "hold_through_warp", "step": "past_curtis",
* "direction": "east", "fade": "unseen", "far_pose_of": "into_oreburgh"}],
* "failed": {"step": "into_oreburgh", "error": "no_banner"},
// code-health: allow header_symbols -- the fault file model and its reader are one unit, a split would scatter it

Check warning on line 18 in SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegReplay.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<header>: header_symbols=7 is within limit 8; remove its code-health allow tag
*/

#ifndef PokemonAutomation_Pokemon_LegReplay_H
#define PokemonAutomation_Pokemon_LegReplay_H

#include <cstddef>
#include <optional>
#include <string>
#include <vector>
#include "Pokemon_Direction.h"
#include "Pokemon_Grid.h"

namespace PokemonAutomation{
namespace Pokemon{


// A tile of a named map.
struct ReplayTile{
std::string map;
TilePos tile;
};

// What went differently on the console than the program counted on.
enum class ReplayFaultKind{
FADE_MISSED, // the `index`th fade of the run goes unseen
BANNER_MISSED, // the `index`th map banner of the run goes unseen
MOVED_FURTHER, // the step's counted taps went `tiles` further (onto a warp, `far_pose_of`)
HOLD_THROUGH_WARP, // the step's hold toward `direction` ran on through a warp (`far_pose_of`)
SCENE_ENDS_FURTHER, // the player stood `tiles` toward `direction` past where the scene step leaves them
PERSON_STANDS, // `name`, a person of the map (who wanders or stays put), stood on `tile`
MOVED_LESS, // the `index`th hold of `step`'s walk (from 1) moved `tiles` fewer than it was held for, with
// nothing on screen: the walker took the move as seen
};
// "fade_missed", "banner_missed", "moved_further", "hold_through_warp", "scene_ends_further", "person_stands",
// "moved_less".
std::string replay_fault_kind_name(ReplayFaultKind kind);

// How the walk saw the fade of a warp it went through.
enum class ReplayFade{
UNSEEN,
BLACK,
DIM,
WHITE,
};

// One fault; the fields of its kind (above) are the ones that count.
struct ReplayFault{
ReplayFaultKind kind = ReplayFaultKind::FADE_MISSED;
// FADE_MISSED, BANNER_MISSED: counted within the checkpoint, from 0.
// MOVED_LESS: counted within the step's walk, from 1.
size_t index = 0;
// MOVED_FURTHER, HOLD_THROUGH_WARP, SCENE_ENDS_FURTHER, MOVED_LESS.
std::string step;
Direction direction = Direction::EAST;
size_t tiles = 1;
ReplayFade fade = ReplayFade::UNSEEN;
bool banner_up = false;
// The step of the checkpoint whose pose after it is where the warp lands.
std::string far_pose_of;
// PERSON_STANDS.
std::string name;
TilePos tile;
};

// A console failure: the checkpoint it ran, its faults and what it failed at.
struct ConsoleFailure{
std::string name;
std::string checkpoint;
// Where the run starts if not on the checkpoint's start.
std::optional<ReplayTile> start;
std::optional<Direction> start_facing;
std::vector<ReplayFault> faults;
// What the console did: the step and the start of its error.
std::string failed_step;
std::string failed_error;
// The frame the failure was checked against, a file name in the lab's
// failure screenshots.
std::string frame;
// The log lines the faults were worked out from.
std::vector<std::string> evidence;
};

// Reads a fault file; throws on a missing or unknown field.
ConsoleFailure parse_console_failure(const std::string& name, const std::string& text);


} // namespace Pokemon
} // namespace PokemonAutomation
#endif
2 changes: 2 additions & 0 deletions SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Programs/AutoStory/PokemonBDSP_AutoStory_Walk_Tests.h"
#include "Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WildBattlePolicy_Tests.h"
#include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WallBattleSim_Tests.h"
#include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.h"
#include "PokemonBDSP_Tests.h"

namespace PokemonAutomation{
Expand All @@ -37,7 +38,7 @@



void add_tests(UnitTestDatabase& database){

Check warning on line 41 in SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonBDSP::add_tests( UnitTestDatabase & database): function_lines=27 (advisory above 25, limit 50)
add_tests_DialogDetector(database);
add_tests_MenuDetector(database);
add_tests_AutoStory_Actions(database);
Expand All @@ -60,6 +61,7 @@
add_tests_AutoStory_RecoveryWalk(database);
add_tests_AutoStory_StorySim(database);
add_tests_AutoStory_SimFailureCases(database);
add_tests_AutoStory_ConsoleFailureReplay(database);
add_tests_AutoStory_FaultSweep(database);
add_tests_AutoStory_StoryActions(database);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"about": "lab-B 2026-11-12 18:27-18:42, 01.02: by_the_east_mouth's counted taps went two tiles past the leg's end onto the Gate's east warp, its fade unseen; into_oreburgh then saw no fade and no OreburghCity banner.",
"checkpoint": "01.02",
"faults": [
{"kind": "moved_further", "step": "by_the_east_mouth", "direction": "east", "tiles": 2, "fade": "unseen", "far_pose_of": "into_oreburgh"}
],
"failed": {"step": "into_oreburgh", "error": "no_banner"},
"frame": "",
"evidence": [
"[Leg] by_the_east_mouth leg 7: east 3 planned, moved 2, dead_reckoned at (26, 22)",
"into_oreburgh: no fade and no OreburghCity banner in 4 taps east"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"about": "lab-B 2026-11-12 20:20:50, 01.02 past_curtis, after the same one tile of drift as 21:02 (Curtis stopped the east walk at 9 tiles, a fight left tiles 13-16 possible): the hold east to find us again ran along row 22 and out the Gate's east door, its fade unseen; the program took it as ending at (16, 22) and walked on in Oreburgh City, which it took for the Gate, until into_oreburgh saw no banner at 20:23:09.",
"checkpoint": "01.02",
"faults": [
{"kind": "person_stands", "name": "camper_1", "tile": [17, 22]},
{"kind": "scene_ends_further", "step": "the_hiker", "direction": "east", "tiles": 1},
{"kind": "hold_through_warp", "step": "past_curtis", "direction": "east", "fade": "unseen", "far_pose_of": "into_oreburgh"}
],
"failed": {"step": "into_oreburgh", "error": "no_banner"},
"frame": "",
"evidence": [
"[Walk] past curtis: east 3 (to wall) to find us again: screen change 266.96 at 1200 ms (the fade), then limit after 1850 ms",
"[Route] past curtis: found again at OreburghGate (16, 22), after 1 hold(s)."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"about": "lab-B 2026-11-12 21:02:53, 01.02 past_curtis: the player stood one tile east of the table's (7, 22) after the Hiker's scene (hikers_trigger's step east, the scene after it; the same drift as 20:15), so the east walk from the believed (7, 22) met Camper Curtis's sight line on column 17 after 9 tiles, not 10, and he stopped it at (17, 22) while the program believed (15-16, 22). Its recovery hold east then ran 12 tiles, out of the Gate.",
"checkpoint": "01.02",
"faults": [
{"kind": "person_stands", "name": "camper_1", "tile": [17, 22]},
{"kind": "scene_ends_further", "step": "the_hiker", "direction": "east", "tiles": 1}
],
"failed": {"step": "past_curtis", "error": "operation_failed: past curtis: east 1 (to wall) to find us again: still moving after 12 tiles, past the wall 1 tiles away at most: position unknown."},
"frame": "20261112-210253120715-attempt0.png",
"evidence": [
"[Event] 01.02/7 hikers_trigger: a step east, limit.",
"[Walk] past curtis: east 13 (open): blocked after 8800 ms, 9 moved chunks",
"[Route] someone the map lacks is at OreburghGate (17, 22)",
"[Leg] past_curtis leg 1: east, moved 9, seen at (15, 22),(16, 22)"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* BDSP AutoStory - Console failure data
*
* From: https://github.com/PokemonAutomation/
*
* The fault files in ConsoleFailures/, built into the program
* (cmake/EmbedTextFiles.cmake): (file name, text), sorted by name.
*
*/

#ifndef PokemonAutomation_PokemonBDSP_AutoStory_ConsoleFailureData_H
#define PokemonAutomation_PokemonBDSP_AutoStory_ConsoleFailureData_H

#include <string>
#include <utility>
#include <vector>

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{


// (file name without ".json", text) of each fault file.
const std::vector<std::pair<std::string, std::string>>& console_failure_json();


} // namespace PokemonBDSP
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
Loading
Loading