Skip to content
Draft
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 @@ -61,7 +61,7 @@
: SmallDictionaryMatcher(dictionary())
{}

static JsonObject dictionary(){

Check warning on line 64 in SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::PlaceNameMatcher::dictionary(): function_lines=29 (advisory above 25, limit 50)
JsonObject english;
for (const auto& [slug, name] : {
std::pair<std::string_view, std::string_view>{"pallet-town", "Pallet Town"},
Expand All @@ -80,6 +80,7 @@
{"vermilion-city", "Vermilion City"},
{"celadon-city", "Celadon City"},
{"rocket-hideout", "Rocket Hideout"},
{"fuchsia-city", "Fuchsia City"},
}){
JsonArray names;
names.push_back(std::string(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ constexpr std::string_view MAP_NAMES[] = {
"RocketHideout_B2F",
"RocketHideout_B3F",
"RocketHideout_B4F",
// Fuchsia City's Center, Koga's gym and the Warden's house.
"FuchsiaCity",
"FuchsiaCity_Gym",
"FuchsiaCity_WardensHouse",
"CeruleanCave_1F",
"CeruleanCave_2F",
"CeruleanCave_B1F",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static void add_tests_AutoStoryRows(UnitTestDatabase& database){
add_tests_AutoStoryVermilion(database);
add_tests_AutoStoryVermilionGym(database);
add_tests_AutoStoryCeladon(database);
add_tests_AutoStoryFuchsiaGym(database);
}

void add_tests(UnitTestDatabase& database){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutoStory Events

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=949 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -339,7 +339,7 @@
return StoryPose{pose.map, tiles[0], facing_of(pose)};
}

std::string save_card_place(const std::string& map){

Check warning on line 342 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::save_card_place( const std :: string & map): function_lines=27 (advisory above 25, limit 50)
// A map of the place, or a building in it ("Route4_PokemonCenter_1F"
// is on Route 4, "Route24" isn't on Route 2).
static const std::pair<std::string, std::string_view> PLACES[] = {
Expand All @@ -357,6 +357,7 @@
{"LavenderTown", "lavender-town"},
{"CeladonCity", "celadon-city"},
{"RocketHideout", "rocket-hideout"},
{"FuchsiaCity", "fuchsia-city"},
};
for (const auto& [prefix, place] : PLACES){
if (map == prefix || map.rfind(prefix + "_", 0) == 0){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
/* AutoStory Fuchsia Gym Tests
*
* From: https://github.com/PokemonAutomation/
*
* Rows 12.01 and 12.02 (StoryData/frlg-12.01.plan.json, 12.02) on the
* overworld sim: from Fuchsia's nurse into the gym past Jugglers Kayden
* and Kirk and round its top edge to west of Koga; and from Koga out to
* the Warden and back to the nurse. And the lead's attacks against the
* gym's parties.
*
*/

#include <format>
#include <functional>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/TestRunners/UnitTest.h"
#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h"
#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h"
#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h"
#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h"
#include "PokemonFRLG_AutoStoryEvents.h"
#include "PokemonFRLG_AutoStoryParty.h"
#include "PokemonFRLG_AutoStoryRooms.h"
#include "PokemonFRLG_AutoStoryMember.h"
#include "PokemonFRLG_AutoStoryRowSim.h"
#include "PokemonFRLG_AutoStoryRows_Tests.h"
#include "PokemonFRLG_AutoStoryTable.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


namespace{

const std::string GYM = "FuchsiaCity_Gym";

struct AutoStoryFuchsiaGymInput{
std::string name;
std::function<UnitTestResult()> body;
};

struct AutoStoryFuchsiaGymExpectation{
std::string_view description;
};

struct AutoStoryFuchsiaGymCase{
AutoStoryFuchsiaGymInput input;
AutoStoryFuchsiaGymExpectation expectation;
};

class Test_AutoStoryFuchsiaGym : public UnitTest{

Check failure on line 56 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFuchsiaGym_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

test-case: construct each UnitTest from one case struct with name, input and expectation fields (input and expectation structs, the name outside the input); register a named table of designated cases in a range-for
public:
explicit Test_AutoStoryFuchsiaGym(AutoStoryFuchsiaGymCase test_case)
: UnitTest(std::format("PokemonFRLG::AutoStory - Simulation: {}", test_case.input.name))
, m_case(std::move(test_case))
{}
virtual UnitTestResult run(Logger&, CancellableScope&) const override{
try{
return m_case.input.body();
}catch (Exception& e){
return std::format("{}: {}", e.name(), e.message());
}
}

private:
AutoStoryFuchsiaGymCase m_case;
};

const StoryCheckpoint& checkpoint(std::string_view id){
for (const StoryCheckpoint& row : story_checkpoints()){
if (row.id == id){
return row;
}
}
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("No checkpoint {}.", id));
}

// The rows on the sim, which can't walk into a Center with no map. Kept
// across sims: the trainers fought.
struct GymWalk{
StoryPose at;
std::optional<OverworldSim> sim;
std::vector<std::string> fought;

explicit GymWalk(StoryPose start)
: at(std::move(start))
{
place();
}
// A fresh sim on `at`, after a step it can't walk.
void place(){
if (sim){
const std::vector<std::string>& beaten = sim->state().trainers_beaten;
fought.insert(fought.end(), beaten.begin(), beaten.end());
}
sim.emplace(story_maps(), MapPosition{at.map, at.tile}, *at.facing);
}
std::vector<std::string> all_fought() const{
std::vector<std::string> all = fought;
const std::vector<std::string>& beaten = sim->state().trainers_beaten;
all.insert(all.end(), beaten.begin(), beaten.end());
return all;
}
};

// A step of a row on the sim: row_step_on_sim(), but the way into a
// Center, which has no map, and Koga's battle, which a talk starts, leave
// the player where the table says.
std::string gym_step_on_sim(const StoryStep& step, const std::string& id, GymWalk& walk){
const bool center = step.action == CENTER_ENTER_VARIANT;
if (center || (step.kind == StoryStepKind::BATTLE && step.name == "koga")){
walk.at = *story_pose(Pokemon::pose_of(*step.pose_after));
if (center){
walk.place();
}
return "";
}
return row_step_on_sim(*walk.sim, walk.at, step, id);
}

// Row `id`'s steps on the sim from `walk.at`: the failure, or empty.
std::string row_on_sim(std::string_view id, GymWalk& walk){
const StoryCheckpoint& row = checkpoint(id);
for (const StoryStep& step : row.steps){
if (const std::string failure = gym_step_on_sim(step, row.id, walk); !failure.empty()){
return std::format("{}: ended on {}; {}", id, to_string(walk.sim->state().position), failure);
}
if (!walk.sim->state().violations.empty()){
return std::format("{}/{}: a violation on the way: {}", id, step.name, walk.sim->state().violations.back());
}
}
return "";
}

// 12.01 from the nurse: the gym, Kayden fought from (14, 16) and Kirk from
// (14, 11), round the top edge to west of Koga, where 12.02 starts; then
// 12.02 from there to the Warden and the nurse, meeting no one else. The
// sim's lookers see every way at once, so Edgar, whose lines the legs to
// the walls cross, always stops the walk there: the worst case, which
// the console meets only when he looks that way.
UnitTestResult test_gym_rows(){

Check warning on line 146 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFuchsiaGym_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::test_gym_rows(): function_lines=27 (advisory above 25, limit 50)
GymWalk walk(*story_pose(Pokemon::pose_of(*checkpoint("12.01").start)));
if (const std::string failure = row_on_sim("12.01", walk); !failure.empty()){
return failure;
}
const MapPosition west_of_koga{GYM, {6, 13}};
if (!(walk.sim->state().position == west_of_koga) || walk.sim->state().facing != Direction::EAST){
return std::format("12.01: ended on {}, not west of Koga {} facing east.", to_string(walk.sim->state().position), to_string(west_of_koga));
}
if (walk.all_fought() != std::vector<std::string>{"rocker", "rocker", "man"}){
return std::format("12.01: fought {} trainers, not Kayden, Kirk and Edgar.", walk.all_fought().size());
}
const StoryPose next = *story_pose(Pokemon::pose_of(*checkpoint("12.02").start));
if (next.map != GYM || !(next.tile == west_of_koga.point)){
return "12.02 doesn't start where 12.01 ends.";
}
if (const std::string failure = row_on_sim("12.02", walk); !failure.empty()){
return failure;
}
if (walk.all_fought().size() != 3){
return "12.02: fought a trainer after Koga.";
}
if (walk.at.map != "FuchsiaCity_PokemonCenter_1F"){
return std::format("12.02: ended on {}, not at Fuchsia's nurse.", walk.at.map);
}
return true;
}

// The lead as pokeguy brings it to the gym after HM03 (12.01): Surf over
// Water Gun, Water Pulse, Bite, Mega Kick. It picks Surf against Koga's
// Poison types (pokeguy: Surf throughout) and Surf or Bite, never Mega
// Kick (5 PP) or Water Pulse, against the Jugglers' Psychic types.
UnitTestResult test_lead_moves_in_gym(){
PartyMember lead;
lead.species = "blastoise";
lead.moves_read = true;
lead.level = 39;
lead.moves = {{"surf", 15}, {"water-pulse", 20}, {"bite", 25}, {"mega-kick", 5}};
constexpr size_t SURF = 0;
constexpr size_t BITE = 2;
for (std::string_view foe : {"koffing", "muk", "weezing"}){
if (attack_slot_against(lead, {std::string(foe)}) != SURF){
return std::format("Against {}: expected Surf.", foe);
}
}
for (std::string_view foe : {"drowzee", "kadabra", "hypno"}){
const std::optional<size_t> slot = attack_slot_against(lead, {std::string(foe)});
if (slot != SURF && slot != BITE){
return std::format("Against {}: expected Surf or Bite.", foe);
}
}
return true;
}

class QuietLogger : public Logger{
public:
using Logger::log;
virtual void log(const std::string&, Color) override{}
};

// Battle checkpoint `id`'s precondition: a LEVEL step on the lead before
// its battle `battle`, at least `pokeguy`, pokeguy's level there (whose
// sims stand for the fight at that level or above). A lead at that level
// passes it; one a level below stops the checkpoint before the fight.
UnitTestResult check_lead_level_precondition(Logger& logger, std::string_view id, std::string_view battle, unsigned pokeguy){

Check warning on line 210 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFuchsiaGym_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::check_lead_level_precondition( Logger & logger , std :: string_view id , std :: string_view battle , unsigned pokeguy): function_lines=28 (advisory above 25, limit 50)
std::optional<LevelCheck> check;
for (const StoryStep& step : checkpoint(id).steps){
if (step.kind == StoryStepKind::BATTLE && step.name == battle){
break;
}
if (step.action == LEVEL_ACTION){
check = level_check_of(step.args);
}
}
if (!check || check->slot != 0 || check->level != pokeguy){
return std::format("{}: expected a LEVEL step on the lead, at least Lv{}, before {}.", id, pokeguy, battle);
}
for (const unsigned level : {pokeguy, pokeguy - 1}){
const MemberReader lead = [level](size_t slot) -> std::optional<MemberInfo>{
if (slot != 0){
return std::nullopt;
}
return MemberInfo{.species = "blastoise", .level = level};
};
const LevelResult result = run_level_check(logger, lead, *check);
const LevelEnd expected = level >= pokeguy ? LevelEnd::REACHED : LevelEnd::BELOW;
if (result.end != expected || result.level != level){
return std::format("{}: a Lv{} lead {} the Lv{} check.", id, level, level >= pokeguy ? "fails" : "passes", pokeguy);
}
}
return true;
}

const AutoStoryFuchsiaGymCase AUTO_STORY_FUCHSIA_GYM_CASES[] = {
{
.input = {.name = "12.01 past Kayden and Kirk to west of Koga and 12.02 to the Warden and the nurse", .body = test_gym_rows},
.expectation = {.description = "Kayden and Kirk fought where the table steps into their lines, no one else; ends at Fuchsia's nurse"},
},
{
.input = {.name = "the lead's attacks in Fuchsia Gym", .body = test_lead_moves_in_gym},
.expectation = {.description = "Surf against Koga's Pokemon, Surf or Bite against the Jugglers'"},
},
{
.input = {.name = "12.02 stops before Koga unless the lead is at least pokeguy's Lv39", .body = []{
QuietLogger logger;
return check_lead_level_precondition(logger, "12.02", "koga", 39);
}},
.expectation = {.description = "a Lv39 lead passes the LEVEL step, a Lv38 one stops there"},
},
};

} // namespace


void add_tests_AutoStoryFuchsiaGym(UnitTestDatabase& database){
for (const auto& item : AUTO_STORY_FUCHSIA_GYM_CASES){
database.add<Test_AutoStoryFuchsiaGym>(item);
}
}



} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ struct Attack{
std::string_view move;
};
constexpr Attack ATTACKS[] = {
// From HM03 (12.01) on, as pokeguy: Surf on everything it is not
// resisted by (1:15:14 on).
{.line = "squirtle", .move = "surf"},
{.line = "squirtle", .move = "water-gun"},
{.line = "squirtle", .move = "bite"},
{.line = "squirtle", .move = "bubble"},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* FRLG AutoStory Plan Golden

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=900 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -849,6 +849,49 @@
"09.02 face north -> RocketHideout_B4F (19, 5)",
"09.02 face_silph_scope from RocketHideout_B4F (19, 5) facing south to RocketHideout_B4F (19, 5) facing east",
"09.02 face east -> RocketHideout_B4F (19, 5)",
"12.01 gym_east_wall from FuchsiaCity_PokemonCenter_1F (7, 4) facing north to FuchsiaCity_Gym (14, 21) facing north",
"12.01 walk south 5 (warp) -> FuchsiaCity (25, 32) [walk only]",
"12.01 walk south 1 -> FuchsiaCity (25, 33)",
"12.01 walk west 16 -> FuchsiaCity (9, 33)",
"12.01 walk north 1 (warp) -> FuchsiaCity_Gym (7, 21)",
"12.01 walk east 7 (to wall) -> FuchsiaCity_Gym (14, 21) [walk only]",
"12.01 face north -> FuchsiaCity_Gym (14, 21) [walk only]",
"12.01 west_of_koga from FuchsiaCity_Gym (6, 13) facing south to FuchsiaCity_Gym (6, 13) facing east",
"12.01 face east -> FuchsiaCity_Gym (6, 13) [walk only]",
"12.02 below_warden from FuchsiaCity_Gym (6, 13) facing east to FuchsiaCity_WardensHouse (3, 6) facing north",
"12.02 walk north 1 (to wall) -> FuchsiaCity_Gym (6, 12) [walk only]",
"12.02 walk west 6 (to wall) -> FuchsiaCity_Gym (0, 12) [walk only]",
"12.02 walk north 1 (to wall) -> FuchsiaCity_Gym (0, 11) [walk only]",
"12.02 walk east 2 (to wall) -> FuchsiaCity_Gym (2, 11) [walk only]",
"12.02 walk north 1 -> FuchsiaCity_Gym (2, 10) [walk only]",
"12.02 walk east 7 (to wall) -> FuchsiaCity_Gym (9, 10) [walk only]",
"12.02 walk north 8 (to wall) -> FuchsiaCity_Gym (9, 2) [walk only]",
"12.02 walk east 5 (to wall) -> FuchsiaCity_Gym (14, 2) [walk only]",
"12.02 walk south 19 (to wall) -> FuchsiaCity_Gym (14, 21) [walk only]",
"12.02 walk west 7 -> FuchsiaCity_Gym (7, 21) [walk only]",
"12.02 walk south 1 (warp) -> FuchsiaCity (9, 33) [walk only]",
"12.02 walk south 4 (to wall) -> FuchsiaCity (9, 37)",
"12.02 walk west 7 (to wall) -> FuchsiaCity (2, 37)",
"12.02 walk north 12 -> FuchsiaCity (2, 25)",
"12.02 walk east 28 (to wall) -> FuchsiaCity (30, 25)",
"12.02 walk south 7 -> FuchsiaCity (30, 32)",
"12.02 walk east 3 -> FuchsiaCity (33, 32)",
"12.02 walk north 1 (warp) -> FuchsiaCity_WardensHouse (6, 9)",
"12.02 walk west 5 (to wall) -> FuchsiaCity_WardensHouse (1, 9) [walk only]",
"12.02 walk north 3 (to wall) -> FuchsiaCity_WardensHouse (1, 6) [walk only]",
"12.02 walk east 2 -> FuchsiaCity_WardensHouse (3, 6) [walk only]",
"12.02 face north -> FuchsiaCity_WardensHouse (3, 6) [walk only]",
"12.02 below_center_door from FuchsiaCity_WardensHouse (3, 6) facing north to FuchsiaCity (25, 32) facing north",
"12.02 walk east 3 -> FuchsiaCity_WardensHouse (6, 6) [walk only]",
"12.02 walk south 4 (warp) -> FuchsiaCity (33, 32) [walk only]",
"12.02 walk west 4 -> FuchsiaCity (29, 32)",
"12.02 walk north 7 -> FuchsiaCity (29, 25)",
"12.02 walk west 27 (to wall) -> FuchsiaCity (2, 25)",
"12.02 walk south 12 (to wall) -> FuchsiaCity (2, 37)",
"12.02 walk east 9 (to wall) -> FuchsiaCity (11, 37)",
"12.02 walk north 5 (to wall) -> FuchsiaCity (11, 32)",
"12.02 walk east 14 -> FuchsiaCity (25, 32)",
"12.02 face north -> FuchsiaCity (25, 32)",
};

} // namespace PokemonFRLG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef PokemonAutomation_PokemonFRLG_AutoStoryRows_Tests_H
#define PokemonAutomation_PokemonFRLG_AutoStoryRows_Tests_H

#include <string_view>
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"

namespace PokemonAutomation{
Expand All @@ -26,6 +27,17 @@ void add_tests_AutoStoryVermilionGym(UnitTestDatabase& database);
void add_tests_AutoStoryCeladon(UnitTestDatabase& database);
// Rows from 08.01 on on the overworld sim (PokemonFRLG_AutoStoryLavender_Tests.cpp).
void add_tests_AutoStoryLavender(UnitTestDatabase& database);
// Rows 12.01 and 12.02, Fuchsia Gym, on the overworld sim (PokemonFRLG_AutoStoryFuchsiaGym_Tests.cpp).
void add_tests_AutoStoryFuchsiaGym(UnitTestDatabase& database);

// Whether checkpoint `id` was authored before the rows that lead up to it:
// it starts from its own declared pose, not where the row before it in
// the table ends. 12.01 starts from Fly's landing in Fuchsia, after the
// Safari Zone (11.02); segments 10 and 11 are authored separately. An id leaves
// this list once the rows before it are in.
inline bool starts_after_unauthored_rows(std::string_view id){
return id == "12.01";
}


} // namespace PokemonFRLG
Expand Down
Loading
Loading