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 @@ -38,6 +38,7 @@
#include "Pokemon/Navigation/Pokemon_LegPlanner_Tests.h"
#include "Pokemon/Navigation/Pokemon_LegWalker_Tests.h"
#include "Pokemon/Navigation/Pokemon_MapData_Tests.h"
#include "Pokemon/Navigation/Pokemon_MoveMechanics_Tests.h"
#include "Pokemon/Navigation/Pokemon_RouteLog_Tests.h"
#include "Pokemon/Navigation/Pokemon_RuntimeMap_Tests.h"
#include "Pokemon/Navigation/Pokemon_WallRecovery_Tests.h"
Expand All @@ -59,7 +60,7 @@



UnitTestDatabase make_UNIT_TESTS_ALL(){

Check warning on line 63 in SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::ComputerPrograms::make_UNIT_TESTS_ALL(): function_lines=44 (advisory above 25, limit 50)
UnitTestDatabase ret;

add_tests_QtEventThreadPool(ret, GlobalThreadPools::computation_normal());
Expand All @@ -83,6 +84,7 @@
Pokemon::add_tests_LegWalker(ret);
Pokemon::add_tests_WallRecovery(ret);
Pokemon::add_tests_MapData(ret);
Pokemon::add_tests_MoveMechanics(ret);
Pokemon::add_tests_RuntimeMap(ret);
Pokemon::add_tests_RouteLog(ret);
Pokemon::add_tests_AutoStory(ret);
Expand Down
119 changes: 119 additions & 0 deletions SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* Move Mechanics

Check warning on line 1 in SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<header>: header_symbols=7 (advisory above 6, limit 8)
*
* From: https://github.com/PokemonAutomation/
*
* How each game moves the player for a press, as measured on the console:
* one entry per game, read by that game's walker and by its sim.
*
*/

#ifndef PokemonAutomation_Pokemon_MoveMechanics_H
#define PokemonAutomation_Pokemon_MoveMechanics_H

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

namespace PokemonAutomation{
namespace Pokemon{


// How the walker presses an open leg, one that ends short of a wall.
enum class OpenLegPress{
STEP_TAPS, // a step tap a tile: the count is exact
TIMED_HOLD, // one hold, timed by the tile time
};

// Time per tile along each axis of the screen.
struct TileTime{
Milliseconds across{}; // east or west
Milliseconds up_down{}; // north or south

constexpr Milliseconds along(Direction direction) const{
return direction == Direction::EAST || direction == Direction::WEST ? across : up_down;
}
};

// A tap that takes one step: the press, and the release before the next
// press. Their sum is the time per tapped tile.
struct StepTap{
Milliseconds hold{};
Milliseconds release{};
};

// One way of moving: walking, running or riding.
struct Gait{
TileTime tile;
// The step tap in this gait; a game's taps differ by gait (FRLG's
// Bicycle taps far faster than its walk).
StepTap tap;
OpenLegPress open_legs = OpenLegPress::STEP_TAPS;
};

// How one game moves the player: its turn tap, and a tile time and step
// tap per gait.
struct MoveMechanics{
// A tap that turns a player facing another way, without a step.
Milliseconds turn_tap{};
// From pressing, standing still, to the first step under way.
Milliseconds start_delay{};
Gait walk;
// B held, once the player has the Running Shoes.
Gait run;
// None where the walker does not ride yet.
std::optional<Gait> bike;
};


// Brilliant Diamond and Shining Pearl, measured on console B. The camera
// tilts, so a row takes longer than a column. D-pad taps move exactly a
// tile each, while a held run overshoots about 3 tiles in 10 (2026-11-09,
// Jubilife), so open legs are tapped. Taps: PokemonBDSP_AutoStory_RouteInput.h;
// tile times: PokemonBDSP_AutoStory_RouteTiming.h.
inline constexpr MoveMechanics BDSP_MOVE_MECHANICS{
.turn_tap = Milliseconds(50),
.start_delay = Milliseconds(250),
.walk = {
.tile = {.across = Milliseconds(160), .up_down = Milliseconds(240)},
.tap = {.hold = Milliseconds(160), .release = Milliseconds(640)},
.open_legs = OpenLegPress::STEP_TAPS,
},
.run = {
.tile = {.across = Milliseconds(100), .up_down = Milliseconds(150)},
.tap = {.hold = Milliseconds(160), .release = Milliseconds(640)},
.open_legs = OpenLegPress::STEP_TAPS,
},
.bike = std::nullopt,
};

// FireRed and LeafGreen, measured on console B: a walking tile is 16
// frames, running 8, and a held leg stops where its time says, so open
// legs on foot are timed holds; on the Bicycle they are counted in taps,
// 40 ms at one per 100 ms (BIKE_TAP_PERIOD_WORKED; at a 60 ms period one
// tap in 12 drops). The walker's holds count no start delay.
// Measurements: PokemonFRLG_MovementMechanics.h and
// PokemonFRLG_BikeSpinMechanics.h.
inline constexpr MoveMechanics FRLG_MOVE_MECHANICS{
.turn_tap = Milliseconds(40),
.start_delay = Milliseconds(0),
.walk = {
.tile = {.across = Milliseconds(267), .up_down = Milliseconds(267)},
.tap = {.hold = Milliseconds(66), .release = Milliseconds(700)},
.open_legs = OpenLegPress::TIMED_HOLD,
},
.run = {
.tile = {.across = Milliseconds(133), .up_down = Milliseconds(133)},
.tap = {.hold = Milliseconds(66), .release = Milliseconds(700)},
.open_legs = OpenLegPress::TIMED_HOLD,
},
.bike = Gait{
.tile = {.across = Milliseconds(100), .up_down = Milliseconds(100)},
.tap = {.hold = Milliseconds(40), .release = Milliseconds(60)},
.open_legs = OpenLegPress::STEP_TAPS,
},
};


} // namespace Pokemon
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/* Move Mechanics Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <format>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include "Common/Cpp/TestRunners/UnitTest.h"
#include "Pokemon_MoveMechanics.h"
#include "Pokemon_MoveMechanics_Tests.h"

namespace PokemonAutomation{
namespace Pokemon{
namespace{


struct MoveMechanicsInput{
std::string_view game;
MoveMechanics mechanics;
};
struct MoveMechanicsExpectation{
// How the walker presses an open leg on foot (the user's pick,
// 2026-11-11: BDSP taps, FRLG timed holds).
OpenLegPress open_legs_on_foot;
};
struct MoveMechanicsCase{
MoveMechanicsInput input;
MoveMechanicsExpectation expectation;
};

// Why `faster` is not faster than `slower` on both axes, if it is not.
std::optional<std::string> not_faster(std::string_view faster_name, const Gait& faster, std::string_view slower_name, const Gait& slower){
if (faster.tile.across >= slower.tile.across || faster.tile.up_down >= slower.tile.up_down){
return std::format("{} ({}/{} ms) is not faster than {} ({}/{} ms).",
faster_name, faster.tile.across.count(), faster.tile.up_down.count(),
slower_name, slower.tile.across.count(), slower.tile.up_down.count());
}
return std::nullopt;
}

// Why the turn tap would step on foot in `gait`, if it would: a turn tap
// must be shorter than the gait's step tap.
std::optional<std::string> turn_steps(std::string_view gait_name, const Gait& gait, Milliseconds turn_tap){
if (turn_tap >= gait.tap.hold){
return std::format("The turn tap ({} ms) is not shorter than the {} step tap ({} ms).",
turn_tap.count(), gait_name, gait.tap.hold.count());
}
return std::nullopt;
}

// Why a gait's step tap is unusable, if it is: both its press and its
// release must take time.
std::optional<std::string> empty_tap(std::string_view gait_name, const Gait& gait){
if (gait.tap.hold <= Milliseconds(0) || gait.tap.release <= Milliseconds(0)){
return std::format("The {} step tap is {} ms pressed, {} ms released; both must be over 0.",
gait_name, gait.tap.hold.count(), gait.tap.release.count());
}
return std::nullopt;
}

std::string_view open_leg_press_name(OpenLegPress press){
return press == OpenLegPress::STEP_TAPS ? "step taps" : "a timed hold";
}

// Why `gait` presses its open legs other than `expected`, if it does.
std::optional<std::string> wrong_open_legs(std::string_view gait_name, const Gait& gait, OpenLegPress expected){
if (gait.open_legs != expected){
return std::format("Open legs {} are pressed as {}, expected {}.",
gait_name, open_leg_press_name(gait.open_legs), open_leg_press_name(expected));
}
return std::nullopt;
}

class Test_MoveMechanics : public UnitTest{
public:
explicit Test_MoveMechanics(MoveMechanicsCase scenario)
: UnitTest(std::format("Pokemon::MoveMechanics - {}", scenario.input.game)), m_scenario(std::move(scenario))
{}
virtual UnitTestResult run(Logger&, CancellableScope&) const override{
const MoveMechanics& game = m_scenario.input.mechanics;
const OpenLegPress expected = m_scenario.expectation.open_legs_on_foot;
const std::optional<std::string> failures[] = {
empty_tap("walking", game.walk),
empty_tap("running", game.run),
game.bike ? empty_tap("bike", *game.bike) : std::nullopt,
turn_steps("walking", game.walk, game.turn_tap),
turn_steps("running", game.run, game.turn_tap),
not_faster("running", game.run, "walking", game.walk),
game.bike ? not_faster("the bike", *game.bike, "running", game.run) : std::nullopt,
wrong_open_legs("walking", game.walk, expected),
wrong_open_legs("running", game.run, expected),
};
for (const std::optional<std::string>& failure : failures){
if (failure){
return *failure;
}
}
return true;
}
private:
MoveMechanicsCase m_scenario;
};

const MoveMechanicsCase MOVE_MECHANICS_CASES[] = {
{
.input = {.game = "BDSP", .mechanics = BDSP_MOVE_MECHANICS},
.expectation = {.open_legs_on_foot = OpenLegPress::STEP_TAPS},
},
{
.input = {.game = "FRLG", .mechanics = FRLG_MOVE_MECHANICS},
.expectation = {.open_legs_on_foot = OpenLegPress::TIMED_HOLD},
},
};


} // namespace

void add_tests_MoveMechanics(UnitTestDatabase& database){
for (const MoveMechanicsCase& scenario : MOVE_MECHANICS_CASES){
database.add<Test_MoveMechanics>(scenario);
}
}


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

#ifndef PokemonAutomation_Pokemon_MoveMechanics_Tests_H
#define PokemonAutomation_Pokemon_MoveMechanics_Tests_H

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

namespace PokemonAutomation{
namespace Pokemon{


// Registers the checks on each game's movement table.
void add_tests_MoveMechanics(UnitTestDatabase& database);


} // namespace Pokemon
} // namespace PokemonAutomation
#endif
3 changes: 3 additions & 0 deletions SerialPrograms/cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,9 @@ file(GLOB LIBRARY_SOURCES
Source/Pokemon/Navigation/Pokemon_MapData.h
Source/Pokemon/Navigation/Pokemon_MapData_Tests.cpp
Source/Pokemon/Navigation/Pokemon_MapData_Tests.h
Source/Pokemon/Navigation/Pokemon_MoveMechanics.h
Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp
Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.h
Source/Pokemon/Navigation/Pokemon_RuntimeMap.cpp
Source/Pokemon/Navigation/Pokemon_RuntimeMap.h
Source/Pokemon/Navigation/Pokemon_RuntimeMap_Tests.cpp
Expand Down
Loading