Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ce5baf4
Merge commit 'b84099b26' into frlg/stage16b-silph
dayfine Nov 13, 2026
18a37e0
FRLG AutoStory: Silph Co. 5F to Giovanni, Lapras gift, Master Ball, b…
dayfine Nov 13, 2026
1836dd3
AutoStory: shared RNG handoff contract
dayfine Nov 13, 2026
00624b4
AutoStory RNG handoff: a program's end can be the user's turn
dayfine Nov 13, 2026
36644ec
Merge autostory/rng-handoff into frlg/stage16b-silph
dayfine Nov 13, 2026
8169680
FRLG AutoStory: Starter RNG and Gift RNG run through the shared RNG h…
dayfine Nov 13, 2026
eed3b65
AutoStory RNG handoff: options struct for the mode, test table
dayfine Nov 13, 2026
231142e
Merge remote-tracking branch 'origin/autostory/rng-handoff' into frlg…
dayfine Nov 13, 2026
c975585
FRLG AutoStory RNG handoff: one rng_handoff_result(), gift run keeps …
dayfine Nov 13, 2026
991987f
Merge branch 'frlg/gates' into frlg/stage16b-silph
dayfine Nov 13, 2026
d0b14c1
FRLG Silph tests: read the Card Key from the sim's state
dayfine Nov 13, 2026
1a7e1f4
FRLG gates merge: keep stage16b's card_key_held() accessor on the sim
dayfine Nov 13, 2026
c4acda6
Merge autostory/rng-handoff (#445) into autostory/engine
dayfine Nov 13, 2026
ad5016d
Merge frlg/gates into frlg/stage16b-silph (real maps, pin 4b886bb)
dayfine Nov 13, 2026
730044f
FRLG: drop the synthetic Silph GateMaps (real pinned maps carry the d…
dayfine Nov 13, 2026
6261723
FRLG: code-health fixes (approach list lines, namespace closes)
dayfine Nov 13, 2026
8cac3e6
Merge remote-tracking branch 'origin/frlg/gates' into frlg/stage16b-s…
dayfine Nov 13, 2026
f38edb8
FRLG: the walk tests' maps carry the run's flags (silph_cleared); 16.…
dayfine Nov 13, 2026
f8177cf
FRLG: 16.06's golden plan walks the maps without Giovanni's Rockets
dayfine Nov 13, 2026
e858326
Merge frlg/gates into frlg/stage16b-silph
dayfine Nov 13, 2026
2faecd4
Merge frlg/gates (14.02 split) into frlg/stage16b-silph
dayfine Nov 13, 2026
4708d97
Merge frlg/gates (14.04 split) into frlg/stage16b-silph
dayfine Nov 13, 2026
5b39bf0
FRLG AutoStory: the chain test expects 71 checkpoints (the split's me…
dayfine Nov 13, 2026
6f9ec5f
FRLG 16.03: the rival alone; the walk to the employee is 16.03b
dayfine Nov 13, 2026
5c846aa
Merge remote-tracking branch 'origin/frlg/gates' into HEAD
dayfine Nov 13, 2026
e823cba
Merge frlg/gates into frlg/stage16b-silph
dayfine Nov 13, 2026
2eee644
Merge origin/frlg/gates into frlg/stage16b-silph
dayfine Nov 13, 2026
2569cc5
Merge branch 'nav/grid-nav' into autostory/engine (#360)
dayfine Nov 13, 2026
45a46f7
AutoStory RNG handoff: red test: a stop reports its message and lines
dayfine Nov 13, 2026
0877430
AutoStory RNG handoff: report_rng_handoff_stop, the stop's log, overl…
dayfine Nov 13, 2026
8b81149
Merge commit '0877430cf' into frlg/rng-handoff-work
dayfine Nov 13, 2026
c98d66c
FRLG AutoStory: the handoff stop reports through the shared report; o…
dayfine Nov 13, 2026
b05eec5
Merge branch 'frlg/gates' into frlg/stage16b-silph
dayfine Nov 13, 2026
784a043
Merge frlg/gates into frlg/stage16b-silph: upstream #1881 free party …
dayfine Nov 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "Pokemon_StoryInterrupts_Tests.h"
#include "Pokemon_StoryLog_Tests.h"
#include "Pokemon_StoryRun_Tests.h"
#include "Pokemon_StoryRngHandoff_Tests.h"
#include "Pokemon_StorySavePolicy_Tests.h"
#include "Pokemon_StorySegments_Tests.h"
#include "Pokemon_StoryStepExecutor_Tests.h"
Expand All @@ -44,6 +45,7 @@ inline void add_tests_AutoStory(UnitTestDatabase& database){
add_tests_StoryRun(database);
add_tests_AutoStoryStats(database);
add_tests_StoryLog(database);
add_tests_StoryRngHandoff(database);
add_tests_StoryRangeOptions(database);
add_tests_StoryEvents(database);
add_tests_StorySegments(database);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* Story RNG Handoff
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "Common/Cpp/Color.h"
#include "Common/Cpp/Exceptions.h"
#include "CommonFramework/Exceptions/OperationFailedException.h"
#include "Pokemon_StoryRngHandoff.h"

namespace PokemonAutomation{
namespace Pokemon{


RngHandoffMode rng_handoff_mode(const RngHandoffOptions& options){
if (options.run){
return RngHandoffMode::RUN;
}
return options.stop ? RngHandoffMode::STOP : RngHandoffMode::OFF;
}

bool RngHandoffResult::succeeded() const{
return failure.empty();
}

std::optional<std::string> run_rng_handoff_or_user_turn(
Logger& logger, const std::string& program, const RngHandoffCall& call
){
const RngHandoffResult result = call();
if (!result.succeeded()){
throw_and_log<OperationFailedException>(logger, ErrorReportMode::SEND_ERROR_REPORT, result.failure);
}
if (!result.user_turn.empty()){
logger.log(program + " stopped for the user: " + result.user_turn, COLOR_BLUE);

Check warning on line 35 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")

Check warning on line 35 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")
return result.user_turn;
}
logger.log(program + " succeeded: " + result.summary, COLOR_BLUE);

Check warning on line 38 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")

Check warning on line 38 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")
return std::nullopt;
}

Outcome run_rng_handoff(Logger& logger, const std::string& program, const RngHandoffCall& call){
const std::optional<std::string> user_turn = run_rng_handoff_or_user_turn(logger, program, call);
if (user_turn){
// A story action has no stop to give the user's turn to.
throw_and_log<OperationFailedException>(logger, ErrorReportMode::SEND_ERROR_REPORT, *user_turn);
}
return outcome_ok();
}

std::string report_rng_handoff_stop(
Logger& logger, const std::string& message, const std::vector<std::string>& lines,
const std::function<void(const std::string&)>& show
){
std::string text = message;
logger.log(message, COLOR_BLUE);
show(message);
for (const std::string& line : lines){
logger.log(line, COLOR_BLUE);
show(line);
text += "\n" + line;

Check warning on line 61 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")

Check warning on line 61 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")
}
return text;
}


} // namespace Pokemon
} // namespace PokemonAutomation
96 changes: 96 additions & 0 deletions SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* Story RNG Handoff

Check warning on line 1 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<header>: header_symbols=8 (advisory above 6, limit 8)

Check warning on line 1 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<header>: header_symbols=8 (advisory above 6, limit 8)
*
* From: https://github.com/PokemonAutomation/
*
* The part of an AutoStory run that hands the game to an RNG program (BDSP
* Starter RNG, FRLG Starter RNG and Gift RNG) and takes it back. A game
* supplies the program's call; the contract around it is shared:
*
* - A handoff row has a mode: OFF (the story plays it by hand), STOP (the run
* ends after the row's handoff save, for the user to run the RNG program)
* or RUN (the story calls the RNG program itself and continues).
* - The call ends in an RngHandoffResult: no failure means the game stands
* where the story goes on; a failure is the reason it does not. A game
* whose program can also end where the user takes over (FRLG: the target
* hit but not shiny, the attempts spent) gives that end a user_turn, which
* is a stop and not an error. What the story runs after a continuation
* (FRLG: the rows after a shiny) is the game's, built from the call.
* - A failed RUN stops the program. It never retries the row: the program's
* own reset loop is the retry, and a reload of the save would lose a
* shiny it caught.
*
*/

#ifndef PokemonAutomation_Pokemon_StoryRngHandoff_H
#define PokemonAutomation_Pokemon_StoryRngHandoff_H

#include <functional>
#include <optional>
#include <string>
#include <vector>
#include "Common/Cpp/Logging/AbstractLogger.h"
#include "Pokemon_StoryOutcome.h"

namespace PokemonAutomation{
namespace Pokemon{


// What a handoff row does with its RNG program.
enum class RngHandoffMode{
OFF,
STOP,
RUN,
};

// A handoff's two options.
struct RngHandoffOptions{
bool stop = false;
bool run = false;
};

// The mode for a handoff's two options: RUN takes precedence over STOP.
RngHandoffMode rng_handoff_mode(const RngHandoffOptions& options);


// How an RNG program's call ended, as the story needs it.
struct RngHandoffResult{
// Empty: the game stands where the story goes on. Otherwise why it does not.
std::string failure;
// What a success did, for the log: the resets used, the target hit.
std::string summary;
// Not empty (and no failure): the program ended where the user takes
// over, with this for them. The run stops without an error report.
std::string user_turn;

bool succeeded() const;
};

// The call a handoff row runs in place of its steps.
using RngHandoffCall = std::function<RngHandoffResult()>;

// Runs `call` for the RNG program `program` ("Starter RNG"). A success is
// logged with its summary and returned as an ok Outcome. A failure throws
// OperationFailedException with an error report, so that no row retry
// reruns the program's reset loop.
Outcome run_rng_handoff(Logger& logger, const std::string& program, const RngHandoffCall& call);

// As run_rng_handoff(), for a program whose call may end in the user's turn:
// returns that message, which is logged, and the run stops there. Returns
// nothing when the game stands where the story goes on.
std::optional<std::string> run_rng_handoff_or_user_turn(
Logger& logger, const std::string& program, const RngHandoffCall& call
);

// A run that stops for the user to run an RNG program, as the game's program
// reports it: `message` (what to do) and then `lines` (the RNG plan's
// attempts), each logged and passed to `show` (the overlay's log). Returns
// the whole text, one line each, for the program's finish notification.
std::string report_rng_handoff_stop(
Logger& logger, const std::string& message, const std::vector<std::string>& lines,
const std::function<void(const std::string&)>& show
);


} // namespace Pokemon
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/* Story RNG Handoff Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <format>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include "Common/Cpp/TestRunners/UnitTest.h"
#include "CommonFramework/Exceptions/OperationFailedException.h"
#include "Pokemon_StoryRngHandoff.h"
#include "Pokemon_StoryRngHandoff_Tests.h"

namespace PokemonAutomation{
namespace Pokemon{

namespace{

struct RngHandoffInput{
std::string_view name;
UnitTestResult (*body)(Logger& logger);
};

struct RngHandoffExpectation{
std::string_view description;
};

struct RngHandoffTestCase{
RngHandoffInput input;
RngHandoffExpectation expectation;
};

class Test_RngHandoff : public UnitTest{
public:
explicit Test_RngHandoff(RngHandoffTestCase scenario)
: UnitTest("Pokemon::StoryRngHandoff - " + std::string(scenario.input.name))

Check warning on line 39 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")

Check warning on line 39 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")
, m_scenario(scenario)
{}

virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{
return m_scenario.input.body(logger);
}

private:
RngHandoffTestCase m_scenario;
};

// rng_handoff_mode()'s two options.
UnitTestResult test_mode(Logger&){
struct Case{
RngHandoffOptions options;
RngHandoffMode expected;
};
const Case cases[] = {
{.options = {.stop = false, .run = false}, .expected = RngHandoffMode::OFF},
{.options = {.stop = true, .run = false}, .expected = RngHandoffMode::STOP},
{.options = {.stop = false, .run = true}, .expected = RngHandoffMode::RUN},
{.options = {.stop = true, .run = true}, .expected = RngHandoffMode::RUN},
};
for (const Case& item : cases){
if (rng_handoff_mode(item.options) != item.expected){
return std::format("stop={}, run={}: wrong mode", item.options.stop, item.options.run);
}
}
return true;
}

// A success is an ok Outcome and calls the program once.
UnitTestResult test_success(Logger& logger){
int calls = 0;
const Outcome outcome = run_rng_handoff(logger, "Test RNG", [&]{
calls++;
return RngHandoffResult{.summary = "2 resets"};
});
if (!outcome.succeeded()){
return "Expected an ok outcome";
}
if (calls != 1){
return std::format("Expected 1 call, got {}", calls);
}
return true;
}

// A failure throws, once: nothing reruns the program.
UnitTestResult test_failure(Logger& logger){
int calls = 0;
try{
run_rng_handoff(logger, "Test RNG", [&]{
calls++;
return RngHandoffResult{.failure = "out of resets"};
});
}catch (OperationFailedException&){
if (calls != 1){
return std::format("Expected 1 call, got {}", calls);
}
return true;
}
return "Expected OperationFailedException";
}

// The user's turn is returned, not thrown, once; a success has none; a
// failure throws even with one.
UnitTestResult test_user_turn(Logger& logger){

Check warning on line 106 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::Pokemon::test_user_turn( Logger & logger): function_lines=27 (advisory above 25, limit 50)

Check warning on line 106 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::Pokemon::test_user_turn( Logger & logger): function_lines=27 (advisory above 25, limit 50)
int calls = 0;
const std::optional<std::string> turn = run_rng_handoff_or_user_turn(logger, "Test RNG", [&]{
calls++;
return RngHandoffResult{.user_turn = "save by hand"};
});
if (!turn || *turn != "save by hand"){
return "Expected the user's turn";
}
if (calls != 1){
return std::format("Expected 1 call, got {}", calls);
}
const std::optional<std::string> none = run_rng_handoff_or_user_turn(logger, "Test RNG", []{
return RngHandoffResult{.summary = "shiny"};
});
if (none){
return "A success has no user's turn";
}
try{
run_rng_handoff_or_user_turn(logger, "Test RNG", []{
return RngHandoffResult{.failure = "out of resets", .user_turn = "ignored"};
});
}catch (OperationFailedException&){
return true;
}
return "A failure must throw even with a user's turn";
}

// A stop reports its message, then each line, to the log and to `show`;
// the notification text is one line each.
UnitTestResult test_stop_report(Logger& logger){
std::vector<std::string> shown;
const auto show = [&](const std::string& line){
shown.push_back(line);
};
const std::string text = report_rng_handoff_stop(logger, "Stopped for RNG.", {"Attempt 1", "Attempt 2"}, show);
if (text != "Stopped for RNG.\nAttempt 1\nAttempt 2"){
return std::format("Wrong notification text: {}", text);
}
if (shown != std::vector<std::string>{"Stopped for RNG.", "Attempt 1", "Attempt 2"}){
return "The overlay must get the message and then each line";
}
shown.clear();
if (report_rng_handoff_stop(logger, "Stopped.", {}, show) != "Stopped." || shown.size() != 1){
return "A stop without lines is its message alone";
}
return true;
}

const RngHandoffTestCase RNG_HANDOFF_CASES[] = {
{
.input = {.name = "RUN takes precedence over STOP", .body = test_mode},
.expectation = {.description = "RUN wins when both options are on"},
},
{
.input = {.name = "a stop reports its message and lines", .body = test_stop_report},
.expectation = {.description = "log, overlay and notification text agree"},
},
{
.input = {.name = "a success is ok", .body = test_success},
.expectation = {.description = "an ok outcome after one call"},
},
{
.input = {.name = "a failure throws without a retry", .body = test_failure},
.expectation = {.description = "OperationFailedException after one call"},
},
{
.input = {.name = "a user's turn is returned, not an error", .body = test_user_turn},
.expectation = {.description = "the message comes back; a failure still throws"},
},
};

} // namespace


void add_tests_StoryRngHandoff(UnitTestDatabase& database){
for (const RngHandoffTestCase& scenario : RNG_HANDOFF_CASES){
database.add<Test_RngHandoff>(scenario);
}
}


} // namespace Pokemon
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Story RNG Handoff Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_Pokemon_StoryRngHandoff_Tests_H
#define PokemonAutomation_Pokemon_StoryRngHandoff_Tests_H

#include "Common/Cpp/TestRunners/UnitTestDatabase.h"

namespace PokemonAutomation{
namespace Pokemon{


// Registers unit tests for the shared RNG handoff contract.
void add_tests_StoryRngHandoff(UnitTestDatabase& database);



} // namespace Pokemon
} // namespace PokemonAutomation
#endif
Loading
Loading