Skip to content
Merged
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
Expand Up @@ -21,22 +21,42 @@ constexpr int MARKER_NEAR = 20;
// the objective's (MarkerArrival::arrived()); also the least read taken
// first (MarkerArrival::look()).
constexpr int MARKER_PROMPT_NEAR = 10;
// How fast a walk can come nearer the marker, in meters a second, and
// how much more a read may drop for OCR's jitter. The walk that passed
// 03.09 in run 10 read 23 down to 12 in 3.2 s, 3.4 a second, with 16 to
// 12 in 0.64 s (console B, 2026-11-16 21:36:55 to 21:36:58).
constexpr int MARKER_MAX_SPEED = 5;
constexpr int MARKER_READ_JITTER = 2;

// Whether a walk can come from `from` to `to` in `time`.
bool can_come_near(int from, int to, Milliseconds time){
return (from - to - MARKER_READ_JITTER) * 1000 <= MARKER_MAX_SPEED * time.count();
}

} // namespace


bool MarkerArrival::look(const MarkerLook& look){
MarkerRead MarkerArrival::look(const MarkerLook& look){
const std::optional<int>& distance = look.distance;
bool taken = false;
const std::optional<int> last = m_distance.position();
MarkerRead read;
if (distance && *distance > 0 && (m_double_digits || *distance >= MARKER_PROMPT_NEAR)){
m_far_digits = m_far_digits || *distance > MARKER_NEAR;
taken = m_distance.read(*distance);
m_double_digits = m_double_digits || (taken && *distance >= MARKER_PROMPT_NEAR);
const Milliseconds since_taken = std::chrono::duration_cast<Milliseconds>(look.at - m_taken_at);
if (last && *distance <= MARKER_NEAR && !can_come_near(*last, *distance, since_taken)){
read.too_fast_after = since_taken;
}else{
m_far_digits = m_far_digits || *distance > MARKER_NEAR;
read.taken = m_distance.read(*distance);
m_double_digits = m_double_digits || (read.taken && *distance >= MARKER_PROMPT_NEAR);
}
if (read.taken){
m_taken_at = look.at;
}
}
const std::optional<int> at = m_distance.position();
const bool close_or_marker_gone = !look.marker_shows || !at || *at < MARKER_PROMPT_NEAR;
m_arrived = look.prompt_or_dialog && near() && close_or_marker_gone;
return taken;
return read;
}

bool MarkerArrival::near() const{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define PokemonAutomation_PokemonLZA_AutoStoryMarkerArrival_H

#include <optional>
#include "Common/Cpp/Time.h"
#include "PokemonLZA_AutoStoryMarkerDistance.h"

namespace PokemonAutomation{
Expand Down Expand Up @@ -41,6 +42,17 @@ struct MarkerLook{
bool marker_shows = true;
// An A prompt or a dialog shows.
bool prompt_or_dialog = false;
// When the look was taken.
WallClock at = {};
};

// What came of a look's distance read.
struct MarkerRead{
// Taken (MarkerDistance::read()).
bool taken = false;
// A read of 20 or less not taken because it is nearer than the walk
// can have come since the last read taken: the time since that read.
std::optional<Milliseconds> too_fast_after = std::nullopt;
};

// Where a walk to the objective's prompt is, one look at a time.
Expand All @@ -51,12 +63,16 @@ class MarkerArrival{
, m_distance(MarkerDirection::TOWARD, std::nullopt)
{}

// A look. Returns whether its distance is taken
// (MarkerDistance::read()).
// A look. Returns what came of its distance read (MarkerRead).
// A read below 10 is taken only after one of 10 or more: junk OCR
// ("E5", "v1", "E6") by a street dialog agreed on 6 at the start of
// 03.09's walk and passed it there (console B, 2026-11-16 18:47).
bool look(const MarkerLook& look);
// A read of 20 or less is taken only if the walk can have come that
// near since the last read taken: at Wild Zone 1's exit "1", "4" and
// "4" agreed on 4 5.4 s after 40 (the marker showed 39), and the exit
// pillar's prompt passed 03.09's walk there (console B, 2026-11-16
// 21:33).
MarkerRead look(const MarkerLook& look);

// Whether the last look showed an A prompt or a dialog with the walk
// near(), and, with the marker still up, with no read taken or the
Expand All @@ -80,6 +96,7 @@ class MarkerArrival{
private:
const MarkerProof m_proof;
MarkerDistance m_distance;
WallClock m_taken_at = {}; // when the last read taken was read
bool m_far_digits = false; // digits over 20 read on some look
bool m_double_digits = false; // a read of 10 or more taken
bool m_arrived = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
*/

#include <chrono>
#include <format>
#include <optional>
#include <string>
Expand All @@ -21,6 +22,7 @@ namespace PokemonLZA{
namespace{

using Look = MarkerLook;
using namespace std::chrono_literals;

constexpr std::optional<int> NO_DIGITS = std::nullopt;

Expand Down Expand Up @@ -50,6 +52,10 @@ struct ArrivalCase{
struct Input{
MarkerProof proof = MarkerProof::NEAR_READ;
std::vector<Look> looks = {};
// The time from one look to the next: 0.64 s on the walk that
// passed 03.09 in run 10 (console B, 2026-11-16 21:36:55 to
// 21:36:58).
Milliseconds look_period = 640ms;
};
Input input;
struct Expectation{
Expand All @@ -63,6 +69,43 @@ struct ArrivalCase{
};

const ArrivalCase ARRIVAL_CASES[] = {
{
// console B, 2026-11-16 21:33:36 to 21:33:50 (run 9): 40 taken at
// Wild Zone 1's exit, then "1", "0", "4" and "4" (the marker
// showed 39) agreed on 4 with the exit pillar's "Esci" prompt up,
// 5.4 s after 40, and the walk passed there.
.name = "03.09's walk: a read of 4 five seconds after 40 is a misread, so the exit's prompt is not the lab gate",
.input = {
.proof = MarkerProof::NEAR_READ,
.looks = concat(
reads({174, 1, NO_DIGITS, 731, 1, 51, 7, 5, 41, NO_DIGITS, 4, NO_DIGITS, NO_DIGITS, 40, NO_DIGITS, 1, NO_DIGITS, 4, NO_DIGITS, NO_DIGITS}),
{Look{.distance = 4, .marker_shows = true, .prompt_or_dialog = true}}
),
.look_period = 770ms,
},
.expectation = {.arrived_on = std::nullopt, .near = false},
},
{
// console B, 2026-11-16 21:36:55 to 21:36:58 (run 10, passed): 23
// down to 12 at 0.64 s a look, 16 to 12 in one.
.name = "a walk at full pace: 23 down to 8, then a prompt, is at the objective",
.input = {
.proof = MarkerProof::NEAR_READ,
.looks = concat(reads({23, 21, 18, 16, 12, 9}), {Look{.distance = 8, .marker_shows = true, .prompt_or_dialog = true}}),
},
.expectation = {.arrived_on = 7, .near = true},
},
{
.name = "40, then no digits for 7 s, then 9 and 8: the walk can have come that near",
.input = {
.proof = MarkerProof::NEAR_READ,
.looks = concat(
reads({46, 44, 42, 40, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, 9, 8}),
{Look{.distance = 8, .marker_shows = true, .prompt_or_dialog = true}}
),
},
.expectation = {.arrived_on = 17, .near = true},
},
{
// console B, 2026-11-16 17:34:33 to 17:34:37: 03.09's walk from
// the far gate read "t", "", "1" and nothing more, and passed on
Expand Down Expand Up @@ -177,7 +220,8 @@ UnitTestResult check_arrival(const ArrivalCase& test){
MarkerArrival arrival(test.input.proof);
std::optional<size_t> arrived_on;
for (size_t index = 0; index < test.input.looks.size() && !arrived_on; index++){
const Look& look = test.input.looks[index];
Look look = test.input.looks[index];
look.at = WallClock{} + test.input.look_period * index;
arrival.look(look);
if (arrival.arrived()){
arrived_on = index + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ class MarkerWalk{
bool at_objective(const ScreenObservation& look, const std::optional<ObjectiveMarker>& marker){
const bool prompt = look.events.has(ScreenEvent::INTERACT_PROMPT) || look.events.has(ScreenEvent::DIALOG_BOX);
const std::optional<int> read = marker && marker->distance > 0 ? std::optional<int>(marker->distance) : std::nullopt;
if (m_arrival.look(MarkerLook{.distance = read, .marker_shows = marker.has_value(), .prompt_or_dialog = prompt})){
on_distance(*read);
}
on_read(read, m_arrival.look(MarkerLook{
.distance = read, .marker_shows = marker.has_value(), .prompt_or_dialog = prompt, .at = current_time(),
}));
if (m_arrival.arrived()){
m_backend.log(std::format(
"[PLZA] walk_to_marker: a prompt or dialog near the objective (last read taken {})", m_arrival.position().value_or(-1)
Expand Down Expand Up @@ -253,6 +253,20 @@ class MarkerWalk{
return MarkerStep::WALKING;
}

// What came of `read` on a walk to the objective's prompt: a read
// taken goes on to on_distance(), one too near too soon is logged.
void on_read(std::optional<int> read, const MarkerRead& result){
if (result.taken){
on_distance(*read);
}
if (result.too_fast_after){
m_backend.log(std::format(
"[PLZA] walk_to_marker: read {} after {} in {:.1f} s: ignored",
*read, m_arrival.position().value_or(-1), result.too_fast_after->count() / 1000.0
));
}
}

// A taken read on a walk to the objective's prompt (no stop_at; a
// walk to a stop is held up by MarkerDistance): logged when it
// changes; 4 reads with no new best is a walk held up (the Research
Expand Down Expand Up @@ -328,6 +342,7 @@ bool objective_reached(StoryEnv& env, PlzaBackend& backend, MarkerArrival& arriv
.distance = std::nullopt,
.marker_shows = marker,
.prompt_or_dialog = look.events.has(ScreenEvent::INTERACT_PROMPT) || look.events.has(ScreenEvent::DIALOG_BOX),
.at = current_time(),
});
if (arrival.arrived()){
return true;
Expand Down
Loading