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 @@ -43,6 +43,7 @@
#include "Pokemon/Navigation/Pokemon_RouteLog_Tests.h"
#include "Pokemon/Navigation/Pokemon_RuntimeMap_Tests.h"
#include "Pokemon/Navigation/Pokemon_WallRecovery_Tests.h"
#include "Pokemon/Navigation/Simulation/Pokemon_SimFaults_Tests.h"
#include "Pokemon/Navigation/Simulation/Pokemon_SimGolden_Tests.h"
#include "VideoGames/PokemonHome/PokemonHome_Tests.h"
#include "VideoGames/PokemonSwSh/PokemonSwSh_Tests.h"
Expand All @@ -62,7 +63,7 @@



UnitTestDatabase make_UNIT_TESTS_ALL(){

Check warning on line 66 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=47 (advisory above 25, limit 50)
UnitTestDatabase ret;

add_tests_QtEventThreadPool(ret, GlobalThreadPools::computation_normal());
Expand Down Expand Up @@ -90,6 +91,7 @@
Pokemon::add_tests_MoveMechanics(ret);
Pokemon::add_tests_RuntimeMap(ret);
Pokemon::add_tests_RouteLog(ret);
Pokemon::add_tests_SimFaults(ret);
Pokemon::add_tests_SimGolden(ret);
Pokemon::add_tests_AutoStory(ret);
NintendoSwitch::add_tests_CheckOnlineDetector(ret);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* Sim Faults
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <utility>
#include "Pokemon_SimFaults.h"

namespace PokemonAutomation{
namespace Pokemon{


const std::vector<FaultClass>& fault_classes(){
static const std::vector<FaultClass> classes{
FaultClass::SCENE_END_POSE,
FaultClass::SCENE_EARLY,
FaultClass::BATTLE_OPENING,
FaultClass::WILD_BATTLES,
FaultClass::LATE_FADE,
FaultClass::SLOW_FADE_IN,
FaultClass::WARP_NO_OP,
FaultClass::DARK_CAVE,
FaultClass::LOST_TAP,
FaultClass::UNSEEN_STEP,
};
return classes;
}

std::string_view fault_class_name(FaultClass fault){
switch (fault){
case FaultClass::SCENE_END_POSE:
return "scene end pose";
case FaultClass::SCENE_EARLY:
return "scene early";
case FaultClass::BATTLE_OPENING:
return "battle opening";
case FaultClass::WILD_BATTLES:
return "wild battles";
case FaultClass::LATE_FADE:
return "late fade";
case FaultClass::SLOW_FADE_IN:
return "slow fade-in";
case FaultClass::WARP_NO_OP:
return "warp no-op";
case FaultClass::DARK_CAVE:
return "dark cave";
case FaultClass::LOST_TAP:
return "lost tap";
case FaultClass::UNSEEN_STEP:
return "unseen step";
}
return "?";
}


FaultOccurrences::FaultOccurrences(std::set<int> faulted)
: m_numbers(std::move(faulted))
{}

bool FaultOccurrences::next(){
m_chances++;
if (!m_numbers.contains(m_chances)){
return false;
}
m_faulted++;
return true;
}


SimFaults::SimFaults(std::map<FaultClass, std::set<int>> faulted){
for (auto& [fault, numbers] : faulted){
m_classes.emplace(fault, FaultOccurrences(std::move(numbers)));
}
}

bool SimFaults::next(FaultClass fault){
return m_classes[fault].next();
}

int SimFaults::chances(FaultClass fault) const{
const auto iter = m_classes.find(fault);
return iter == m_classes.end() ? 0 : iter->second.chances();
}

int SimFaults::faulted(FaultClass fault) const{
const auto iter = m_classes.find(fault);
return iter == m_classes.end() ? 0 : iter->second.faulted();
}



} // namespace Pokemon
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/* Sim Faults
*
* From: https://github.com/PokemonAutomation/
*
* The faults the games' overworld simulations inject, shared by BDSP's
* and FRLG's: the classes of failure the consoles showed, and a counter
* per class that says which of a fault's chances to fault. A chance is
* each time the sim reaches a point where the game could fail that way
* (a tap, a warp, a step's end); a test names the chances it faults by
* number, from 1 in the order the sim reaches them.
*
* How a class is injected is each game's (its sim's knobs and its fault
* sweep); a game may inject only some of the classes.
*
*/

#ifndef PokemonAutomation_Pokemon_SimFaults_H
#define PokemonAutomation_Pokemon_SimFaults_H

#include <map>
#include <set>
#include <string_view>
#include <vector>

namespace PokemonAutomation{
namespace Pokemon{


// A class of failure a console showed, which a sim can inject.
enum class FaultClass{
// A step whose end the game sets (a talk, a scene, a battle) leaves the
// player on another walkable tile next to the expected one.
SCENE_END_POSE,
// A scene starts on the last tiles of the walk before it.
SCENE_EARLY,
// A battle's opening is still playing when a step starts.
BATTLE_OPENING,
// Wild battles while walking, more than a clean run meets.
WILD_BATTLES,
// A warp's fade shows late.
LATE_FADE,
// Every warp's fade-in runs long: a move right after it goes nowhere.
SLOW_FADE_IN,
// A step onto a warp shows the fade's black but does not warp.
WARP_NO_OP,
// A dark cave walked without Flash.
DARK_CAVE,
// A tap the game drops.
LOST_TAP,
// A step tap that moved the player, read as not moved.
UNSEEN_STEP,
};

// Every fault class, in the enum's order.
const std::vector<FaultClass>& fault_classes();

// The class's name for logs: "scene end pose".
std::string_view fault_class_name(FaultClass fault);


// Which chances of one fault to fault: those numbered in `faulted`,
// counted from 1 as next() reaches them.
class FaultOccurrences{
public:
FaultOccurrences() = default;
explicit FaultOccurrences(std::set<int> faulted);

// Counts one more chance: whether it is one to fault.
bool next();

// The chances counted so far.
int chances() const{
return m_chances;
}
// How many of them were faulted.
int faulted() const{
return m_faulted;
}

private:
std::set<int> m_numbers;
int m_chances = 0;
int m_faulted = 0;
};


// A FaultOccurrences per fault class: a class not given counts its
// chances and faults none.
class SimFaults{
public:
SimFaults() = default;
explicit SimFaults(std::map<FaultClass, std::set<int>> faulted);

// Counts one more chance of `fault`: whether it is one to fault.
bool next(FaultClass fault);

// The chances of `fault` counted so far, and how many were faulted.
int chances(FaultClass fault) const;
int faulted(FaultClass fault) const;

private:
std::map<FaultClass, FaultOccurrences> m_classes;
};



} // namespace Pokemon
} // namespace PokemonAutomation
#endif
Loading
Loading