Skip to content
Draft
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
@@ -1,4 +1,4 @@
/* BDSP AutoStory - Console failure cases on the story simulation

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=696 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -181,13 +181,13 @@
run->failed_step, run->error));
}
};
for (size_t i = 0; i < clean.misses().fades; i++){
for (size_t i = 0; i < looked_for(clean.misses().fade_chances); i++){
miss(true, i);
}
for (size_t i = 0; i < clean.misses().banners; i++){
for (size_t i = 0; i < looked_for(clean.misses().banner_chances); i++){
miss(false, i);
}
std::string out = std::format("{} of {} single misses fail their row:", failed.size(), clean.misses().fades + clean.misses().banners);
std::string out = std::format("{} of {} single misses fail their row:", failed.size(), looked_for(clean.misses().fade_chances) + looked_for(clean.misses().banner_chances));
for (const std::string& line : failed){
out += "\n " + line;
}
Expand All @@ -204,13 +204,13 @@
return "the run fails without misses: " + clean.result().error;
}
std::vector<std::string> failed;
for (size_t i = 0; i < clean.misses().fades; i++){
for (size_t i = 0; i < looked_for(clean.misses().fade_chances); i++){
const std::optional<SimRun> run = run_single_miss(logger, clean.result().rows, SingleMiss::HOLD, i);
if (run){
failed.push_back(std::format("fade {}'s hold unseen: stopped in {}: {}", i, run->failed_step, run->error));
}
}
std::string out = std::format("{} of {} fades with their hold unseen fail their row:", failed.size(), clean.misses().fades);
std::string out = std::format("{} of {} fades with their hold unseen fail their row:", failed.size(), looked_for(clean.misses().fade_chances));
for (const std::string& line : failed){
out += "\n " + line;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
}

// Row `row` run clean on its own, a line per fact.
void golden_row(const StoryCheckpoint& row, std::vector<std::string>& lines){

Check warning on line 77 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimGolden_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonBDSP::golden_row( const StoryCheckpoint & row , std :: vector<std::string> & lines): function_lines=32 (advisory above 25, limit 50)
QuietLogger quiet;
SimExecutor executor(quiet, {.fade = {}, .banner = {}}, {});
const Pokemon::SegmentReport report = run_rows_on(executor, quiet, {.from = row.id, .to = row.id});
Expand All @@ -99,7 +99,8 @@
const SimMisses& misses = executor.misses();
lines.push_back(std::format(
" looked for {} fades, {} banners, {} doors, {} tap steps",
misses.fades, misses.banners, misses.doors, misses.tap_steps
looked_for(misses.fade_chances), looked_for(misses.banner_chances),
looked_for(misses.door_chances), looked_for(misses.tap_step_chances)
));
for (const std::string& note : executor.notes()){
add_indented(note, " | ", lines);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* BDSP AutoStory - Story simulation

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=925 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -157,9 +157,30 @@
m_sim.end_dialogue();
}

namespace{

// The fault counter for a miss counted from 0: none if not set.
Pokemon::FaultOccurrences miss_chances(std::optional<size_t> miss){
if (!miss){
return {};
}
return Pokemon::FaultOccurrences({(int)*miss + 1});
}

} // namespace

void arm_misses(SimMisses& misses){
misses.fade_chances = miss_chances(misses.fade);
misses.hold_chances = miss_chances(misses.hold);
misses.banner_chances = miss_chances(misses.banner);
misses.door_chances = miss_chances(misses.dark);
misses.tap_step_chances = miss_chances(misses.through);
}

SimStoryStepIO::FadeShown SimStoryStepIO::next_fade(){
const size_t fade = m_misses.fades++;
const FadeShown shown = m_misses.fade == fade ? FadeShown::UNSEEN : m_misses.hold == fade ? FadeShown::HOLD_UNSEEN : FadeShown::SEEN;
const bool unseen = m_misses.fade_chances.next();
const bool hold_unseen = m_misses.hold_chances.next();
const FadeShown shown = unseen ? FadeShown::UNSEEN : hold_unseen ? FadeShown::HOLD_UNSEEN : FadeShown::SEEN;
m_misses.missed |= shown != FadeShown::SEEN;
return shown;
}
Expand Down Expand Up @@ -243,7 +264,7 @@
return taps;
}
std::optional<size_t> SimStoryStepIO::taps_to_banner(Direction direction, const std::string& map, size_t max_taps){
if (m_misses.through == m_misses.tap_steps++){
if (m_misses.tap_step_chances.next()){
m_misses.missed = true;
if (m_far_side() && m_misses.through_banner){
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* BDSP AutoStory - Story simulation

Check warning on line 1 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (bypass)

<header>: header_symbols=11 over limit 8, bypassed by the tag at line 11: "story simulation executor, scenario runners and mock IO"

Check warning on line 1 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=606 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -28,6 +28,7 @@
#include "CommonFramework/ImageTools/ImageStats.h"
#include "Pokemon/AutoStory/Pokemon_StoryActions.h"
#include "Pokemon/AutoStory/Pokemon_StorySegments.h"
#include "Pokemon/Navigation/Simulation/Pokemon_SimFaults.h"
#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h"
#include "PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h"
#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryActions.h"
Expand Down Expand Up @@ -55,22 +56,26 @@
// dark detail::SIM_FALSE_DARK in, short of the door, as lab-B's did on 2026-11-08.
// The `through`th tap step (tap_to_banner(), from 0) starts on its far side,
// its banner gone unless `through_banner`: the walk before it slid onto the
// warp (lab-B 2026-11-08). The counts and flags below are the run's: how
// many fades and banners it looked for, whether a miss happened since the
// executor last looked, whether a missed fade is still unseen, whether a
// walk slid on (SimSlide) since the executor last looked, and the map whose
// banner a slide left up for the next step.
// warp (lab-B 2026-11-08). The counters and flags below are the run's: each
// miss's chances on the shared fault counters (arm_misses()), whether a miss
// happened since the executor last looked, whether a missed fade is still
// unseen, whether a walk slid on (SimSlide) since the executor last looked,
// and the map whose banner a slide left up for the next step.
struct SimMisses{
std::optional<size_t> fade;
std::optional<size_t> banner;
std::optional<size_t> hold = {};
std::optional<size_t> dark = {};
std::optional<size_t> through = {};
bool through_banner = false;
size_t tap_steps = 0;
size_t fades = 0;
size_t banners = 0;
size_t doors = 0;
// The chances of the misses above, numbered from 1 where they count
// from 0: a fade is a chance of `fade` and of `hold`, a door run one of
// `dark`, a tap step one of `through`.
Pokemon::FaultOccurrences fade_chances = {};
Pokemon::FaultOccurrences hold_chances = {};
Pokemon::FaultOccurrences banner_chances = {};
Pokemon::FaultOccurrences door_chances = {};
Pokemon::FaultOccurrences tap_step_chances = {};
bool missed = false;
bool fade_unseen = false;
// A door's fade showed and nothing has settled since: on the console
Expand All @@ -81,6 +86,14 @@
std::string banner_up = {};
};

// Sets the chances' counters of `misses` from its misses, none counted yet.
void arm_misses(SimMisses& misses);
// How many of a miss's chances the run looked for: its fades, banners,
// door runs or tap steps.
inline size_t looked_for(const Pokemon::FaultOccurrences& chances){
return (size_t)chances.chances();
}

// How a warp's fade looks on the screen (#268's design note); the
// program's fade_of() judges it, as the walk's watchers do.
enum class SimFade{
Expand Down Expand Up @@ -365,12 +378,12 @@
// Whether this door run reads dark short of the door, or the run
// misses this banner (SimMisses).
bool false_dark(){
const bool dark = m_misses.dark == m_misses.doors++;
const bool dark = m_misses.door_chances.next();
m_misses.missed |= dark;
return dark;
}
bool banner_missed(){
const bool miss = m_misses.banner == m_misses.banners++;
const bool miss = m_misses.banner_chances.next();
m_misses.missed |= miss;
return miss;
}
Expand Down Expand Up @@ -435,6 +448,7 @@
, m_table(story_action_table(m_walks, sim_actions()))
, m_interrupts(story_interrupts([this](bool fresh){ return look(fresh); }, sim_interrupt_actions()))
{
arm_misses(m_misses);
if (m_knobs.clear_interrupts){
set_interrupts(&m_interrupts);
}
Expand All @@ -460,7 +474,7 @@
m_start_mismatch = data.start ? off_pose(Pokemon::pose_of(*data.start)) : "";
m_ran.clear();
m_astray = false;
m_result.rows.push_back({.row = data.id, .fades = m_misses.fades, .banners = m_misses.banners});
m_result.rows.push_back({.row = data.id, .fades = looked_for(m_misses.fade_chances), .banners = looked_for(m_misses.banner_chances)});
m_walks.begin_attempt(data.id, data.steps);
arm("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ UnitTestResult run_exit_test(Logger& logger, const std::string& row_id, const St
return "the table's row fails without misses: " + clean.result().error;
}
std::vector<SimMisses> runs;
for (size_t i = 0; i < clean.misses().fades; i++){
for (size_t i = 0; i < looked_for(clean.misses().fade_chances); i++){
runs.push_back({.fade = i, .banner = std::nullopt});
}
for (size_t i = 0; i < clean.misses().banners; i++){
for (size_t i = 0; i < looked_for(clean.misses().banner_chances); i++){
runs.push_back({.fade = std::nullopt, .banner = i});
}
for (const SimMisses& m : runs){
Expand Down Expand Up @@ -148,10 +148,10 @@ UnitTestResult test_story_sim_misses(Logger& logger){
if (!run_rows_on(clean, logger, range).completed){
return "the run fails without misses: " + clean.result().error;
}
logger.log(std::format("{} fades and {} banners to miss.", clean.misses().fades, clean.misses().banners));
logger.log(std::format("{} fades and {} banners to miss.", looked_for(clean.misses().fade_chances), looked_for(clean.misses().banner_chances)));
std::vector<std::string> unseen;
for (size_t i = 0; i < clean.misses().fades + clean.misses().banners; i++){
const std::string line = miss(logger, clean.result(), i < clean.misses().fades, i < clean.misses().fades ? i : i - clean.misses().fades);
for (size_t i = 0; i < looked_for(clean.misses().fade_chances) + looked_for(clean.misses().banner_chances); i++){
const std::string line = miss(logger, clean.result(), i < looked_for(clean.misses().fade_chances), i < looked_for(clean.misses().fade_chances) ? i : i - looked_for(clean.misses().fade_chances));
if (!line.empty()){
unseen.push_back(line);
}
Expand Down Expand Up @@ -219,10 +219,10 @@ UnitTestResult test_tap_through_already(Logger& logger, bool banner){
const SimRun& run = through.result();
const std::optional<TilePos> at = run.world ? story_to_local(*run.world, "OreburghGate", run.end) : std::nullopt;
const bool passed = banner
? run.error.empty() && through.misses().fades + 1 == clean.misses().fades
? run.error.empty() && looked_for(through.misses().fade_chances) + 1 == looked_for(clean.misses().fade_chances)
: run.failed_step == "01.05 into_oreburgh_gate" && at && at->y == 22 && at->x >= 21;
return passed ? UnitTestResult(true) : UnitTestResult(std::format("failed in '{}' on {} after {} fades (clean {}): {}",
run.failed_step, end_of(run), through.misses().fades, clean.misses().fades, run.error.empty() ? "no failure" : run.error));
run.failed_step, end_of(run), looked_for(through.misses().fade_chances), looked_for(clean.misses().fade_chances), run.error.empty() ? "no failure" : run.error));
}

UnitTestResult test_story_sim_step_failure(Logger& logger, const std::string& row, const StoryStep& old_step, const std::string& expected_failed_step, const std::string& expected_error){
Expand All @@ -242,7 +242,7 @@ UnitTestResult test_story_sim_step_failure(Logger& logger, const std::string& ro
UnitTestResult test_heal_fade_unseen(Logger& logger){
SimExecutor clean(logger);
run_rows_on(clean, logger, {.from = "01.03", .to = "01.03"});
for (size_t i = 0; i < clean.misses().fades; i++){
for (size_t i = 0; i < looked_for(clean.misses().fade_chances); i++){
SimExecutor sim(logger, {.fade = i, .banner = {}});
run_rows_on(sim, logger, {.from = "01.03", .to = "01.03"});
const SimRun& run = sim.result();
Expand Down
Loading