diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryMonteCarlo.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryMonteCarlo.cpp new file mode 100644 index 0000000000..b26b246fcf --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryMonteCarlo.cpp @@ -0,0 +1,174 @@ +/* Story Monte Carlo + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "Pokemon_StoryMonteCarlo.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +uint64_t SimRandom::next(){ + m_state += 0x9e3779b97f4a7c15ULL; + uint64_t z = m_state; + z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL; + z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL; + return z ^ (z >> 31); +} +double SimRandom::uniform(){ + return (double)(next() >> 11) / (double)(1ULL << 53); +} +int64_t SimRandom::between(int64_t lo, int64_t hi){ + if (hi <= lo){ + return lo; + } + return lo + (int64_t)(next() % (uint64_t)(hi - lo + 1)); +} +bool SimRandom::chance(double p){ + return uniform() < p; +} + + +DisturbancePlan make_disturbance_plan(uint64_t seed, const DisturbanceRates& rates, size_t fades, size_t banners){ + SimRandom root(seed); + DisturbancePlan plan{ + .seed = seed, + .rates = rates, + .battles = SimRandom(root.next()), + .drift = SimRandom(root.next()), + .wanderers = SimRandom(root.next()), + .missed_fade = std::nullopt, + .missed_banner = std::nullopt, + }; + SimRandom misses(root.next()); + if (fades + banners > 0 && misses.chance(rates.missed_detection * (double)(fades + banners))){ + const size_t which = (size_t)misses.between(0, (int64_t)(fades + banners) - 1); + if (which < fades){ + plan.missed_fade = which; + }else{ + plan.missed_banner = which - fades; + } + } + SimRandom holds(root.next()); + if (fades > 0 && holds.chance(rates.missed_hold)){ + plan.missed_hold = (size_t)holds.between(0, (int64_t)fades - 1); + } + plan.dialogs = SimRandom(root.next()); + return plan; +} + +std::string describe(const DisturbancePlan& plan){ + std::string text = std::format("seed {}", plan.seed); + if (plan.missed_fade){ + text += std::format(": miss fade {}", *plan.missed_fade); + } + if (plan.missed_banner){ + text += std::format(": miss banner {}", *plan.missed_banner); + } + if (plan.missed_hold){ + text += std::format(": fade {}'s hold unseen", *plan.missed_hold); + } + return text; +} + + +std::vector story_seeds(size_t count){ + std::vector seeds; + SimRandom pinned(20261108); + for (size_t i = 0; i < count; i++){ + // Short enough to type into a reproduction. + seeds.push_back(pinned.next() % 1000000); + } + return seeds; +} + +size_t seed_count(std::string_view name, size_t fallback){ + const auto* value = std::getenv(std::string(name).c_str()); + if (value == nullptr){ + return fallback; + } + const long long count = std::atoll(value); + return count > 0 ? (size_t)count : fallback; +} + +std::vector selected_rows(std::string_view name, const std::vector& rows){ + const auto* value = std::getenv(std::string(name).c_str()); + if (value == nullptr || *value == '\0'){ + return rows; + } + const std::string wanted = std::string(",") + value + ","; + std::vector out; + for (const std::string& row : rows){ + if (wanted.find("," + row + ",") != std::string::npos){ + out.push_back(row); + } + } + return out; +} + + +std::string failure_kind(std::string_view failure, std::string_view message, size_t limit){ + std::string text(failure); + if (!message.empty()){ + text += ": "; + text += message; + } + std::string kind; + for (char c : text){ + const bool digit = std::isdigit((unsigned char)c) != 0; + if (!digit){ + kind += c; + }else if (kind.empty() || kind.back() != '#'){ + kind += '#'; + } + } + return kind.size() > limit ? kind.substr(0, limit) + "..." : kind; +} + + +RowReport run_row_seeds(const std::string& row, const std::vector& seeds, const SeedRun& run){ + RowReport report{.row = row}; + for (uint64_t seed : seeds){ + const SeedOutcome outcome = run(row, seed); + report.runs++; + if (outcome.passed){ + report.passes++; + continue; + } + KindCount& count = report.failures[outcome.failed_step][outcome.kind]; + if (count.runs++ == 0){ + count.seed = seed; + count.detail = outcome.detail; + } + } + return report; +} + +std::vector run_seeds(const std::vector& rows, const std::vector& seeds, const SeedRun& run){ + std::vector reports; + for (const std::string& row : rows){ + reports.push_back(run_row_seeds(row, seeds, run)); + } + return reports; +} + +std::string format_report(const RowReport& report){ + const double rate = report.runs == 0 ? 0.0 : 100.0 * (double)report.passes / (double)report.runs; + std::string text = std::format("{}: {}/{} passed ({:.0f}%)", report.row, report.passes, report.runs, rate); + for (const auto& [step, kinds] : report.failures){ + for (const auto& [kind, count] : kinds){ + text += std::format("\n {} x{}: {} (seed {}; {})", step, count.runs, kind, count.seed, count.detail); + } + } + return text; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryMonteCarlo.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryMonteCarlo.h new file mode 100644 index 0000000000..f55c7a3441 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryMonteCarlo.h @@ -0,0 +1,196 @@ +/* Story Monte Carlo + * + * From: https://github.com/PokemonAutomation/ + * + * Runs story rows on a game's simulation many times, each time disturbed + * the way the console disturbs a run: wild battles at random moments on + * encounter tiles, a walk that ends part of a tile off, someone wandering + * into the way, a fade or a banner that goes unseen. Each run is one seed + * of a pinned list, so a failure found is a failure reproduced: the report + * gives, per row, the pass rate and, per failing step, its failure kinds + * with a seed that shows each. + * + * Game-agnostic: a game binds it by running one row for one seed's + * DisturbancePlan (a SeedRun) on its own simulation. + * +// code-health: allow header_symbols -- Monte Carlo framework types, disturbance plan and reporter + */ + +#ifndef PokemonAutomation_Pokemon_StoryMonteCarlo_H +#define PokemonAutomation_Pokemon_StoryMonteCarlo_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Time.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// A deterministic random stream (splitmix64): the same seed draws the same +// numbers on every platform. +class SimRandom{ +public: + explicit SimRandom(uint64_t seed = 0) + : m_state(seed) + {} + + uint64_t next(); + // Uniform in [0, 1). + double uniform(); + // Uniform in [lo, hi], both inclusive. + int64_t between(int64_t lo, int64_t hi); + // True with probability `p`. + bool chance(double p); + +private: + uint64_t m_state; +}; + + +// How hard a run is disturbed. The rates are per tile the player enters. +// They are measured on lab-B's BDSP runs of rows 00.00 to 01.11, 2026-10-31 +// to 2026-11-08 (its SerialPrograms.log and the one rotated before it, the +// AutoStory program's lines only), as noted on each. +struct DisturbanceRates{ + // A wild battle on an encounter tile. Caves: 16 battles in 838 tiles + // (the "[Walk] ...: N moved chunks, M wild battle(s)" lines of 01.03's + // mine steps, 2026-11-07 and 08; their taps move a tile a chunk). Per + // run it is less: 42 battles in the 71 runs that reached the mine, at + // the 52 cave tiles the simulation walks there, 1.1%. Grass: 10 + // battles in about 1,200 tiles, from the battles logged in the steps of + // 00.03, 00.04d, 01.06 and 01.08 that cross grass, times each step's + // runs, times the grass tiles the simulation walks in it (14, 43, 12, + // 13). Gen IV's rate / 180 (30 and 10 there) drew 8 to 14 battles a + // 01.03 run; the console met 0 to 2. + double grass_encounter = 10.0 / 1200; + double cave_encounter = 16.0 / 838; + // Where a stick hold that does not end at a wall ends, along its way: + // off by up to this many thousandths of a tile per tile walked, + // uniformly. Not measured. + int drift_per_tile = 150; + // The same for D-pad taps, which move whole tiles: 54 runs of 01.03's + // above_the_mine ended nine open taps on the tile above the mine's + // warp, none on the warp. One open leg of the 466 of more than a tile + // went a tile past (11:55 on 2026-11-08); that is not modelled. + int tap_drift_per_tile = 0; + // Off by no more than this, the player still fits a one-tile gap (a + // door, a corridor); past it the player covers two tiles. Assumed: a + // door frame stopped a player 0.375 tile off (the grid sim's measure). + int fit = 250; + // Someone wandering starts their walk up to this far into it. + Milliseconds wanderer_start = Milliseconds(10000); + // Someone wandering tries a step this often (a fifth of the tries they + // stay). Oreburgh's hiker stopped 15 of 54 above_the_mine runs short of + // the wall ("stopped after about N tiles"); in 11 the way cleared after + // taps or waits, 4 talked to him, 1 failed with no plan. The simulation + // at 2000 ms: 17 of 100 seeds stopped, 16 talked, 16 failed; at 1000 ms + // 16, 14 and 14. The step's pace is not what keeps him in the way. + Milliseconds wander_step = Milliseconds(2000); + // The chance a seed misses each fade or banner its row looks for (it + // misses one at most). The door's own watcher missed 13 of 35 fades, + // but settle() then saw each arrival: no door step of 01.03 failed for + // a fade on 2026-11-08. Over the whole week 9 door steps failed "no + // fade within 120 s" in about 230 settles, most of them a step that + // had not reached its door; 2 required banners went unread, both + // 01.03's old out_of_the_mine. + double missed_detection = 0.02; + // The chance a seed drops the hold of one fade its row looks for: a + // short fade whose dark or white fell between two frames, so only its + // fall and the scene after show. 0 in the rates measured; 1 in the + // tests that every seed survives it. + double missed_hold = 0; + // The chance someone walks up and talks to the player before a step + // (a dialog between two steps, cleared by the executor's look). Not + // measured: 0 in the rates measured, set by the tests that pop them. + double dialog_between_steps = 0; +}; + +// One seed's disturbances: independent random streams for each kind, so a +// change in how many battles a run draws does not move its drift, and the +// one detection the run misses, if any (as an index into the row's fades, +// then its banners, from an undisturbed run), and the one fade whose hold +// it drops, if any (an index into the row's fades). The hold is drawn +// from a stream of its own, so a plan's other draws do not move with it. +struct DisturbancePlan{ + uint64_t seed = 0; + DisturbanceRates rates; + SimRandom battles; + SimRandom drift; + SimRandom wanderers; + std::optional missed_fade; + std::optional missed_banner; + std::optional missed_hold = std::nullopt; + // Whether a dialog pops up before each step, drawn last from the + // seed, so the other draws do not move with it. + SimRandom dialogs = SimRandom(); +}; +// The plan for `seed`, for a row whose undisturbed run looks for `fades` +// fades and `banners` banners. +DisturbancePlan make_disturbance_plan(uint64_t seed, const DisturbanceRates& rates, size_t fades, size_t banners); +// "seed 17: miss fade 1": what a plan draws up front, to reproduce it. +// A dropped hold reads "fade 2's hold unseen". +std::string describe(const DisturbancePlan& plan); + + +// The pinned seeds: the same `count` seeds on every run, the first of a +// longer list the first of a shorter one. +std::vector story_seeds(size_t count); +// The seed count to run: `fallback`, or the environment variable `name` +// when it holds a positive number (the heavy, on-demand mode). +size_t seed_count(std::string_view name, size_t fallback); +// The rows to run: all of `rows`, or those the environment variable +// `name` lists (comma-separated ids), in `rows`' order. +std::vector selected_rows(std::string_view name, const std::vector& rows); + + +// What one seed's run of a row did. +struct SeedOutcome{ + bool passed = false; + // The step it failed in, and how ("short_leg", "sim_failure: no door + // north of (#, #)"): numbers become '#', so runs that failed the same + // way group together. + std::string failed_step; + std::string kind; + // The failure as it was, for the seed that shows it first. + std::string detail; +}; +// `failure: message` with digit runs as '#', at most `limit` characters. +std::string failure_kind(std::string_view failure, std::string_view message, size_t limit = 90); + +// Runs row `row` once, disturbed by `seed`. +using SeedRun = std::function; + +// One failure kind of a step: how often, and the first seed that shows it. +struct KindCount{ + size_t runs = 0; + uint64_t seed = 0; + std::string detail; +}; +// A row's runs over the seeds. +struct RowReport{ + std::string row; + size_t runs = 0; + size_t passes = 0; + // By failed step, then by kind. + std::map> failures; +}; +// Runs `row` once for each of `seeds`. +RowReport run_row_seeds(const std::string& row, const std::vector& seeds, const SeedRun& run); +// Runs each of `rows` for each of `seeds`, in order. +std::vector run_seeds(const std::vector& rows, const std::vector& seeds, const SeedRun& run); +// "01.03: 41/50 passed (82%)", then a line per failing step and kind +// with its count and seed. +std::string format_report(const RowReport& report); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp index c51b846fd4..7c32cc3448 100644 --- a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp @@ -20,6 +20,7 @@ #include "Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h" #include "Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h" #include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.h" +#include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryMonteCarlo_Tests.h" #include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim_Tests.h" #include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySimulation_Tests.h" #include "Programs/AutoStory/PokemonBDSP_AutoStory_StoryData_Tests.h" @@ -57,6 +58,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStory_WallBattleSim(database); add_tests_AutoStory_RecoveryWalk(database); add_tests_AutoStory_StorySim(database); + add_tests_AutoStory_StoryMonteCarlo(database); add_tests_AutoStory_SimFailureCases(database); add_tests_AutoStory_FaultSweep(database); add_tests_AutoStory_StoryActions(database); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimDisturbance.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimDisturbance.cpp new file mode 100644 index 0000000000..df74f30fc7 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimDisturbance.cpp @@ -0,0 +1,322 @@ +/* BDSP AutoStory - Disturbances on the grid simulation + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WalkRules.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_LegBattle.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" +#include "PokemonBDSP_AutoStory_SimDisturbance.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; +using Pokemon::Direction; +using Pokemon::TileKind; +using Pokemon::TilePos; + + +namespace{ + +// The caves on the story's way, where every tile has wild Pokemon. +constexpr std::string_view CAVE_MAPS[] = {"OreburghMineB1F", "OreburghMine", "RavagedPath"}; +// Drift comes in steps of this many thousandths of a tile: 4 ms of stick +// across, 6 ms up or down, so the grid sim puts it back on the grid exactly. +constexpr int DRIFT_STEP = 25; + +bool across(Direction direction){ + return direction == Direction::EAST || direction == Direction::WEST; +} +// The player's offset from their nearest tile along an axis. +int offset_of(const SimPos& pos, bool along_x){ + const TilePos tile = nearest_tile(pos); + return along_x ? pos.x - tile.x * SIM_TILE : pos.y - tile.y * SIM_TILE; +} +int along(const SimPos& pos, Direction direction){ + return across(direction) ? pos.x : pos.y; +} +bool wanderer_on(const GridSim& sim, const TilePos& pos){ + const std::vector& people = detail::sim_wanderers(sim); + return std::any_of(people.begin(), people.end(), [&](const SimWanderer& person){ return person.pos == pos; }); +} +// Whether the player can drift a little toward `direction`: the tile there +// is open ground with nobody on it, not a wall or a door. +bool room_toward(const GridSim& sim, Direction direction){ + const TilePos next = nearest_tile(sim.player().pos).next(direction); + const std::optional tile = sim.world().tile(next); + return tile && *tile != TileKind::DOOR && standable(sim.world(), next) && !wanderer_on(sim, next); +} +// A hold that stopped against what is in its way, not against a person. +bool stopped_at_wall(const GridSim& sim, const SimMove& move, Direction direction){ + return move.stop == SimStop::BLOCKED && !wanderer_on(sim, nearest_tile(sim.player().pos).next(direction)); +} + +bool in_cave(const StoryWorld& world, const TilePos& pos){ + const std::optional tile = world.to_local(pos); + return tile && std::ranges::any_of(CAVE_MAPS, [&](std::string_view map){ return tile->map == story_banner_name(std::string(map)); }); +} + +// Whether `box` of `map` holds `pos`. +bool holds(const Pokemon::TileBox& box, const TilePos& pos){ + return box.x0 <= pos.x && pos.x <= box.x1 && box.y0 <= pos.y && pos.y <= box.y1; +} + +WalkStop walk_stop(SimStop stop){ + switch (stop){ + case SimStop::BLOCKED: + return WalkStop::BLOCKED; + case SimStop::DIALOG: + return WalkStop::DIALOG; + case SimStop::WARP: + return WalkStop::TRANSITION; + case SimStop::DONE: + case SimStop::LIMIT: + return WalkStop::LIMIT; + } + return WalkStop::LIMIT; +} + +} // namespace + + +SimDisturbance::SimDisturbance(Pokemon::DisturbancePlan plan) + : m_plan(std::move(plan)) +{} + +bool SimDisturbance::battle_at(const StoryWorld& world, const TilePos& pos){ + const std::optional tile = world.tile(pos); + if (!tile){ + return false; + } + const bool grass = *tile == TileKind::TALL_GRASS; + const bool cave = !grass && in_cave(world, pos); + m_tiles.grass += grass ? 1 : 0; + m_tiles.cave += cave ? 1 : 0; + const double rate = grass ? m_plan.rates.grass_encounter : cave ? m_plan.rates.cave_encounter : 0; + if (rate <= 0 || !m_plan.battles.chance(rate)){ + return false; + } + m_battles++; + return true; +} + +void SimDisturbance::reset(){ + m_x = {}; + m_y = {}; +} + +// The grid sim's position is the truth: a wall it stopped at, or a place +// the executor put the player, changes the offset, and the drift with it. +void SimDisturbance::sync(const GridSim& sim){ + for (bool along_x : {true, false}){ + Axis& axis = along_x ? m_x : m_y; + const int actual = offset_of(sim.player().pos, along_x); + if (actual != axis.applied){ + axis.drift = actual; + axis.applied = actual; + } + } +} + +void SimDisturbance::walked(GridSim& sim, Direction direction, int thousandths, bool at_wall, int drift_per_tile){ + sync(sim); + Axis& axis = across(direction) ? m_x : m_y; + if (at_wall){ + axis.drift = axis.applied; + return; + } + // In steps of DRIFT_STEP, which a stick press moves exactly. + const int64_t most = drift_per_tile / DRIFT_STEP; + const int64_t steps = m_plan.drift.between(-most, most) * thousandths / SIM_TILE; + axis.drift = std::clamp(axis.drift + (int)steps * DRIFT_STEP, -SIM_TILE + 100, SIM_TILE - 100); + materialize(sim, across(direction)); +} + +// Puts the drift past `fit` on the grid sim's position, with a stick press +// that far, and turns back the way the player faced. A wall or a door in +// the way absorbs it. +void SimDisturbance::materialize(GridSim& sim, bool along_x){ + Axis& axis = along_x ? m_x : m_y; + const int target = std::abs(axis.drift) > m_plan.rates.fit ? axis.drift : 0; + const int delta = target - axis.applied; + if (delta == 0){ + return; + } + const Direction direction = along_x ? (delta > 0 ? Direction::EAST : Direction::WEST) + : (delta > 0 ? Direction::SOUTH : Direction::NORTH); + if (!room_toward(sim, direction)){ + axis.drift = axis.applied; + return; + } + const Direction facing = sim.player().facing; + const SimPos before = sim.player().pos; + const Milliseconds tile_time = route_ms_per_tile(direction, MoveSpeed::WALK); + sim.tap(direction, Milliseconds((std::abs(delta) * tile_time.count() + SIM_TILE / 2) / SIM_TILE), true); + const int moved = along(sim.player().pos, direction) - along(before, direction); + axis.applied += moved; + if (std::abs(moved - delta) >= DRIFT_STEP){ + axis.drift = axis.applied; + } + sim.tap(facing, ROUTE_TURN_TAP, false); +} + +// The maps' wanderers on `world`, found from its wandering tiles: each +// tile's map, and who on that map wanders over it. +const std::vector& SimDisturbance::people(const StoryWorld& world){ + auto found = m_people.find(&world); + if (found != m_people.end()){ + return found->second; + } + std::vector& people = m_people[&world]; + for (const TilePos& pos : wandering_hazards(world)){ + const std::optional tile = world.to_local(pos); + for (const auto& [name, json] : bdsp_map_json()){ + if (!tile || story_banner_name(name) != tile->map){ + continue; + } + add_people(people, name, {pos.x - tile->pos.x, pos.y - tile->pos.y}, tile->pos); + } + } + return people; +} + +// Who on `map` (its tile (0, 0) at world tile `corner`) wanders over its +// tile `local`, if not in `people` yet. +void SimDisturbance::add_people(std::vector& people, const std::string& map, const TilePos& corner, const TilePos& local){ + for (const Pokemon::MapObject& object : story_map(map).objects){ + const std::string name = map + "/" + object.name; + const bool known = std::ranges::any_of(people, [&](const SimWanderer& person){ return person.name == name; }); + if (!object.wander || object.hide_flag || known || !holds(*object.wander, local)){ + continue; + } + const Pokemon::TileBox& box = *object.wander; + people.push_back({.name = name, .box = {corner.x + box.x0, corner.y + box.y0, corner.x + box.x1, corner.y + box.y1}, + .pos = {corner.x + object.x, corner.y + object.y}}); + } +} + +std::vector SimDisturbance::wanderers(const StoryWorld& world){ + std::vector out = people(world); + for (SimWanderer& person : out){ + person.seed = m_plan.wanderers.next(); + person.time_offset = Milliseconds(m_plan.wanderers.between(0, m_plan.rates.wanderer_start.count())); + person.step_interval = m_plan.rates.wander_step; + } + return out; +} + + +DisturbedHold disturbed_hold(GridSim& sim, SimDisturbance* noise, Direction direction, Milliseconds limit, SimPace pace){ + if (noise == nullptr){ + return {.move = sim.hold(direction, limit, pace)}; + } + // A tile at a time, at the hold's own pace. + const Milliseconds tile_time = sim_ms_per_tile(direction, pace, sim.player().can_run); + const int64_t tiles = limit < ROUTE_START_DELAY ? 0 : (limit - ROUTE_START_DELAY) / tile_time; + DisturbedHold out{.move = {.stop = SimStop::LIMIT}}; + for (int64_t i = 0; i < tiles && out.move.stop == SimStop::LIMIT; i++){ + const SimMove step = sim.hold(direction, ROUTE_START_DELAY + tile_time, pace); + out.move.distance += step.distance; + out.move.stop = step.stop; + if (step.stop == SimStop::LIMIT && noise->battle_at(sim.world(), nearest_tile(sim.player().pos))){ + out.battles++; + out.first_tile |= i == 0; + } + } + if (out.move.stop == SimStop::LIMIT){ + out.move.time = limit; + }else{ + const Milliseconds seen = out.move.stop == SimStop::BLOCKED ? 800ms : 0ms; + out.move.time = ROUTE_START_DELAY + tile_time * out.move.distance / SIM_TILE + seen; + } + if (out.move.stop == SimStop::LIMIT || out.move.stop == SimStop::BLOCKED){ + noise->walked(sim, direction, SIM_TILE, stopped_at_wall(sim, out.move, direction), noise->plan().rates.drift_per_tile); + } + return out; +} + + +WalkResult DisturbedRouteIO::walk_to_wall(const RouteWallWalk& walk){ + if (m_noise == nullptr){ + return GridSimRouteIO::walk_to_wall(walk); + } + const SimPace pace = walk.options.pace == DpadPace::RUN ? SimPace::RUN : SimPace::WALK; + const DisturbedHold hold = disturbed_hold(m_sim, m_noise, walk.direction, walk.limit, pace); + m_notes.push_back(std::format("[Sim] {}: held {} to {} at {}, {} wild battle(s).", walk.label, direction_name(walk.direction), + detail::sim_stop_name(hold.move.stop), to_string(m_sim.player().pos), hold.battles)); + WalkResult result{.stop = walk_stop(hold.move.stop), .walked = hold.move.time, .wild_battles = hold.battles, + .moved_chunks = (size_t)(hold.move.distance / SIM_TILE)}; + if (hold.first_tile){ + result.origin = WalkOrigin::MAY_PRECEDE_LEG; + } + return result; +} + +// A tap a tile, as GridSimRouteIO taps, drifting as the rates say; a battle on a tile stepped onto +// is fled and credited as a moved tile, as the console's walk credits it, +// and the taps go on. One on the first tap may have begun before it. +WalkResult DisturbedRouteIO::walk_taps(Direction direction, size_t tiles, const std::string& label){ + if (m_noise == nullptr){ + return GridSimRouteIO::walk_taps(direction, tiles, label); + } + WalkResult result{.stop = WalkStop::LIMIT, .walked = 0ms, .wild_battles = 0, .moved_chunks = 0}; + result.events.record({}, result.started); + size_t still = 0; + size_t moved_at_battle = 0; + for (size_t tap = 0; tap < tiles && result.stop == WalkStop::LIMIT; tap++){ + const SimMove move = m_sim.tap(direction, ROUTE_MS_PER_TILE_ACROSS, false); + result.walked += 800ms; + still = move.distance > 0 ? 0 : still + 1; + result.moved_chunks += move.distance > 0 ? 1 : 0; + if (move.stop == SimStop::DIALOG || move.stop == SimStop::WARP){ + result.stop = walk_stop(move.stop); + }else if (still >= 2){ + result.stop = WalkStop::BLOCKED; + } + const int tap_drift = m_noise->plan().rates.tap_drift_per_tile; + if (move.distance > 0 && result.stop == WalkStop::LIMIT && tap_drift > 0){ + m_noise->walked(m_sim, direction, SIM_TILE, false, tap_drift); + } + if (move.distance > 0 && move.stop == SimStop::DONE && m_noise->battle_at(m_sim.world(), nearest_tile(m_sim.player().pos))){ + result.wild_battles++; + result.origin = tap == 0 ? WalkOrigin::MAY_PRECEDE_LEG : result.origin; + // The console's watchers time the battle from this tap. + record_tap_battle(result, tap + 1); + moved_at_battle = result.moved_chunks; + m_notes.push_back("[Sim] wild battle during " + label); + } + } + if (result.wild_battles > 0){ + result.moved_after_battle = result.moved_chunks - moved_at_battle; + } + m_notes.push_back(std::format("[Sim] {}: {} taps {}, {} moved, {} at {}.", label, tiles, direction_name(direction), + result.moved_chunks, walk_stop_name(result.stop), to_string(m_sim.player().pos))); + return result; +} + +// A stick press drifts with the tiles it moves. +void DisturbedRouteIO::press(const RouteInput& input){ + const SimPos before = m_sim.player().pos; + GridSimRouteIO::press(input); + if (m_noise == nullptr || input.kind != RouteInputKind::STICK){ + return; + } + const int moved = std::abs(along(m_sim.player().pos, input.direction) - along(before, input.direction)); + if (moved > 0){ + m_noise->walked(m_sim, input.direction, moved, false, m_noise->plan().rates.drift_per_tile); + } +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimDisturbance.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimDisturbance.h new file mode 100644 index 0000000000..14fdc775b4 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimDisturbance.h @@ -0,0 +1,126 @@ +/* BDSP AutoStory - Disturbances on the grid simulation + * + * From: https://github.com/PokemonAutomation/ + * + * One seed's disturbances (Pokemon::DisturbancePlan) played on a GridSim, + * as the console disturbs a run: + * + * - A wild battle on tall grass, or anywhere in a cave (Oreburgh Mine, + * the Ravaged Path), once the player has stepped onto the tile. It is + * fled, and the input goes on, as the console's walks go on. + * - Drift: a stick press or a hold stopped short of a wall ends up to + * DisturbanceRates::drift_per_tile off along its way, a D-pad tap up + * to DisturbanceRates::tap_drift_per_tile (none by default). Within DisturbanceRates::fit of the tile the player still + * fits a one-tile gap; past it, the grid sim has them part of a tile + * off, where a door frame or a rock's corner stops them. A walk that + * stops at a wall ends on its tile, and on the grid along that way. + * - The people who wander on the maps (MapObject::wander) walk about, + * each from a seed and a start of the plan's. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_SimDisturbance_H +#define PokemonAutomation_PokemonBDSP_AutoStory_SimDisturbance_H + +#include +#include +#include +#include "Pokemon/AutoStory/Pokemon_StoryMonteCarlo.h" +#include "PokemonBDSP_AutoStory_GridSim.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// A seed's disturbances on a GridSim. Not thread-safe; one per run. +class SimDisturbance{ +public: + explicit SimDisturbance(Pokemon::DisturbancePlan plan); + + const Pokemon::DisturbancePlan& plan() const{ + return m_plan; + } + // Wild battles drawn so far. + size_t battles() const{ + return m_battles; + } + // Encounter tiles stepped onto so far. + struct EncounterTiles{ + size_t grass = 0; + size_t cave = 0; + }; + const EncounterTiles& encounter_tiles() const{ + return m_tiles; + } + // Whether stepping onto world tile `pos` starts a wild battle. + bool battle_at(const StoryWorld& world, const Pokemon::TilePos& pos); + // The player moved `thousandths` of a tile toward `direction` and did + // not stop at a wall (or, `at_wall`, stopped at one): drifts them by up + // to `drift_per_tile` thousandths a tile walked. + void walked(GridSim& sim, Pokemon::Direction direction, int thousandths, bool at_wall, int drift_per_tile); + // The player was put on a tile: no drift. + void reset(); + // The people who wander on `world`, each with a seed and start drawn. + std::vector wanderers(const StoryWorld& world); + +private: + // How far off the player is along one axis, in thousandths of a tile: + // `drift` in all, `applied` of it on the grid sim's position. + struct Axis{ + int drift = 0; + int applied = 0; + }; + void sync(const GridSim& sim); + void materialize(GridSim& sim, bool across); + const std::vector& people(const StoryWorld& world); + void add_people(std::vector& people, const std::string& map, const Pokemon::TilePos& corner, const Pokemon::TilePos& local); + + Pokemon::DisturbancePlan m_plan; + size_t m_battles = 0; + EncounterTiles m_tiles; + Axis m_x; + Axis m_y; + std::map> m_people; +}; + + +// A hold on the grid sim (GridSim::hold()), a tile at a time with wild +// battles and drift from `noise` if given. +struct DisturbedHold{ + SimMove move; + size_t battles = 0; + // A battle on the hold's first tile: the console cannot tell it from + // one that began before the hold (WalkOrigin::MAY_PRECEDE_LEG). + bool first_tile = false; +}; +// Holds toward `direction` for up to `limit`; see DisturbedHold. +DisturbedHold disturbed_hold(GridSim& sim, SimDisturbance* noise, Pokemon::Direction direction, Milliseconds limit, SimPace pace); + + +// GridSimRouteIO, disturbed by `noise` (none: GridSimRouteIO itself). +class DisturbedRouteIO : public GridSimRouteIO{ +public: + DisturbedRouteIO(GridSim& sim, std::vector& notes, SimDisturbance* noise, SimGrassBattles grass = {}) + : GridSimRouteIO(sim, notes, {}, {}, grass) + , m_sim(sim) + , m_notes(notes) + , m_noise(noise) + {} + + virtual WalkResult walk_to_wall(const RouteWallWalk& walk) override; + virtual WalkResult walk_taps(Pokemon::Direction direction, size_t tiles, const std::string& label) override; + virtual void press(const RouteInput& input) override; + +private: + GridSim& m_sim; + std::vector& m_notes; + SimDisturbance* m_noise; +}; + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryMonteCarlo_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryMonteCarlo_Tests.cpp new file mode 100644 index 0000000000..6ddcae5aad --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryMonteCarlo_Tests.cpp @@ -0,0 +1,475 @@ +/* BDSP AutoStory Story Monte Carlo Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The story's rows on the story simulation (SimExecutor: the program's own + * walking steps on the grid sim), each run once per pinned seed with that + * seed's disturbances (SimDisturbance): wild battles on grass and in caves, + * drift off the grid, the maps' wanderers, and sometimes one missed fade or + * banner. Each row's test logs its pass rate and, per failing step, the + * failure kinds with a seed that reproduces each, and fails only below the + * row's pinned floor. The old 01.03 test shows the harness finds the + * failure lab-B met across Roark's room on 2026-11-08. Each row's seeds that pass with no + * miss run again with one fade's hold unseen, and must pass again. With + * dialogs popping up between steps, a seed that passes without them + * must pass with them, the executor clearing them before each step. + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Time.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_StoryMonteCarlo.h" +#include "Pokemon/AutoStory/Pokemon_TilePose.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.h" +#include "PokemonBDSP_AutoStory_SimDisturbance.h" +#include "PokemonBDSP_AutoStory_StorySim.h" +#include "PokemonBDSP_AutoStory_StoryMonteCarlo_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +namespace{ + +using namespace std::chrono_literals; +using Pokemon::Direction; +using Pokemon::RowReport; +using Pokemon::SeedOutcome; +using Pokemon::StoryStep; +using Pokemon::TilePos; + +constexpr std::string_view SEEDS_VARIABLE = "PA_BDSP_STORY_MC_SEEDS"; +constexpr std::string_view ROWS_VARIABLE = "PA_BDSP_STORY_MC_ROWS"; +constexpr std::string_view TRACE_VARIABLE = "PA_BDSP_STORY_MC_TRACE"; +constexpr size_t DEFAULT_SEEDS = 20; + +// The runs log nothing: a seed's own log is a reproduction away. +class SilentLogger : public Logger{ +public: + virtual void log(const std::string&, Color) override{} +}; + +// The fades and banners an undisturbed run of `row` looks for. +SimMisses looked_for(const std::vector& rows, const std::string& row){ + SilentLogger logger; + SimExecutor executor(logger); + run_rows_on(executor, logger, {.from = row, .to = row}, rows); + return executor.misses(); +} + +// How a failed run failed, as the report groups it. +SeedOutcome failed_outcome(const Pokemon::SegmentReport& report, const SimRun& run, const SimDisturbance& noise){ + const bool in_step = !run.failed_step.empty(); + SeedOutcome out{ + .passed = false, + .failed_step = in_step ? run.failed_step : report.failed_checkpoint + " " + report.failed_event, + .kind = in_step ? Pokemon::failure_kind(run.failure, run.failure_detail) + : Pokemon::failure_kind(report.failure.failure, report.failure.detail), + .detail = std::format("{}; {} wild battle(s)", describe(noise.plan()), run.battles), + }; + if (run.failed_step_battles > 0){ + out.kind += " [wild battle in the step]"; + } + if (in_step && run.missed_step == run.failed_step){ + out.kind += " [missed detection in the step]"; + } + return out; +} + +// How a row's seeds are disturbed: at `rates`, missing one of the fades +// and banners its undisturbed run looked for (`clean`). +struct RowNoise{ + SimMisses clean; + Pokemon::DisturbanceRates rates; +}; + +// The rates the harness was first built with, harsher than lab-B's (see +// DisturbanceRates): Gen IV's encounter rates, taps that drift as the +// stick does, and a miss in about a quarter of 01.03's seeds. +Pokemon::DisturbanceRates stress_rates(){ + Pokemon::DisturbanceRates rates; + rates.grass_encounter = 30.0 / 180; + rates.cave_encounter = 10.0 / 180; + rates.tap_drift_per_tile = rates.drift_per_tile; + rates.missed_detection = 0.04; + return rates; +} + +// What the executor does with a dialog that pops up between steps. +enum class PoppedDialog{ + CLEARED, // cleared before the next step, as the console does + LEFT_UP, // left up, as before the executor looked (SimWorldKnobs::clear_interrupts) +}; + +// Row `row` of `rows`, disturbed by `seed`, logging to `logger`. +SeedOutcome run_seed( + Logger& logger, const std::vector& rows, const RowNoise& noise_of, const std::string& row, uint64_t seed, + PoppedDialog popped = PoppedDialog::CLEARED +){ + const SimMisses& clean = noise_of.clean; + SimDisturbance noise(Pokemon::make_disturbance_plan(seed, noise_of.rates, clean.fades, clean.banners)); + Pokemon::SimRandom dialogs = noise.plan().dialogs; + const double dialog_rate = noise_of.rates.dialog_between_steps; + SimWorldKnobs knobs{ + .dialog_before = [&dialogs, dialog_rate](const std::string&, const std::string&){ + return dialog_rate > 0 && dialogs.chance(dialog_rate); + }, + .clear_interrupts = popped == PoppedDialog::CLEARED, + .noise = &noise, + }; + SimExecutor executor(logger, {.fade = noise.plan().missed_fade, .banner = noise.plan().missed_banner, .hold = noise.plan().missed_hold}, std::move(knobs)); + try{ + const Pokemon::SegmentReport report = run_rows_on(executor, logger, {.from = row, .to = row}, rows); + logger.log(std::format("[Sim] {}: {} wild battle(s) over {} grass and {} cave tiles.", describe(noise.plan()), + noise.battles(), noise.encounter_tiles().grass, noise.encounter_tiles().cave)); + return report.completed ? SeedOutcome{.passed = true} : failed_outcome(report, executor.result(), noise); + }catch (const GridSimFailure& e){ + return {.failed_step = row + " (thrown)", .kind = Pokemon::failure_kind("sim_failure", e.message), .detail = describe(noise.plan())}; + }catch (const Exception& e){ + return {.failed_step = row + " (thrown)", .kind = Pokemon::failure_kind(e.name(), e.message()), .detail = describe(noise.plan())}; + } +} + +RowReport run_row(const std::vector& rows, const std::string& row, size_t seeds, + const Pokemon::DisturbanceRates& rates = {} +){ + const RowNoise noise{.clean = looked_for(rows, row), .rates = rates}; + return Pokemon::run_row_seeds(row, Pokemon::story_seeds(seeds), [&](const std::string& id, uint64_t seed){ + SilentLogger logger; + return run_seed(logger, rows, noise, id, seed); + }); +} + + +// A row's seeds (run_row()), and each that passes with no miss run again +// with one fade's hold dropped (a short fade between two frames; the +// door's watcher missed 13 of 35 on lab-B, 2026-11-08): the program's fade +// watch takes the scene after the fall, so it must pass again. How many +// ran again, and those that then failed, as "plan: step kind". +struct HeldRowReport{ + RowReport report; + size_t rerun = 0; + std::vector hold_failed; +}; +HeldRowReport run_row_holding(const std::vector& rows, const std::string& row, size_t seeds){ + const RowNoise noise{.clean = looked_for(rows, row), .rates = {}}; + RowNoise hold_noise = noise; + hold_noise.rates.missed_hold = 1; + HeldRowReport out; + out.report = Pokemon::run_row_seeds(row, Pokemon::story_seeds(seeds), [&](const std::string& id, uint64_t seed){ + SilentLogger silent; + const SeedOutcome plain = run_seed(silent, rows, noise, id, seed); + const Pokemon::DisturbancePlan plan = Pokemon::make_disturbance_plan(seed, noise.rates, noise.clean.fades, noise.clean.banners); + if (plain.passed && noise.clean.fades > 0 && !plan.missed_fade && !plan.missed_banner){ + out.rerun++; + const SeedOutcome hold = run_seed(silent, rows, hold_noise, id, seed); + if (!hold.passed){ + out.hold_failed.push_back(std::format("{}: {} {}", hold.detail, hold.failed_step, hold.kind)); + } + } + return plain; + }); + return out; +} + + +// Row `row` for the seeds, under `floor` passes in a hundred a failure: +// each row's floor is what it passed at this branch's tip, so a row that +// passes less often has got worse. A row PA_BDSP_STORY_MC_ROWS leaves out +// is skipped. +UnitTestResult test_row(Logger& logger, const std::string& row, size_t floor){ + if (Pokemon::selected_rows(ROWS_VARIABLE, {row}).empty()){ + return {UnitTestResult::SKIPPED, std::string(ROWS_VARIABLE) + " leaves it out"}; + } + // One seed's run, logged step by step: how a failure the report + // names came about. + if (const size_t traced = Pokemon::seed_count(TRACE_VARIABLE, 0); traced > 0){ + const std::vector rows = story_checkpoints(); + const SeedOutcome out = run_seed(logger, rows, {.clean = looked_for(rows, row), .rates = {}}, row, traced); + logger.log(std::format("{} seed {}: {} {} {}", row, traced, out.passed ? "passed" : "failed", out.failed_step, out.kind)); + return true; + } + const size_t seeds = Pokemon::seed_count(SEEDS_VARIABLE, DEFAULT_SEEDS); + const WallClock start = current_time(); + const HeldRowReport held = run_row_holding(story_checkpoints(), row, seeds); + const RowReport& report = held.report; + const std::vector& hold_failed = held.hold_failed; + const auto took = std::chrono::duration_cast(current_time() - start); + logger.log(Pokemon::format_report(report) + std::format("\n ({} seeds in {} ms)", seeds, took.count())); + logger.log(std::format("{}: one fade's hold unseen: {} of {} seeds that passed with no miss fail.", row, hold_failed.size(), held.rerun)); + if (!hold_failed.empty()){ + std::string out = std::format("{} fails with one fade's hold unseen where it passed without:", row); + for (const std::string& line : hold_failed){ + out += "\n " + line; + } + return out; + } + // The floors are the default seeds' counts; other counts only report. + if (seeds == DEFAULT_SEEDS && report.passes * 100 < floor * report.runs){ + return std::format("{} passed {} of {}, under its floor of {}%:\n{}", row, report.passes, report.runs, + floor, Pokemon::format_report(report)); + } + return true; +} + + +// The chance a dialog pops up before a step, in the test that pops them, +// and its seeds a row: each runs three times, so fewer than a row's own. +constexpr double DIALOG_RATE = 0.1; +constexpr size_t DIALOG_SEEDS = 5; + +// How a row's seeds fare with dialogs popping up between steps: without +// them, with them cleared before each step, and with them left up (the +// executor before it looked). Seeds that pass without them and fail with +// them cleared, as "row plan: step kind". +struct DialogRowReport{ + size_t runs = 0; + size_t plain = 0; + size_t cleared = 0; + size_t left = 0; + std::vector regressions; +}; +void run_row_dialogs(DialogRowReport& out, const std::vector& rows, const std::string& row, size_t seeds){ + const RowNoise plain{.clean = looked_for(rows, row), .rates = {}}; + RowNoise popping = plain; + popping.rates.dialog_between_steps = DIALOG_RATE; + for (uint64_t seed : Pokemon::story_seeds(seeds)){ + SilentLogger silent; + const bool passes = run_seed(silent, rows, plain, row, seed).passed; + const SeedOutcome cleared = run_seed(silent, rows, popping, row, seed); + const bool left = run_seed(silent, rows, popping, row, seed, PoppedDialog::LEFT_UP).passed; + out.runs++; + out.plain += passes ? 1 : 0; + out.cleared += cleared.passed ? 1 : 0; + out.left += left ? 1 : 0; + if (passes && !cleared.passed){ + out.regressions.push_back(std::format("{} {}: {} {}", row, cleared.detail, cleared.failed_step, cleared.kind)); + } + } +} + +// Every row to 01.11, its seeds with dialogs popping up between steps +// (DIALOG_RATE a step): one that passes without them must pass with them. +UnitTestResult test_dialogs_between_steps(Logger& logger){ + const std::vector rows = story_checkpoints(); + const size_t seeds = Pokemon::seed_count(SEEDS_VARIABLE, DIALOG_SEEDS); + DialogRowReport report; + for (const StoryCheckpoint& row : rows){ + if (row.id > "01.11"){ + continue; + } + run_row_dialogs(report, rows, row.id, seeds); + } + logger.log(std::format( + "Dialogs between steps, {} runs: {} pass without them, {} with them cleared, {} with them left up.", + report.runs, report.plain, report.cleared, report.left + )); + if (report.regressions.empty()){ + return true; + } + std::string out = "Seeds that pass without dialogs between steps fail with them cleared:"; + for (const std::string& line : report.regressions){ + out += "\n " + line; + } + return out; +} + + +// 01.03's steps across Roark's room as they were before 4f13c19bb: +// counted taps onto Roark's row, then west against his rock. +std::vector old_steps_to_roark(){ + StoryStep taps; + taps.kind = Pokemon::StoryStepKind::LEGS; + taps.name = "above_roarks_row"; + taps.action = "legs"; + taps.args["legs"] = std::vector{ + {.direction = Direction::EAST, .tiles = 1}, {.direction = Direction::SOUTH, .tiles = 2}, + {.direction = Direction::WEST, .tiles = 1}, {.direction = Direction::SOUTH, .tiles = 5}, + {.direction = Direction::EAST, .tiles = 14}, {.direction = Direction::SOUTH, .tiles = 10}, + {.direction = Direction::WEST, .tiles = 2}, {.direction = Direction::SOUTH, .tiles = 2}, + }; + taps.pose_after = Pokemon::TileDeclared{.map = "OreburghMine", .tiles = {TilePos{27, 28}}, .facing = Direction::SOUTH}; + StoryStep walls; + walls.kind = Pokemon::StoryStepKind::LEGS; + walls.name = "beside_roarks_rock"; + walls.action = "to_wall"; + walls.args["legs"] = std::vector{{.direction = Direction::WEST, .tiles = 7}, {.direction = Direction::SOUTH, .tiles = 1}}; + walls.pose_after = Pokemon::TileDeclared{.map = "OreburghMine", .tiles = {TilePos{20, 29}}, .facing = Direction::SOUTH}; + return {taps, walls}; +} + +// 01.03 as it was before 4f13c19bb: counted taps across Roark's room. +std::vector old_0103(){ + const std::vector old = old_steps_to_roark(); + std::vector rows = story_checkpoints(); + for (StoryCheckpoint& row : rows){ + if (row.id != "01.03"){ + continue; + } + std::replace_if(row.steps.begin(), row.steps.end(), [](const StoryStep& step){ return step.name == "to_roarks_corner"; }, old[0]); + std::replace_if(row.steps.begin(), row.steps.end(), [](const StoryStep& step){ return step.name == "beside_roarks_rock"; }, old[1]); + } + return rows; +} + +// Whether `report` failed `step` in a way whose kind holds `text` and `also`. +bool failed_with(const RowReport& report, const std::string& step, const std::string& text, const std::string& also = ""){ + const auto found = report.failures.find(step); + return found != report.failures.end() && std::ranges::any_of(found->second, [&](const auto& kind){ + return kind.first.find(text) != std::string::npos && kind.first.find(also) != std::string::npos; + }); +} + +// lab-B 2026-11-08 11:55: a wild battle on the counted taps across +// Roark's room re-planned to an open leg and the row went one off. The +// old row must show it, at the stress rates: at lab-B's own, 200 seeds +// need not draw it. +UnitTestResult test_old_0103(Logger& logger){ + const size_t seeds = std::max(200, Pokemon::seed_count(SEEDS_VARIABLE, DEFAULT_SEEDS)); + const RowReport whole = run_row(old_0103(), "01.03", seeds, stress_rates()); + logger.log("The old 01.03: " + Pokemon::format_report(whole)); + // A battle on the taps, then the row ends off the tile the taps count. + if (!failed_with(whole, "01.03 above_roarks_row", "sim_mismatch", "[wild battle in the step]")){ + return "expected the old 01.03 to fail across Roark's room after a wild battle:\n" + Pokemon::format_report(whole); + } + return true; +} + + +// A disturbed hold with no disturbance walks as the grid sim's own hold +// does, at its pace: a hold timed a tile at the walker's 160 ms east +// moved no tile at the sim's 200 ms (fe2da03e7), and every hold east or +// west at a walk stood still (00.05 east_to_the_wall, 2026-11-12). +UnitTestResult test_disturbed_hold_as_plain(Logger& logger){ + const StoryWorld* world = story_plan_world("JubilifeCity", "JubilifeCity"); + if (world == nullptr){ + return "JubilifeCity world not found"; + } + struct Hold{ + Direction direction; + SimPace pace; + bool can_run; + }; + const Hold holds[] = { + {Direction::EAST, SimPace::WALK, false}, {Direction::WEST, SimPace::WALK, false}, + {Direction::NORTH, SimPace::WALK, false}, {Direction::EAST, SimPace::RUN, true}, + }; + Pokemon::DisturbanceRates still; + still.grass_encounter = 0; + still.cave_encounter = 0; + still.drift_per_tile = 0; + const TilePos start = story_to_world(*world, "JubilifeCity", {46, 54}); + for (const Hold& hold : holds){ + GridSim plain({.world = world}, start, hold.direction, hold.can_run); + const SimMove expected = plain.hold(hold.direction, 10000ms, hold.pace); + GridSim disturbed({.world = world}, start, hold.direction, hold.can_run); + SimDisturbance noise(Pokemon::make_disturbance_plan(1, still, 0, 0)); + const SimMove got = disturbed_hold(disturbed, &noise, hold.direction, 10000ms, hold.pace).move; + logger.log(std::format("{}: plain {} to {}, disturbed {} to {}.", direction_name(hold.direction), + expected.distance / SIM_TILE, to_string(plain.player().pos), got.distance / SIM_TILE, to_string(disturbed.player().pos))); + if (got.distance != expected.distance || got.stop != expected.stop || disturbed.player().pos != plain.player().pos){ + return std::format("{} held: the disturbed hold moved {} where the plain one moved {}.", + direction_name(hold.direction), got.distance / SIM_TILE, expected.distance / SIM_TILE); + } + } + return true; +} + + +// A row of the table, disturbed; or, with a body, another test. +struct StoryMonteCarloInput{ + std::string row; + std::function body = nullptr; +}; + +// The fewest passes in a hundred a row's seeds may have. +struct StoryMonteCarloExpectation{ + size_t floor = 0; +}; + +struct StoryMonteCarloCase{ + StoryMonteCarloInput input; + StoryMonteCarloExpectation expectation; +}; + +class Test_StoryMonteCarlo : public UnitTest{ +public: + explicit Test_StoryMonteCarlo(StoryMonteCarloCase test_case) + : UnitTest("PokemonBDSP::AutoStory - Story Monte Carlo: " + test_case.input.row) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_case.input.body ? m_case.input.body(logger) + : test_row(logger, m_case.input.row, m_case.expectation.floor); + }catch (const GridSimFailure& e){ + return "GridSimFailure: " + e.message; + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + StoryMonteCarloCase m_case; +}; + +} // namespace + + +const StoryMonteCarloCase AUTO_STORY_MONTE_CARLO_CASES[] = { + {.input = {"00.00"}, .expectation = {.floor = 100}}, + {.input = {"00.01"}, .expectation = {.floor = 95}}, + {.input = {"00.02"}, .expectation = {.floor = 100}}, + {.input = {"00.03"}, .expectation = {.floor = 95}}, + {.input = {"00.04"}, .expectation = {.floor = 95}}, + {.input = {"00.04b"}, .expectation = {.floor = 100}}, + {.input = {"00.04c"}, .expectation = {.floor = 100}}, + {.input = {"00.04d"}, .expectation = {.floor = 100}}, + {.input = {"00.05"}, .expectation = {.floor = 100}}, + {.input = {"00.05b"}, .expectation = {.floor = 85}}, + {.input = {"00.05c"}, .expectation = {.floor = 100}}, + {.input = {"01.01"}, .expectation = {.floor = 100}}, + {.input = {"01.02"}, .expectation = {.floor = 85}}, + {.input = {"01.02b"}, .expectation = {.floor = 90}}, + {.input = {"01.03"}, .expectation = {.floor = 75}}, + {.input = {"01.04"}, .expectation = {.floor = 100}}, + {.input = {"01.05"}, .expectation = {.floor = 100}}, + {.input = {"01.06"}, .expectation = {.floor = 95}}, + {.input = {"01.07"}, .expectation = {.floor = 100}}, + {.input = {"01.08"}, .expectation = {.floor = 40}}, + {.input = {"01.09"}, .expectation = {.floor = 100}}, + {.input = {"01.10"}, .expectation = {.floor = 80}}, + {.input = {"01.11"}, .expectation = {.floor = 100}}, + { + .input = {"a disturbed hold with no disturbance walks as the plain hold does", test_disturbed_hold_as_plain}, + .expectation = {}, + }, + { + .input = {"the old 01.03 fails across Roark's room after a wild battle (lab-B, 2026-11-08)", test_old_0103}, + .expectation = {}, + }, + { + .input = {"dialogs pop up between steps, 00.00 to 01.11", test_dialogs_between_steps}, + .expectation = {}, + }, +}; + +void add_tests_AutoStory_StoryMonteCarlo(UnitTestDatabase& database){ + for (const StoryMonteCarloCase& item : AUTO_STORY_MONTE_CARLO_CASES){ + database.add(item); + } +} + + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryMonteCarlo_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryMonteCarlo_Tests.h new file mode 100644 index 0000000000..9f75939200 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryMonteCarlo_Tests.h @@ -0,0 +1,29 @@ +/* BDSP AutoStory Story Monte Carlo Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryMonteCarlo_Tests_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryMonteCarlo_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + + +// Each row of the story table run on the story simulation for the pinned +// seeds, disturbed (wild battles, drift, wanderers, a missed detection): +// its pass rate and failing steps. PA_BDSP_STORY_MC_SEEDS sets the seed +// count (20 by default), PA_BDSP_STORY_MC_ROWS the rows ("01.03,01.04"). +void add_tests_AutoStory_StoryMonteCarlo(UnitTestDatabase& database); + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp index 7e63509263..aac87b9697 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp @@ -190,10 +190,10 @@ void SimStoryStepIO::walk_until_stopped(Direction direction, size_t tiles, const m_route.check_fade_in(label); m_sim.tap(direction, ROUTE_TURN_TAP, false); Milliseconds limit = ROUTE_START_DELAY + 800ms + route_ms_per_tile(direction) * (int64_t)(2 * tiles); - SimMove move = m_sim.hold(direction, limit, SimPace::WALK); + SimMove move = disturbed_hold(m_sim, m_noise, direction, limit, SimPace::WALK).move; if (move.stop == SimStop::WARP && next_fade() != FadeShown::SEEN && m_far_side()){ limit -= std::min(limit, move.time); - move = m_sim.hold(direction, limit, SimPace::WALK); + move = disturbed_hold(m_sim, m_noise, direction, limit, SimPace::WALK).move; } if (move.stop == SimStop::DIALOG || move.stop == SimStop::WARP){ m_route.note(label + ": " + std::string(sim_stop_name(move.stop)) + " instead of a stop.", RouteNote::FAILURE); @@ -281,12 +281,12 @@ void SimKnobRouteIO::check_fade_in(const std::string& label){ WalkResult SimKnobRouteIO::walk_to_wall(const RouteWallWalk& walk){ check_fade_in(walk.label); - return GridSimRouteIO::walk_to_wall(walk); + return DisturbedRouteIO::walk_to_wall(walk); } WalkResult SimKnobRouteIO::walk_taps(Direction direction, size_t tiles, const std::string& label){ check_fade_in(label); - const WalkResult result = GridSimRouteIO::walk_taps(direction, tiles, label); + const WalkResult result = DisturbedRouteIO::walk_taps(direction, tiles, label); if (result.stop != WalkStop::LIMIT || m_slid_steps.contains(m_step)){ return result; } @@ -417,7 +417,7 @@ SimWorld SimExecutor::setup(const StoryWorld* world) const{ } out.triggers.push_back(std::move(trigger)); } - out.wanderers = wanderers(*world); + out.wanderers = m_noise != nullptr ? m_noise->wanderers(*world) : wanderers(*world); return out; } @@ -483,8 +483,8 @@ void SimExecutor::arm(const std::string& after){ m_armed.insert(m_armed.end(), now.begin(), now.end()); const size_t armed = now.size(); const SimPlayer& player = m_sim.player(); - if (armed > 0 && m_placed && on_grid(player.pos) && !player.dialog){ - m_sim.place(setup(&m_sim.world()), nearest_tile(player.pos), player.facing); + if (armed > 0 && m_placed && settled() && !player.dialog){ + place(&m_sim.world(), nearest_tile(player.pos), player.facing); } } @@ -504,10 +504,10 @@ bool SimExecutor::sync(const Pose& pose, const StoryWorld* on){ const SimPlayer& player = m_sim.player(); const std::optional local = !m_placed || &m_sim.world() != world ? std::nullopt : story_to_local(*world, pose.map, nearest_tile(player.pos)); - if (local && on_grid(player.pos) && std::find(tiles.begin(), tiles.end(), *local) != tiles.end()){ + if (local && settled() && std::find(tiles.begin(), tiles.end(), *local) != tiles.end()){ return true; } - m_sim.place(setup(world), story_to_world(*world, pose.map, tiles.front()), Pokemon::facing_of(pose)); + place(world, story_to_world(*world, pose.map, tiles.front()), Pokemon::facing_of(pose)); m_placed = true; return true; } @@ -569,7 +569,7 @@ bool SimExecutor::cross_to(const Pose& far){ if (world == nullptr || tiles.empty()){ return false; } - m_sim.place(setup(world), story_to_world(*world, far.map, tiles.front()), std::nullopt); + place(world, story_to_world(*world, far.map, tiles.front()), std::nullopt); return true; } @@ -587,7 +587,7 @@ std::string SimExecutor::off_pose(const Pose& pose) const{ // story_to_world() throws for a map not on the player's world. try{ const auto there = [&](const TilePos& tile){ return story_to_world(m_sim.world(), pose.map, tile) == at; }; - if (on_grid(player.pos) && std::ranges::any_of(tiles, there)){ + if (settled() && std::ranges::any_of(tiles, there)){ return ""; } }catch (const InternalProgramError&){} @@ -770,6 +770,32 @@ Outcome SimExecutor::run_step(const StoryStep& step, RunState& state){ return Pokemon::TableExecutor::run(step, state); } +// Puts the player on `start` of `world`: on the grid, no drift. +void SimExecutor::place(const StoryWorld* world, const TilePos& start, std::optional facing){ + m_sim.place(setup(world), start, facing); + if (m_noise != nullptr){ + m_noise->reset(); + } +} + +// Whether the player stands on their tile: on the grid, or, disturbed, +// anywhere nearer it than another (how far off is the run's to find out). +bool SimExecutor::settled() const{ + return m_noise != nullptr || on_grid(m_sim.player().pos); +} + +void SimExecutor::record_failure(const Outcome& outcome, const StoryStep& step, size_t battles_before){ + // The walker's last notes, to see why. + for (size_t i = m_notes.size() - std::min(m_notes.size(), 40); i < m_notes.size(); i++){ + m_logger.log(std::format("[{}] note: {}", m_row, m_notes[i])); + } + m_result.error = m_row + " " + Pokemon::to_string(outcome); + m_result.failed_step = m_row + " " + step.name; + m_result.failure = outcome.failure; + m_result.failure_detail = outcome.detail; + m_result.failed_step_battles = m_noise == nullptr ? 0 : m_noise->battles() - battles_before; +} + void SimExecutor::show_before(const StoryStep& step){ if (m_knobs.dialog_before && m_knobs.dialog_before(m_row, step.name)){ m_dialog_up = m_dialog_rose = true; @@ -785,8 +811,9 @@ Outcome SimExecutor::run(const StoryStep& step, RunState& state){ Outcome outcome; m_passed_over = false; m_step = step.name; - sim_forget_warp(m_sim); + detail::sim_forget_warp(m_sim); show_before(step); + const size_t battles_before = m_noise == nullptr ? 0 : m_noise->battles(); try{ outcome = run_step(step, state); }catch (const GridSimFailure& e){ @@ -813,13 +840,9 @@ Outcome SimExecutor::run(const StoryStep& step, RunState& state){ m_result.missed_step = m_row + " " + step.name; } if (!outcome.succeeded() && m_result.error.empty()){ - // The walker's last notes, to see why. - for (size_t i = m_notes.size() - std::min(m_notes.size(), 40); i < m_notes.size(); i++){ - m_logger.log(std::format("[{}] note: {}", m_row, m_notes[i])); - } - m_result.error = m_row + " " + Pokemon::to_string(outcome); - m_result.failed_step = m_row + " " + step.name; + record_failure(outcome, step, battles_before); } + m_result.battles = m_noise == nullptr ? 0 : m_noise->battles(); const std::vector& fought = m_sim.player().scenes_fought; for (; m_scenes_fought < fought.size(); m_scenes_fought++){ m_logger.log(std::format("[{}] {}: the walk fought {}'s dialogue as a trainer's.", m_row, step.name, fought[m_scenes_fought])); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h index d467e53da6..f2e98b9818 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h @@ -7,6 +7,9 @@ * (StoryWalkSteps) on the grid simulation; see StorySim_Tests.cpp for * what is simulated and what is stubbed. Moved out of the tests so the * console failure cases (SimFailureCases_Tests) run on the same executor. + * With a SimDisturbance the run is disturbed as the console disturbs it + * (wild battles, drift off the grid, people wandering): the story's Monte + * Carlo tests. * // code-health: allow header_symbols -- story simulation executor, scenario runners and mock IO */ @@ -40,6 +43,7 @@ #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkScreen.h" #include "PokemonBDSP_AutoStory_GridSim.h" +#include "PokemonBDSP_AutoStory_SimDisturbance.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -171,6 +175,10 @@ struct SimWorldKnobs{ // Whether the executor clears what came up between steps // (story_interrupts()), as the console does; off, as before it did. bool clear_interrupts = true; + // A seed's disturbances (wild battles, drift off the grid, people + // wandering), which must outlive the run: the story's Monte Carlo tests. + // Within half a tile of where a step should end counts as there. + SimDisturbance* noise = nullptr; // Where a step really leaves the player, by step name, when that is // not the table's pose_after or the walk's end: the program goes on // from the table's pose, the player from here (00.03's scene a row @@ -193,15 +201,15 @@ struct SimWorldKnobs{ namespace detail{ // The walker's RouteIO on the story simulation, with SimWorldKnobs' slides -// and late first lines. `step` names the step running now; `cross` puts -// the player on a pose past a warp. -class SimKnobRouteIO : public GridSimRouteIO{ +// and late first lines, disturbed by SimWorldKnobs::noise if set. `step` +// names the step running now; `cross` puts the player on a pose past a warp. +class SimKnobRouteIO : public DisturbedRouteIO{ public: SimKnobRouteIO( GridSim& sim, std::vector& notes, SimMisses& misses, const SimWorldKnobs& knobs, const std::string& step, std::function cross ) - : GridSimRouteIO(sim, notes, {}, {}, knobs.grass) + : DisturbedRouteIO(sim, notes, knobs.noise, knobs.grass) , m_grid(sim) , m_misses(misses) , m_knobs(knobs) @@ -286,6 +294,12 @@ struct SimRun{ // Where the player stood after the last step, if placed. const StoryWorld* world = nullptr; Pokemon::TilePos end; + // Wild battles in the run, and in the step it failed in. + size_t battles = 0; + size_t failed_step_battles = 0; + // How the run failed: the failure and its message. + std::string failure; + std::string failure_detail; // Scenes a walk took for a trainer's and pressed through, as // "row step: scene" (the console's unknown-trainer handler, lab-B // 2026-11-09 17:29: Mom's call, then her scene's fade missed). @@ -303,6 +317,7 @@ class SimStoryStepIO : public StoryStepIO{ const std::string& step, std::function far_side, std::function cross ) : m_sim(sim) + , m_noise(knobs.noise) , m_route(sim, notes, misses, knobs, step, std::move(cross)) , m_misses(misses) , m_knobs(knobs) @@ -328,10 +343,10 @@ class SimStoryStepIO : public StoryStepIO{ m_route.check_fade_in(std::format("{}: run into the door", m_step)); const SimPace pace = run ? SimPace::RUN : SimPace::WALK; if (false_dark() && dark_from <= detail::SIM_FALSE_DARK && detail::SIM_FALSE_DARK < timeout){ - m_sim.hold(direction, detail::SIM_FALSE_DARK, pace); + disturbed_hold(m_sim, m_noise, direction, detail::SIM_FALSE_DARK, pace); return {.fade = WarpFade::BLACK}; } - if (m_sim.hold(direction, timeout, pace).stop != SimStop::WARP){ + if (disturbed_hold(m_sim, m_noise, direction, timeout, pace).move.stop != SimStop::WARP){ return {}; } const WarpSeen seen = door_fade(banner); @@ -381,6 +396,7 @@ class SimStoryStepIO : public StoryStepIO{ double floor_here() const; GridSim& m_sim; + SimDisturbance* m_noise; detail::SimKnobRouteIO m_route; SimMisses& m_misses; const SimWorldKnobs& m_knobs; @@ -429,6 +445,7 @@ class SimExecutor : public Pokemon::TableExecutor{ , m_logger(logger) , m_misses(misses) , m_knobs(std::move(knobs)) + , m_noise(m_knobs.noise) , m_sim({}, {0, 0}, Pokemon::Direction::NORTH, false) , m_io(m_sim, m_notes, m_misses, m_knobs, m_step, [this]{ return cross(); }, [this](const Pokemon::Pose& far){ cross_to(far); }) , m_walks(m_io) @@ -515,11 +532,15 @@ class SimExecutor : public Pokemon::TableExecutor{ std::string off_pose(const Pokemon::Pose& pose) const; std::string check(const Pokemon::StoryStep& step, const Pokemon::Outcome& outcome); Pokemon::Outcome run_step(const Pokemon::StoryStep& step, Pokemon::RunState& state); + void place(const StoryWorld* world, const Pokemon::TilePos& start, std::optional facing); + bool settled() const; + void record_failure(const Pokemon::Outcome& outcome, const Pokemon::StoryStep& step, size_t battles_before); Logger& m_logger; std::vector m_notes; SimMisses m_misses; SimWorldKnobs m_knobs; + SimDisturbance* m_noise; // The step running now. std::string m_step; GridSim m_sim; diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 51fb711c83..5fb0a3fe81 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1620,6 +1620,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_StoryLog.h Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.h + Source/Pokemon/AutoStory/Pokemon_StoryMonteCarlo.cpp + Source/Pokemon/AutoStory/Pokemon_StoryMonteCarlo.h Source/Pokemon/AutoStory/Pokemon_StoryOutcome.h Source/Pokemon/AutoStory/Pokemon_StoryPose.h Source/Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.cpp @@ -1841,11 +1843,15 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_LegTrace_Tests.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_OldStorySteps.cpp Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_OldStorySteps.h + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimDisturbance.cpp + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimDisturbance.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimTriggers.cpp Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.h + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryMonteCarlo_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryMonteCarlo_Tests.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim_Tests.cpp