From c46992540e9dfc7f0999abb629d470f4fcb18144 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 17:00:24 -0800 Subject: [PATCH] AutoStory: pose certainty per step, a seeded Monte Carlo runner, badge checks Shared story types the BDSP rebuild chain uses, as bdsp/rebuild-base carries them: StoryCertainty (95a273e1e: what pose certainty an action needs and leaves, with the optional per-action override on StoryActionSpec), StoryMonteCarlo (e42f03c3c: disturbed story runs over pinned seeds) and BadgeCheck (ea8483a07: the game-agnostic badge check type). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/Pokemon_StoryCertainty.cpp | 86 ++++++++ .../AutoStory/Pokemon_StoryCertainty.h | 46 ++++ .../AutoStory/Pokemon_StoryMonteCarlo.cpp | 174 ++++++++++++++++ .../AutoStory/Pokemon_StoryMonteCarlo.h | 196 ++++++++++++++++++ .../AutoStory/Types/Pokemon_BadgeCheck.cpp | 37 ++++ .../AutoStory/Types/Pokemon_BadgeCheck.h | 47 +++++ .../AutoStory/Types/Pokemon_StoryActionSpec.h | 18 ++ SerialPrograms/cmake/SourceFiles.cmake | 6 + 8 files changed, 610 insertions(+) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryMonteCarlo.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryMonteCarlo.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp new file mode 100644 index 0000000000..f962515c48 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp @@ -0,0 +1,86 @@ +/* Story Certainty + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Pokemon_BuiltinStoryActions.h" +#include "Pokemon_StoryStepExecutor.h" +#include "Pokemon_StoryCertainty.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +namespace{ + +StoryCertainty kind_certainty(StoryStepKind kind){ + switch (kind){ + case StoryStepKind::ROUTE: + return {PoseCertainty::TILE, PoseEnd::WALKED}; + case StoryStepKind::LEGS: + return {PoseCertainty::SET, PoseEnd::KEEPS}; + case StoryStepKind::STEP: + case StoryStepKind::HEAL: + return {PoseCertainty::TILE, PoseEnd::DECLARED}; + case StoryStepKind::TALK: + return {PoseCertainty::TILE, PoseEnd::KEEPS}; + case StoryStepKind::NEW_GAME: + return {PoseCertainty::UNKNOWN, PoseEnd::DECLARED}; + default: + return {PoseCertainty::UNKNOWN, PoseEnd::KEEPS}; + } +} + +} // namespace + + +StoryCertainty story_step_certainty(const StoryStep& step, std::span specs){ + StoryCertainty out = kind_certainty(step.kind); + if (const StoryActionSpec* spec = find_story_action(specs, step.kind, step.action)){ + out.needs = spec->certainty.value_or(out).needs; + out.leaves = spec->certainty.value_or(out).leaves; + } + return out; +} + +PoseCertainty certainty_after(const StoryStep& step, PoseEnd leaves, PoseCertainty before){ + switch (leaves){ + case PoseEnd::WALKED: + return PoseCertainty::TILE; + case PoseEnd::DECLARED: + return step.pose_after ? pose_of(*step.pose_after).certainty : before; + case PoseEnd::GAME_SET: + return step.pose_after ? PoseCertainty::SET : before; + case PoseEnd::KEEPS: + // A declared end the step does not walk onto is where the game + // leaves us, unseen. + return step.pose_after ? PoseCertainty::SET : before; + } + return before; +} + +PoseCertainty start_certainty(const StoryCheckpoint& data){ + return data.start ? PoseCertainty::SET : PoseCertainty::UNKNOWN; +} + +std::vector certainty_gaps(const StoryCheckpoint& data, std::span specs){ + std::vector gaps; + PoseCertainty have = start_certainty(data); + for (size_t c = 0; c < data.steps.size(); c++){ + const StoryStep& step = data.steps[c]; + const StoryCertainty certainty = story_step_certainty(step, specs); + if (!certainty_covers(have, certainty.needs)){ + gaps.push_back(std::format("{} step {} {}: needs {}, has {}", + data.id, c + 1, step.name, certainty_name(certainty.needs), certainty_name(have))); + } + have = certainty_after(step, certainty.leaves, have); + } + return gaps; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h new file mode 100644 index 0000000000..e1941b3db6 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h @@ -0,0 +1,46 @@ +/* Story Certainty + * + * From: https://github.com/PokemonAutomation/ + * + * How sure of the player's tile each step must be when it starts, and how + * sure it leaves the run. A step that needs more than the steps before it + * guarantee walks from a guess: 00.05's route planned open legs from its + * save's declared start, a tile the save was never seen on, and walked + * into a building (lab-B 2026-11-11 15:22). + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryCertainty_H +#define PokemonAutomation_Pokemon_StoryCertainty_H + +#include +#include +#include +#include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// What a step needs at its start and leaves at its end: the action's spec +// where it says, else its kind's default (a route needs one tile and +// leaves one; a scene needs nothing and leaves its declared end unseen). +StoryCertainty story_step_certainty(const StoryStep& step, std::span specs); + +// How sure the run is after `step` succeeds from `before`. +PoseCertainty certainty_after(const StoryStep& step, PoseEnd leaves, PoseCertainty before); + +// How sure a checkpoint is at its start: SET from its save (its declared +// start was never seen on the screen), UNKNOWN without one. +PoseCertainty start_certainty(const StoryCheckpoint& data); + +// Each step of `data` that needs a surer pose than the steps before it +// leave, as "00.05 step 1 to_the_center: needs TILE, has SET". +std::vector certainty_gaps(const StoryCheckpoint& data, std::span specs); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif 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/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.cpp new file mode 100644 index 0000000000..027f91a463 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.cpp @@ -0,0 +1,37 @@ +/* Badge Check + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Pokemon_BadgeCheck.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +bool badge_check_wanted(StoryCheckLevel level){ + return level == StoryCheckLevel::TESTING || level == StoryCheckLevel::THOROUGH; +} + +std::string badge_check_failure(BadgeReading reading, std::string_view badge){ + if (reading == BadgeReading::PRESENT){ + return ""; + } + if (reading == BadgeReading::UNREADABLE){ + return std::format( + "The Trainer Card could not be read, so the {} is not confirmed (the card's screenshot is kept).", + badge + ); + } + return std::format( + "The Trainer Card has no {}: the battle that ended the step was not the gym leader's.", + badge + ); +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.h new file mode 100644 index 0000000000..b2f4c76dcf --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.h @@ -0,0 +1,47 @@ +/* Badge Check + * + * From: https://github.com/PokemonAutomation/ + * + * After a gym leader's battle, a thorough run opens the Trainer Card and + * checks the badge is on it: a battle can end with a win that was not the + * leader's (BDSP 01.04, lab-B 2026-11-12: the second gym trainer was taken + * for Roark and 01.05 saved with no badge). Each game reads its own card + * and says what it saw; the verdict and the wording are shared. + * + */ + +#ifndef PokemonAutomation_Pokemon_BadgeCheck_H +#define PokemonAutomation_Pokemon_BadgeCheck_H + +#include +#include +#include "Pokemon_StoryCheckLevel.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// What a game's Trainer Card reader saw for one badge. +enum class BadgeReading{ + PRESENT, + MISSING, + // The reader has no reference for the card yet, or the card was not on + // screen. A badge not seen is not a badge confirmed: this fails too. + UNREADABLE, +}; + +// Whether a run at `level` opens the Trainer Card after a leader's battle: +// the levels that check everything for the user. +bool badge_check_wanted(StoryCheckLevel level); + +// The failure text when the badge is missing or the card was not read, "" +// when the badge was seen. The check runs only at the levels that check +// everything (badge_check_wanted()), and there an unreadable card must not +// pass as a badge confirmed; the caller keeps the card's screenshot. +std::string badge_check_failure(BadgeReading reading, std::string_view badge); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h index f9deb09ebb..cef4e27ef5 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h @@ -15,6 +15,7 @@ #include #include "Pokemon_StoryActionArg.h" #include "Pokemon_StoryStepKind.h" +#include "Pokemon/AutoStory/Pokemon_StoryPose.h" namespace PokemonAutomation{ namespace Pokemon{ @@ -31,6 +32,21 @@ struct StoryArgSpec{ std::string why; }; +// What an action leaves the pose as. +enum class PoseEnd{ + KEEPS, // as sure as before (a talk; taps counted from where we were) + WALKED, // walked onto its target and checked there: one tile + DECLARED, // its declared end, reached on walls or through a door + GAME_SET, // where a scene or battle leaves us: declared, not seen +}; + +// How sure of the player's tile an action must be at its start, and what +// it leaves (Pokemon_StoryCertainty.h). +struct StoryCertainty{ + PoseCertainty needs = PoseCertainty::UNKNOWN; + PoseEnd leaves = PoseEnd::KEEPS; +}; + // An action: the kind of step it does, its name and the args it takes. struct StoryActionSpec{ StoryStepKind kind = StoryStepKind::GAME; @@ -40,6 +56,8 @@ struct StoryActionSpec{ // keyboard, a battle AI): the engine refuses it on any other backend // (StoryBackendKind) with the failure "console_only". bool console_only = false; + // None: its kind's default (story_step_certainty()). + std::optional certainty = std::nullopt; }; // Each way `args` don't fit `spec`: a key it doesn't name, a value of diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index bc315ba159..0839bd8453 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1593,6 +1593,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_StoryActions_Tests.cpp Source/Pokemon/AutoStory/Pokemon_StoryActions_Tests.h Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.h + Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp + Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h Source/Pokemon/AutoStory/Pokemon_StoryEvent.h Source/Pokemon/AutoStory/Pokemon_StoryEvents.cpp Source/Pokemon/AutoStory/Pokemon_StoryEvents.h @@ -1606,6 +1608,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 @@ -1635,6 +1639,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Types/Pokemon_StoryActionArg_Tests.h Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.cpp Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h + Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.cpp + Source/Pokemon/AutoStory/Types/Pokemon_BadgeCheck.h Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.cpp Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h