Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5fedcce
BDSP AutoStory: stop for Starter RNG at the Verity Lakefront
dayfine Nov 12, 2026
03bc3d4
BDSP: port Starter RNG from #1366 (theastrogoth)
dayfine Nov 12, 2026
874c461
BDSP Starter RNG: make the attempt loop callable
dayfine Nov 12, 2026
1e1a9bd
Merge branch 'bdsp/starter-rng-callable' into bdsp/autostory-starter-rng
dayfine Nov 12, 2026
2102439
BDSP AutoStory: run Starter RNG in 00.02
dayfine Nov 12, 2026
651fbca
Merge remote-tracking branch 'origin/bdsp/autostory-v4' into bdsp/sta…
dayfine Nov 12, 2026
db63d7e
Merge remote-tracking branch 'origin/bdsp/autostory-v4' into bdsp/aut…
dayfine Nov 12, 2026
b6ec3bc
Merge branches 'bdsp/autostory-starter-rng-handoff' and 'bdsp/starter…
dayfine Nov 12, 2026
76f0726
BDSP AutoStory: red test: the Starter RNG handoff save checks the Ver…
dayfine Nov 13, 2026
1e40b62
BDSP AutoStory: the Starter RNG handoff save checks the card; one han…
dayfine Nov 13, 2026
5824ff6
BDSP AutoStory: document plan_story_run for Code Health
dayfine Nov 13, 2026
d141c1a
BDSP AutoStory: plan_story_run comment names its parameter
dayfine Nov 13, 2026
bf6e870
BDSP Starter RNG: red test: the default filter row is a shiny of any …
dayfine Nov 13, 2026
b0bb884
BDSP Starter RNG: set_default_shiny_row seeds the filter table; the s…
dayfine Nov 13, 2026
393c83d
Merge remote-tracking branch 'origin/bdsp/starter-rng-callable' into …
dayfine Nov 13, 2026
fa59f9c
Merge origin/bdsp/autostory-starter-rng-handoff into bdsp/autostory-s…
dayfine Nov 13, 2026
fe6aa23
BDSP AutoStory: Starter RNG default row, player model option, fatal o…
dayfine Nov 13, 2026
bd1b9da
BDSP AutoStory Starter RNG: lint fixes (private options, split tests …
dayfine Nov 13, 2026
29a2278
BDSP AutoStory Starter RNG: const filters accessor
dayfine Nov 13, 2026
89b2d42
BDSP AutoStory Starter RNG: drop const filters accessor
dayfine Nov 13, 2026
7a46b79
AutoStory: shared RNG handoff contract; BDSP Starter RNG adopts it
dayfine Nov 13, 2026
bb44bba
Merge autostory/rng-handoff into bdsp/autostory-starter-rng
dayfine Nov 13, 2026
9d96ad0
Merge bdsp/autostory-starter-rng (#439) into bdsp/starter-rng-callable
dayfine Nov 13, 2026
b7edc14
Merge commit '0877430cf' into bdsp/rng-handoff-work
dayfine Nov 13, 2026
c2c6ae9
BDSP AutoStory: the Starter RNG handoff takes the shared RngHandoffMo…
dayfine Nov 13, 2026
62142f2
Merge origin/bdsp/autostory-v4 into bdsp/starter-rng-callable
dayfine Nov 13, 2026
c3e840b
Merge origin/bdsp/starter-rng-callable into bdsp/starter-rng-adopt
dayfine Nov 15, 2026
4b52729
Merge remote-tracking branch 'origin/bdsp/story-engine' into bdsp/sta…
dayfine Nov 15, 2026
1226973
CI: pin CommandLineTests with the BDSP MenuDetector French menu image
dayfine Nov 15, 2026
bd94ddb
Merge bdsp/seam5-adopt (#549) into bdsp/starter-rng-adopt
dayfine Nov 17, 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
4 changes: 2 additions & 2 deletions .github/workflows/cpp-ci-serial-programs-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ jobs:
uses: actions/checkout@v7
if: inputs.run-tests
with:
# The fork's fixtures: upstream's plus the SystemKeyboardDetector and HomeTileReader screenshots.
# The fork's fixtures: upstream's plus the SystemKeyboardDetector, HomeTileReader and BDSP MenuDetector screenshots.
repository: 'dayfine/CommandLineTests'
ref: 'eae4697738d5fe18975e77c05a4e01216bed68e7'
ref: '248d24fc7d1803c5187aae680d37ad1c5c0f13e7'
path: 'CommandLineTests'

# The unit tests assume the downloadable resources they need are already downloaded
Expand Down
220 changes: 220 additions & 0 deletions SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
/* BDSP RNG Filter
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/Logging/Logger.h"
#include "PokemonBDSP_RngFilter.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{

using namespace Pokemon;


const uint8_t BDSP_HEIGHT_MIN = 0;
const uint8_t BDSP_HEIGHT_MAX = 255;


BdspRngFilterRow::BdspRngFilterRow(EditableTableOption& parent_table)
: EditableTableRow(parent_table)
, misc(static_cast<const BdspRngFilterTable&>(parent_table).feature_flags)
, height(
LockMode::UNLOCK_WHILE_RUNNING,
BDSP_HEIGHT_MIN, BDSP_HEIGHT_MAX, BDSP_HEIGHT_MIN, BDSP_HEIGHT_MIN,
BDSP_HEIGHT_MIN, BDSP_HEIGHT_MAX, BDSP_HEIGHT_MAX, BDSP_HEIGHT_MAX
)
, iv_hp(LockMode::UNLOCK_WHILE_RUNNING, 0, 31, 0, 0, 0, 31, 31, 31)
, iv_atk(LockMode::UNLOCK_WHILE_RUNNING, 0, 31, 0, 0, 0, 31, 31, 31)
, iv_def(LockMode::UNLOCK_WHILE_RUNNING, 0, 31, 0, 0, 0, 31, 31, 31)
, iv_spatk(LockMode::UNLOCK_WHILE_RUNNING, 0, 31, 0, 0, 0, 31, 31, 31)
, iv_spdef(LockMode::UNLOCK_WHILE_RUNNING, 0, 31, 0, 0, 0, 31, 31, 31)
, iv_speed(LockMode::UNLOCK_WHILE_RUNNING, 0, 31, 0, 0, 0, 31, 31, 31)
{
if (misc.feature_flags.action){
PA_ADD_OPTION(misc.action);
}
if (misc.feature_flags.shiny){
PA_ADD_OPTION(misc.shiny);
}
if (misc.feature_flags.gender){
PA_ADD_OPTION(misc.gender);
}
if (misc.feature_flags.nature){
PA_ADD_OPTION(misc.nature);
}
PA_ADD_OPTION(height);
PA_ADD_OPTION(iv_hp);
PA_ADD_OPTION(iv_atk);
PA_ADD_OPTION(iv_def);
PA_ADD_OPTION(iv_spatk);
PA_ADD_OPTION(iv_spdef);
PA_ADD_OPTION(iv_speed);
}
std::unique_ptr<EditableTableRow> BdspRngFilterRow::clone() const{
std::unique_ptr<BdspRngFilterRow> ret(new BdspRngFilterRow(parent()));

Check failure on line 57 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

style: no new/delete outside allocators; use std::make_unique / std::make_shared (TotW #126)
ret->misc.set(misc);
ret->height.set(height);
ret->iv_hp.set(iv_hp);
ret->iv_atk.set(iv_atk);
ret->iv_def.set(iv_def);
ret->iv_spatk.set(iv_spatk);
ret->iv_spdef.set(iv_spdef);
ret->iv_speed.set(iv_speed);
return ret;
}
bool BdspRngFilterRow::match_iv(
const IntegerRangeCell<uint8_t>& desired, const IvRange& actual
){
uint8_t lo, hi;
desired.current_values(lo, hi);
if (lo == 0 && hi == 31){
return true;
}
if (actual.high < (int8_t)lo){
return false;
}
if ((int8_t)hi < actual.low){
return false;
}
return true;
}
bool BdspRngFilterRow::matches(
bool shiny,
StatsHuntGenderFilter gender,
NatureCheckerValue nature,
uint8_t height,
const IvRanges& ivs
) const{
if (!misc.matches(shiny, gender, nature)){
return false;
}

uint8_t height_lo, height_hi;
this->height.current_values(height_lo, height_hi);
if (height < height_lo || height_hi < height){
return false;
}

if (!match_iv(iv_hp, ivs.hp)){
return false;
}
if (!match_iv(iv_atk, ivs.attack)){
return false;
}
if (!match_iv(iv_def, ivs.defense)){
return false;
}
if (!match_iv(iv_spatk, ivs.spatk)){
return false;
}
if (!match_iv(iv_spdef, ivs.spdef)){
return false;
}
if (!match_iv(iv_speed, ivs.speed)){
return false;
}

return true;
}


BdspRngFilterTable::BdspRngFilterTable(
const std::string& label,
const StatsHuntMiscFeatureFlags& p_feature_flags
)
: EditableTableOption_t<BdspRngFilterRow>(label, LockMode::UNLOCK_WHILE_RUNNING)
, feature_flags(p_feature_flags)
{}
std::vector<std::string> BdspRngFilterTable::make_header() const{
std::vector<std::string> ret;
if (feature_flags.action){
ret.emplace_back("Action");
}
if (feature_flags.shiny){
ret.emplace_back("Shininess");
}
if (feature_flags.gender){
ret.emplace_back("Gender");
}
if (feature_flags.nature){
ret.emplace_back("Nature");
}

ret.emplace_back("Height");

ret.emplace_back("HP");
ret.emplace_back("Atk");
ret.emplace_back("Def");
ret.emplace_back("SpAtk");
ret.emplace_back("SpDef");
ret.emplace_back("Spd");

return ret;
}
BdspRngFilterSnapshot BdspRngFilterTable::make_snapshot() const{
return BdspRngFilterSnapshot(copy_snapshot());
}
void set_default_shiny_row(BdspRngFilterTable& table){
std::vector<std::unique_ptr<EditableTableRow>> defaults;
auto row = std::make_unique<BdspRngFilterRow>(table);
row->misc.shiny.set(StatsHuntShinyFilter::Shiny);
defaults.emplace_back(std::move(row));
table.set_default(std::move(defaults));
table.restore_defaults();
}
StatsHuntAction BdspRngFilterTable::get_action(
bool shiny,
StatsHuntGenderFilter gender,
NatureCheckerValue nature,
uint8_t height,
const IvRanges& ivs
) const{
return make_snapshot().get_action(shiny, gender, nature, height, ivs);
}


BdspRngFilterSnapshot::BdspRngFilterSnapshot(std::vector<std::unique_ptr<BdspRngFilterRow>> rows)
: m_rows(std::move(rows))
{}
StatsHuntAction BdspRngFilterSnapshot::get_action(
bool shiny,
StatsHuntGenderFilter gender,
NatureCheckerValue nature,
uint8_t height,
const IvRanges& ivs
) const{
StatsHuntAction action = StatsHuntAction::Discard;
for (size_t c = 0; c < m_rows.size(); c++){
const BdspRngFilterRow& filter = *m_rows[c];

if (!filter.matches(shiny, gender, nature, height, ivs)){
continue;
}

StatsHuntAction filter_action = filter.misc.action;

// No action matched so far. Take the current action and continue.
if (action == StatsHuntAction::Discard){
action = filter_action;
continue;
}

// Conflicting actions.
if (action != filter_action){
global_logger_tagged().log(
"Multiple filters matched with conflicting actions. Stopping program...",
COLOR_RED
);
return StatsHuntAction::StopProgram;
}
}
return action;
}


}

Check failure on line 218 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace PokemonBDSP
}

Check failure on line 219 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace NintendoSwitch
}

Check failure on line 220 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace PokemonAutomation
106 changes: 106 additions & 0 deletions SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* BDSP RNG Filter
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonBDSP_RngFilter_H
#define PokemonAutomation_PokemonBDSP_RngFilter_H

#include <stdint.h>
#include <string>
#include <vector>
#include "Common/Cpp/Options/EditableTableOption.h"
#include "Common/Cpp/Options/IntegerRangeOption.h"
#include "Pokemon/Pokemon_NatureChecker.h"
#include "Pokemon/Pokemon_StatsCalculation.h"
#include "Pokemon/Options/Pokemon_StatsHuntFilter.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{


class BdspRngFilterTable;

Check failure on line 24 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

header-comment: document each namespace-scope header symbol
class BdspRngFilterRow : public EditableTableRow{

Check failure on line 25 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

header-comment: document each namespace-scope header symbol
public:
BdspRngFilterRow(EditableTableOption& parent_table);
virtual std::unique_ptr<EditableTableRow> clone() const override;

bool matches(
bool shiny,
Pokemon::StatsHuntGenderFilter gender,
Pokemon::NatureCheckerValue nature,
uint8_t height,
const Pokemon::IvRanges& ivs
) const;

private:
static bool match_iv(const IntegerRangeCell<uint8_t>& desired, const Pokemon::IvRange& actual);

public:
Pokemon::StatsHuntRowMisc misc;

IntegerRangeCell<uint8_t> height;

IntegerRangeCell<uint8_t> iv_hp;
IntegerRangeCell<uint8_t> iv_atk;
IntegerRangeCell<uint8_t> iv_def;
IntegerRangeCell<uint8_t> iv_spatk;
IntegerRangeCell<uint8_t> iv_spdef;
IntegerRangeCell<uint8_t> iv_speed;
};


// The table copied once. Calling get_action() on the table itself clones every row on
// every call, which is far too slow for a scan running over millions of advances.
class BdspRngFilterSnapshot{
public:
explicit BdspRngFilterSnapshot(std::vector<std::unique_ptr<BdspRngFilterRow>> rows);

Pokemon::StatsHuntAction get_action(
bool shiny,
Pokemon::StatsHuntGenderFilter gender,
Pokemon::NatureCheckerValue nature,
uint8_t height,
const Pokemon::IvRanges& ivs
) const;

private:
std::vector<std::unique_ptr<BdspRngFilterRow>> m_rows;
};


class BdspRngFilterTable : public EditableTableOption_t<BdspRngFilterRow>{

Check failure on line 74 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

header-comment: document each namespace-scope header symbol
public:
BdspRngFilterTable(
const std::string& label,
const Pokemon::StatsHuntMiscFeatureFlags& p_feature_flags
);
virtual std::vector<std::string> make_header() const override;

BdspRngFilterSnapshot make_snapshot() const;

Pokemon::StatsHuntAction get_action(
bool shiny,
Pokemon::StatsHuntGenderFilter gender,
Pokemon::NatureCheckerValue nature,
uint8_t height,
const Pokemon::IvRanges& ivs
) const;

public:
const Pokemon::StatsHuntMiscFeatureFlags feature_flags;
};


// Makes the table's default, and its current content, one row: a shiny of
// any nature, gender and IVs. An empty table matches nothing, so a program
// that stops on a match must seed its table with this.
void set_default_shiny_row(BdspRngFilterTable& table);


}

Check failure on line 103 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace PokemonBDSP
}

Check failure on line 104 in SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_RngFilter.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace NintendoSwitch
}
#endif
2 changes: 2 additions & 0 deletions SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include "Programs/RngManipulation/PokemonBDSP_BedroomSeedFinder.h"
#include "Programs/RngManipulation/PokemonBDSP_IntroSeedFinder.h"
#include "Programs/RngManipulation/PokemonBDSP_StarterRng.h"

#include "Programs/TestPrograms/PokemonBDSP_ShinyEncounterTester.h"
#include "Programs/TestPrograms/PokemonBDSP_SoundListener.h"
Expand All @@ -67,6 +68,7 @@ void add_beta_and_developer_panels(std::vector<PanelEntry>& ret){
ret.emplace_back("---- Untested/Beta/WIP ----");
ret.emplace_back(make_SingleSwitchProgram<IntroSeedFinder>());
ret.emplace_back(make_SingleSwitchProgram<BedroomSeedFinder>());
ret.emplace_back(make_SingleSwitchProgram<StarterRng>());
}
if (STATIC_GLOBALS.DEVELOPER_MODE){
ret.emplace_back("---- Developer Tools ----");
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Programs/AutoStory/PokemonBDSP_AutoStory_Walk_Tests.h"
#include "Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WildBattlePolicy_Tests.h"
#include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WallBattleSim_Tests.h"
#include "Programs/RngManipulation/PokemonBDSP_StarterRng_Tests.h"
#include "PokemonBDSP_Tests.h"

namespace PokemonAutomation{
Expand Down Expand Up @@ -62,6 +63,7 @@ void add_tests(UnitTestDatabase& database){
add_tests_AutoStory_SimFailureCases(database);
add_tests_AutoStory_FaultSweep(database);
add_tests_AutoStory_StoryActions(database);
add_tests_StarterRng(database);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ void azure_flute_if_there(VideoStream& stream, ProControllerContext& context){



// 00.02 with Run Starter RNG in AutoStory: runs Starter RNG from the
// Verity Lakefront (17, 14) start save through the Starly battle and
// Rowan's scene, ending on the VerityLakefront overworld at (17, 14..15).
Pokemon::Outcome starter_rng(StoryEnv& story, Pokemon::RunState&, const Pokemon::StoryStep&){
if (!story.run_starter_rng){
return Pokemon::outcome_failed("starter_rng_not_configured", "Starter RNG is not configured on StoryEnv.");
}
return story.run_starter_rng();
}

// 00.04: Dawn's catching tutorial on Route 202: her lines and her demo
// battle, B for 70 s.
void catch_tutorial(VideoStream& stream, ProControllerContext& context){
Expand All @@ -134,6 +144,7 @@ void add_lake_events(StoryEvents& events){
events.emplace("azure_flute_if_there", console_event(azure_flute_if_there));
events.emplace("starter_briefcase", console_event(starter_briefcase));
events.emplace("choose_starter", choose_starter);
events.emplace("starter_rng", starter_rng);


events.emplace("catch_tutorial", console_event(catch_tutorial));
Expand Down
Loading
Loading