Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
6cc5286
FRLG AutoStory 16.03: the Silph rival by PokeGuy's C2 policy, Blizzar…
dayfine Nov 15, 2026
249cad3
FRLG AutoStory teach: scroll the TM Case to a TM below its rows; a mi…
dayfine Nov 15, 2026
d290a6e
FRLG AutoStory teach tests: the fake TM Case scrolls with the cursor …
dayfine Nov 15, 2026
85e02a9
FRLG AutoStory teach: move the cursor onto a list row by name, found …
dayfine Nov 15, 2026
1719da6
FRLG AutoStory: a TEACH to the lead updates the battles' lead
dayfine Nov 15, 2026
fb34e9e
Merge origin/frlg/stage20-league into frlg/silph-rival-battle
dayfine Nov 15, 2026
cb8daed
Merge frlg/stage20-league into frlg/silph-rival-battle (CommandLineTe…
dayfine Nov 15, 2026
aadd271
CI: pin CommandLineTests to 6e1d3bb (Silph Co. black-below frame)
dayfine Nov 15, 2026
b8d7705
FRLG AutoStory: no evolution hold or battle on black below a map
dayfine Nov 15, 2026
4f17436
FRLG AutoStory: define read_text_screen outside the anonymous namespa…
dayfine Nov 15, 2026
a9b4540
FRLG AutoStory: evolution wait on a reading source; scripted-readings…
dayfine Nov 15, 2026
47a54f5
FRLG AutoStory: EvolutionHold::wait_out; console readings in Pokemon/…
dayfine Nov 15, 2026
06f0233
FRLG AutoStory tests: std::format for the new test names
dayfine Nov 15, 2026
5b9be5e
FRLG AutoStory sim: walker from the believed facing; 16.05 president …
dayfine Nov 15, 2026
1a81337
FRLG AutoStory 16.05: Giovanni's battle leaves the player facing east
dayfine Nov 15, 2026
1ab56ca
FRLG AutoStory battle: stop at once when the lead faints
dayfine Nov 15, 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
4 changes: 2 additions & 2 deletions .github/workflows/cpp-ci-serial-programs-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ jobs:
uses: actions/checkout@v7
if: inputs.run-tests
with:
# The fork's fixtures: upstream's, the SystemKeyboardDetector and HomeTileReader screenshots and pending FRLG image submissions (Fly landing, party menu, Route 21 battle, Pokemon Mansion 1F and B1F hold frames, and the Pidgey known-moves frame).
# The fork's fixtures: upstream's, the SystemKeyboardDetector and HomeTileReader screenshots and pending FRLG image submissions (Fly landing, party menu, Route 21 battle, Pokemon Mansion 1F and B1F hold frames, the Pidgey known-moves frame, and the Silph Co. fainted-lead party list).
repository: 'dayfine/CommandLineTests'
ref: '47763e72e1de0489bfd91433a78f40e80f3cedf8'
ref: '5ea4c10bc1ef518a69395f12d6c53207a7f8a75c'
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
Expand Up @@ -25,6 +25,7 @@
#include "Pokemon_FrameReplay_Tests.h"
#include "Pokemon_Interrupts_Tests.h"
#include "Pokemon_SceneJudges_Tests.h"
#include "Pokemon_ScriptedReadings_Tests.h"
#include "Pokemon_StoryActions_Tests.h"
#include "Pokemon_StoryEvents_Tests.h"
#include "Pokemon_StoryFailureClasses_Tests.h"
Expand All @@ -44,7 +45,7 @@


// Registers every shared AutoStory suite, for the unit test runner.
inline void add_tests_AutoStory(UnitTestDatabase& database){

Check warning on line 48 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::Pokemon::add_tests_AutoStory( UnitTestDatabase & database): function_lines=29 (advisory above 25, limit 50)
add_tests_AutoStorySelect(database);
add_tests_StoryRun(database);
add_tests_StoryRunCounts(database);
Expand All @@ -69,6 +70,7 @@
add_tests_Interrupts(database);
add_tests_Transitions(database);
add_tests_FrameReplay(database);
add_tests_ScriptedReadings(database);
add_tests_StoryActions(database);
add_tests_StoryInterrupts(database);
}
Expand Down
63 changes: 63 additions & 0 deletions SerialPrograms/Source/Pokemon/AutoStory/Pokemon_ConsoleReadings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* Console Readings
*
* From: https://github.com/PokemonAutomation/
*
* The program's ReadingSource (Pokemon_ScriptedReadings.h): a wait on the
* controller, then the console's latest frame through a game's reader.
*
*/

#ifndef PokemonAutomation_Pokemon_ConsoleReadings_H
#define PokemonAutomation_Pokemon_ConsoleReadings_H

#include <optional>
#include "Common/Cpp/Time.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/VideoPipeline/VideoFeed.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
#include "Pokemon_ScriptedReadings.h"

namespace PokemonAutomation{
namespace Pokemon{


// `reader` on the console's frames, on the wall clock.
template <typename Reading>
class ConsoleReadings : public ReadingSource<Reading>{
public:
using Reader = Reading (*)(const ImageViewRGB32& screen);

ConsoleReadings(NintendoSwitch::ConsoleHandle& console, NintendoSwitch::ProControllerContext& context, Reader reader)
: m_console(console)
, m_context(context)
, m_reader(reader)
{}

virtual void wait(Milliseconds duration) override{
NintendoSwitch::pbf_wait(m_context, duration);
m_context.wait_for_all_requests();
}
virtual std::optional<Reading> read() override{
VideoSnapshot screen = m_console.video().snapshot();
if (!screen){
return std::nullopt;
}
return m_reader(screen);
}
virtual WallClock now() const override{
return current_time();
}

private:
NintendoSwitch::ConsoleHandle& m_console;
NintendoSwitch::ProControllerContext& m_context;
Reader m_reader;
};



} // namespace Pokemon
} // namespace PokemonAutomation
#endif
98 changes: 98 additions & 0 deletions SerialPrograms/Source/Pokemon/AutoStory/Pokemon_ScriptedReadings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* Scripted Readings
*
* From: https://github.com/PokemonAutomation/
*
* A loop that polls the screen, waits and reads it again, written against
* ReadingSource so a test feeds it scripted readings on a virtual clock
* instead of a console's frames. The program's source waits on the
* controller and reads a snapshot; ScriptedReadings shows each scripted
* reading for its time, and the last one after the script ends.
*
* A reading is whatever the loop decides on, read from one frame (a
* game's struct of detector results). FrameReplay (Pokemon_FrameReplay.h)
* replays recorded frames through the detectors instead; scripted
* readings test the loop's decisions without images.
*
*/

#ifndef PokemonAutomation_Pokemon_ScriptedReadings_H
#define PokemonAutomation_Pokemon_ScriptedReadings_H

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

namespace PokemonAutomation{
namespace Pokemon{


// Where a polling loop gets its readings, and its clock.
template <typename Reading>
class ReadingSource{
public:
virtual ~ReadingSource() = default;

// Lets `duration` pass: nothing pressed.
virtual void wait(Milliseconds duration) = 0;
// The screen now; none if no frame came.
virtual std::optional<Reading> read() = 0;
// The source's clock.
virtual WallClock now() const = 0;
};


// One step of a script: `reading` for `lasts`. No reading: no frame.
template <typename Reading>
struct ScriptedReading{
Milliseconds lasts = Milliseconds(0);
std::optional<Reading> reading = {};
};

// Scripted readings on a virtual clock that only wait() moves. A reading
// shows from the end of the one before it for its `lasts`; the last one
// shows on after the script ends. An empty script reads no frame.
template <typename Reading>
class ScriptedReadings : public ReadingSource<Reading>{
public:
ScriptedReadings(std::vector<ScriptedReading<Reading>> script, WallClock origin)
: m_script(std::move(script))
, m_origin(origin)
{}

// How long the source has waited in all.
Milliseconds elapsed() const{
return m_elapsed;
}

virtual void wait(Milliseconds duration) override{
m_elapsed += duration;
}
virtual std::optional<Reading> read() override{
Milliseconds end(0);
for (const ScriptedReading<Reading>& step : m_script){
end += step.lasts;
if (m_elapsed < end){
return step.reading;
}
}
if (m_script.empty()){
return std::nullopt;
}
return m_script.back().reading;
}
virtual WallClock now() const override{
return m_origin + m_elapsed;
}

private:
std::vector<ScriptedReading<Reading>> m_script;
WallClock m_origin;
Milliseconds m_elapsed = Milliseconds(0);
};



} // namespace Pokemon
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/* Scripted Readings Tests
*
* From: https://github.com/PokemonAutomation/
*
* ScriptedReadings on integer readings: which one shows after each wait,
* frames missing, the last one past the script's end, and the clock.
*
*/

#include <format>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "Common/Cpp/TestRunners/UnitTest.h"
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "Pokemon_ScriptedReadings.h"
#include "Pokemon_ScriptedReadings_Tests.h"

namespace PokemonAutomation{
namespace Pokemon{

namespace{

using namespace std::chrono_literals;

const WallClock T0 = WallClock() + std::chrono::hours(1);

struct ScriptedReadingsInput{
std::vector<ScriptedReading<int>> script;
// Waited before each read.
std::vector<Milliseconds> waits;
};

struct ScriptedReadingsExpectation{
// One per wait.
std::vector<std::optional<int>> readings;
};

struct ScriptedReadingsCase{
std::string name;
ScriptedReadingsInput input;
ScriptedReadingsExpectation expectation;
};

std::string reading_name(const std::optional<int>& reading){
return reading ? std::format("{}", *reading) : "no frame";
}

class Test_ScriptedReadings : public UnitTest{
public:
explicit Test_ScriptedReadings(ScriptedReadingsCase test_case)
: UnitTest(std::format("Pokemon::ScriptedReadings - {}", test_case.name))
, m_case(std::move(test_case))
{}
virtual UnitTestResult run(Logger&, CancellableScope&) const override{
ScriptedReadings<int> source(m_case.input.script, T0);
Milliseconds waited(0);
for (size_t c = 0; c < m_case.input.waits.size(); c++){
source.wait(m_case.input.waits[c]);
waited += m_case.input.waits[c];
const std::optional<int> reading = source.read();
if (reading != m_case.expectation.readings[c]){
return std::format(
"at {} ms: expected {}, read {}",
waited.count(), reading_name(m_case.expectation.readings[c]), reading_name(reading)
);
}
if (source.now() != T0 + waited || source.elapsed() != waited){
return std::format("at {} ms: the clock is at {} ms", waited.count(), source.elapsed().count());
}
}
return true;
}

private:
ScriptedReadingsCase m_case;
};

const ScriptedReadingsCase SCRIPTED_READINGS_CASES[] = {
{
.name = "each reading for its time",
.input = {.script = {{100ms, 1}, {200ms, 2}}, .waits = {0ms, 99ms, 1ms, 199ms}},
.expectation = {.readings = {1, 1, 2, 2}},
},
{
.name = "the last reading after the script ends",
.input = {.script = {{100ms, 1}, {100ms, 2}}, .waits = {200ms, 60000ms}},
.expectation = {.readings = {2, 2}},
},
{
.name = "a step without a reading is no frame",
.input = {.script = {{100ms, 1}, {100ms, std::nullopt}, {100ms, 3}}, .waits = {0ms, 100ms, 100ms}},
.expectation = {.readings = {1, std::nullopt, 3}},
},
{
.name = "an empty script reads no frame",
.input = {.script = {}, .waits = {0ms, 1000ms}},
.expectation = {.readings = {std::nullopt, std::nullopt}},
},
{
.name = "reading again without a wait reads the same",
.input = {.script = {{100ms, 1}, {100ms, 2}}, .waits = {50ms, 0ms, 0ms}},
.expectation = {.readings = {1, 1, 1}},
},
};

} // namespace


void add_tests_ScriptedReadings(UnitTestDatabase& database){
for (const ScriptedReadingsCase& test_case : SCRIPTED_READINGS_CASES){
database.add<Test_ScriptedReadings>(test_case);
}
}



} // namespace Pokemon
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Scripted Readings Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_Pokemon_ScriptedReadings_Tests_H
#define PokemonAutomation_Pokemon_ScriptedReadings_Tests_H

#include "Common/Cpp/TestRunners/UnitTestDatabase.h"

namespace PokemonAutomation{
namespace Pokemon{


// Scripted readings served on their virtual clock.
void add_tests_ScriptedReadings(UnitTestDatabase& database);



} // namespace Pokemon
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,10 @@ RouteCalls OverworldSimWalker::calls(){
return calls;
}

std::string OverworldSimWalker::run(const std::vector<RouteStep>& route, const RoutePlanning& planning){
std::string OverworldSimWalker::run(const std::vector<RouteStep>& route, const RoutePlanning& planning, std::optional<Direction> believed_facing){
m_at_known = planning.start.has_value();
try{
run_route(route, m_sim.state().facing, &planning, calls());
run_route(route, believed_facing.value_or(m_sim.state().facing), &planning, calls());
}catch (OperationFailedException& e){
return e.message();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Sim

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=549 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -440,9 +440,16 @@
// console's does.
RouteCalls calls();

// run_route() from the sim's facing, planned with `planning`. Returns
// the failure's message, or empty if the route was walked.
std::string run(const std::vector<RouteStep>& route, const RoutePlanning& planning);
// run_route() from the facing the program believes, `believed_facing`
// (the sim's own if none), planned with `planning`. A belief that is
// not the sim's facing walks as the console did: the first hold turns
// the player and loses a tile (console B, 2026-11-15 13:02, 16.05
// below_president). Returns the failure's message, or empty if the
// route was walked.
std::string run(
const std::vector<RouteStep>& route, const RoutePlanning& planning,
std::optional<Direction> believed_facing = std::nullopt
);

const std::vector<std::string>& log() const{ return m_log; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <format>
#include "CommonFramework/Exceptions/ProgramFinishedException.h"
#include "PokemonFRLG_AutoStoryAbilities.h"
#include "PokemonFRLG_AutoStoryParty.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand All @@ -31,11 +32,13 @@ Outcome teach(Logger& logger, const TeachPlan& plan, StoryAbilities& abilities){
logger.log(std::format("Party: {} is used by slot {} ({}).", plan.move, result.member + 1, species.empty() ? "species unread" : species));
abilities.party->users().record(plan.move, result.member, species);
}
if (result.end == TeachEnd::LEARNED && result.member == 0 && abilities.lead != nullptr){
learn_taught(plan.move, result.forgot, *abilities.lead);
}
if (result.end == TeachEnd::LEARNED){
return Pokemon::outcome_ok();
}
// NO_ITEM: skipped, with run_teach()'s log line.
if (result.end == TeachEnd::ALREADY_KNOWN || result.end == TeachEnd::NO_ITEM){
if (result.end == TeachEnd::ALREADY_KNOWN){
return Pokemon::outcome_unchanged();
}
return Pokemon::outcome_failed(std::format("teach_{}", teach_end_name(result.end)), teach_message(plan, result));
Expand Down
Loading
Loading