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=628 (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,45 @@
}


// Logs sparse collection milestones while the thresholds are still moving.
static void log_calibration_progress(
const BlinkRecoveryConfig& config,
size_t events,
SingleSwitchProgramEnvironment& env
){
const bool milestone = events == 1
|| events == config.min_rolls_to_try
|| (events < config.min_rolls_to_try && events % 5 <= 1);
if (!milestone){
return;
}
env.log(std::format(
"Calibrating blink detection: {}/{} rolls collected.",
events, config.min_rolls_to_try
));
}

// Updates the option display and reports the active calibration or confirmation phase.
static void report_blink_progress(
const BlinkRecoveryConfig& config,
size_t events,
bool have_candidate,
size_t candidate_events,
SingleSwitchProgramEnvironment& env,
BlinkCollectionDisplay& display
){
display.set_progress(events, config.min_rolls_to_try + config.confirmation_events);
if (!have_candidate){
log_calibration_progress(config, events, env);
return;
}
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
));
}

BlinkRecovery recover_state_from_blinks(
SingleSwitchProgramEnvironment& env,
ProControllerContext& context,
Expand Down Expand Up @@ -271,8 +311,6 @@
longest = &stream;
}
}
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 +332,7 @@
if (!fresh){
continue;
}
report_blink_progress(config, events, have_candidate, candidate_events, env, display);

if (longest->size() < 3){
continue;
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=798 (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,39 @@
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, SingleSwitchProgramEnvironment& env){
env.log(std::format(
"Waiting at the blink position for press advance {} (about {}s); re-anchoring every 30s.",
press_advance, tostr_default(wait_seconds)
), COLOR_BLUE);
}

// Logs every scheduled input before the blind timeline begins.
void log_blind_timeline(
uint64_t press_advance,
double starly_seconds,
double select_seconds,
double confirm_seconds,
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(starly_seconds), tostr_default(select_seconds),
tostr_default(confirm_seconds), accept_advance
), COLOR_BLUE);
}


std::function<bool(const BdspPokemonResult&)> resolve_wanted_predicate(
const StarterRngSettings& settings
){
Expand Down Expand Up @@ -433,7 +467,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 +547,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, 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 +572,10 @@

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.starly_seconds, schedule.select_seconds, schedule.confirm_seconds,
target_advance - timeline.advances_after_accept, env
);

std::string sequence_failure;
if (!wait_until_moment(context, env.logger(), briefcase_time)){
Expand All @@ -557,11 +588,11 @@
)){
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.
env.log("Checking the battle animation, then reporting the target hit or signed advance miss.", COLOR_BLUE);
DoublesShinyDetection wild;
ShinyDetectionResult own;
detect_shiny_battle(
Expand Down
Loading