Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* BDSP Blink Recovery

Check warning on line 1 in SerialPrograms/Source/PokemonBDSP/Programs/RngManipulation/PokemonBDSP_BlinkRecovery.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=649 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -7,6 +7,7 @@
#include <algorithm>
#include <chrono>
#include <cmath>
#include <format>
#include "Common/Cpp/PrettyPrint.h"
#include "Common/Cpp/Logging/AbstractLogger.h"
#include "CommonFramework/GlobalAutoPaths.h"
Expand Down Expand Up @@ -183,6 +184,65 @@
}


// Logs sparse collection milestones until a provisional state is found.
static void log_search_progress(
const BlinkRecoveryConfig& config,
size_t events,
size_t search_updates,
SingleSwitchProgramEnvironment& env
){
if (events < config.min_rolls_to_try){
if (events != 1 && events % 5 != 0){
return;
}
env.log(std::format(
"Calibrating blink detection: {}/{} rolls collected.",
events, config.min_rolls_to_try
));
return;
}
if (search_updates == 1 || search_updates % 5 == 0){
env.log(std::format(
"Still searching for the first RNG state: {} rolls available.", events
));
}
}

// Reports the active calibration or confirmation phase.
static void report_blink_progress(
const BlinkRecoveryConfig& config,
size_t events,
size_t search_updates,
bool have_candidate,
size_t candidate_events,
SingleSwitchProgramEnvironment& env
){
if (!have_candidate){
log_search_progress(config, events, search_updates, env);
return;
}
// confirmation_events is deliberately small (six by default), so report
// every fresh roll in this bounded phase.
size_t confirmed = std::min(events - candidate_events, config.confirmation_events);
env.log(std::format(
"Confirming the provisional RNG state: {}/{} additional rolls collected.",
confirmed, config.confirmation_events
));
}

static size_t report_fresh_progress(
const BlinkRecoveryConfig& config,
size_t events,
size_t search_updates,
bool have_candidate,
size_t candidate_events,
SingleSwitchProgramEnvironment& env
){
search_updates += !have_candidate && events >= config.min_rolls_to_try ? 1 : 0;
report_blink_progress(config, events, search_updates, have_candidate, candidate_events, env);
return search_updates;
}

BlinkRecovery recover_state_from_blinks(
SingleSwitchProgramEnvironment& env,
ProControllerContext& context,
Expand All @@ -202,6 +262,7 @@
std::vector<size_t> estimated_from(watchers.size(), 0);

bool have_candidate = false;
size_t search_updates = 0;
Xorshift128State candidate;
size_t candidate_events = 0;
std::vector<WallClock> newest_blink(watchers.size(), WallClock::min());
Expand Down Expand Up @@ -272,7 +333,6 @@
}
}
display.set_progress(events, config.min_rolls_to_try + config.confirmation_events);

// don't trim if there is a candidate (the solution is pinned to the earliest blink)
if (!have_candidate){
trim_to_window(watchers, streams, origin, config.window_events / streams.size());
Expand All @@ -294,6 +354,7 @@
if (!fresh){
continue;
}
search_updates = report_fresh_progress(config, events, search_updates, have_candidate, candidate_events, env);

if (longest->size() < 3){
continue;
Expand Down Expand Up @@ -332,7 +393,6 @@
}
if (!solved.success){
failed_solves++;
env.log(std::to_string(events) + " rolls seen, no solution yet.");
continue;
}
failed_solves = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* BDSP Starter RNG Attempts

Check warning on line 1 in SerialPrograms/Source/PokemonBDSP/Programs/RngManipulation/PokemonBDSP_StarterRngAttempts.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=799 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -6,6 +6,7 @@

#include <chrono>
#include <cmath>
#include <format>
#include <memory>
#include <vector>
#include "Common/Cpp/Exceptions.h"
Expand Down Expand Up @@ -51,6 +52,42 @@
const uint64_t SKIP_ARRIVAL_OVERSHOOT_ALLOWANCE = 200000;


// Logs the lake observation phase before frame collection begins.
void log_calibration_start(size_t rolls, SingleSwitchProgramEnvironment& env){
env.log(std::format(
"Calibrating blink detection; collecting {} rolls before the first solve.", rolls
), COLOR_BLUE);
}

// Logs why the program remains at the blink position and how it guards the clock.
void log_target_wait(
uint64_t press_advance,
double wait_seconds,
Seconds reanchor_interval,
SingleSwitchProgramEnvironment& env
){
env.log(std::format(
"Waiting at the blink position for press advance {} (about {}s); re-anchoring every {}s.",
press_advance, tostr_default(wait_seconds), reanchor_interval.count()
), COLOR_BLUE);
}

// Logs every scheduled input before the blind timeline begins.
void log_blind_timeline(
uint64_t press_advance,
const PressSchedule& schedule,
uint64_t accept_advance,
SingleSwitchProgramEnvironment& env
){
env.log(std::format(
"Blind timeline starts at advance {}. Starly press at {}s, selecting at {}s, "
"confirming at {}s, on advance {}.",
press_advance, tostr_default(schedule.starly_seconds), tostr_default(schedule.select_seconds),
tostr_default(schedule.confirm_seconds), accept_advance
), COLOR_BLUE);
}


std::function<bool(const BdspPokemonResult&)> resolve_wanted_predicate(
const StarterRngSettings& settings
){
Expand Down Expand Up @@ -433,7 +470,7 @@

BlinkRecoveryConfig blink_config;
blink_config.npcs = target_info.observation_npcs;

log_calibration_start(blink_config.min_rolls_to_try, env);
BlinkRecovery recovery = recover_state_from_blinks(
env, context, watchers, callbacks, collection_display, blink_config
);
Expand Down Expand Up @@ -513,8 +550,7 @@
).count();
env.log("Target advance " + std::to_string(target_advance) + ": " + target.to_string(),
COLOR_BLUE);
env.log("Pressing at advance " + std::to_string(press_advance) + ", in "
+ tostr_default(wait_seconds) + "s.", COLOR_BLUE);
log_target_wait(press_advance, wait_seconds, blink_config.reanchor_interval, env);
env.log("Schedule spans " + std::to_string(schedule.span) + " advances, confirming after "
+ std::to_string(schedule.blinks_before_confirm) + " Starly blink(s), "
+ tostr_default(schedule.confirm_seconds) + "s in"
Expand All @@ -539,12 +575,9 @@

state_display.set_advances(press_advance);

env.log("Timeline starts at advance " + std::to_string(press_advance)
+ ". Blind from here: Starly press at " + tostr_default(schedule.starly_seconds)
+ "s, selecting at " + tostr_default(schedule.select_seconds)
+ "s, confirming at " + tostr_default(schedule.confirm_seconds)
+ "s, on advance " + std::to_string(target_advance - timeline.advances_after_accept)
+ ".", COLOR_BLUE);
log_blind_timeline(
press_advance, schedule, target_advance - timeline.advances_after_accept, env
);

std::string sequence_failure;
if (!wait_until_moment(context, env.logger(), briefcase_time)){
Expand All @@ -557,11 +590,10 @@
)){
return abandon(sequence_failure);
}
env.log("Timeline finished; the starter should be in hand.", COLOR_BLUE);
env.log("Blind timeline finished; verifying the obtained starter.", COLOR_BLUE);

state_display.set_advances(target_advance);

// Check what was actually obtained.
DoublesShinyDetection wild;
ShinyDetectionResult own;
detect_shiny_battle(
Expand Down
Loading