Skip to content
Closed
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 @@ -42,8 +42,10 @@ std::string waypoint_text(const MapWaypoint& waypoint){


std::optional<MapPoint> read_pin_on_map(StoryEnv& env, PlzaBackend& backend){
// No minimap arrow read here: indoors there is none, and the start
// check reads the pin there too (03.11's office threw after 40 s,
// console B 2026-11-17 01:29).
backend.observe();
const double heading = minimap_arrow(env)();
backend.press(BUTTON_PLUS, /*hold=*/100ms, /*release=*/MAP_OPEN_WAIT);
std::optional<MapPoint> pin;
for (int looks = 0; looks < PIN_LOOKS && !pin; looks++){
Expand All @@ -57,10 +59,7 @@ std::optional<MapPoint> read_pin_on_map(StoryEnv& env, PlzaBackend& backend){
}
}
backend.press(BUTTON_B, /*hold=*/100ms, /*release=*/MAP_CLOSE_WAIT);
backend.log(pin
? std::format("[PLZA] map pin: {} heading {:.0f}", pin_text(*pin), heading)
: std::format("[PLZA] map pin: none, heading {:.0f}", heading)
);
backend.log(pin ? std::format("[PLZA] map pin: {}", pin_text(*pin)) : std::string("[PLZA] map pin: none"));
return pin;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*
*/

#include <cmath>
#include <span>
#include "PokemonLZA_AutoStoryZone1Map.h"

namespace PokemonAutomation{
Expand All @@ -22,6 +24,58 @@ std::optional<MapWaypoint> catch_spot_waypoint(int spot){
}
}

namespace{

// Wild Zone 1's green outline on the full map, clockwise from its north
// west corner: traced on the map frames of console B (2026-11-16,
// zone1-map-after-try6 and zone1-map-at-north-fence), the bottom edge
// by the outline's lowest green in each column. Every pin read in the
// zone on console B (2026-11-16, 2026-11-17: the rocks (476, 224), the
// road entry, the 100 and 60 spots, the north fence (359, 227) and the
// catch west of the 60 spot (365, 257)) is inside it.
constexpr MapPoint ZONE1_OUTLINE[] = {
{.x = 281, .y = 199}, {.x = 506, .y = 199}, {.x = 515, .y = 218}, {.x = 510, .y = 226},
{.x = 500, .y = 230}, {.x = 450, .y = 248}, {.x = 400, .y = 260}, {.x = 370, .y = 265},
{.x = 359, .y = 264}, {.x = 357, .y = 248}, {.x = 281, .y = 249},
};

// Where the full map puts the player when the player is out of every
// wild zone: the map opens on the player, at its centre (400, 225),
// instead of on the zone. On the street outside the far gate (03.08b's
// menu save, the minimap's arrow by the gate's "!") the pin read
// (401, 225) and (401, 223) (console B, 2026-11-17 01:06), the middle of
// the zone's outline; no pin in the zone read within 15 of it. From these
// two reads only: no map frame of the street yet.
constexpr MapPoint MAP_CENTRE{.x = 400, .y = 225};
constexpr double MAP_CENTRE_RADIUS = 6;

// Whether `point` is inside the polygon `outline` (even-odd rule).
bool inside(std::span<const MapPoint> outline, MapPoint point){
bool in = false;
size_t previous = outline.size() - 1;
for (size_t index = 0; index < outline.size(); previous = index++){
const MapPoint& a = outline[index];
const MapPoint& b = outline[previous];
if ((a.y > point.y) == (b.y > point.y)){
continue;
}
const double crossing_x = a.x + (point.y - a.y) * (b.x - a.x) / (b.y - a.y);
if (point.x < crossing_x){
in = !in;
}
}
return in;
}

} // namespace

bool pin_in_zone_1(MapPoint pin){
if (std::hypot(pin.x - MAP_CENTRE.x, pin.y - MAP_CENTRE.y) <= MAP_CENTRE_RADIUS){
return false;
}
return inside(ZONE1_OUTLINE, pin);
}



} // namespace PokemonLZA
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* PokemonLZA AutoStory - Wild Zone 1 map

Check failure on line 1 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZone1Map.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

<header>: header_symbols=9, limit=8, allowed 8; split the header by concern, or move helpers into a detail namespace or the .cpp
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -67,6 +67,13 @@
std::optional<MapWaypoint> catch_spot_waypoint(int spot);


// Whether `pin`, a read of read_map_pin(), is in Wild Zone 1: inside the
// zone's outline on the full map, traced from console B's map frames,
// and not at the map's centre, where the map puts a player out of every
// wild zone (see the .cpp for both).
bool pin_in_zone_1(MapPoint pin);



} // namespace PokemonLZA
} // namespace NintendoSwitch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h"
#include "Pokemon/Pokemon_Strings.h"
#include "Actions/PokemonLZA_AutoStoryBackupSave.h"
#include "Actions/PokemonLZA_AutoStoryMapWalk.h"
#include "Actions/PokemonLZA_AutoStoryNewGame.h"
#include "PokemonLZA_AutoStoryBackups.h"
#include "PokemonLZA_AutoStoryGame.h"
Expand Down Expand Up @@ -164,20 +165,36 @@
return StartSignature{};
}

// Where the player stands: read_start_signature() and, when the overworld
// reads, wild_zone from the player's pin on the full map (PLUS opens it,
// B closes it: read_pin_on_map()).
StartSignature read_start_position(StoryEnv& story, PlzaBackend& backend){
StartSignature read = read_start_signature(story.env.console, story.context);
if (read != StartSignature{}){
read.wild_zone = wild_zone_from_map(read_pin_on_map(story, backend));
}
return read;
}

// The checkpoint a run asked to start at `plan.first` plays from: where the
// screen says the player is (run_start()), `first` or an earlier
// checkpoint. Throws OperationFailedException, with a screenshot, as
// screen and the map say the player is (run_start()), `first` or an
// earlier checkpoint. Throws OperationFailedException, with a screenshot, as
// "start_position_unknown" when the position matches no start: no
// checkpoint's events run from the wrong place. When `plan.max_rewinds`
// allows, an unknown start first rewinds to `backup` (start_or_rewind()).
size_t checked_first_row(
ConsoleHandle& console, ProControllerContext& context, PlzaBackend& backend,
const RewindPlan& plan, const BackupSave& backup
){
size_t checked_first_row(StoryEnv& story, PlzaBackend& backend, const RewindPlan& plan, const BackupSave& backup){

Check warning on line 185 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonLZA::checked_first_row( StoryEnv & story , PlzaBackend & backend , const RewindPlan & plan , const BackupSave & backup): function_lines=33 (advisory above 25, limit 50)
ConsoleHandle& console = story.env.console;
const std::span<const StoryCheckpoint> rows = plan.rows;
const size_t first = plan.first;
const std::span<const CheckpointStart> starts = plan.starts;
const StartSignature read = read_start_signature(console, context);
// A row with no start signature runs as it is: no screen read, no map
// (03.11's start indoors, the user 2026-11-17: "we don't need a start
// check for this checkpoint").
if (find_start(starts, rows[first].id) == nullptr){
console.log(std::format("AutoStory: {} has no start signature: running it, no start check", rows[first].id));
return first;
}
const StartSignature read = read_start_position(story, backend);
const std::optional<size_t> from = start_or_rewind(backend, plan, read, backup);
if (!from){
OperationFailedExceptionWithScreenshot::fire(
Expand All @@ -193,8 +210,6 @@
console.log(std::format(
"AutoStory: the save is at {}'s start ({}), not {}'s: running from {}", rows[*from].id, to_string(read), rows[first].id, rows[*from].id
));
}else if (find_start(starts, rows[first].id) == nullptr){
console.log(std::format("AutoStory: {} has no start signature to check the screen ({}) against: running it", rows[first].id, to_string(read)));
}else{
console.log(std::format("AutoStory: the screen ({}) is {}'s start", to_string(read), rows[first].id));
}
Expand Down Expand Up @@ -282,7 +297,7 @@
if (LOAD_SAVE_FIRST){
load_first_save(env.console, game, backend, rows[first]);
}
plan.first = checked_first_row(env.console, context, backend, plan, console_backup_save(story));
plan.first = checked_first_row(story, backend, plan, console_backup_save(story));
}

const SegmentReport report = run_plza_with_rewinds(game, plan, console_backup_save(story), backend, sightings, state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <string_view>
#include <vector>
#include "VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.h"
#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.h"
#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZone1Map.h"
#include "PokemonLZA_AutoStoryScreenEvents.h"
#include "PokemonLZA_AutoStoryStarts.h"

Expand Down Expand Up @@ -136,19 +136,24 @@ StartSignature read_start_screen(const ImageViewRGB32& screen){
if (unreadable){
return StartSignature{};
}
BattlePanelDetector lead_panel;
PartyBarDetector party_bar;
std::optional<size_t> party;
if (party_bar.detect(screen) && party_bar.filled_slots() > 0){
party = (size_t)party_bar.filled_slots();
}
return StartSignature{
.talk_prompt = events.has(ScreenEvent::INTERACT_PROMPT),
.wild_zone = lead_panel.detect(screen),
.party = party,
};
}

std::optional<bool> wild_zone_from_map(const std::optional<MapPoint>& pin){
if (!pin){
return std::nullopt;
}
return pin_in_zone_1(*pin);
}



} // namespace PokemonLZA
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* PokemonLZA AutoStory - Checkpoint starts

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStarts.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<header>: header_symbols=8 (advisory above 6, limit 8)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -22,6 +22,7 @@
#include <string>
#include <string_view>
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMapPinReader.h"
#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h"

namespace PokemonAutomation{
Expand All @@ -37,8 +38,10 @@
std::optional<size_t> registered = std::nullopt;
// An A prompt over the scene, as at the Center counter ("A Talk").
std::optional<bool> talk_prompt = std::nullopt;
// The lead Pokemon's panel at the bottom left (level badge and HP
// bar): the player is in a wild zone.
// In Wild Zone 1, by the player's pin on the full map
// (wild_zone_from_map()). Not the lead Pokemon's panel at the bottom
// left: it shows on the street outside the zone too, and 03.08b's menu
// save there read as in the zone (console B, 2026-11-17 01:06).
std::optional<bool> wild_zone = std::nullopt;
// The overworld party bar's filled slots (PartyBarDetector): every
// catch in Main Mission 03 is a new species, so the party tells 03.08's
Expand Down Expand Up @@ -85,11 +88,16 @@
size_t asked, const StartSignature& read
);

// The overworld fields of the signature on `screen`: talk_prompt,
// wild_zone and, when the party bar shows, party. A fading screen reads
// nothing.
// The overworld fields of the signature on `screen`: talk_prompt and,
// when the party bar shows, party. A fading screen reads nothing.
// wild_zone needs the full map: wild_zone_from_map().
StartSignature read_start_screen(const ImageViewRGB32& screen);

// The signature's wild_zone by the player's pin on the full map
// (read_map_pin()): whether it is in Wild Zone 1 (pin_in_zone_1()).
// None when the pin was not read.
std::optional<bool> wild_zone_from_map(const std::optional<MapPoint>& pin);



} // namespace PokemonLZA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ const BuiltinCase BUILTIN_CASES[] = {
.input = {.asked = "03.09", .read = {.talk_prompt = true, .wild_zone = false, .party = 5}},
.expectation = {.from = "03.09"},
},
{
// console B, 2026-11-17 01:06: asked 03.09, 03.08b's menu save on
// the street outside the far gate read the lead's panel as in a
// wild zone, and 03.08b walked into the street's fence. The map
// pin read (401, 225) there.
.name = "asked 03.09, 03.08b's menu save on the street by its map pin: from 03.09",
.input = {.asked = "03.09", .read = {
.talk_prompt = false, .wild_zone = wild_zone_from_map(MapPoint{.x = 401, .y = 225}), .party = 5,
}},
.expectation = {.from = "03.09"},
},
{
.name = "asked 03.08b, the menu save out of the far gate: stop",
.input = {.asked = "03.08b", .read = {.talk_prompt = false, .wild_zone = false, .party = 5}},
Expand Down Expand Up @@ -278,13 +289,63 @@ UnitTestResult check_table(const TableCase& test){
}


// wild_zone by the player's pin on the full map: pins read on console B
// ("[PLZA] map pin" lines, lab-B 2026-11-16 and 2026-11-17).
struct MapPinCase{
std::string name;
struct Input{
std::optional<MapPoint> pin;
};
Input input;
struct Expectation{
std::optional<bool> wild_zone;
};
Expectation expectation;
};

const MapPinCase MAP_PIN_CASES[] = {
{.name = "Taunie's rocks: in", .input = {.pin = MapPoint{.x = 476, .y = 224}}, .expectation = {.wild_zone = true}},
{.name = "the 100 spot: in", .input = {.pin = MapPoint{.x = 431, .y = 236}}, .expectation = {.wild_zone = true}},
{.name = "the 60 spot by the far gate: in", .input = {.pin = MapPoint{.x = 386, .y = 252}}, .expectation = {.wild_zone = true}},
{.name = "the catch west of the 60 spot: in", .input = {.pin = MapPoint{.x = 365, .y = 257}}, .expectation = {.wild_zone = true}},
{.name = "stuck at the north fence: in", .input = {.pin = MapPoint{.x = 358.9, .y = 227.3}}, .expectation = {.wild_zone = true}},
{.name = "the patrol's stop 10: in", .input = {.pin = MapPoint{.x = 415.4, .y = 230.4}}, .expectation = {.wild_zone = true}},
{
// console B, 2026-11-17 01:06 and 01:07: 03.08b's menu save.
.name = "the street outside the far gate: out",
.input = {.pin = MapPoint{.x = 401, .y = 225}},
.expectation = {.wild_zone = false},
},
{.name = "the street outside the far gate, a second read: out", .input = {.pin = MapPoint{.x = 401, .y = 223}}, .expectation = {.wild_zone = false}},
{.name = "south of the zone's outline: out", .input = {.pin = MapPoint{.x = 400, .y = 280}}, .expectation = {.wild_zone = false}},
{.name = "no pin read: unknown", .input = {.pin = std::nullopt}, .expectation = {.wild_zone = std::nullopt}},
};

std::string zone_text(const std::optional<bool>& wild_zone){
if (!wild_zone){
return "unknown";
}
return *wild_zone ? "in a wild zone" : "not in a wild zone";
}

UnitTestResult check_map_pin(const MapPinCase& test){
const std::optional<bool> wild_zone = wild_zone_from_map(test.input.pin);
if (wild_zone != test.expectation.wild_zone){
return std::format("expected {}, got {}", zone_text(test.expectation.wild_zone), zone_text(wild_zone));
}
return true;
}


// The console's frames, PokemonLZA/AutoStoryStarts/<file> (console B,
// 2026-11-16, Italian), read and placed for a run asked to start at
// 03.08.
// 2026-11-16 Italian, 2026-11-17 German), read with the map pin read
// there and placed for a run asked to start at `asked`.
struct FrameCase{
std::string name;
struct Input{
std::string file;
std::string asked;
std::optional<MapPoint> map_pin;
};
Input input;
struct Expectation{
Expand All @@ -297,24 +358,42 @@ const FrameCase FRAME_CASES[] = {
{
// lab-B outbox za_bk5_g: "A Parla" at the counter.
.name = "the Center counter: 03.06",
.input = {.file = "Italian_center_counter.png"},
.input = {.file = "Italian_center_counter.png", .asked = "03.08", .map_pin = std::nullopt},
.expectation = {.from = "03.06"},
},
{
// fails/it_0308_run3_rocks_120: the lead's panel at the bottom left.
.name = "Taunie's rocks in Wild Zone 1: 03.08",
.input = {.file = "Italian_zone1_rocks.png"},
.input = {.file = "Italian_zone1_rocks.png", .asked = "03.08", .map_pin = MapPoint{.x = 476, .y = 224}},
.expectation = {.from = "03.08"},
},
{
// 0309-start-facing-marker-de: 03.08b's menu save on the street
// outside the far gate, the lead's panel up (console B,
// 2026-11-17 01:06); the map pin read (401, 225).
.name = "the street outside the far gate, facing the marker: 03.09",
.input = {.file = "German_0309_start_facing_marker.png", .asked = "03.09", .map_pin = MapPoint{.x = 401, .y = 225}},
.expectation = {.from = "03.09"},
},
{
// 0309-start-facing-street2-de: the same save, facing the street.
.name = "the street outside the far gate, facing the street: 03.09",
.input = {.file = "German_0309_start_facing_street.png", .asked = "03.09", .map_pin = MapPoint{.x = 401, .y = 225}},
.expectation = {.from = "03.09"},
},
};

UnitTestResult check_frame(const FrameCase& test){
const std::string path = std::format("{}PokemonLZA/AutoStoryStarts/{}", UNIT_TEST_RESOURCE_PATH(), test.input.file);
if (!Filesystem::exists(Filesystem::Path(path))){
return UnitTestResult(UnitTestResult::SKIPPED, std::format("{} is not in the test images.", test.input.file));
}
const StartSignature read = read_start_screen(ImageRGB32(path));
const std::string from = run_start_id(builtin_story_data().checkpoints, builtin_checkpoint_starts(), "03.08", read);
StartSignature read = read_start_screen(ImageRGB32(path));
if (read.wild_zone){
return std::format("{}: read {}: the screen alone must not decide wild_zone", test.input.file, to_string(read));
}
read.wild_zone = wild_zone_from_map(test.input.map_pin);
const std::string from = run_start_id(builtin_story_data().checkpoints, builtin_checkpoint_starts(), test.input.asked, read);
if (from != test.expectation.from){
return std::format("{}: read {}: expected {}, got {}", test.input.file, to_string(read), test.expectation.from, from);
}
Expand Down Expand Up @@ -346,6 +425,9 @@ void add_tests_AutoStoryStarts(UnitTestDatabase& database){
for (const TableCase& test : TABLE_CASES){
database.add<CaseTest<TableCase, check_table>>("table", test);
}
for (const MapPinCase& test : MAP_PIN_CASES){
database.add<CaseTest<MapPinCase, check_map_pin>>("map pin", test);
}
for (const FrameCase& test : FRAME_CASES){
database.add<CaseTest<FrameCase, check_frame>>("frame", test);
}
Expand Down
Loading