Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ccfe85d
PLZA AutoStory: 03.08 Wild Zone 1's five species and the far gate (03…
dayfine Nov 16, 2026
c044542
PLZA AutoStory: 03.08 code health fixes
dayfine Nov 16, 2026
696ce06
Merge branch 'plza/slice5' into plza/slice5b
dayfine Nov 16, 2026
3e8d835
PLZA: style fixes in the 03.08 readers
dayfine Nov 16, 2026
061c5cf
Merge branch 'plza/slice5' into plza/slice5b
dayfine Nov 16, 2026
75328c8
Merge commit '8165f511d' into HEAD
dayfine Nov 16, 2026
b72aa25
Merge branch 'plza/slice5' into plza/slice5b
dayfine Nov 16, 2026
8114db2
Merge branch 'plza/slice5' into plza/slice5b
dayfine Nov 16, 2026
b459a08
Merge branch 'plza/slice5' into plza/slice5b
dayfine Nov 16, 2026
b533878
PLZA scene machine: per-screen lines to the file log only
dayfine Nov 16, 2026
1a3ba10
PLZA scene machine: A on a banner that stays, with end_after_black_fades
dayfine Nov 16, 2026
e66fd6e
PLZA autosave reader: cyan tests take only blue-leaning pixels
dayfine Nov 16, 2026
c9f475e
PLZA choice rows: find rows by the menu's geometry, not its text
dayfine Nov 16, 2026
59dfaa0
CI (fork only): pin CommandLineTests 8b376ff (01.02 Italian choice me…
dayfine Nov 16, 2026
be34e52
PLZA scene machine: an A prompt on the overworld is control, never bl…
dayfine Nov 16, 2026
4afd5d6
PLZA scene machine: fail fast as scene_loop when blind A keeps restar…
dayfine Nov 16, 2026
3f7cc8b
CI (fork only): pin CommandLineTests 848e0b0 (01.02 Italian talk prom…
dayfine Nov 16, 2026
fd653ee
Revert "PLZA scene machine: fail fast as scene_loop when blind A keep…
dayfine Nov 16, 2026
cc86801
PLZA scene machine: act on classified screens, no blind A in story sc…
dayfine Nov 16, 2026
7e7fc0d
PLZA scene machine: a textless cutscene is a scene under way, not nev…
dayfine Nov 16, 2026
22d05e0
Merge branch 'plza/slice5' into plza/slice5b
dayfine Nov 16, 2026
bf0d142
Merge origin/plza/slice5 into plza/slice5b
dayfine Nov 16, 2026
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
5 changes: 3 additions & 2 deletions .github/workflows/cpp-ci-serial-programs-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,10 @@ jobs:
if: inputs.run-tests
with:
# The fork's fixtures: upstream's plus the PLZA AutoStory frames (Confirm Choices, opening and arrival folders), dayfine/CommandLineTests PR #18,
# and the 01.01 banner and controls hint in English and Italian (branch plza/hint-banner-any-language).
# and the 01.01 banner and controls hint in English and Italian (branch plza/hint-banner-any-language),
# and the 01.02 choice menu and talk prompt in Italian (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff.
repository: 'dayfine/CommandLineTests'
ref: '2abde09b6bfdf9ae1b372b04c0e6265dc8559556'
ref: '848e0b03a03d9cdca580f21f3389486478d52f4d'
path: 'CommandLineTests'

# The unit tests assume the downloadable resources they need are already downloaded
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/* Party Bar Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <format>
#include <string>
#include "CommonFramework/ImageTools/ImageStats.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "Tests/ImageUnitTest.h"
#include "PokemonLZA_PartyBarDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLZA{

namespace{

// The slot's HP bar: 52 of 1920 wide from x = 86 + 76.4 * i, rows
// 1028-1031 of 1080; the box stays inside the bar.
constexpr double SLOT_X = 0.045;
constexpr double SLOT_PITCH = 0.0398;
constexpr double BAR_WIDTH = 0.026;
constexpr double BAR_Y = 0.9519;
constexpr double BAR_HEIGHT = 0.0037;
// The card between the icon and the bar: rows 1021-1025.
constexpr double CARD_Y = 0.9454;
constexpr double CARD_HEIGHT = 0.0046;

// The trough is the card darkened: a black overlay at about half.
constexpr double TROUGH_BRIGHTNESS_RATIO = 0.65;
// A bar's box reads 0.79 and up (a nearly empty red bar over a bright
// teal scene); a slot with none 0.16 at most (the Poke Ball of the slot
// sent out).
constexpr double BAR_SHARE_MIN = 0.5;

// An HP bar's green, yellow or red.
bool is_hp_color(Color color){
const uint32_t r = color.red();
const uint32_t g = color.green();
const uint32_t b = color.blue();
const bool green = g > 140 && g > r + 60 && g > b + 60;
const bool yellow = r > 170 && g > 150 && b < 100;
const bool red = r > 170 && g < 110 && b < 110;
return green || yellow || red;
}

double brightness(Color color){
return (color.red() + color.green() + color.blue()) / 3.0;
}

} // namespace


PartyBarDetector::PartyBarDetector(Color color, VideoOverlay* overlay)
: m_selection(color, overlay)
{
for (size_t i = 0; i < 6; i++){
const double x = SLOT_X + SLOT_PITCH * i;
m_bar_boxes[i] = {x, BAR_Y, BAR_WIDTH, BAR_HEIGHT};
m_card_boxes[i] = {x, CARD_Y, BAR_WIDTH, CARD_HEIGHT};
}
}

void PartyBarDetector::make_overlays(VideoOverlaySet& items) const{
m_selection.make_overlays(items);
for (size_t i = 0; i < 6; i++){
items.add(COLOR_GREEN, m_bar_boxes[i]);
}
}

bool PartyBarDetector::slot_has_hp_bar(const ImageViewRGB32& screen, size_t index) const{
const ImageViewRGB32 card = extract_box_reference(screen, m_card_boxes[index]);
const ImageViewRGB32 bar = extract_box_reference(screen, m_bar_boxes[index]);
const size_t total = bar.width() * bar.height();
if (total == 0 || card.width() * card.height() == 0){
return false;
}
const double trough_max = image_average(card).sum() / 3.0 * TROUGH_BRIGHTNESS_RATIO;
size_t count = 0;
for (size_t y = 0; y < bar.height(); y++){
for (size_t x = 0; x < bar.width(); x++){
const Color color(bar.pixel(x, y));
if (is_hp_color(color) || brightness(color) < trough_max){
count++;
}
}
}
return (double)count / (double)total >= BAR_SHARE_MIN;
}

bool PartyBarDetector::detect(const ImageViewRGB32& screen){
m_filled_slots = 0;
if (screen.width() == 0 || screen.height() == 0){
return false;
}
if (!m_selection.detect(screen)){
return false;
}
const uint8_t sent_out = m_selection.dpad_down_idx();
for (size_t i = 0; i < 6; i++){
if (i == sent_out || slot_has_hp_bar(screen, i)){
m_filled_slots++;
}
}
return true;
}

namespace{

// The filled slots of the party bar on `screen`: 0 when no bar is on it.
int party_bar_filled_slots(const ImageViewRGB32& screen){
PartyBarDetector detector;
detector.detect(screen);
return detector.filled_slots();
}

struct PartyBarCase{
std::string name;
struct Input{
std::string image; // In CommandLineTests/PokemonLZA/PartyBarDetector/.
};
Input input;
struct Expectation{
int filled_slots;
};
Expectation expectation;
};

const PartyBarCase PARTY_BAR_CASES[] = {
{
.name = "five filled, slot 0 selected (D-pad up), the sixth empty",
.input = {.image = "party5_slot0_selected.png"},
.expectation = {.filled_slots = 5},
},
{
.name = "five filled, slot 0's partner sent out (Poke Ball, no bar), Mareep's bar red",
.input = {.image = "party5_slot0_sent_out.png"},
.expectation = {.filled_slots = 5},
},
{
.name = "five filled, slot 0's partner sent out, over bright ground",
.input = {.image = "party5_b.png"},
.expectation = {.filled_slots = 5},
},
};

class Test_PartyBarDetector : public ImageUnitTest{
public:
explicit Test_PartyBarDetector(const PartyBarCase& test_case)
: ImageUnitTest(
std::format("PokemonLZA::PartyBarDetector - {}", test_case.name),
{std::format("PokemonLZA/PartyBarDetector/{}", test_case.input.image)}
)
, m_case(test_case)
{}

virtual UnitTestResult run_on_images(
Logger& logger, CancellableScope& scope,
const std::vector<ImageRGB32>& images
) const override{
const int filled = party_bar_filled_slots(images[0]);
if (filled != m_case.expectation.filled_slots){
return std::format("Expected {} filled slots, got {}.", m_case.expectation.filled_slots, filled);
}
return true;
}

private:
const PartyBarCase& m_case;
};

} // namespace


void add_tests_PartyBarDetector(UnitTestDatabase& database){
for (const PartyBarCase& item : PARTY_BAR_CASES){
database.add<Test_PartyBarDetector>(item);
}
}



} // namespace PokemonLZA
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* Party Bar Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonLZA_PartyBarDetector_H
#define PokemonAutomation_PokemonLZA_PartyBarDetector_H

#include <array>
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "Common/Cpp/Color.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonTools/VisualDetector.h"
#include "PokemonLZA_OverworldPartySelectionDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLZA{


// Counts the filled slots of the overworld party bar (bottom left, 6
// slots). The bar is on screen when its D-pad marker shows
// (OverworldPartySelectionDetector). A filled slot has an HP bar under
// its icon: green, yellow or red by its HP, over a dark trough. The slot
// whose partner is sent out (the D-pad down marker's) shows a Poke Ball
// and no HP bar: it counts too. An empty slot shows only its card.
// Boxes measured on 1920x1080 frames (console B, 2026-11-14): the bars
// on rows 1028-1031, slot i from x = 86 + 76.4 * i, 52 wide.
class PartyBarDetector : public StaticScreenDetector{
public:
PartyBarDetector(Color color = COLOR_RED, VideoOverlay* overlay = nullptr);

virtual void make_overlays(VideoOverlaySet& items) const override;

// Whether the party bar is on screen; then filled_slots() is its count.
virtual bool detect(const ImageViewRGB32& screen) override;

virtual void reset_state() override{
m_selection.reset_state();
m_filled_slots = 0;
}

// The filled slots of the bar on the last detect()'s screen: 0 when
// no bar was on it.
int filled_slots() const{ return m_filled_slots; }

private:
// Whether slot `index`'s HP bar shows: the bar's box is mostly HP
// color or darker than the card above it (the trough).
bool slot_has_hp_bar(const ImageViewRGB32& screen, size_t index) const;

OverworldPartySelectionDetector m_selection;
// Each slot's HP bar and, above it, the card between icon and bar.
std::array<ImageFloatBox, 6> m_bar_boxes;
std::array<ImageFloatBox, 6> m_card_boxes;
int m_filled_slots = 0;
};


// Registers the party bar detector's tests on the PartyBarDetector frames.
void add_tests_PartyBarDetector(UnitTestDatabase& database);



} // namespace PokemonLZA
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#include "Inference/Map/PokemonLZA_MapDetector.h"
#include "Inference/Map/PokemonLZA_MapIconDetector.h"
#include "Inference/PokemonLZA_OverworldPartySelectionDetector.h"
#include "Inference/PokemonLZA_PartyBarDetector.h"
#include "Inference/PokemonLZA_SelectionArrowDetector.h"
#include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.h"
#include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.h"
#include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h"
#include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox_Tests.h"
Expand All @@ -27,6 +29,7 @@
#include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.h"
#include "Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.h"
#include "Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.h"
#include "Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.h"
#include "Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.h"

namespace PokemonAutomation{
Expand All @@ -35,7 +38,7 @@



void add_tests(UnitTestDatabase& database){

Check warning on line 41 in SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonLZA::add_tests( UnitTestDatabase & database): function_lines=29 (advisory above 25, limit 50)
add_tests_AlertEyeDetector(database);
add_tests_BoxCellInfoDetector(database);
add_tests_ButtonDetector(database);
Expand All @@ -49,15 +52,18 @@
add_tests_MapDetector(database);
add_tests_MapIconDetector(database);
add_tests_OverworldPartySelectionDetector(database);
add_tests_PartyBarDetector(database);
add_tests_SelectionArrowDetector(database);
add_tests_AutoStoryDetectors(database);
add_tests_AutoStoryDialogChoiceBox(database);
add_tests_AutoStoryConfirmChoicesReader(database);
add_tests_AutoStoryCaughtMarkReader(database);
add_tests_AutoStoryDialogDetector(database);
add_tests_AutoStoryGame(database);
add_tests_AutoStoryLines(database);
add_tests_AutoStoryObjectiveMarkerReader(database);
add_tests_AutoStorySceneMachine(database);
add_tests_AutoStorySceneReplay(database);
add_tests_AutoStoryScreenEvents(database);

}
Expand Down
Loading
Loading