From 88ebb7eb0283b2a81653a470b5d277891a5b440c Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 01:45:59 -0800 Subject: [PATCH 1/3] PokemonLZA AutoStory: catches in Wild Zone 1 and the objective marker walks --- .../Actions/PokemonLZA_AutoStoryCatches.cpp | 1062 +++++++++++++++++ .../Actions/PokemonLZA_AutoStoryCatches.h | 125 ++ .../PokemonLZA_AutoStoryMarkerWalks.cpp | 102 ++ .../Actions/PokemonLZA_AutoStoryMarkerWalks.h | 55 + SerialPrograms/cmake/SourceFiles.cmake | 4 + 5 files changed, 1348 insertions(+) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.h diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp new file mode 100644 index 0000000000..9ccd9cc059 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp @@ -0,0 +1,1062 @@ +/* PokemonLZA AutoStory - Catches + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonLZA/Inference/Battles/PokemonLZA_RunFromBattleDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_AlertEyeDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_DialogDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_LockOnBracketDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.h" +#include "VideoGames/PokemonLZA/Programs/PokemonLZA_TrainerBattle.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDexRegisteredDetector.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryObjectiveMarkerReader.h" +#include "PokemonLZA_AutoStoryBracketWatch.h" +#include "PokemonLZA_AutoStoryCatchPlan.h" +#include "PokemonLZA_AutoStoryCatchStop.h" +#include "PokemonLZA_AutoStoryCatches.h" +#include "PokemonLZA_AutoStoryDialogs.h" +#include "PokemonLZA_AutoStoryMarkerWalks.h" +#include "PokemonLZA_AutoStoryScenes.h" +#include "PokemonLZA_AutoStorySpeciesCheck.h" +#include "PokemonLZA_AutoStoryZone1Road.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; + + +namespace{ + +// A through text and tutorial cards until neither has shown for 3 s +// (30 s at most). +ScreensPassed advance_text_and_cards(ConsoleHandle& console, ProControllerContext& context){ + return press_a_until_quiet(console, context, {}, 3s, 30s); +} + +// ZL held 0.5 s, then ZL+ZR held 1.5 s (ZL never let go from the lock; 0.5 s +// of ZR only aims) throws, then 8 s for the flight, shakes and the banner (it +// showed 6.9 s in, 03.08). Returns whether the Pokedex's "Registered!" banner +// (a new species) showed, judged on the frames watched: UNKNOWN when a gap +// could hide it (REGISTERED_BANNER_WATCH). +// TODO: unify with the ZL + ZR throw of PokemonLZA_InPlaceCatcher.cpp and +// AsyncCommandSession (CommonTools/Async/InterruptableCommands.h) - the +// lock-on may drop between separate commands; needs a console test. +Pokemon::WatchResult throw_ball(ConsoleHandle& console, ProControllerContext& context){ + DetectorToFinder registered("DexRegisteredWatcher", REGISTERED_BANNER_HOLD); + const Pokemon::WatchResult banner = Pokemon::run_watched( + console, context, + [](ProControllerContext& context){ + pbf_controller_state(context, BUTTON_ZL, DPAD_NONE, {0, 0}, {0, 0}, 500ms); + pbf_controller_state(context, BUTTON_ZL | BUTTON_ZR, DPAD_NONE, {0, 0}, {0, 0}, 1500ms); + pbf_wait(context, 8000ms); + }, + REGISTERED_BANNER_WATCH, registered + ); + console.log(std::format("throw_ball(): the Registered! banner: {}.", Pokemon::describe(banner))); + if (banner.verdict == Pokemon::WatchVerdict::SEEN){ + context.wait_for(3000ms); + } + context.wait_for_all_requests(); + return banner; +} + +// Whether a wild battle is on: its Run prompt ("-" at the left), which +// story battles do not show, or the red alert bar with the eye at the top +// (AlertEyeDetector), which shows while a wild Pokemon attacks the player +// before the partner is out: Bunnelby's Tackle at stop 100, where the Run +// prompt did not show (03.08). A target a ball broke +// out of can turn on the player too (Mareep). +bool wild_battle_on(ConsoleHandle& console, ProControllerContext& context){ + context.wait_for_all_requests(); + const VideoSnapshot screen = console.video().snapshot(); + if (!screen){ + return false; + } + RunFromBattleDetector run_prompt(COLOR_RED, nullptr); + if (run_prompt.detect(screen)){ + console.log("wild_battle_on(): the Run prompt shows."); + return true; + } + AlertEyeDetector alert(COLOR_RED, nullptr); + if (alert.detect(screen)){ + console.log("wild_battle_on(): the alert eye shows: a wild Pokemon attacks."); + return true; + } + return false; +} + +// What tells weaken_then_throw() a throw caught its target. +enum class CatchSign{ + NO_TARGET, // only a later round with nothing to lock on (Bunnelby) + REGISTERED, // the Pokedex's "Registered!" banner: a new species + CARD, // a tutorial card after the throw (03.07's tutorial) +}; + +// How weaken_then_throw() ended. +struct WeakenThrows{ + bool caught = false; + int throws = 0; +}; + +// TrainerBattleState attacks until 3 land (12 tries at most). Two lock-ons +// in a row with no move symbols press D-pad up (twice at most): the +// partner may not be out. Returns the attacks that landed. +int weaken_target(ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, TrainerBattleState& battle_state){ + int landed = 0; + int misses = 0; + int sends = 0; + for (int tries = 0; tries < 12 && landed < 3; tries++){ + if (battle_state.attempt_one_attack(env, console, context)){ + landed++; + misses = 0; + }else if (++misses == 2 && sends < 2){ + console.log("weaken_target(): no lock-on twice: D-pad up to send the partner out."); + pbf_press_dpad(context, DPAD_UP, 100ms, 2000ms); + misses = 0; + sends++; + } + } + return landed; +} + +// Rounds of weaken_target() and a throw, with A through any lines, until +// `sign` shows, a round after the first finds nothing to lock on (caught +// for NO_TARGET, gone otherwise), or `max_throws` throws. +WeakenThrows weaken_then_throw( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai, CatchSign sign, int max_throws, std::string_view caller +){ + TrainerBattleState battle_state(battle_ai); + WeakenThrows out; + while (out.throws < max_throws){ + const int landed = weaken_target(env, console, context, battle_state); + if (landed == 0 && out.throws > 0){ + console.log(std::format("{}: nothing to lock on in round {}: {}.", caller, out.throws + 1, sign == CatchSign::NO_TARGET ? "caught" : "gone")); + out.caught = sign == CatchSign::NO_TARGET; + return out; + } + advance_text_and_cards(console, context); + const bool registered = throw_ball(console, context).verdict == Pokemon::WatchVerdict::SEEN; + out.throws++; + const bool card = advance_text_and_cards(console, context).card; + console.log(std::format("{}: round {}: {} attacks landed, then a throw.", caller, out.throws, landed)); + if ((sign == CatchSign::REGISTERED && registered) || (sign == CatchSign::CARD && card)){ + out.caught = true; + return out; + } + } + return out; +} + +// ZL held across reads of the screen: each hold is queued before the last +// one ends, so ZL is never let go from the lock to the throw (throw_ball() +// queues its own ZL first). +class HeldZl{ +public: + HeldZl(ConsoleHandle& console, ProControllerContext& context) + : m_console(console) + , m_context(context) + , m_end(current_time()) + {} + + // Queues `time` of ZL with the sticks at `left` and `right`. + void hold(Milliseconds time, const JoystickPosition& left, const JoystickPosition& right){ + pbf_controller_state(m_context, BUTTON_ZL, DPAD_NONE, left, right, time); + m_end = std::max(m_end, current_time()) + time; + } + + // Holds ZL still until 0.6 s after what was queued and reads the plate + // locked on to, with 0.4 s more of ZL queued. + std::optional read(){ + hold(1000ms, {0, 0}, {0, 0}); + const WallClock at = m_end - 400ms; + const WallClock now = current_time(); + if (at > now){ + m_context.wait_for(std::chrono::duration_cast(at - now)); + } + const VideoSnapshot frame = m_console.video().snapshot(); + if (!frame){ + return std::nullopt; + } + const std::optional bar = lock_target_plate_bar(frame); + if (!bar){ + return std::nullopt; + } + LockTarget target; + target.x = bar->x + bar->width / 2; + target.y = bar->y + bar->height / 2; + target.width = bar->width; + target.caught = lock_target_caught(frame); + return target; + } + + // Reads the plate (read()) with ZL held on until one shows or `limit` + // passes. The lock can take over 1.5 s to show. + std::optional wait_for_plate(Milliseconds limit){ + const WallClock end = current_time() + limit; + while (true){ + const std::optional target = read(); + if (target || current_time() >= end){ + return target; + } + } + } + + // The right stick flicked `x` (right when positive) with ZL held moves + // the lock to the next target that way (the user). Returns + // the plate after it. + std::optional flick(double x){ + hold(150ms, {0, 0}, {x, 0}); + return read(); + } + +private: + ConsoleHandle& m_console; + ProControllerContext& m_context; + WallClock m_end; +}; + +// A full flick of the right stick: what moves the lock to the next target. +constexpr double TARGET_FLICK = 0.8; + +void log_target(ConsoleHandle& console, std::string_view caller, std::string_view what, const LockTarget& target){ + console.log(std::format( + "{}: {}: plate at ({:.2f}, {:.2f}), {:.3f} wide, {}.", + caller, what, target.x, target.y, target.width, target.caught_text() + )); +} + +// What choose_target() found. +struct TargetChoice{ + // The target locked on to now; nothing when no plate read. + std::optional target; + // Plates read, all of species already caught. + bool all_caught = false; +}; + +// How long ZL is held for the lock to show before a stop gives up on the +// target: the lock took longer than the old 1.5 s at times (the user, +// the console). +constexpr Milliseconds LOCK_ON_WAIT = 3000ms; + +// With ZL held until the lock shows (LOCK_ON_WAIT at most), flicks the +// right stick right up to 3 times, reading each +// target's plate (LockTargetCycle), then flicks back to the nearest one +// not caught: the closer one is much more likely to be caught. +// The plate's height on the screen stands for the distance; +// the cyan catch-chance icon over the target is not read. +TargetChoice choose_target(ConsoleHandle& console, HeldZl& held, std::string_view caller){ + LockTargetCycle cycle(4); + std::optional view = held.wait_for_plate(LOCK_ON_WAIT); + if (!view){ + console.log(std::format("{}: ZL held {} ms, but no name plate: no lock on.", caller, LOCK_ON_WAIT.count())); + } + for (int flicks = 0; view && flicks < 4; flicks++){ + log_target(console, caller, std::format("target {}", cycle.targets().size()), *view); + if (!cycle.add(*view)){ + break; + } + view = held.flick(TARGET_FLICK); + } + TargetChoice choice; + const std::vector& targets = cycle.targets(); + const std::optional best = nearest_uncaught(targets); + if (!best){ + choice.all_caught = !targets.empty(); + console.log(std::format("{}: {} plates read, none of a species not caught.", caller, targets.size())); + return choice; + } + const int flicks = cycle.flicks_to(*best); + console.log(std::format("{}: choosing target {} of {}: {} flicks {}.", caller, *best, targets.size(), std::abs(flicks), flicks < 0 ? "left" : "right")); + std::optional now = targets[*best]; + for (int i = 0; i < std::abs(flicks); i++){ + now = held.flick(flicks < 0 ? -TARGET_FLICK : TARGET_FLICK); + } + if (now && !same_lock_target(*now, targets[*best])){ + log_target(console, caller, "the lock moved on to another plate", *now); + } + choice.target = now ? now : targets[*best]; + return choice; +} + +// Walks toward a far target with ZL held (the lock keeps the camera on +// it): 0.5 s steps, re-reading the plate, 4 at most (2 s). +void approach_target(ConsoleHandle& console, HeldZl& held, LockTarget target, std::string_view caller){ + int steps = 0; + for (; steps < 4 && lock_target_far(target); steps++){ + held.hold(500ms, {0, 1}, {0, 0}); + const std::optional view = held.read(); + if (!view){ + console.log(std::format("{}: the plate went after {} steps toward the target.", caller, steps + 1)); + return; + } + target = *view; + } + log_target(console, caller, std::format("after {} steps toward the target", steps), target); +} + +// ZL held: chooses the nearest target not caught (choose_target()) and +// walks toward it when it is far, then leaves ZL held for throw_ball(). +TargetChoice aim_choose_approach(ConsoleHandle& console, ProControllerContext& context, std::string_view caller){ + HeldZl held(console, context); + const TargetChoice choice = choose_target(console, held, caller); + if (choice.target){ + approach_target(console, held, *choice.target, caller); + } + return choice; +} + +// Turns the camera, without walking, until the objective marker is in the +// middle (15 turns at most). +void face_objective(ConsoleHandle& console, ProControllerContext& context){ + for (int i = 0; i < 15; i++){ + context.wait_for_all_requests(); + const std::optional marker = read_objective_marker(console, console.video().snapshot()); + const double off = marker ? marker->x - 0.5 : 0.5; + if (off > -0.06 && off < 0.06){ + return; + } + pbf_move_right_joystick(context, {off > 0 ? 0.4 : -0.4, 0}, Milliseconds((int)(std::min(1.0, std::abs(off) * 4) * 400)) + 80ms, 150ms); + } +} + +// Throws at `target` (`max_throws` at most), then as after_throw() says: +// again at once at a plate that locks on again with ZL held after a miss, +// or weaken_then_throw() when it broke out into a wild battle. +GrassCatches throw_at_target( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai, const LockTarget& target, int max_throws +){ + GrassCatches out; + LockTarget aimed = target; + while (out.throws < max_throws && out.throws < THROWS_AT_ONE_TARGET){ + const bool registered = throw_ball(console, context).verdict == Pokemon::WatchVerdict::SEEN; + out.throws++; + advance_text_and_cards(console, context); + const bool battle = !registered && wild_battle_on(console, context); + const std::optional relocked = registered || battle + ? std::nullopt : HeldZl(console, context).wait_for_plate(LOCK_ON_WAIT); + const ThrowSeen seen{registered, aimed.caught, !registered && !battle && !relocked}; + const std::optional sign = seen.new_species(); + out.found = sign ? 1 : 0; + out.found_by_plate = sign == NewSpeciesSign::PLATE_NOT_CAUGHT ? 1 : 0; + console.log(std::format("catch_in_zone(): throw {}: {}.", out.throws, seen.new_species_text())); + const AfterThrow next = after_throw(seen, battle, relocked); + if (next == AfterThrow::THROW_AGAIN){ + log_target(console, "catch_in_zone()", "missed, locked on again, throwing at once", *relocked); + aimed = *relocked; + continue; + } + if (next == AfterThrow::WEAKEN && out.throws < max_throws){ + console.log("catch_in_zone(): the throw broke out: battle, weakening."); + const WeakenThrows weakened = weaken_then_throw(env, console, context, battle_ai, CatchSign::REGISTERED, max_throws - out.throws, "catch_in_zone()"); + out.throws += weakened.throws; + out.found += weakened.caught ? 1 : 0; + } + return out; + } + return out; +} + +// The brackets on the frame now, if any. +std::optional read_brackets(ConsoleHandle& console){ + const VideoSnapshot frame = console.video().snapshot(); + if (!frame){ + return std::nullopt; + } + const std::optional brackets = find_lock_on_brackets(frame); + if (!brackets){ + return std::nullopt; + } + return BracketSighting{brackets->x, brackets->y, brackets->height}; +} + +// Stands still and watches for the brackets (BracketWatch: until the +// first, BRACKET_SETTLE, `limit` at most), logging each one seen at stop +// `at` (the distance read there). Returns the tallest seen. +std::optional watch_for_brackets(ConsoleHandle& console, ProControllerContext& context, int at, Milliseconds limit){ + BracketWatch watch(BRACKET_SETTLE, limit); + const WallClock start = current_time(); + while (!watch.done()){ + context.wait_for_all_requests(); + const std::optional seen = read_brackets(console); + if (seen){ + console.log(std::format( + "catch_in_zone(): at {}: brackets at ({:.2f}, {:.2f}), {:.3f} tall.", + at, seen->x, seen->y, seen->height + )); + } + watch.add(std::chrono::duration_cast(current_time() - start), seen); + context.wait_for(250ms); + } + console.log(std::format("catch_in_zone(): at {}: {} sightings of brackets.", at, watch.sightings().size())); + return watch.nearest(); +} + +// A catch stop's camera sweep (camera_sweep()): 4 looks, the turn between +// two about what camera_turn_toward() gives for a third of the screen +// (the "look further right" turn). NEEDS CONSOLE: how far right the last +// look sees; the user's catches were in the grass right of the road. +constexpr CameraTurn SWEEP_STEP{0.5, 400ms}; +constexpr int SWEEP_STEPS = 3; + +// How long each look of the sweep watches for brackets: shorter than a +// lone look's 6 s, as the sweep looks 4 times. +constexpr Milliseconds SWEEP_LOOK_LIMIT = 3000ms; + +void turn_camera(ProControllerContext& context, const CameraTurn& turn){ + if (turn.time.count() > 0){ + pbf_move_right_joystick(context, {turn.stick_x, 0}, turn.time, 300ms); + } +} + +// Sweeps the camera from straight on toward the grass right of the road +// and back (camera_sweep()), watching for brackets at each look +// (watch_for_brackets()). Returns the nearest brackets of the first look +// that saw any, the camera left there; nothing (the camera back straight +// on) when no look did. +std::optional sweep_for_brackets(ConsoleHandle& console, ProControllerContext& context, int at){ + const std::vector looks = camera_sweep(SWEEP_STEP, SWEEP_STEPS); + for (size_t i = 0; i < looks.size(); i++){ + turn_camera(context, looks[i].turn); + if (!looks[i].watch){ + continue; + } + const std::optional seen = watch_for_brackets(console, context, at, SWEEP_LOOK_LIMIT); + if (seen){ + console.log(std::format("catch_in_zone(): at {}: brackets at look {} of the sweep.", at, i)); + return seen; + } + } + context.wait_for_all_requests(); + return std::nullopt; +} + +// Turns the camera toward `target` (camera_turn_toward()) so the +// brackets stay on it when ZL is held. +void turn_to_brackets(ConsoleHandle& console, ProControllerContext& context, const BracketSighting& target){ + const CameraTurn turn = camera_turn_toward(target.x); + console.log(std::format( + "catch_in_zone(): choosing the brackets at ({:.2f}, {:.2f}), {:.3f} tall: stick {:.1f} for {} ms.", + target.x, target.y, target.height, turn.stick_x, turn.time.count() + )); + if (turn.time.count() > 0){ + pbf_move_right_joystick(context, {turn.stick_x, 0}, turn.time, 300ms); + } + context.wait_for_all_requests(); + const std::optional now = read_brackets(console); + if (now){ + console.log(std::format("catch_in_zone(): after the turn, brackets at ({:.2f}, {:.2f}), {:.3f} tall.", now->x, now->y, now->height)); + } +} + +// Attacks (weaken_target(), which sends the partner out when no move +// symbols show) until the wild battle is over or a round lands nothing, +// 3 rounds at most: a wild Pokemon of a species already caught, fought +// off with no throws. +void fight_off(ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, BattleAIOption& battle_ai){ + TrainerBattleState battle_state(battle_ai); + for (int round = 1; round <= 3; round++){ + const int landed = weaken_target(env, console, context, battle_state); + advance_text_and_cards(console, context); + const bool still_on = wild_battle_on(console, context); + console.log(std::format("catch_in_zone(): fighting off, round {}: {} attacks landed, battle {}.", round, landed, still_on ? "on" : "over")); + if (landed == 0 || !still_on){ + return; + } + } +} + +// A wild Pokemon fighting the player (a Mareep often does, the user's walk +// on; Bunnelby): ZL locks on to it and +// reads its plate. Of a species already caught, it is fought off +// (fight_off()); otherwise weaken_then_throw() until it is caught or +// gone, `max_throws` at most. +GrassCatches fight_back( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai, int max_throws +){ + GrassCatches out; + std::optional attacker; + { + HeldZl held(console, context); + attacker = held.wait_for_plate(LOCK_ON_WAIT); + } + if (attacker){ + log_target(console, "catch_in_zone()", "a wild battle at the stop, locked on to", *attacker); + } + if (attacker && attacker->caught == true){ + console.log("catch_in_zone(): a species already caught: fighting it off, no throws."); + fight_off(env, console, context, battle_ai); + return out; + } + console.log("catch_in_zone(): a wild battle at the stop: weakening and throwing."); + const WeakenThrows weakened = weaken_then_throw( + env, console, context, battle_ai, CatchSign::REGISTERED, max_throws, "catch_in_zone()" + ); + out.throws = weakened.throws; + out.found = weakened.caught ? 1 : 0; + return out; +} + +// At one stop (`at` from the objective), 4 tries at most, until a new +// species is caught (the stop ends) or `max_throws`: a wild battle on is +// fought (fight_back()); otherwise it sweeps for brackets, turns the +// camera to the first seen, holds ZL until the plate shows the lock +// (LOCK_ON_WAIT at most), chooses the nearest target not caught +// (aim_choose_approach()) and throws (throw_at_target()). No brackets: on +// to the next stop. All species caught: turns the camera right a little +// and watches again. The pitch is reset only after ZL (CameraPitch). +GrassCatches catch_at_stop( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai, int at, int max_throws +){ + GrassCatches out; + CameraPitch pitch; + for (int tries = 0; tries < 4 && out.found == 0 && out.throws < max_throws; tries++){ + if (pitch.level_now()){ + level_camera(console, context); + } + if (wild_battle_on(console, context)){ + out += fight_back(env, console, context, battle_ai, max_throws - out.throws); + pitch.zl_held(); + continue; + } + const std::optional target = sweep_for_brackets(console, context, at); + if (!target){ + console.log(std::format("catch_in_zone(): no brackets at {} in the sweep.", at)); + break; + } + turn_to_brackets(console, context, *target); + const TargetChoice choice = aim_choose_approach(console, context, "catch_in_zone()"); + pitch.zl_held(); + if (!choice.target && !choice.all_caught){ + continue; + } + if (choice.all_caught){ + console.log("catch_in_zone(): only species already caught lock on: looking further right."); + out.caught_seen++; + pbf_move_right_joystick(context, {0.5, 0}, 400ms, 300ms); + continue; + } + out += throw_at_target(env, console, context, battle_ai, *choice.target, max_throws - out.throws); + } + if (out.found > 0){ + console.log(std::format("catch_in_zone(): caught at {}: the stop ends, on to the next.", at)); + } + if (pitch.level_now()){ + level_camera(console, context); + } + return out; +} + +// Turns the camera toward the marker at `x` (0 to 1) and walks 0.6 s on. +void steer_and_step(ProControllerContext& context, double x){ + const double off = x - 0.5; + if (off > 0.06 || off < -0.06){ + pbf_move_right_joystick(context, {off > 0 ? 0.4 : -0.4, 0}, Milliseconds((int)(std::min(1.0, std::abs(off) * 4) * 400)) + 80ms, 150ms); + } + pbf_move_left_joystick(context, {0, 1}, 600ms, 0ms); +} + +// Whether a walk toward the marker is held up: the distance has not +// dropped below its best for 4 reads (a fence or a wall in the way, the +// Research Lab's front fence on the console). +class StuckWatch{ +public: + bool stuck(int distance){ + if (distance < m_best){ + m_best = distance; + m_still = 0; + return false; + } + if (++m_still < 4){ + return false; + } + m_still = 0; + return true; + } + // Steps sideways around what is in the way: right, then left twice as + // far, and so on (4 at most). + void sidestep(ConsoleHandle& console, ProControllerContext& context){ + if (m_sidesteps >= 4){ + return; + } + const bool right = m_sidesteps % 2 == 0; + const Milliseconds time = Milliseconds(1500 * (m_sidesteps + 1)); + console.log(std::format("walk_to_objective(): held up at {}: {} for {} ms.", m_best, right ? "right" : "left", time.count())); + pbf_move_left_joystick(context, {right ? 1.0 : -1.0, 0}, time, 200ms); + m_sidesteps++; + } + +private: + int m_best = 1 << 30; + int m_still = 0; + int m_sidesteps = 0; +}; + +// The marker's distance reads, with misreads dropped. A read far from the +// last one is a misread: a 0.6 s step covers about 3. Below: 36 as "3" or +// 29 on the console; above: 110 as "1110", which then rejected +// every true read after it. So three agreeing reads in a row far from the +// last mean the last read was the wrong one, and they are taken. +class DistanceReads{ +public: + std::optional last() const{ + return m_last; + } + + // Whether `distance` (a read above 0) is taken as the last read. + bool accept(int distance){ + if (m_last && !near(distance, *m_last)){ + m_rejected = m_rejected_read && near(distance, *m_rejected_read) ? m_rejected + 1 : 1; + m_rejected_read = distance; + if (m_rejected < 3){ + return false; + } + } + m_rejected_read.reset(); + m_rejected = 0; + m_last = distance; + return true; + } + +private: + static bool near(int a, int b){ + return a >= b - 12 && a <= b + 12; + } + + std::optional m_last; + // Reads far from `m_last` in a row that agree with each other. + std::optional m_rejected_read; + int m_rejected = 0; +}; + +// How one step of ObjectiveWalk ended. +enum class ObjectiveStep{ + WALKING, // on toward the marker + ARRIVED, // within the distance asked, or (stop at 0) a prompt or a dialog shows + LOST, // the marker did not show for 12 camera turns +}; + +// walk_to_objective()'s walk, one look and one move at a time. +class ObjectiveWalk{ +public: + ObjectiveWalk(ConsoleHandle& console, ProControllerContext& context, int stop_at) + : m_console(console) + , m_context(context) + , m_stop_at(stop_at) + {} + + std::optional last() const{ + return m_reads.last(); + } + + // Reads the screen, then turns the camera or walks a step. + ObjectiveStep step(){ + m_context.wait_for_all_requests(); + const VideoSnapshot frame = m_console.video().snapshot(); + const ScreenEvents events = m_observer.observe(frame, current_time()); + if (m_stop_at <= 0 && events.any_of({ScreenEvent::INTERACT_PROMPT, ScreenEvent::DIALOG_BOX})){ + return ObjectiveStep::ARRIVED; + } + const std::optional marker = read_objective_marker(m_console, frame); + if (!marker){ + return look_behind(); + } + m_unseen = 0; + m_last_x = marker->x; + if (turn_to_pinned_marker(m_context, marker->x)){ + return ObjectiveStep::WALKING; + } + if (marker->distance > 0 && on_distance(*marker) == ObjectiveStep::ARRIVED){ + return ObjectiveStep::ARRIVED; + } + steer_and_step(m_context, marker->x); + return ObjectiveStep::WALKING; + } + +private: + // The marker is behind us: turn the camera, toward where it was last, + // until it shows. + ObjectiveStep look_behind(){ + if (++m_unseen > 12){ + return ObjectiveStep::LOST; + } + pbf_move_right_joystick(m_context, {m_last_x < 0.5 ? -0.5 : 0.5, 0}, 500ms, 200ms); + return ObjectiveStep::WALKING; + } + + // A distance read above 0: dropped as a misread (a step on), taken + // and within `m_stop_at` (arrived), or taken, with a sidestep when the + // walk is held up. + ObjectiveStep on_distance(const ObjectiveMarker& marker){ + const std::optional before = m_reads.last(); + if (!m_reads.accept(marker.distance)){ + return ObjectiveStep::WALKING; + } + if (before != marker.distance){ + m_console.log(std::format("walk_to_objective(): {} to go, marker at x = {:.2f}.", marker.distance, marker.x)); + } + if (marker.distance <= m_stop_at){ + m_console.log(std::format("walk_to_objective(): {} to the objective.", marker.distance)); + return ObjectiveStep::ARRIVED; + } + if (m_stuck.stuck(marker.distance)){ + m_stuck.sidestep(m_console, m_context); + } + return ObjectiveStep::WALKING; + } + + ConsoleHandle& m_console; + ProControllerContext& m_context; + const int m_stop_at; + PlzaScreenObserver m_observer; + DistanceReads m_reads; + StuckWatch m_stuck; + int m_unseen = 0; + double m_last_x = 0.5; +}; + +} // namespace + + +std::optional walk_to_objective(ConsoleHandle& console, ProControllerContext& context, int stop_at, Milliseconds limit){ + const WallClock deadline = current_time() + limit; + ObjectiveWalk walk(console, context, stop_at); + while (current_time() < deadline){ + switch (walk.step()){ + case ObjectiveStep::WALKING: + break; + case ObjectiveStep::ARRIVED: + return walk.last(); + case ObjectiveStep::LOST: + return std::nullopt; + } + } + console.log(std::format("walk_to_objective(): not within {} in time (last read {}).", stop_at, walk.last().value_or(-1))); + return walk.last(); +} + +namespace{ + +// Walks to stop `stop` from `last` (nothing: from the start, further +// out than every stop), toward the objective or back from it. +std::optional walk_to_stop(ConsoleHandle& console, ProControllerContext& context, std::optional last, int stop){ + if (last && stop > *last){ + return walk_from_objective(console, context, stop, 30s); + } + return walk_to_objective(console, context, stop, last ? 30s : 90s); +} + +// The patrol's visits to CATCH_SPOTS at most (5 rounds). +constexpr size_t PATROL_VISITS = 10; + +// Steps sideways with the camera on the objective (face_objective()): +// right onto the middle of the road, or back left (ROAD_MIDDLE_STEP). +void step_across_road(ConsoleHandle& console, ProControllerContext& context, bool right){ + face_objective(console, context); + pbf_move_left_joystick(context, {right ? 1.0 : -1.0, 0}, ROAD_MIDDLE_STEP, 300ms); + context.wait_for_all_requests(); +} + +// catch_at_stop() at the user's two catch spots (CATCH_SPOTS, 100 and +// 60), back and forth (PATROL_VISITS visits), 10 minutes at most: at each, +// a step right to the middle of the road first and back left after, so +// the walks between the spots go as before; it turns back at once where a +// new species was caught (spot_visit()). A wild battle that starts on the +// way is fought at the next stop. +// The party bar's filled slots, read before the first stop and after each +// stop that threw, end it at `goal.dex_species` (party_has_species()). +struct Patrol{ + GrassCatches catches; + // The party bar's filled slots at the last read; none: not read. + std::optional party_slots; +}; + +// The party bar's filled slots, when the bar shows within 2 s (none: it +// did not, a dialog or a fade still on; or it read no slot, a misread). +std::optional read_party_slots(ConsoleHandle& console, ProControllerContext& context){ + context.wait_for_all_requests(); + DetectorToFinder bar("PartyBarWatcher", 100ms, COLOR_RED, &console.overlay()); + if (wait_until(console, context, 2s, {bar}) < 0){ + console.log("catch_in_zone(): the party bar did not show within 2 s: its slots not read."); + return std::nullopt; + } + console.log(std::format("catch_in_zone(): the party bar shows {} filled slots.", bar.filled_slots())); + if (bar.filled_slots() == 0){ + return std::nullopt; + } + return bar.filled_slots(); +} + +Patrol patrol_and_catch( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai, const ZoneCatchGoal& goal +){ + const std::vector stops = alternating_stops(CATCH_SPOTS, PATROL_VISITS); + const WallClock deadline = current_time() + 10min; + Patrol patrol; + GrassCatches& result = patrol.catches; + patrol.party_slots = read_party_slots(console, context); + if (party_has_species(patrol.party_slots, goal.dex_species)){ + console.log(std::format("catch_in_zone(): the party already holds {} species: nothing to catch.", goal.dex_species)); + return patrol; + } + std::vector caught_at; + std::optional last; + for (size_t i = 0; i < stops.size() && result.found < goal.new_species && result.throws < goal.max_throws; i++){ + if (current_time() > deadline){ + console.log("catch_in_zone(): out of time for the patrol."); + break; + } + const std::optional at = walk_to_stop(console, context, last, stops[i]); + last = at ? at : stops[i]; + if (spot_visit(stops[i], caught_at) == SpotVisit::TURN_BACK && !wild_battle_on(console, context)){ + console.log(std::format("catch_in_zone(): stop {} of {} at {} (for {}): a new species was caught here: turning back.", i + 1, stops.size(), at.value_or(-1), stops[i])); + continue; + } + step_across_road(console, context, true); + const GrassCatches stop = catch_at_stop( + env, console, context, battle_ai, at.value_or(-1), goal.max_throws - result.throws + ); + step_across_road(console, context, false); + console.log(std::format( + "catch_in_zone(): stop {} of {} at {} (for {}): {} throws, {} new species, {} locks on caught species only.", + i + 1, stops.size(), at.value_or(-1), stops[i], stop.throws, stop.found, stop.caught_seen + )); + result += stop; + if (stop.found > 0){ + caught_at.push_back(stops[i]); + } + if (stop.throws > 0){ + patrol.party_slots = read_party_slots(console, context); + if (party_has_species(patrol.party_slots, goal.dex_species)){ + console.log(std::format("catch_in_zone(): the party holds {} species: the patrol is done.", goal.dex_species)); + break; + } + } + } + return patrol; +} + +// The Pokedex's count of registered species. Not read yet: there is no +// reader for the Pokedex screen (no frames of it to build one from), so +// the count is left unread and catch_in_zone() keeps its own tally. The +// menu is not opened until the reader can read what it shows. +std::optional read_dex_species_count(ConsoleHandle& console){ + console.log("catch_in_zone(): the Pokedex's count is wanted, but there is no reader for its screen yet: keeping the tally."); + return std::nullopt; +} + +} // namespace + + +void catch_in_zone( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai, const ZoneCatchGoal& goal +){ + // Taunie's two rocks stand between the start and the marker: a step + // right first, around them, from the start (a catch's autosave can + // leave the save further on). + context.wait_for_all_requests(); + const std::optional start = read_objective_marker(console, console.video().snapshot()); + if (start && start->distance >= 115){ + pbf_move_left_joystick(context, {1, 0}, 1000ms, 300ms); + } + const Patrol patrol = patrol_and_catch(env, console, context, battle_ai, goal); + const GrassCatches& result = patrol.catches; + const SpeciesTally tally = species_tally(result, goal.new_species); + console.log(std::format( + "catch_in_zone(): {} new species ({} by a plate only) in {} throws, {} locks on caught species only: {}; the party bar: {}.", + result.found, result.found_by_plate, result.throws, result.caught_seen, species_tally_text(tally), + patrol.party_slots ? std::format("{} filled slots", *patrol.party_slots) : std::string("not read") + )); + if (party_has_species(patrol.party_slots, goal.dex_species)){ + return; + } + // The party bar's count, read, stands in for the Pokedex's. + std::optional dex_count = patrol.party_slots; + if (!dex_count && read_dex_count(goal.checks, tally)){ + dex_count = read_dex_species_count(console); + } + if (!enough_species(tally, dex_count, goal.dex_species)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + dex_count + ? std::format("catch_in_zone(): the party holds {} species of {} ({} new by the banners in {} throws).", *dex_count, goal.dex_species, result.found, result.throws) + : std::format("catch_in_zone(): {} new species of {} in {} throws.", result.found, goal.new_species, result.throws), + console + ); + } +} + +// How long walk_to_marker() waits, after the walk, for the objective's +// prompt or dialog. A scene at the objective (03.09's lab gate) takes the +// marker away first and starts its talk 9 to 11 s later +// (three runs saw the dialog only at the end of the walk's +// camera sweep, the fourth missed it). +constexpr std::chrono::milliseconds MARKER_SCENE_WAIT = 15000ms; + +void walk_to_marker(ConsoleHandle& console, ProControllerContext& context){ + walk_to_objective(console, context, 0, 90s); + PlzaScreenObserver observer; + const WallClock deadline = current_time() + MARKER_SCENE_WAIT; + bool arrived = false; + while (true){ + context.wait_for_all_requests(); + const ScreenEvents events = observer.observe(console.video().snapshot(), current_time()); + if (events.any_of({ScreenEvent::INTERACT_PROMPT, ScreenEvent::DIALOG_BOX})){ + arrived = true; + break; + } + if (current_time() >= deadline){ + break; + } + context.wait_for(250ms); + } + if (!arrived){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "walk_to_marker(): no A prompt or dialog at the objective.", + console + ); + } +} + +namespace{ + +// The objective's distance on the screen now, if it reads. +std::optional objective_distance_now(ConsoleHandle& console, ProControllerContext& context){ + context.wait_for_all_requests(); + const std::optional marker = read_objective_marker(console, console.video().snapshot()); + if (!marker || marker->distance <= 0){ + return std::nullopt; + } + return marker->distance; +} + +} // namespace + +void walk_back_to_zone_road(ConsoleHandle& console, ProControllerContext& context){ + std::optional at = objective_distance_now(console, context); + for (int stop : road_stops_to_gate(CATCH_SPOTS, at)){ + console.log(std::format("walk_back_to_zone_road(): to {} on the road, from {}.", stop, at.value_or(-1))); + const bool toward = !at || stop <= *at; + const std::optional reached = walk_to_stop(console, context, at, stop); + const bool arrived = reached && (toward ? *reached <= stop + ROAD_STOP_SLACK : *reached >= stop - ROAD_STOP_SLACK); + if (!arrived){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("walk_back_to_zone_road(): not back on the road at {} (last read {}).", stop, reached.value_or(-1)), + console + ); + } + at = reached; + } + face_objective(console, context); +} + +namespace{ + +// Whether lock-on brackets show around a wild Pokemon within `limit`, +// looking every 250 ms with ZL let go. +bool brackets_show(ConsoleHandle& console, ProControllerContext& context, Milliseconds limit){ + context.wait_for_all_requests(); + const WallClock end = current_time() + limit; + while (true){ + const std::optional seen = read_brackets(console); + if (seen){ + console.log(std::format("catch_tutorial(): brackets at ({:.2f}, {:.2f}), {:.3f} tall.", seen->x, seen->y, seen->height)); + return true; + } + if (current_time() >= end){ + return false; + } + context.wait_for(250ms); + } +} + +} // namespace + +void catch_tutorial( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai, int max_throws +){ + int throws = 0; + while (throws < max_throws){ + // Fletchling, the tutorial's target, is never caught yet: the + // throw goes at whatever the choice locked on to. + const TargetChoice choice = aim_choose_approach(console, context, "catch_tutorial()"); + // Nothing to lock on to and no brackets before the first throw: + // the player is not where the tutorial is (a wrong save), so the + // balls would go at a wall. + if (throws == 0 && !choice.target && !brackets_show(console, context, 3000ms)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "catch_tutorial(): no lock-on target or brackets before the first throw.", + console + ); + } + throw_ball(console, context); + throws++; + if (advance_text_and_cards(console, context).card){ + console.log(std::format("catch_tutorial(): caught on throw {}.", throws)); + return; + } + if (throws < max_throws && wild_battle_on(console, context)){ + console.log(std::format("catch_tutorial(): throw {} broke out: battle, weakening.", throws)); + const WeakenThrows weakened = weaken_then_throw( + env, console, context, battle_ai, CatchSign::CARD, max_throws - throws, "catch_tutorial()" + ); + throws += weakened.throws; + if (weakened.caught){ + console.log(std::format("catch_tutorial(): caught on throw {}.", throws)); + return; + } + } + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("catch_tutorial(): no catch in {} throws.", max_throws), + console + ); +} + +void battle_then_catch( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai, int max_rounds +){ + // D-pad up is ignored while Bunnelby's "weaken it" banner shows. + pbf_press_button(context, BUTTON_A, 160ms, 840ms); + advance_text_and_cards(console, context); + pbf_press_dpad(context, DPAD_UP, 100ms, 2000ms); + if (weaken_then_throw(env, console, context, battle_ai, CatchSign::NO_TARGET, max_rounds, "battle_then_catch()").caught){ + return; + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("battle_then_catch(): still a target after {} rounds.", max_rounds), + console + ); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h new file mode 100644 index 0000000000..e7e2a8712c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h @@ -0,0 +1,125 @@ +/* PokemonLZA AutoStory - Catches + * + * From: https://github.com/PokemonAutomation/ + * + * Wild Zone 1's catches (03.07's tutorial, 03.08's five species), from + * . + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryCatches_H +#define PokemonAutomation_PokemonLZA_AutoStoryCatches_H + +#include +#include "Common/Cpp/Time.h" +#include "CommonFramework/Tools/ProgramEnvironment.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" +#include "VideoGames/PokemonLZA/Options/PokemonLZA_BattleAIOption.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// 03.07's first catch (Fletchling): ZL locks on, ZL+ZR held 1.5 s throws +// (0.5 s only aims). A break-out brings two or three lines from Taunie and +// control back; the catch brings her lines and then the "Battling wild +// Pokemon" cards. So: lock with ZL held, choose +// the nearest target and walk toward it when far (as catch_in_zone() +// does), throw, A through her lines, again until a card shows, then A +// through the cards. When a +// break-out starts a wild battle, the rest of the throws go after +// `battle_ai`'s attacks (weaken_then_throw). Throws +// OperationFailedException after `max_throws` throws with no card. +void catch_tutorial( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai, int max_throws +); + +// 03.07's second catch (Bunnelby), after the cards: A past its "weaken +// it" banner (D-pad up is ignored while it shows), D-pad up sends the +// partner out (again, twice at most per round, after two lock-ons with no +// move symbols), then rounds of TrainerBattleState attacks (3 that land), +// a throw and A through any lines (weaken_then_throw), until no target +// locks on for a round: caught. Throws OperationFailedException after +// `max_rounds`. +void battle_then_catch( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai, int max_rounds +); + +// Walks toward the objective marker (read_objective_marker()): turns the camera to keep it in the +// middle (to find it when it is behind) and walks on, until its distance +// reads `stop_at` or less, or (with `stop_at` 0) an A prompt or a dialog +// shows, or `limit`. Returns the last distance read. +std::optional walk_to_objective(ConsoleHandle& console, ProControllerContext& context, int stop_at, Milliseconds limit); + +// What catch_in_zone() is after: `new_species` new species caught, so +// the Pokedex has `dex_species`, in `max_throws` at most; `checks` is the +// run's check level. +struct ZoneCatchGoal{ + int new_species = 0; + int dex_species = 0; + int max_throws = 0; + Pokemon::StoryCheckLevel checks = Pokemon::StoryCheckLevel::DEFAULT; +}; + +// 03.08's catches for the "register five species" quest (3/5 after the +// tutorial): walks toward the objective (Wild Zone 1's far gate, around +// Taunie's rocks from the start), then goes back and forth between the +// user's two catch spots (CATCH_SPOTS): 100 from the objective +// (Scatterbug on the plaza's road) and 60 (Mareep by the gate), +// PATROL_VISITS visits, 10 minutes at most. At each stop +// it fights a wild battle that is on (the Run prompt, or the alert eye of +// a wild Pokemon attacking: one of a species already caught is fought +// off, others weakened and caught), else watches for the lock-on +// brackets the game draws around one wild Pokemon (6 s at most), turns +// the camera to the tallest (the nearest), holds ZL until the target's +// name plate shows the lock (3 s at most), cycles the targets with ZL held, walks toward +// the nearest one not caught when it is far, and throws without letting +// ZL go, counting the Pokedex's "Registered!" banners. A break-out that +// starts a wild battle gets `battle_ai`'s attacks before the next throws. +// The overworld party bar's filled slots (PartyBarDetector), read before +// the first stop and after each stop that threw, end the patrol at +// `goal.dex_species` (party_has_species()): every catch is a new species, +// so the filled slots are the registered species, and the banner is +// missed at times. When only species already caught lock on (a rerun +// from a save after the catch), the quest is taken as done. Unread, the +// Pokedex's count is read when the tally is not all banners, or at +// THOROUGH and TESTING checks (read_dex_count()), and then decides +// (enough_species()). Throws OperationFailedException, still in the zone, +// when short of `goal.dex_species` in the party bar or the Pokedex or, +// unread, of `goal.new_species` new species after the patrol or +// `goal.max_throws`. +void catch_in_zone( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai, const ZoneCatchGoal& goal +); + +// On to the objective marker until an A prompt (a gate's "Leave", a door's +// "Enter") or a dialog (a scene that starts on arriving) shows. Where a +// walk starts facing whichever way the last scene left the player (out of +// a wild zone's gate), the marker sets the way, not timed legs (03.08, +// the console). Throws OperationFailedException when neither +// shows within 90 s. +void walk_to_marker(ConsoleHandle& console, ProControllerContext& context); + +// 03.08, after the catches: back onto the road at the catch spots +// (road_stops_to_gate()), ending at the one nearest the far gate (60), +// facing the objective marker. From 60 the far gate's pillars are straight +// down the road, some 5 s on; the marker is not on the gate but past it +// and to its left, behind the zone's fence, so a walk at the marker was +// held up at 36 and wandered off. +// The walk through the gate is walk_to_zone_gate_entrance()'s, steered by +// the pillars on screen. Throws OperationFailedException when a road stop +// is not reached. +void walk_back_to_zone_road(ConsoleHandle& console, ProControllerContext& context); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.cpp new file mode 100644 index 0000000000..a5cb5c1595 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.cpp @@ -0,0 +1,102 @@ +/* PokemonLZA AutoStory - Walks back from the objective marker + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMinimapZoneDetector.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryObjectiveMarkerReader.h" +#include "PokemonLZA_AutoStoryBracketWatch.h" +#include "PokemonLZA_AutoStoryCatches.h" +#include "PokemonLZA_AutoStoryMarkerWalks.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; + + +// the right stick down held 1500 ms pins the +// pitch at its lowest; from there the stick up held 600 ms gives the +// walking pitch (400 ms is still too low, 1000 ms looks at the sky). +constexpr Milliseconds CAMERA_PITCH_DOWN_HOLD = 1500ms; +constexpr Milliseconds CAMERA_PITCH_UP_HOLD = 600ms; + +void level_camera(ConsoleHandle& console, ProControllerContext& context){ + console.log("level_camera(): pitch reset"); + pbf_move_right_joystick(context, {0, -1}, CAMERA_PITCH_DOWN_HOLD, 100ms); + pbf_move_right_joystick(context, {0, 1}, CAMERA_PITCH_UP_HOLD, 300ms); +} + +bool turn_to_pinned_marker(ProControllerContext& context, double x){ + if (x >= 0.10 && x <= 0.90){ + return false; + } + pbf_move_right_joystick(context, {x < 0.5 ? -0.5 : 0.5, 0}, 400ms, 200ms); + return true; +} + +std::optional walk_from_objective(ConsoleHandle& console, ProControllerContext& context, int stop_at, Milliseconds limit){ + const WallClock deadline = current_time() + limit; + std::optional last; + while (current_time() < deadline){ + context.wait_for_all_requests(); + const std::optional marker = read_objective_marker(console, console.video().snapshot()); + if (marker && turn_to_pinned_marker(context, marker->x)){ + continue; + } + if (marker && marker->distance > 0 && (!last || std::abs(marker->distance - *last) <= 12)){ + last = marker->distance; + if (*last >= stop_at){ + console.log(std::format("walk_from_objective(): {} from the objective.", *last)); + return last; + } + } + // Back in the middle before each step: walking toward the camera + // turns it, so with no steering the walk from 60 to 100 bent off + // the road (held up at 103). + const CameraTurn turn = marker ? camera_turn_toward(marker->x) : CameraTurn{}; + if (turn.time.count() > 0){ + pbf_move_right_joystick(context, {turn.stick_x, 0}, turn.time, 150ms); + } + pbf_move_left_joystick(context, {0, -1}, 600ms, 0ms); + } + console.log(std::format("walk_from_objective(): not back to {} in time (last read {}).", stop_at, last.value_or(-1))); + return last; +} + +void check_out_of_wild_zone(ConsoleHandle& console, ProControllerContext& context){ + MinimapZoneDetector zone; + for (int look = 0; look < 4; look++){ + if (look > 0){ + // On, away from the gate: just outside it the arrow still + // touches the zone's green edge. + pbf_move_left_joystick(context, {0, 1}, 600ms, 200ms); + } + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + if (frame && !zone.detect(frame)){ + console.log(std::format("check_out_of_wild_zone(): the minimap's arrow is out of the zone's green (look {}).", look + 1)); + return; + } + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "check_out_of_wild_zone(): the minimap's arrow is still in the wild zone's green after the gate.", + console + ); +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.h new file mode 100644 index 0000000000..d268f4836f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.h @@ -0,0 +1,55 @@ +/* PokemonLZA AutoStory - Walks by the objective marker's distance + * + * From: https://github.com/PokemonAutomation/ + * + * Walks that keep the camera on the main mission's objective marker + * (read_objective_marker(), PokemonLZA_AutoStoryObjectiveMarkerReader.h) + * and stop at a distance it reads: 03.08's road stops back from it. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryMarkerWalks_H +#define PokemonAutomation_PokemonLZA_AutoStoryMarkerWalks_H + +#include +#include "Common/Cpp/Time.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Off screen, the game pins the marker to the edge with no digits +// (anything read there is noise): turns the camera to it. Returns whether +// the marker at `x` (0 to 1) was pinned. +bool turn_to_pinned_marker(ProControllerContext& context, double x); + +// A ZL lock-on and throw leave the camera looking steeply down, and every +// later sweep for brackets sees only the ground. Pins the pitch at its +// lowest (the right stick down), then tips it up to the walking pitch +// (horizon in the middle, far markers in the upper third). +void level_camera(ConsoleHandle& console, ProControllerContext& context); + +// Walks back away from the objective marker (the stick down: toward the +// camera, turned back onto the marker before each step) until its distance reads `stop_at` +// or more, or `limit`. A read more than 12 from the last is a misread, as +// in walk_to_objective(). Returns the last distance read. +std::optional walk_from_objective(ConsoleHandle& console, ProControllerContext& context, int stop_at, Milliseconds limit); + +// After A at a wild zone's gate on the way out: the minimap's player arrow +// out of the zone's green (MinimapZoneDetector) on one of 4 looks, walking +// on 600 ms away from the gate before each look after the first: just +// outside the gate the arrow still touches the green's edge. +// An A the game dropped leaves the player at the gate inside the +// zone with the step after it passing on the prompt and party bar (the +// fault sweep's lost tap). Throws OperationFailedException when the arrow +// stays in the green. +void check_out_of_wild_zone(ConsoleHandle& console, ProControllerContext& context); + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index b1e9b02f1f..a664991553 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2410,6 +2410,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatchStop.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatchStop_Tests.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatchStop_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp @@ -2418,6 +2420,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryGateWalk.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryGateWalk.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp From 106b9d9d3de5eac708effa87098ecf30fc4c5ff6 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 03:39:51 -0800 Subject: [PATCH 2/3] PokemonLZA AutoStory: walk_from_objective() drops misreads with DistanceReads walk_from_objective() kept the first read and dropped any read more than 12 from it, so a misread first read (36 as "3", 110 as "1110") rejected every true read after it, and a high one could end the walk early. DistanceReads moves from Catches.cpp to MarkerWalks.h and both walks use it. Also: Catches.h's header sentence is finished, MARKER_SCENE_WAIT is Milliseconds, and the camera-pitch comment names level_camera(). --- .../Actions/PokemonLZA_AutoStoryCatches.cpp | 39 +--------------- .../Actions/PokemonLZA_AutoStoryCatches.h | 3 +- .../PokemonLZA_AutoStoryMarkerWalks.cpp | 45 ++++++++++++++----- .../Actions/PokemonLZA_AutoStoryMarkerWalks.h | 26 ++++++++++- 4 files changed, 59 insertions(+), 54 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp index 9ccd9cc059..471cf148bc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp @@ -609,43 +609,6 @@ class StuckWatch{ int m_sidesteps = 0; }; -// The marker's distance reads, with misreads dropped. A read far from the -// last one is a misread: a 0.6 s step covers about 3. Below: 36 as "3" or -// 29 on the console; above: 110 as "1110", which then rejected -// every true read after it. So three agreeing reads in a row far from the -// last mean the last read was the wrong one, and they are taken. -class DistanceReads{ -public: - std::optional last() const{ - return m_last; - } - - // Whether `distance` (a read above 0) is taken as the last read. - bool accept(int distance){ - if (m_last && !near(distance, *m_last)){ - m_rejected = m_rejected_read && near(distance, *m_rejected_read) ? m_rejected + 1 : 1; - m_rejected_read = distance; - if (m_rejected < 3){ - return false; - } - } - m_rejected_read.reset(); - m_rejected = 0; - m_last = distance; - return true; - } - -private: - static bool near(int a, int b){ - return a >= b - 12 && a <= b + 12; - } - - std::optional m_last; - // Reads far from `m_last` in a row that agree with each other. - std::optional m_rejected_read; - int m_rejected = 0; -}; - // How one step of ObjectiveWalk ended. enum class ObjectiveStep{ WALKING, // on toward the marker @@ -910,7 +873,7 @@ void catch_in_zone( // marker away first and starts its talk 9 to 11 s later // (three runs saw the dialog only at the end of the walk's // camera sweep, the fourth missed it). -constexpr std::chrono::milliseconds MARKER_SCENE_WAIT = 15000ms; +constexpr Milliseconds MARKER_SCENE_WAIT = 15000ms; void walk_to_marker(ConsoleHandle& console, ProControllerContext& context){ walk_to_objective(console, context, 0, 90s); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h index e7e2a8712c..337dc14413 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h @@ -2,8 +2,7 @@ * * From: https://github.com/PokemonAutomation/ * - * Wild Zone 1's catches (03.07's tutorial, 03.08's five species), from - * . + * Wild Zone 1's catches (03.07's tutorial, 03.08's five species). * */ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.cpp index a5cb5c1595..03c1de66ef 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.cpp @@ -25,9 +25,33 @@ namespace PokemonLZA{ using namespace std::chrono_literals; -// the right stick down held 1500 ms pins the -// pitch at its lowest; from there the stick up held 600 ms gives the -// walking pitch (400 ms is still too low, 1000 ms looks at the sky). +namespace{ + +// Whether two distance reads agree: within what a few steps cover. +bool reads_agree(int a, int b){ + return a >= b - 12 && a <= b + 12; +} + +} // namespace + +bool DistanceReads::accept(int distance){ + if (m_last && !reads_agree(distance, *m_last)){ + m_rejected = m_rejected_read && reads_agree(distance, *m_rejected_read) ? m_rejected + 1 : 1; + m_rejected_read = distance; + if (m_rejected < 3){ + return false; + } + } + m_rejected_read.reset(); + m_rejected = 0; + m_last = distance; + return true; +} + + +// level_camera() holds the right stick down 1500 ms to pin the pitch at +// its lowest, then up 600 ms for the walking pitch (400 ms is still too +// low, 1000 ms looks at the sky). constexpr Milliseconds CAMERA_PITCH_DOWN_HOLD = 1500ms; constexpr Milliseconds CAMERA_PITCH_UP_HOLD = 600ms; @@ -47,19 +71,16 @@ bool turn_to_pinned_marker(ProControllerContext& context, double x){ std::optional walk_from_objective(ConsoleHandle& console, ProControllerContext& context, int stop_at, Milliseconds limit){ const WallClock deadline = current_time() + limit; - std::optional last; + DistanceReads reads; while (current_time() < deadline){ context.wait_for_all_requests(); const std::optional marker = read_objective_marker(console, console.video().snapshot()); if (marker && turn_to_pinned_marker(context, marker->x)){ continue; } - if (marker && marker->distance > 0 && (!last || std::abs(marker->distance - *last) <= 12)){ - last = marker->distance; - if (*last >= stop_at){ - console.log(std::format("walk_from_objective(): {} from the objective.", *last)); - return last; - } + if (marker && marker->distance > 0 && reads.accept(marker->distance) && *reads.last() >= stop_at){ + console.log(std::format("walk_from_objective(): {} from the objective.", *reads.last())); + return reads.last(); } // Back in the middle before each step: walking toward the camera // turns it, so with no steering the walk from 60 to 100 bent off @@ -70,8 +91,8 @@ std::optional walk_from_objective(ConsoleHandle& console, ProControllerCont } pbf_move_left_joystick(context, {0, -1}, 600ms, 0ms); } - console.log(std::format("walk_from_objective(): not back to {} in time (last read {}).", stop_at, last.value_or(-1))); - return last; + console.log(std::format("walk_from_objective(): not back to {} in time (last read {}).", stop_at, reads.last().value_or(-1))); + return reads.last(); } void check_out_of_wild_zone(ConsoleHandle& console, ProControllerContext& context){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.h index d268f4836f..980d29c2df 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalks.h @@ -32,10 +32,32 @@ bool turn_to_pinned_marker(ProControllerContext& context, double x); // (horizon in the middle, far markers in the upper third). void level_camera(ConsoleHandle& console, ProControllerContext& context); +// The marker's distance reads, with misreads dropped. A read far from the +// last one is a misread: a 0.6 s step covers about 3. Below: 36 can read +// as "3" or 29; above: 110 as "1110", which would then reject every true +// read after it. So three agreeing reads in a row far from the last mean +// the last read was the wrong one, and they are taken. +class DistanceReads{ +public: + std::optional last() const{ + return m_last; + } + + // Whether `distance` (a read above 0) is taken as the last read. + bool accept(int distance); + +private: + std::optional m_last; + // Reads far from `m_last` in a row that agree with each other. + std::optional m_rejected_read; + int m_rejected = 0; +}; + + // Walks back away from the objective marker (the stick down: toward the // camera, turned back onto the marker before each step) until its distance reads `stop_at` -// or more, or `limit`. A read more than 12 from the last is a misread, as -// in walk_to_objective(). Returns the last distance read. +// or more, or `limit`. Misreads are dropped by DistanceReads, as in +// walk_to_objective(). Returns the last distance read. std::optional walk_from_objective(ConsoleHandle& console, ProControllerContext& context, int stop_at, Milliseconds limit); // After A at a wild zone's gate on the way out: the minimap's player arrow From cc98340be0c0f447caa6b585a922f096e432198a Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 12:33:55 -0800 Subject: [PATCH 3/3] PokemonLZA AutoStory: throw_ball() watches with run_until() and an extra wait Callers only tested for a seen banner; it now returns that bool. --- .../Actions/PokemonLZA_AutoStoryCatches.cpp | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp index 471cf148bc..5a44a701e1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp @@ -49,29 +49,33 @@ ScreensPassed advance_text_and_cards(ConsoleHandle& console, ProControllerContex // ZL held 0.5 s, then ZL+ZR held 1.5 s (ZL never let go from the lock; 0.5 s // of ZR only aims) throws, then 8 s for the flight, shakes and the banner (it -// showed 6.9 s in, 03.08). Returns whether the Pokedex's "Registered!" banner -// (a new species) showed, judged on the frames watched: UNKNOWN when a gap -// could hide it (REGISTERED_BANNER_WATCH). +// showed 6.9 s in, 03.08), and REGISTERED_BANNER_EXTRA_WAIT more when it +// has not shown by then. Returns whether the Pokedex's "Registered!" banner +// (a new species) showed. // TODO: unify with the ZL + ZR throw of PokemonLZA_InPlaceCatcher.cpp and // AsyncCommandSession (CommonTools/Async/InterruptableCommands.h) - the // lock-on may drop between separate commands; needs a console test. -Pokemon::WatchResult throw_ball(ConsoleHandle& console, ProControllerContext& context){ +bool throw_ball(ConsoleHandle& console, ProControllerContext& context){ DetectorToFinder registered("DexRegisteredWatcher", REGISTERED_BANNER_HOLD); - const Pokemon::WatchResult banner = Pokemon::run_watched( + int ret = run_until( console, context, [](ProControllerContext& context){ pbf_controller_state(context, BUTTON_ZL, DPAD_NONE, {0, 0}, {0, 0}, 500ms); pbf_controller_state(context, BUTTON_ZL | BUTTON_ZR, DPAD_NONE, {0, 0}, {0, 0}, 1500ms); pbf_wait(context, 8000ms); }, - REGISTERED_BANNER_WATCH, registered + {registered} ); - console.log(std::format("throw_ball(): the Registered! banner: {}.", Pokemon::describe(banner))); - if (banner.verdict == Pokemon::WatchVerdict::SEEN){ + if (ret < 0){ + ret = wait_until(console, context, REGISTERED_BANNER_EXTRA_WAIT, {registered}); + } + const bool seen = ret == 0; + console.log(std::format("throw_ball(): the Registered! banner {}.", seen ? "showed" : "did not show")); + if (seen){ context.wait_for(3000ms); } context.wait_for_all_requests(); - return banner; + return seen; } // Whether a wild battle is on: its Run prompt ("-" at the left), which @@ -150,7 +154,7 @@ WeakenThrows weaken_then_throw( return out; } advance_text_and_cards(console, context); - const bool registered = throw_ball(console, context).verdict == Pokemon::WatchVerdict::SEEN; + const bool registered = throw_ball(console, context); out.throws++; const bool card = advance_text_and_cards(console, context).card; console.log(std::format("{}: round {}: {} attacks landed, then a throw.", caller, out.throws, landed)); @@ -344,7 +348,7 @@ GrassCatches throw_at_target( GrassCatches out; LockTarget aimed = target; while (out.throws < max_throws && out.throws < THROWS_AT_ONE_TARGET){ - const bool registered = throw_ball(console, context).verdict == Pokemon::WatchVerdict::SEEN; + const bool registered = throw_ball(console, context); out.throws++; advance_text_and_cards(console, context); const bool battle = !registered && wild_battle_on(console, context);